Rename some classes. Change the logic of getting the subreddit icon. Prepare to display posts in ViewSubredditDetailActivity.

This commit is contained in:
Alex Ning 2018-08-20 00:04:49 +08:00
parent 23bf92d9cf
commit 07b32b3900
14 changed files with 190 additions and 182 deletions

View File

@ -41,10 +41,10 @@ public class BestPostFragment extends Fragment {
private RecyclerView mBestPostRecyclerView; private RecyclerView mBestPostRecyclerView;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
private ProgressBar mProgressBar; private ProgressBar mProgressBar;
private ArrayList<BestPostData> mBestPostData; private ArrayList<PostData> mPostData;
private String mLastItem; private String mLastItem;
private PaginationSynchronizer mPaginationSynchronizer; private PaginationSynchronizer mPaginationSynchronizer;
private BestPostRecyclerViewAdapter mAdapter; private PostRecyclerViewAdapter mAdapter;
private String bestPostDataParcelableState = "BPDPS"; private String bestPostDataParcelableState = "BPDPS";
private String lastItemState = "LIS"; private String lastItemState = "LIS";
@ -64,11 +64,11 @@ public class BestPostFragment extends Fragment {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if(savedInstanceState != null) { if(savedInstanceState != null) {
if(savedInstanceState.containsKey(bestPostDataParcelableState)) { if(savedInstanceState.containsKey(bestPostDataParcelableState)) {
mBestPostData = savedInstanceState.getParcelableArrayList(bestPostDataParcelableState); mPostData = savedInstanceState.getParcelableArrayList(bestPostDataParcelableState);
mLastItem = savedInstanceState.getString(lastItemState); mLastItem = savedInstanceState.getString(lastItemState);
mAdapter = new BestPostRecyclerViewAdapter(getActivity(), mBestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue); mAdapter = new PostRecyclerViewAdapter(getActivity(), mPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
mBestPostRecyclerView.setAdapter(mAdapter); mBestPostRecyclerView.setAdapter(mAdapter);
mBestPostRecyclerView.addOnScrollListener(new BestPostPaginationScrollListener(getActivity(), mLinearLayoutManager, mAdapter, mLastItem, mBestPostData, mPaginationSynchronizer, mBestPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(getActivity(), mLinearLayoutManager, mAdapter, mLastItem, mPostData, mPaginationSynchronizer,
mAcquireAccessTokenRequestQueue, mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess())); mAcquireAccessTokenRequestQueue, mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess()));
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} else { } else {
@ -94,11 +94,11 @@ public class BestPostFragment extends Fragment {
} }
if(mPaginationRequestQueue != null) { if(mPaginationRequestQueue != null) {
mPaginationRequestQueue.cancelAll(BestPostPaginationScrollListener.class); mPaginationRequestQueue.cancelAll(PostPaginationScrollListener.class);
} }
if(mBestPostData != null) { if(mPostData != null) {
outState.putParcelableArrayList(bestPostDataParcelableState, mBestPostData); outState.putParcelableArrayList(bestPostDataParcelableState, mPostData);
outState.putString(lastItemState, mLastItem); outState.putString(lastItemState, mLastItem);
outState.putParcelable(paginationSynchronizerState, mPaginationSynchronizer); outState.putParcelable(paginationSynchronizerState, mPaginationSynchronizer);
} }
@ -180,27 +180,27 @@ public class BestPostFragment extends Fragment {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("response", response); ClipData clip = ClipData.newPlainText("response", response);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
//new ParseBestPostDataAsyncTask(response, accessToken).execute(); //new ParsePostDataAsyncTask(response, accessToken).execute();
new ParseBestPost(getActivity(), new ParseBestPost.ParseBestPostListener() { new ParsePost(getActivity(), new ParsePost.ParsePostListener() {
@Override @Override
public void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem) { public void onParsePostSuccess(ArrayList<PostData> bestPostData, String lastItem) {
mBestPostData = bestPostData; mPostData = bestPostData;
mLastItem = lastItem; mLastItem = lastItem;
mAdapter = new BestPostRecyclerViewAdapter(getActivity(), bestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue); mAdapter = new PostRecyclerViewAdapter(getActivity(), bestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
mBestPostRecyclerView.setAdapter(mAdapter); mBestPostRecyclerView.setAdapter(mAdapter);
mBestPostRecyclerView.addOnScrollListener(new BestPostPaginationScrollListener(getActivity(), mLinearLayoutManager, mAdapter, lastItem, bestPostData, mPaginationSynchronizer, mBestPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(getActivity(), mLinearLayoutManager, mAdapter, lastItem, bestPostData, mPaginationSynchronizer,
mAcquireAccessTokenRequestQueue, mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess())); mAcquireAccessTokenRequestQueue, mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess()));
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} }
@Override @Override
public void onParseBestPostFail() { public void onParsePostFail() {
Toast.makeText(getActivity(), "Error parsing data", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "Error parsing data", Toast.LENGTH_SHORT).show();
Log.i("Best post fetch error", "Error parsing data"); Log.i("Best post fetch error", "Error parsing data");
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} }
}).parseBestPost(response, new ArrayList<BestPostData>()); }).parseBestPost(response, new ArrayList<PostData>());
} }
} }
}, new Response.ErrorListener() { }, new Response.ErrorListener() {

View File

@ -66,6 +66,7 @@ class FetchSubscribedThing {
String lastItem) { String lastItem) {
mSubscribedSubredditData = subscribedSubredditData; mSubscribedSubredditData = subscribedSubredditData;
mSubscribedUserData = subscribedUserData; mSubscribedUserData = subscribedUserData;
mSubredditData = subredditData;
mLastItem = lastItem; mLastItem = lastItem;
if(mLastItem.equals("null")) { if(mLastItem.equals("null")) {
mFetchSubscribedSubredditsListener.onFetchSubscribedSubredditsSuccess(mSubscribedSubredditData, mFetchSubscribedSubredditsListener.onFetchSubscribedSubredditsSuccess(mSubscribedSubredditData,

View File

@ -54,6 +54,7 @@ class JSONUtils {
static final String SUBREDDIT_KEY = "subreddit"; static final String SUBREDDIT_KEY = "subreddit";
static final String BANNER_IMG_KEY = "banner_img"; static final String BANNER_IMG_KEY = "banner_img";
static final String ICON_IMG_KEY = "icon_img"; static final String ICON_IMG_KEY = "icon_img";
static final String COMMUNITY_ICON_KEY = "community_icon";
static final String LINK_KARMA_KEY = "link_karma"; static final String LINK_KARMA_KEY = "link_karma";
static final String COMMENT_KARMA_KEY = "comment_karma"; static final String COMMENT_KARMA_KEY = "comment_karma";
static final String DISPLAY_NAME = "display_name"; static final String DISPLAY_NAME = "display_name";

View File

@ -16,16 +16,16 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao subredditDao; private SubredditDao subredditDao;
private String subredditName; private String subredditName;
private String iconImageUrl; private String iconImageUrl;
private BestPostData bestPostData; private PostData postData;
LoadSubredditIconAsyncTask(Context context, CircleImageView iconImageView, LoadSubredditIconAsyncTask(Context context, CircleImageView iconImageView,
SubredditDao subredditDao, String subredditName, SubredditDao subredditDao, String subredditName,
BestPostData bestPostData) { PostData postData) {
contextWeakReference = new WeakReference<>(context); contextWeakReference = new WeakReference<>(context);
circleImageViewWeakReference = new WeakReference<>(iconImageView); circleImageViewWeakReference = new WeakReference<>(iconImageView);
this.subredditDao = subredditDao; this.subredditDao = subredditDao;
this.subredditName = subredditName; this.subredditName = subredditName;
this.bestPostData = bestPostData; this.postData = postData;
} }
@Override @Override
@ -52,6 +52,6 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
} }
} }
bestPostData.setSubredditIconUrl(iconImageUrl); postData.setSubredditIconUrl(iconImageUrl);
} }
} }

View File

@ -17,6 +17,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -165,6 +166,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) { public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) {
if(!mIsInserting) { if(!mIsInserting) {
Log.i("view", "observed");
if(subscribedUserData == null || subscribedUserData.size() == 0) { if(subscribedUserData == null || subscribedUserData.size() == 0) {
followingLabelTextView.setVisibility(View.GONE); followingLabelTextView.setVisibility(View.GONE);
} else { } else {
@ -219,7 +221,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onFetchUserInfoFail() { public void onFetchUserInfoFail() {
mFetchUserInfoSuccess = false;
} }
}, 1); }, 1);
} }
@ -251,7 +253,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onFetchSubscribedSubredditsFail() { public void onFetchSubscribedSubredditsFail() {
mInsertSuccess = false;
} }
}, 1); }, 1);
} }

View File

@ -17,37 +17,37 @@ import java.util.Calendar;
* Created by alex on 3/21/18. * Created by alex on 3/21/18.
*/ */
class ParseBestPost { class ParsePost {
interface ParseBestPostListener { interface ParsePostListener {
void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem); void onParsePostSuccess(ArrayList<PostData> postData, String lastItem);
void onParseBestPostFail(); void onParsePostFail();
} }
private Context mContext; private Context mContext;
private ParseBestPostListener mParseBetPostListener; private ParsePostListener mParseBetPostListener;
ParseBestPost(Context context, ParseBestPostListener parseBestPostListener) { ParsePost(Context context, ParsePostListener parsePostListener) {
mContext = context; mContext = context;
mParseBetPostListener = parseBestPostListener; mParseBetPostListener = parsePostListener;
} }
void parseBestPost(String response, ArrayList<BestPostData> bestPostData) { void parseBestPost(String response, ArrayList<PostData> postData) {
new ParseBestPostDataAsyncTask(response, bestPostData).execute(); new ParsePostDataAsyncTask(response, postData).execute();
} }
private class ParseBestPostDataAsyncTask extends AsyncTask<Void, Void, Void> { private class ParsePostDataAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse; private JSONObject jsonResponse;
private ArrayList<BestPostData> bestPostData; private ArrayList<PostData> postData;
private ArrayList<BestPostData> newBestPostData; private ArrayList<PostData> newPostData;
private String lastItem; private String lastItem;
private boolean parseFailed; private boolean parseFailed;
ParseBestPostDataAsyncTask(String response, ArrayList<BestPostData> bestPostData) { ParsePostDataAsyncTask(String response, ArrayList<PostData> postData) {
try { try {
jsonResponse = new JSONObject(response); jsonResponse = new JSONObject(response);
this.bestPostData = bestPostData; this.postData = postData;
newBestPostData = new ArrayList<>(); newPostData = new ArrayList<>();
parseFailed = false; parseFailed = false;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -92,10 +92,10 @@ class ParseBestPost {
if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) { if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) {
//Cross post //Cross post
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
parseData(data, permalink, newBestPostData, id, fullName, subredditName, parseData(data, permalink, newPostData, id, fullName, subredditName,
formattedPostTime, title, previewUrl, score, voteType, nsfw, i); formattedPostTime, title, previewUrl, score, voteType, nsfw, i);
} else { } else {
parseData(data, permalink, newBestPostData, id, fullName, subredditName, parseData(data, permalink, newPostData, id, fullName, subredditName,
formattedPostTime, title, previewUrl, score, voteType, nsfw, i); formattedPostTime, title, previewUrl, score, voteType, nsfw, i);
} }
} }
@ -110,15 +110,15 @@ class ParseBestPost {
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
if(!parseFailed) { if(!parseFailed) {
bestPostData.addAll(newBestPostData); postData.addAll(newPostData);
mParseBetPostListener.onParseBestPostSuccess(bestPostData, lastItem); mParseBetPostListener.onParsePostSuccess(postData, lastItem);
} else { } else {
mParseBetPostListener.onParseBestPostFail(); mParseBetPostListener.onParsePostFail();
} }
} }
} }
private void parseData(JSONObject data, String permalink, ArrayList<BestPostData> bestPostData, private void parseData(JSONObject data, String permalink, ArrayList<PostData> bestPostData,
String id, String fullName, String subredditName, String formattedPostTime, String title, String id, String fullName, String subredditName, String formattedPostTime, String title,
String previewUrl, int score, int voteType, boolean nsfw, int i) throws JSONException { String previewUrl, int score, int voteType, boolean nsfw, int i) throws JSONException {
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
@ -128,25 +128,25 @@ class ParseBestPost {
if(url.contains(permalink)) { if(url.contains(permalink)) {
//Text post //Text post
Log.i("text", Integer.toString(i)); Log.i("text", Integer.toString(i));
int postType = BestPostData.TEXT_TYPE; int postType = PostData.TEXT_TYPE;
BestPostData postData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, permalink, score, postType, voteType, nsfw); PostData postData = new PostData(id, fullName, subredditName, formattedPostTime, title, permalink, score, postType, voteType, nsfw);
postData.setSelfText(data.getString(JSONUtils.SELF_TEXT_KEY).trim()); postData.setSelfText(data.getString(JSONUtils.SELF_TEXT_KEY).trim());
bestPostData.add(postData); bestPostData.add(postData);
} else { } else {
//No preview link post //No preview link post
Log.i("no preview link", Integer.toString(i)); Log.i("no preview link", Integer.toString(i));
int postType = BestPostData.NO_PREVIEW_LINK_TYPE; int postType = PostData.NO_PREVIEW_LINK_TYPE;
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw); PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
bestPostData.add(linkPostData); bestPostData.add(linkPostData);
} }
} else if(isVideo) { } else if(isVideo) {
//Video post //Video post
Log.i("video", Integer.toString(i)); Log.i("video", Integer.toString(i));
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY); JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
int postType = BestPostData.VIDEO_TYPE; int postType = PostData.VIDEO_TYPE;
String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY); String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY);
BestPostData videoPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true); PostData videoPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true);
videoPostData.setVideoUrl(videoUrl); videoPostData.setVideoUrl(videoUrl);
videoPostData.setDownloadableGifOrVideo(false); videoPostData.setDownloadableGifOrVideo(false);
@ -157,10 +157,10 @@ class ParseBestPost {
if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) { if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) {
//Gif video post (MP4) //Gif video post (MP4)
Log.i("gif video mp4", Integer.toString(i)); Log.i("gif video mp4", Integer.toString(i));
int postType = BestPostData.GIF_VIDEO_TYPE; int postType = PostData.GIF_VIDEO_TYPE;
String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
BestPostData post = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, false); PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, false);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
post.setDownloadableGifOrVideo(true); post.setDownloadableGifOrVideo(true);
@ -170,11 +170,11 @@ class ParseBestPost {
} else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) { } else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) {
//Gif video post (Dash) //Gif video post (Dash)
Log.i("gif video dash", Integer.toString(i)); Log.i("gif video dash", Integer.toString(i));
int postType = BestPostData.GIF_VIDEO_TYPE; int postType = PostData.GIF_VIDEO_TYPE;
String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY) String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY); .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY);
BestPostData post = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true); PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
post.setDownloadableGifOrVideo(false); post.setDownloadableGifOrVideo(false);
@ -184,13 +184,13 @@ class ParseBestPost {
if (url.endsWith("jpg") || url.endsWith("png")) { if (url.endsWith("jpg") || url.endsWith("png")) {
//Image post //Image post
Log.i("image", Integer.toString(i)); Log.i("image", Integer.toString(i));
int postType = BestPostData.IMAGE_TYPE; int postType = PostData.IMAGE_TYPE;
bestPostData.add(new BestPostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw)); bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
} else { } else {
//Link post //Link post
Log.i("link", Integer.toString(i)); Log.i("link", Integer.toString(i));
int postType = BestPostData.LINK_TYPE; int postType = PostData.LINK_TYPE;
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw); PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
bestPostData.add(linkPostData); bestPostData.add(linkPostData);
} }
} }
@ -198,13 +198,13 @@ class ParseBestPost {
if (url.endsWith("jpg") || url.endsWith("png")) { if (url.endsWith("jpg") || url.endsWith("png")) {
//Image post //Image post
Log.i("CP no preview image", Integer.toString(i)); Log.i("CP no preview image", Integer.toString(i));
int postType = BestPostData.IMAGE_TYPE; int postType = PostData.IMAGE_TYPE;
bestPostData.add(new BestPostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw)); bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
} else { } else {
//Link post //Link post
Log.i("CP no preview link", Integer.toString(i)); Log.i("CP no preview link", Integer.toString(i));
int postType = BestPostData.LINK_TYPE; int postType = PostData.LINK_TYPE;
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw); PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
bestPostData.add(linkPostData); bestPostData.add(linkPostData);
} }
} }

View File

@ -18,17 +18,15 @@ class ParseSubscribedThing {
void onParseSubscribedSubredditsFail(); void onParseSubscribedSubredditsFail();
} }
private ParseSubscribedSubredditsListener mParseSubscribedSubredditsListener;
void parseSubscribedSubreddits(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData, void parseSubscribedSubreddits(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
ArrayList<SubscribedUserData> subscribedUserData, ArrayList<SubscribedUserData> subscribedUserData,
ArrayList<SubredditData> subredditData, ArrayList<SubredditData> subredditData,
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) { ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) {
mParseSubscribedSubredditsListener = parseSubscribedSubredditsListener; new ParseSubscribedSubredditsAsyncTask(response, subscribedSubredditData, subscribedUserData, subredditData,
new ParseSubscribedSubredditsAsyncTask(response, subscribedSubredditData, subscribedUserData, subredditData).execute(); parseSubscribedSubredditsListener).execute();
} }
private class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> { private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse; private JSONObject jsonResponse;
private boolean parseFailed; private boolean parseFailed;
private String lastItem; private String lastItem;
@ -38,10 +36,12 @@ class ParseSubscribedThing {
private ArrayList<SubscribedSubredditData> newSubscribedSubredditData; private ArrayList<SubscribedSubredditData> newSubscribedSubredditData;
private ArrayList<SubscribedUserData> newSubscribedUserData; private ArrayList<SubscribedUserData> newSubscribedUserData;
private ArrayList<SubredditData> newSubredditData; private ArrayList<SubredditData> newSubredditData;
private ParseSubscribedSubredditsListener parseSubscribedSubredditsListener;
ParseSubscribedSubredditsAsyncTask(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData, ParseSubscribedSubredditsAsyncTask(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
ArrayList<SubscribedUserData> subscribedUserData, ArrayList<SubscribedUserData> subscribedUserData,
ArrayList<SubredditData> subredditData){ ArrayList<SubredditData> subredditData,
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener){
try { try {
jsonResponse = new JSONObject(response); jsonResponse = new JSONObject(response);
parseFailed = false; parseFailed = false;
@ -51,9 +51,10 @@ class ParseSubscribedThing {
newSubscribedSubredditData = new ArrayList<>(); newSubscribedSubredditData = new ArrayList<>();
newSubscribedUserData = new ArrayList<>(); newSubscribedUserData = new ArrayList<>();
newSubredditData = new ArrayList<>(); newSubredditData = new ArrayList<>();
this.parseSubscribedSubredditsListener = parseSubscribedSubredditsListener;
} catch (JSONException e) { } catch (JSONException e) {
Log.i("user info json error", e.getMessage()); Log.i("user info json error", e.getMessage());
mParseSubscribedSubredditsListener.onParseSubscribedSubredditsFail(); parseSubscribedSubredditsListener.onParseSubscribedSubredditsFail();
} }
} }
@ -66,12 +67,15 @@ class ParseSubscribedThing {
String name = data.getString(JSONUtils.DISPLAY_NAME); String name = data.getString(JSONUtils.DISPLAY_NAME);
String bannerUrl = data.getString(JSONUtils.BANNER_IMG_KEY); String bannerUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
String iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); String iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
String id = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.NAME_KEY); String id = data.getString(JSONUtils.NAME_KEY);
if(iconUrl.equals("") || iconUrl.equals("null")) {
iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
if(iconUrl.equals("null")) { if(iconUrl.equals("null")) {
iconUrl = ""; iconUrl = "";
} }
}
if(children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.SUBREDDIT_TYPE_KEY) if(data.getString(JSONUtils.SUBREDDIT_TYPE_KEY)
.equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) { .equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) {
//It's a user //It's a user
newSubscribedUserData.add(new SubscribedUserData(id, name.substring(2), iconUrl)); newSubscribedUserData.add(new SubscribedUserData(id, name.substring(2), iconUrl));
@ -86,7 +90,7 @@ class ParseSubscribedThing {
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
} catch (JSONException e) { } catch (JSONException e) {
parseFailed = true; parseFailed = true;
Log.i("parse comment error", e.getMessage()); Log.i("parse subscribed error", e.getMessage());
} }
return null; return null;
} }
@ -97,10 +101,10 @@ class ParseSubscribedThing {
subscribedSubredditData.addAll(newSubscribedSubredditData); subscribedSubredditData.addAll(newSubscribedSubredditData);
subscribedUserData.addAll(newSubscribedUserData); subscribedUserData.addAll(newSubscribedUserData);
subredditData.addAll(newSubredditData); subredditData.addAll(newSubredditData);
mParseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData, parseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData,
subscribedUserData, subredditData, lastItem); subscribedUserData, subredditData, lastItem);
} else { } else {
mParseSubscribedSubredditsListener.onParseSubscribedSubredditsFail(); parseSubscribedSubredditsListener.onParseSubscribedSubredditsFail();
} }
} }
} }

View File

@ -7,7 +7,7 @@ import android.os.Parcelable;
* Created by alex on 3/1/18. * Created by alex on 3/1/18.
*/ */
class BestPostData implements Parcelable { class PostData implements Parcelable {
static final int TEXT_TYPE = 0; static final int TEXT_TYPE = 0;
static final int IMAGE_TYPE = 1; static final int IMAGE_TYPE = 1;
static final int LINK_TYPE = 2; static final int LINK_TYPE = 2;
@ -34,7 +34,7 @@ class BestPostData implements Parcelable {
private boolean isDashVideo; private boolean isDashVideo;
private boolean isDownloadableGifOrVideo; private boolean isDownloadableGifOrVideo;
BestPostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, boolean nsfw, boolean isDashVideo) { PostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, boolean nsfw, boolean isDashVideo) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -49,7 +49,7 @@ class BestPostData implements Parcelable {
this.isDashVideo = isDashVideo; this.isDashVideo = isDashVideo;
} }
BestPostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, boolean nsfw) { PostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, boolean nsfw) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -64,7 +64,7 @@ class BestPostData implements Parcelable {
this.nsfw = nsfw; this.nsfw = nsfw;
} }
BestPostData(String id, String fullName, String subredditName, String postTime, String title, String permalink, int score, int postType, int voteType, boolean nsfw) { PostData(String id, String fullName, String subredditName, String postTime, String title, String permalink, int score, int postType, int voteType, boolean nsfw) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -77,7 +77,7 @@ class BestPostData implements Parcelable {
this.nsfw = nsfw; this.nsfw = nsfw;
} }
protected BestPostData(Parcel in) { protected PostData(Parcel in) {
id = in.readString(); id = in.readString();
fullName = in.readString(); fullName = in.readString();
subredditName = in.readString(); subredditName = in.readString();
@ -98,15 +98,15 @@ class BestPostData implements Parcelable {
isDownloadableGifOrVideo = in.readByte() != 0; isDownloadableGifOrVideo = in.readByte() != 0;
} }
public static final Creator<BestPostData> CREATOR = new Creator<BestPostData>() { public static final Creator<PostData> CREATOR = new Creator<PostData>() {
@Override @Override
public BestPostData createFromParcel(Parcel in) { public PostData createFromParcel(Parcel in) {
return new BestPostData(in); return new PostData(in);
} }
@Override @Override
public BestPostData[] newArray(int size) { public PostData[] newArray(int size) {
return new BestPostData[size]; return new PostData[size];
} }
}; };

View File

@ -24,11 +24,11 @@ import java.util.Map;
* Created by alex on 3/12/18. * Created by alex on 3/12/18.
*/ */
class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener { class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
private Context mContext; private Context mContext;
private LinearLayoutManager mLayoutManager; private LinearLayoutManager mLayoutManager;
private BestPostRecyclerViewAdapter mAdapter; private PostRecyclerViewAdapter mAdapter;
private ArrayList<BestPostData> mBestPostData; private ArrayList<PostData> mPostData;
private PaginationSynchronizer mPaginationSynchronizer; private PaginationSynchronizer mPaginationSynchronizer;
private PaginationRetryNotifier mPaginationRetryNotifier; private PaginationRetryNotifier mPaginationRetryNotifier;
private LastItemSynchronizer mLastItemSynchronizer; private LastItemSynchronizer mLastItemSynchronizer;
@ -40,14 +40,14 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
private RequestQueue mRequestQueue; private RequestQueue mRequestQueue;
private RequestQueue mAcquireAccessTokenRequestQueue; private RequestQueue mAcquireAccessTokenRequestQueue;
BestPostPaginationScrollListener(Context context, LinearLayoutManager layoutManager, BestPostRecyclerViewAdapter adapter, String lastItem, ArrayList<BestPostData> bestPostData, PaginationSynchronizer paginationSynchronizer, PostPaginationScrollListener(Context context, LinearLayoutManager layoutManager, PostRecyclerViewAdapter adapter, String lastItem, ArrayList<PostData> postData, PaginationSynchronizer paginationSynchronizer,
RequestQueue acquireAccessTokenRequestQueue, boolean isLoading, boolean loadSuccess) { RequestQueue acquireAccessTokenRequestQueue, boolean isLoading, boolean loadSuccess) {
if(context != null) { if(context != null) {
this.mContext = context; this.mContext = context;
this.mLayoutManager = layoutManager; this.mLayoutManager = layoutManager;
this.mAdapter = adapter; this.mAdapter = adapter;
this.mLastItem = lastItem; this.mLastItem = lastItem;
this.mBestPostData = bestPostData; this.mPostData = postData;
this.mPaginationSynchronizer = paginationSynchronizer; this.mPaginationSynchronizer = paginationSynchronizer;
this.mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue; this.mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue;
this.isLoading = isLoading; this.isLoading = isLoading;
@ -103,9 +103,9 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("response", response); ClipData clip = ClipData.newPlainText("response", response);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
new ParseBestPost(mContext, new ParseBestPost.ParseBestPostListener() { new ParsePost(mContext, new ParsePost.ParsePostListener() {
@Override @Override
public void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem) { public void onParsePostSuccess(ArrayList<PostData> bestPostData, String lastItem) {
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
mLastItem = lastItem; mLastItem = lastItem;
mLastItemSynchronizer.lastItemChanged(mLastItem); mLastItemSynchronizer.lastItemChanged(mLastItem);
@ -117,12 +117,12 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
} }
@Override @Override
public void onParseBestPostFail() { public void onParsePostFail() {
Toast.makeText(mContext, "Error parsing data", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "Error parsing data", Toast.LENGTH_SHORT).show();
Log.i("Best post", "Error parsing data"); Log.i("Best post", "Error parsing data");
loadFailed(); loadFailed();
} }
}).parseBestPost(response, mBestPostData); }).parseBestPost(response, mPostData);
} }
}, new Response.ErrorListener() { }, new Response.ErrorListener() {
@Override @Override
@ -153,7 +153,7 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
return RedditUtils.getOAuthHeader(accessToken); return RedditUtils.getOAuthHeader(accessToken);
} }
}; };
bestPostRequest.setTag(BestPostPaginationScrollListener.class); bestPostRequest.setTag(PostPaginationScrollListener.class);
mRequestQueue.add(bestPostRequest); mRequestQueue.add(bestPostRequest);
} }

View File

@ -39,8 +39,8 @@ import de.hdodenhof.circleimageview.CircleImageView;
* Created by alex on 2/25/18. * Created by alex on 2/25/18.
*/ */
class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private ArrayList<BestPostData> mBestPostData; private ArrayList<PostData> mPostData;
private Context mContext; private Context mContext;
private PaginationSynchronizer mPaginationSynchronizer; private PaginationSynchronizer mPaginationSynchronizer;
private RequestQueue mVoteThingRequestQueue; private RequestQueue mVoteThingRequestQueue;
@ -54,11 +54,11 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
private static final int VIEW_TYPE_LOADING = 1; private static final int VIEW_TYPE_LOADING = 1;
BestPostRecyclerViewAdapter(Context context, ArrayList<BestPostData> bestPostData, PaginationSynchronizer paginationSynchronizer, PostRecyclerViewAdapter(Context context, ArrayList<PostData> postData, PaginationSynchronizer paginationSynchronizer,
RequestQueue voteThingRequestQueue, RequestQueue acquireAccessTokenRequestQueue) { RequestQueue voteThingRequestQueue, RequestQueue acquireAccessTokenRequestQueue) {
if(context != null) { if(context != null) {
mContext = context; mContext = context;
mBestPostData = bestPostData; mPostData = postData;
mPaginationSynchronizer = paginationSynchronizer; mPaginationSynchronizer = paginationSynchronizer;
mVoteThingRequestQueue = voteThingRequestQueue; mVoteThingRequestQueue = voteThingRequestQueue;
mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue; mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue;
@ -88,22 +88,22 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override @Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) { public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
if(holder instanceof DataViewHolder) { if(holder instanceof DataViewHolder) {
if(mBestPostData.get(position) == null) { if(mPostData.get(position) == null) {
Log.i("is null", Integer.toString(position)); Log.i("is null", Integer.toString(position));
} else { } else {
final String id = mBestPostData.get(position).getFullName(); final String id = mPostData.get(position).getFullName();
final String subredditName = mBestPostData.get(position).getSubredditName(); final String subredditName = mPostData.get(position).getSubredditName();
final String postTime = mBestPostData.get(position).getPostTime(); final String postTime = mPostData.get(position).getPostTime();
final String title = mBestPostData.get(position).getTitle(); final String title = mPostData.get(position).getTitle();
final String permalink = mBestPostData.get(position).getPermalink(); final String permalink = mPostData.get(position).getPermalink();
int voteType = mBestPostData.get(position).getVoteType(); int voteType = mPostData.get(position).getVoteType();
boolean nsfw = mBestPostData.get(position).getNSFW(); boolean nsfw = mPostData.get(position).getNSFW();
if(mBestPostData.get(position).getSubredditIconUrl() == null) { if(mPostData.get(position).getSubredditIconUrl() == null) {
new LoadSubredditIconAsyncTask(mContext, ((DataViewHolder) holder).subredditIconCircleImageView, new LoadSubredditIconAsyncTask(mContext, ((DataViewHolder) holder).subredditIconCircleImageView,
subredditDao, subredditName, mBestPostData.get(position)).execute(); subredditDao, subredditName, mPostData.get(position)).execute();
} else if(!mBestPostData.get(position).getSubredditIconUrl().equals("")) { } else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
glide.load(mBestPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView); glide.load(mPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView);
} else { } else {
glide.load(R.drawable.subreddit_default_icon).into(((DataViewHolder) holder).subredditIconCircleImageView); glide.load(R.drawable.subreddit_default_icon).into(((DataViewHolder) holder).subredditIconCircleImageView);
} }
@ -115,7 +115,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
canStartActivity = false; canStartActivity = false;
Intent intent = new Intent(mContext, ViewPostDetailActivity.class); Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title); intent.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, mBestPostData.get(position)); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, mPostData.get(position));
mContext.startActivity(intent); mContext.startActivity(intent);
} }
} }
@ -124,7 +124,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
((DataViewHolder) holder).subredditNameTextView.setText(subredditName); ((DataViewHolder) holder).subredditNameTextView.setText(subredditName);
((DataViewHolder) holder).postTimeTextView.setText(postTime); ((DataViewHolder) holder).postTimeTextView.setText(postTime);
((DataViewHolder) holder).titleTextView.setText(title); ((DataViewHolder) holder).titleTextView.setText(title);
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore())); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
if(nsfw) { if(nsfw) {
((DataViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE); ((DataViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE);
@ -141,17 +141,17 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
break; break;
} }
if(mBestPostData.get(position).getPostType() != BestPostData.TEXT_TYPE && mBestPostData.get(position).getPostType() != BestPostData.NO_PREVIEW_LINK_TYPE) { if(mPostData.get(position).getPostType() != PostData.TEXT_TYPE && mPostData.get(position).getPostType() != PostData.NO_PREVIEW_LINK_TYPE) {
((DataViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE); ((DataViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE);
((DataViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((DataViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((DataViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((DataViewHolder) holder).imageView.setVisibility(View.VISIBLE);
} }
switch (mBestPostData.get(position).getPostType()) { switch (mPostData.get(position).getPostType()) {
case BestPostData.IMAGE_TYPE: case PostData.IMAGE_TYPE:
((DataViewHolder) holder).typeTextView.setText("IMAGE"); ((DataViewHolder) holder).typeTextView.setText("IMAGE");
final String previewImageUrl = mBestPostData.get(position).getPreviewUrl(); final String previewImageUrl = mPostData.get(position).getPreviewUrl();
final String imageUrl = mBestPostData.get(position).getUrl(); final String imageUrl = mPostData.get(position).getUrl();
glide.load(previewImageUrl).listener(new RequestListener<Drawable>() { glide.load(previewImageUrl).listener(new RequestListener<Drawable>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@ -176,9 +176,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}); });
break; break;
case BestPostData.LINK_TYPE: case PostData.LINK_TYPE:
((DataViewHolder) holder).typeTextView.setText("LINK"); ((DataViewHolder) holder).typeTextView.setText("LINK");
String linkPreviewUrl = mBestPostData.get(position).getPreviewUrl(); String linkPreviewUrl = mPostData.get(position).getPreviewUrl();
glide.load(linkPreviewUrl).listener(new RequestListener<Drawable>() { glide.load(linkPreviewUrl).listener(new RequestListener<Drawable>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@ -191,7 +191,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
return false; return false;
} }
}).into(((DataViewHolder) holder).imageView); }).into(((DataViewHolder) holder).imageView);
final String linkUrl = mBestPostData.get(position).getUrl(); final String linkUrl = mPostData.get(position).getUrl();
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() { ((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -204,9 +204,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}); });
break; break;
case BestPostData.GIF_VIDEO_TYPE: case PostData.GIF_VIDEO_TYPE:
((DataViewHolder) holder).typeTextView.setText("GIF"); ((DataViewHolder) holder).typeTextView.setText("GIF");
String gifVideoPreviewUrl = mBestPostData.get(position).getPreviewUrl(); String gifVideoPreviewUrl = mPostData.get(position).getPreviewUrl();
glide.load(gifVideoPreviewUrl).listener(new RequestListener<Drawable>() { glide.load(gifVideoPreviewUrl).listener(new RequestListener<Drawable>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@ -220,7 +220,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}).into(((DataViewHolder) holder).imageView); }).into(((DataViewHolder) holder).imageView);
String gifVideoUrl = mBestPostData.get(position).getVideoUrl(); String gifVideoUrl = mPostData.get(position).getVideoUrl();
final Uri gifVideoUri = Uri.parse(gifVideoUrl); final Uri gifVideoUri = Uri.parse(gifVideoUrl);
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() { ((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@ -229,10 +229,10 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
Intent intent = new Intent(mContext, ViewVideoActivity.class); Intent intent = new Intent(mContext, ViewVideoActivity.class);
intent.setData(gifVideoUri); intent.setData(gifVideoUri);
intent.putExtra(ViewVideoActivity.TITLE_KEY, title); intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mBestPostData.get(position).isDashVideo()); intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mBestPostData.get(position).isDownloadableGifOrVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
if(mBestPostData.get(position).isDownloadableGifOrVideo()) { if(mPostData.get(position).isDownloadableGifOrVideo()) {
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mBestPostData.get(position).getGifOrVideoDownloadUrl()); intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
intent.putExtra(ViewVideoActivity.ID_KEY, id); intent.putExtra(ViewVideoActivity.ID_KEY, id);
} }
@ -240,9 +240,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}); });
break; break;
case BestPostData.VIDEO_TYPE: case PostData.VIDEO_TYPE:
((DataViewHolder) holder).typeTextView.setText("VIDEO"); ((DataViewHolder) holder).typeTextView.setText("VIDEO");
String videoPreviewUrl = mBestPostData.get(position).getPreviewUrl(); String videoPreviewUrl = mPostData.get(position).getPreviewUrl();
glide.load(videoPreviewUrl).listener(new RequestListener<Drawable>() { glide.load(videoPreviewUrl).listener(new RequestListener<Drawable>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@ -256,7 +256,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}).into(((DataViewHolder) holder).imageView); }).into(((DataViewHolder) holder).imageView);
String videoUrl = mBestPostData.get(position).getVideoUrl(); String videoUrl = mPostData.get(position).getVideoUrl();
final Uri videoUri = Uri.parse(videoUrl); final Uri videoUri = Uri.parse(videoUrl);
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() { ((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@ -265,10 +265,10 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
Intent intent = new Intent(mContext, ViewVideoActivity.class); Intent intent = new Intent(mContext, ViewVideoActivity.class);
intent.setData(videoUri); intent.setData(videoUri);
intent.putExtra(ViewVideoActivity.TITLE_KEY, title); intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mBestPostData.get(position).isDashVideo()); intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mBestPostData.get(position).isDownloadableGifOrVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
if(mBestPostData.get(position).isDownloadableGifOrVideo()) { if(mPostData.get(position).isDownloadableGifOrVideo()) {
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mBestPostData.get(position).getGifOrVideoDownloadUrl()); intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
intent.putExtra(ViewVideoActivity.ID_KEY, id); intent.putExtra(ViewVideoActivity.ID_KEY, id);
} }
@ -276,9 +276,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
}); });
break; break;
case BestPostData.NO_PREVIEW_LINK_TYPE: case PostData.NO_PREVIEW_LINK_TYPE:
((DataViewHolder) holder).typeTextView.setText("LINK"); ((DataViewHolder) holder).typeTextView.setText("LINK");
final String noPreviewLinkUrl = mBestPostData.get(position).getUrl(); final String noPreviewLinkUrl = mPostData.get(position).getUrl();
((DataViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); ((DataViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
((DataViewHolder) holder).noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() { ((DataViewHolder) holder).noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -307,19 +307,19 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) { if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
if(isDownvotedBefore) { if(isDownvotedBefore) {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 2)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 2));
} else { } else {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 1)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 1));
} }
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() { new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
mBestPostData.get(position).setVoteType(1); mPostData.get(position).setVoteType(1);
if(isDownvotedBefore) { if(isDownvotedBefore) {
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() + 2); mPostData.get(position).setScore(mPostData.get(position).getScore() + 2);
} else { } else {
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() + 1); mPostData.get(position).setScore(mPostData.get(position).getScore() + 1);
} }
} }
@ -327,28 +327,28 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
public void onVoteThingFail(int position) { public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot upvote this post", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "Cannot upvote this post", Toast.LENGTH_SHORT).show();
((DataViewHolder) holder).upvoteButton.clearColorFilter(); ((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore())); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
((DataViewHolder) holder).downvoteButton.setColorFilter(downvoteButtonColorFilter); ((DataViewHolder) holder).downvoteButton.setColorFilter(downvoteButtonColorFilter);
} }
}, id, RedditUtils.DIR_UPVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1); }, id, RedditUtils.DIR_UPVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1);
} else { } else {
//Upvoted before //Upvoted before
((DataViewHolder) holder).upvoteButton.clearColorFilter(); ((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() - 1)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() { new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
mBestPostData.get(position).setVoteType(0); mPostData.get(position).setVoteType(0);
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() - 1); mPostData.get(position).setScore(mPostData.get(position).getScore() - 1);
} }
@Override @Override
public void onVoteThingFail(int position) { public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 1)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 1));
((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() + 1); mPostData.get(position).setScore(mPostData.get(position).getScore() + 1);
} }
}, id, RedditUtils.DIR_UNVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1); }, id, RedditUtils.DIR_UNVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1);
} }
@ -365,19 +365,19 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) { if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
if (isUpvotedBefore) { if (isUpvotedBefore) {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() - 2)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 2));
} else { } else {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() - 1)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 1));
} }
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() { new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
mBestPostData.get(position).setVoteType(-1); mPostData.get(position).setVoteType(-1);
if(isUpvotedBefore) { if(isUpvotedBefore) {
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() - 2); mPostData.get(position).setScore(mPostData.get(position).getScore() - 2);
} else { } else {
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() - 1); mPostData.get(position).setScore(mPostData.get(position).getScore() - 1);
} }
} }
@ -385,28 +385,28 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
public void onVoteThingFail(int position) { public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot downvote this post", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "Cannot downvote this post", Toast.LENGTH_SHORT).show();
((DataViewHolder) holder).downvoteButton.clearColorFilter(); ((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore())); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
((DataViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter); ((DataViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
} }
}, id, RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1); }, id, RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
} else { } else {
//Down voted before //Down voted before
((DataViewHolder) holder).downvoteButton.clearColorFilter(); ((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 1)); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() { new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
mBestPostData.get(position).setVoteType(0); mPostData.get(position).setVoteType(0);
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore()); mPostData.get(position).setScore(mPostData.get(position).getScore());
} }
@Override @Override
public void onVoteThingFail(int position) { public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore())); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore()); mPostData.get(position).setScore(mPostData.get(position).getScore());
} }
}, id, RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1); }, id, RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1);
} }
@ -459,12 +459,12 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override @Override
public int getItemCount() { public int getItemCount() {
return mBestPostData.size() + 1; return mPostData.size() + 1;
} }
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
return (position >= mBestPostData.size() ? VIEW_TYPE_LOADING : VIEW_TYPE_DATA); return (position >= mPostData.size() ? VIEW_TYPE_LOADING : VIEW_TYPE_DATA);
} }
class DataViewHolder extends RecyclerView.ViewHolder { class DataViewHolder extends RecyclerView.ViewHolder {

View File

@ -45,7 +45,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private String orientationState = "OS"; private String orientationState = "OS";
private int mMoreCommentCount; private int mMoreCommentCount;
private BestPostData mPostData; private PostData mPostData;
private CoordinatorLayout mCoordinatorLayout; private CoordinatorLayout mCoordinatorLayout;
private ProgressBar mCommentProgressbar; private ProgressBar mCommentProgressbar;
@ -144,7 +144,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
}); });
switch (mPostData.getPostType()) { switch (mPostData.getPostType()) {
case BestPostData.IMAGE_TYPE: case PostData.IMAGE_TYPE:
typeTextView.setText("IMAGE"); typeTextView.setText("IMAGE");
relativeLayout.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.VISIBLE);
Glide.with(this).load(mPostData.getPreviewUrl()).listener(new RequestListener<Drawable>() { Glide.with(this).load(mPostData.getPreviewUrl()).listener(new RequestListener<Drawable>() {
@ -172,7 +172,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} }
}); });
break; break;
case BestPostData.LINK_TYPE: case PostData.LINK_TYPE:
relativeLayout.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("LINK"); typeTextView.setText("LINK");
String linkPreviewUrl = mPostData.getPreviewUrl(); String linkPreviewUrl = mPostData.getPreviewUrl();
@ -201,7 +201,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} }
}); });
break; break;
case BestPostData.GIF_VIDEO_TYPE: case PostData.GIF_VIDEO_TYPE:
relativeLayout.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("VIDEO"); typeTextView.setText("VIDEO");
String gifVideoPreviewUrl = mPostData.getPreviewUrl(); String gifVideoPreviewUrl = mPostData.getPreviewUrl();
@ -238,7 +238,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} }
}); });
break; break;
case BestPostData.VIDEO_TYPE: case PostData.VIDEO_TYPE:
relativeLayout.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("VIDEO"); typeTextView.setText("VIDEO");
String videoPreviewUrl = mPostData.getPreviewUrl(); String videoPreviewUrl = mPostData.getPreviewUrl();
@ -275,7 +275,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} }
}); });
break; break;
case BestPostData.NO_PREVIEW_LINK_TYPE: case PostData.NO_PREVIEW_LINK_TYPE:
typeTextView.setText("LINK"); typeTextView.setText("LINK");
noPreviewLinkImageView.setVisibility(View.VISIBLE); noPreviewLinkImageView.setVisibility(View.VISIBLE);
noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() { noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() {
@ -290,7 +290,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} }
}); });
break; break;
case BestPostData.TEXT_TYPE: case PostData.TEXT_TYPE:
typeTextView.setText("TEXT"); typeTextView.setText("TEXT");
if(!mPostData.getSelfText().equals("")) { if(!mPostData.getSelfText().equals("")) {
contentTextView.setVisibility(View.VISIBLE); contentTextView.setVisibility(View.VISIBLE);

View File

@ -7,6 +7,8 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout; import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
@ -117,6 +119,10 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
} }
}); });
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment mFragment = new BestPostFragment();
fragmentTransaction.replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
} }
@Override @Override

View File

@ -1,17 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frame_layout_view_subreddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ViewSubredditDetailActivity" tools:context=".ViewSubredditDetailActivity"
tools:showIn="@layout/activity_view_subreddit_detail"> tools:showIn="@layout/activity_view_subreddit_detail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>

View File

@ -2,7 +2,8 @@
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:id="@+id/card_view_view_post_detail"> android:id="@+id/card_view_view_post_detail">
<LinearLayout <LinearLayout