mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Rename some classes. Change the logic of getting the subreddit icon. Prepare to display posts in ViewSubredditDetailActivity.
This commit is contained in:
parent
23bf92d9cf
commit
07b32b3900
@ -41,10 +41,10 @@ public class BestPostFragment extends Fragment {
|
||||
private RecyclerView mBestPostRecyclerView;
|
||||
private LinearLayoutManager mLinearLayoutManager;
|
||||
private ProgressBar mProgressBar;
|
||||
private ArrayList<BestPostData> mBestPostData;
|
||||
private ArrayList<PostData> mPostData;
|
||||
private String mLastItem;
|
||||
private PaginationSynchronizer mPaginationSynchronizer;
|
||||
private BestPostRecyclerViewAdapter mAdapter;
|
||||
private PostRecyclerViewAdapter mAdapter;
|
||||
|
||||
private String bestPostDataParcelableState = "BPDPS";
|
||||
private String lastItemState = "LIS";
|
||||
@ -64,11 +64,11 @@ public class BestPostFragment extends Fragment {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if(savedInstanceState != null) {
|
||||
if(savedInstanceState.containsKey(bestPostDataParcelableState)) {
|
||||
mBestPostData = savedInstanceState.getParcelableArrayList(bestPostDataParcelableState);
|
||||
mPostData = savedInstanceState.getParcelableArrayList(bestPostDataParcelableState);
|
||||
mLastItem = savedInstanceState.getString(lastItemState);
|
||||
mAdapter = new BestPostRecyclerViewAdapter(getActivity(), mBestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
|
||||
mAdapter = new PostRecyclerViewAdapter(getActivity(), mPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
|
||||
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()));
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
@ -94,11 +94,11 @@ public class BestPostFragment extends Fragment {
|
||||
}
|
||||
|
||||
if(mPaginationRequestQueue != null) {
|
||||
mPaginationRequestQueue.cancelAll(BestPostPaginationScrollListener.class);
|
||||
mPaginationRequestQueue.cancelAll(PostPaginationScrollListener.class);
|
||||
}
|
||||
|
||||
if(mBestPostData != null) {
|
||||
outState.putParcelableArrayList(bestPostDataParcelableState, mBestPostData);
|
||||
if(mPostData != null) {
|
||||
outState.putParcelableArrayList(bestPostDataParcelableState, mPostData);
|
||||
outState.putString(lastItemState, mLastItem);
|
||||
outState.putParcelable(paginationSynchronizerState, mPaginationSynchronizer);
|
||||
}
|
||||
@ -180,27 +180,27 @@ public class BestPostFragment extends Fragment {
|
||||
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("response", response);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
//new ParseBestPostDataAsyncTask(response, accessToken).execute();
|
||||
new ParseBestPost(getActivity(), new ParseBestPost.ParseBestPostListener() {
|
||||
//new ParsePostDataAsyncTask(response, accessToken).execute();
|
||||
new ParsePost(getActivity(), new ParsePost.ParsePostListener() {
|
||||
@Override
|
||||
public void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem) {
|
||||
mBestPostData = bestPostData;
|
||||
public void onParsePostSuccess(ArrayList<PostData> bestPostData, String lastItem) {
|
||||
mPostData = bestPostData;
|
||||
mLastItem = lastItem;
|
||||
mAdapter = new BestPostRecyclerViewAdapter(getActivity(), bestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
|
||||
mAdapter = new PostRecyclerViewAdapter(getActivity(), bestPostData, mPaginationSynchronizer, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue);
|
||||
|
||||
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()));
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParseBestPostFail() {
|
||||
public void onParsePostFail() {
|
||||
Toast.makeText(getActivity(), "Error parsing data", Toast.LENGTH_SHORT).show();
|
||||
Log.i("Best post fetch error", "Error parsing data");
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}).parseBestPost(response, new ArrayList<BestPostData>());
|
||||
}).parseBestPost(response, new ArrayList<PostData>());
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
@ -66,6 +66,7 @@ class FetchSubscribedThing {
|
||||
String lastItem) {
|
||||
mSubscribedSubredditData = subscribedSubredditData;
|
||||
mSubscribedUserData = subscribedUserData;
|
||||
mSubredditData = subredditData;
|
||||
mLastItem = lastItem;
|
||||
if(mLastItem.equals("null")) {
|
||||
mFetchSubscribedSubredditsListener.onFetchSubscribedSubredditsSuccess(mSubscribedSubredditData,
|
||||
|
@ -54,6 +54,7 @@ class JSONUtils {
|
||||
static final String SUBREDDIT_KEY = "subreddit";
|
||||
static final String BANNER_IMG_KEY = "banner_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 COMMENT_KARMA_KEY = "comment_karma";
|
||||
static final String DISPLAY_NAME = "display_name";
|
||||
|
@ -16,16 +16,16 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private SubredditDao subredditDao;
|
||||
private String subredditName;
|
||||
private String iconImageUrl;
|
||||
private BestPostData bestPostData;
|
||||
private PostData postData;
|
||||
|
||||
LoadSubredditIconAsyncTask(Context context, CircleImageView iconImageView,
|
||||
SubredditDao subredditDao, String subredditName,
|
||||
BestPostData bestPostData) {
|
||||
PostData postData) {
|
||||
contextWeakReference = new WeakReference<>(context);
|
||||
circleImageViewWeakReference = new WeakReference<>(iconImageView);
|
||||
this.subredditDao = subredditDao;
|
||||
this.subredditName = subredditName;
|
||||
this.bestPostData = bestPostData;
|
||||
this.postData = postData;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,6 +52,6 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
}
|
||||
}
|
||||
|
||||
bestPostData.setSubredditIconUrl(iconImageUrl);
|
||||
postData.setSubredditIconUrl(iconImageUrl);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@ -165,6 +166,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) {
|
||||
if(!mIsInserting) {
|
||||
Log.i("view", "observed");
|
||||
if(subscribedUserData == null || subscribedUserData.size() == 0) {
|
||||
followingLabelTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
@ -219,7 +221,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onFetchUserInfoFail() {
|
||||
|
||||
mFetchUserInfoSuccess = false;
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
@ -251,7 +253,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onFetchSubscribedSubredditsFail() {
|
||||
|
||||
mInsertSuccess = false;
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
@ -17,37 +17,37 @@ import java.util.Calendar;
|
||||
* Created by alex on 3/21/18.
|
||||
*/
|
||||
|
||||
class ParseBestPost {
|
||||
class ParsePost {
|
||||
|
||||
interface ParseBestPostListener {
|
||||
void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem);
|
||||
void onParseBestPostFail();
|
||||
interface ParsePostListener {
|
||||
void onParsePostSuccess(ArrayList<PostData> postData, String lastItem);
|
||||
void onParsePostFail();
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private ParseBestPostListener mParseBetPostListener;
|
||||
private ParsePostListener mParseBetPostListener;
|
||||
|
||||
ParseBestPost(Context context, ParseBestPostListener parseBestPostListener) {
|
||||
ParsePost(Context context, ParsePostListener parsePostListener) {
|
||||
mContext = context;
|
||||
mParseBetPostListener = parseBestPostListener;
|
||||
mParseBetPostListener = parsePostListener;
|
||||
}
|
||||
|
||||
void parseBestPost(String response, ArrayList<BestPostData> bestPostData) {
|
||||
new ParseBestPostDataAsyncTask(response, bestPostData).execute();
|
||||
void parseBestPost(String response, ArrayList<PostData> postData) {
|
||||
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 ArrayList<BestPostData> bestPostData;
|
||||
private ArrayList<BestPostData> newBestPostData;
|
||||
private ArrayList<PostData> postData;
|
||||
private ArrayList<PostData> newPostData;
|
||||
private String lastItem;
|
||||
private boolean parseFailed;
|
||||
|
||||
ParseBestPostDataAsyncTask(String response, ArrayList<BestPostData> bestPostData) {
|
||||
ParsePostDataAsyncTask(String response, ArrayList<PostData> postData) {
|
||||
try {
|
||||
jsonResponse = new JSONObject(response);
|
||||
this.bestPostData = bestPostData;
|
||||
newBestPostData = new ArrayList<>();
|
||||
this.postData = postData;
|
||||
newPostData = new ArrayList<>();
|
||||
parseFailed = false;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -92,10 +92,10 @@ class ParseBestPost {
|
||||
if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) {
|
||||
//Cross post
|
||||
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);
|
||||
} else {
|
||||
parseData(data, permalink, newBestPostData, id, fullName, subredditName,
|
||||
parseData(data, permalink, newPostData, id, fullName, subredditName,
|
||||
formattedPostTime, title, previewUrl, score, voteType, nsfw, i);
|
||||
}
|
||||
}
|
||||
@ -110,15 +110,15 @@ class ParseBestPost {
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if(!parseFailed) {
|
||||
bestPostData.addAll(newBestPostData);
|
||||
mParseBetPostListener.onParseBestPostSuccess(bestPostData, lastItem);
|
||||
postData.addAll(newPostData);
|
||||
mParseBetPostListener.onParsePostSuccess(postData, lastItem);
|
||||
} 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 previewUrl, int score, int voteType, boolean nsfw, int i) throws JSONException {
|
||||
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
|
||||
@ -128,25 +128,25 @@ class ParseBestPost {
|
||||
if(url.contains(permalink)) {
|
||||
//Text post
|
||||
Log.i("text", Integer.toString(i));
|
||||
int postType = BestPostData.TEXT_TYPE;
|
||||
BestPostData postData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, permalink, score, postType, voteType, nsfw);
|
||||
int postType = PostData.TEXT_TYPE;
|
||||
PostData postData = new PostData(id, fullName, subredditName, formattedPostTime, title, permalink, score, postType, voteType, nsfw);
|
||||
postData.setSelfText(data.getString(JSONUtils.SELF_TEXT_KEY).trim());
|
||||
bestPostData.add(postData);
|
||||
} else {
|
||||
//No preview link post
|
||||
Log.i("no preview link", Integer.toString(i));
|
||||
int postType = BestPostData.NO_PREVIEW_LINK_TYPE;
|
||||
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
int postType = PostData.NO_PREVIEW_LINK_TYPE;
|
||||
PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
bestPostData.add(linkPostData);
|
||||
}
|
||||
} else if(isVideo) {
|
||||
//Video post
|
||||
Log.i("video", Integer.toString(i));
|
||||
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);
|
||||
|
||||
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.setDownloadableGifOrVideo(false);
|
||||
@ -157,10 +157,10 @@ class ParseBestPost {
|
||||
if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) {
|
||||
//Gif video post (MP4)
|
||||
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 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.setDownloadableGifOrVideo(true);
|
||||
@ -170,11 +170,11 @@ class ParseBestPost {
|
||||
} else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) {
|
||||
//Gif video post (Dash)
|
||||
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)
|
||||
.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.setDownloadableGifOrVideo(false);
|
||||
@ -184,13 +184,13 @@ class ParseBestPost {
|
||||
if (url.endsWith("jpg") || url.endsWith("png")) {
|
||||
//Image post
|
||||
Log.i("image", Integer.toString(i));
|
||||
int postType = BestPostData.IMAGE_TYPE;
|
||||
bestPostData.add(new BestPostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
|
||||
int postType = PostData.IMAGE_TYPE;
|
||||
bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
|
||||
} else {
|
||||
//Link post
|
||||
Log.i("link", Integer.toString(i));
|
||||
int postType = BestPostData.LINK_TYPE;
|
||||
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
int postType = PostData.LINK_TYPE;
|
||||
PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
bestPostData.add(linkPostData);
|
||||
}
|
||||
}
|
||||
@ -198,13 +198,13 @@ class ParseBestPost {
|
||||
if (url.endsWith("jpg") || url.endsWith("png")) {
|
||||
//Image post
|
||||
Log.i("CP no preview image", Integer.toString(i));
|
||||
int postType = BestPostData.IMAGE_TYPE;
|
||||
bestPostData.add(new BestPostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
|
||||
int postType = PostData.IMAGE_TYPE;
|
||||
bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
|
||||
} else {
|
||||
//Link post
|
||||
Log.i("CP no preview link", Integer.toString(i));
|
||||
int postType = BestPostData.LINK_TYPE;
|
||||
BestPostData linkPostData = new BestPostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
int postType = PostData.LINK_TYPE;
|
||||
PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
|
||||
bestPostData.add(linkPostData);
|
||||
}
|
||||
}
|
@ -18,17 +18,15 @@ class ParseSubscribedThing {
|
||||
void onParseSubscribedSubredditsFail();
|
||||
}
|
||||
|
||||
private ParseSubscribedSubredditsListener mParseSubscribedSubredditsListener;
|
||||
|
||||
void parseSubscribedSubreddits(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||
ArrayList<SubscribedUserData> subscribedUserData,
|
||||
ArrayList<SubredditData> subredditData,
|
||||
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) {
|
||||
mParseSubscribedSubredditsListener = parseSubscribedSubredditsListener;
|
||||
new ParseSubscribedSubredditsAsyncTask(response, subscribedSubredditData, subscribedUserData, subredditData).execute();
|
||||
new ParseSubscribedSubredditsAsyncTask(response, subscribedSubredditData, subscribedUserData, subredditData,
|
||||
parseSubscribedSubredditsListener).execute();
|
||||
}
|
||||
|
||||
private class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private JSONObject jsonResponse;
|
||||
private boolean parseFailed;
|
||||
private String lastItem;
|
||||
@ -38,10 +36,12 @@ class ParseSubscribedThing {
|
||||
private ArrayList<SubscribedSubredditData> newSubscribedSubredditData;
|
||||
private ArrayList<SubscribedUserData> newSubscribedUserData;
|
||||
private ArrayList<SubredditData> newSubredditData;
|
||||
private ParseSubscribedSubredditsListener parseSubscribedSubredditsListener;
|
||||
|
||||
ParseSubscribedSubredditsAsyncTask(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||
ArrayList<SubscribedUserData> subscribedUserData,
|
||||
ArrayList<SubredditData> subredditData){
|
||||
ArrayList<SubredditData> subredditData,
|
||||
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener){
|
||||
try {
|
||||
jsonResponse = new JSONObject(response);
|
||||
parseFailed = false;
|
||||
@ -51,9 +51,10 @@ class ParseSubscribedThing {
|
||||
newSubscribedSubredditData = new ArrayList<>();
|
||||
newSubscribedUserData = new ArrayList<>();
|
||||
newSubredditData = new ArrayList<>();
|
||||
this.parseSubscribedSubredditsListener = parseSubscribedSubredditsListener;
|
||||
} catch (JSONException e) {
|
||||
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 bannerUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
String iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
String id = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.NAME_KEY);
|
||||
if(iconUrl.equals("null")) {
|
||||
iconUrl = "";
|
||||
String id = data.getString(JSONUtils.NAME_KEY);
|
||||
if(iconUrl.equals("") || iconUrl.equals("null")) {
|
||||
iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
if(iconUrl.equals("null")) {
|
||||
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)) {
|
||||
//It's a user
|
||||
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);
|
||||
} catch (JSONException e) {
|
||||
parseFailed = true;
|
||||
Log.i("parse comment error", e.getMessage());
|
||||
Log.i("parse subscribed error", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -97,10 +101,10 @@ class ParseSubscribedThing {
|
||||
subscribedSubredditData.addAll(newSubscribedSubredditData);
|
||||
subscribedUserData.addAll(newSubscribedUserData);
|
||||
subredditData.addAll(newSubredditData);
|
||||
mParseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData,
|
||||
parseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData,
|
||||
subscribedUserData, subredditData, lastItem);
|
||||
} else {
|
||||
mParseSubscribedSubredditsListener.onParseSubscribedSubredditsFail();
|
||||
parseSubscribedSubredditsListener.onParseSubscribedSubredditsFail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import android.os.Parcelable;
|
||||
* Created by alex on 3/1/18.
|
||||
*/
|
||||
|
||||
class BestPostData implements Parcelable {
|
||||
class PostData implements Parcelable {
|
||||
static final int TEXT_TYPE = 0;
|
||||
static final int IMAGE_TYPE = 1;
|
||||
static final int LINK_TYPE = 2;
|
||||
@ -34,7 +34,7 @@ class BestPostData implements Parcelable {
|
||||
private boolean isDashVideo;
|
||||
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.fullName = fullName;
|
||||
this.subredditName = subredditName;
|
||||
@ -49,7 +49,7 @@ class BestPostData implements Parcelable {
|
||||
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.fullName = fullName;
|
||||
this.subredditName = subredditName;
|
||||
@ -64,7 +64,7 @@ class BestPostData implements Parcelable {
|
||||
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.fullName = fullName;
|
||||
this.subredditName = subredditName;
|
||||
@ -77,7 +77,7 @@ class BestPostData implements Parcelable {
|
||||
this.nsfw = nsfw;
|
||||
}
|
||||
|
||||
protected BestPostData(Parcel in) {
|
||||
protected PostData(Parcel in) {
|
||||
id = in.readString();
|
||||
fullName = in.readString();
|
||||
subredditName = in.readString();
|
||||
@ -98,15 +98,15 @@ class BestPostData implements Parcelable {
|
||||
isDownloadableGifOrVideo = in.readByte() != 0;
|
||||
}
|
||||
|
||||
public static final Creator<BestPostData> CREATOR = new Creator<BestPostData>() {
|
||||
public static final Creator<PostData> CREATOR = new Creator<PostData>() {
|
||||
@Override
|
||||
public BestPostData createFromParcel(Parcel in) {
|
||||
return new BestPostData(in);
|
||||
public PostData createFromParcel(Parcel in) {
|
||||
return new PostData(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BestPostData[] newArray(int size) {
|
||||
return new BestPostData[size];
|
||||
public PostData[] newArray(int size) {
|
||||
return new PostData[size];
|
||||
}
|
||||
};
|
||||
|
@ -24,11 +24,11 @@ import java.util.Map;
|
||||
* Created by alex on 3/12/18.
|
||||
*/
|
||||
|
||||
class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
private Context mContext;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private BestPostRecyclerViewAdapter mAdapter;
|
||||
private ArrayList<BestPostData> mBestPostData;
|
||||
private PostRecyclerViewAdapter mAdapter;
|
||||
private ArrayList<PostData> mPostData;
|
||||
private PaginationSynchronizer mPaginationSynchronizer;
|
||||
private PaginationRetryNotifier mPaginationRetryNotifier;
|
||||
private LastItemSynchronizer mLastItemSynchronizer;
|
||||
@ -40,14 +40,14 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
private RequestQueue mRequestQueue;
|
||||
private RequestQueue mAcquireAccessTokenRequestQueue;
|
||||
|
||||
BestPostPaginationScrollListener(Context context, LinearLayoutManager layoutManager, BestPostRecyclerViewAdapter adapter, String lastItem, ArrayList<BestPostData> bestPostData, PaginationSynchronizer paginationSynchronizer,
|
||||
RequestQueue acquireAccessTokenRequestQueue, boolean isLoading, boolean loadSuccess) {
|
||||
PostPaginationScrollListener(Context context, LinearLayoutManager layoutManager, PostRecyclerViewAdapter adapter, String lastItem, ArrayList<PostData> postData, PaginationSynchronizer paginationSynchronizer,
|
||||
RequestQueue acquireAccessTokenRequestQueue, boolean isLoading, boolean loadSuccess) {
|
||||
if(context != null) {
|
||||
this.mContext = context;
|
||||
this.mLayoutManager = layoutManager;
|
||||
this.mAdapter = adapter;
|
||||
this.mLastItem = lastItem;
|
||||
this.mBestPostData = bestPostData;
|
||||
this.mPostData = postData;
|
||||
this.mPaginationSynchronizer = paginationSynchronizer;
|
||||
this.mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue;
|
||||
this.isLoading = isLoading;
|
||||
@ -103,9 +103,9 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("response", response);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
new ParseBestPost(mContext, new ParseBestPost.ParseBestPostListener() {
|
||||
new ParsePost(mContext, new ParsePost.ParsePostListener() {
|
||||
@Override
|
||||
public void onParseBestPostSuccess(ArrayList<BestPostData> bestPostData, String lastItem) {
|
||||
public void onParsePostSuccess(ArrayList<PostData> bestPostData, String lastItem) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
mLastItem = lastItem;
|
||||
mLastItemSynchronizer.lastItemChanged(mLastItem);
|
||||
@ -117,12 +117,12 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParseBestPostFail() {
|
||||
public void onParsePostFail() {
|
||||
Toast.makeText(mContext, "Error parsing data", Toast.LENGTH_SHORT).show();
|
||||
Log.i("Best post", "Error parsing data");
|
||||
loadFailed();
|
||||
}
|
||||
}).parseBestPost(response, mBestPostData);
|
||||
}).parseBestPost(response, mPostData);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
@ -153,7 +153,7 @@ class BestPostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
return RedditUtils.getOAuthHeader(accessToken);
|
||||
}
|
||||
};
|
||||
bestPostRequest.setTag(BestPostPaginationScrollListener.class);
|
||||
bestPostRequest.setTag(PostPaginationScrollListener.class);
|
||||
mRequestQueue.add(bestPostRequest);
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ import de.hdodenhof.circleimageview.CircleImageView;
|
||||
* Created by alex on 2/25/18.
|
||||
*/
|
||||
|
||||
class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private ArrayList<BestPostData> mBestPostData;
|
||||
class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private ArrayList<PostData> mPostData;
|
||||
private Context mContext;
|
||||
private PaginationSynchronizer mPaginationSynchronizer;
|
||||
private RequestQueue mVoteThingRequestQueue;
|
||||
@ -54,11 +54,11 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
private static final int VIEW_TYPE_LOADING = 1;
|
||||
|
||||
|
||||
BestPostRecyclerViewAdapter(Context context, ArrayList<BestPostData> bestPostData, PaginationSynchronizer paginationSynchronizer,
|
||||
RequestQueue voteThingRequestQueue, RequestQueue acquireAccessTokenRequestQueue) {
|
||||
PostRecyclerViewAdapter(Context context, ArrayList<PostData> postData, PaginationSynchronizer paginationSynchronizer,
|
||||
RequestQueue voteThingRequestQueue, RequestQueue acquireAccessTokenRequestQueue) {
|
||||
if(context != null) {
|
||||
mContext = context;
|
||||
mBestPostData = bestPostData;
|
||||
mPostData = postData;
|
||||
mPaginationSynchronizer = paginationSynchronizer;
|
||||
mVoteThingRequestQueue = voteThingRequestQueue;
|
||||
mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue;
|
||||
@ -88,22 +88,22 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
|
||||
if(holder instanceof DataViewHolder) {
|
||||
if(mBestPostData.get(position) == null) {
|
||||
if(mPostData.get(position) == null) {
|
||||
Log.i("is null", Integer.toString(position));
|
||||
} else {
|
||||
final String id = mBestPostData.get(position).getFullName();
|
||||
final String subredditName = mBestPostData.get(position).getSubredditName();
|
||||
final String postTime = mBestPostData.get(position).getPostTime();
|
||||
final String title = mBestPostData.get(position).getTitle();
|
||||
final String permalink = mBestPostData.get(position).getPermalink();
|
||||
int voteType = mBestPostData.get(position).getVoteType();
|
||||
boolean nsfw = mBestPostData.get(position).getNSFW();
|
||||
final String id = mPostData.get(position).getFullName();
|
||||
final String subredditName = mPostData.get(position).getSubredditName();
|
||||
final String postTime = mPostData.get(position).getPostTime();
|
||||
final String title = mPostData.get(position).getTitle();
|
||||
final String permalink = mPostData.get(position).getPermalink();
|
||||
int voteType = mPostData.get(position).getVoteType();
|
||||
boolean nsfw = mPostData.get(position).getNSFW();
|
||||
|
||||
if(mBestPostData.get(position).getSubredditIconUrl() == null) {
|
||||
if(mPostData.get(position).getSubredditIconUrl() == null) {
|
||||
new LoadSubredditIconAsyncTask(mContext, ((DataViewHolder) holder).subredditIconCircleImageView,
|
||||
subredditDao, subredditName, mBestPostData.get(position)).execute();
|
||||
} else if(!mBestPostData.get(position).getSubredditIconUrl().equals("")) {
|
||||
glide.load(mBestPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView);
|
||||
subredditDao, subredditName, mPostData.get(position)).execute();
|
||||
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
|
||||
glide.load(mPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView);
|
||||
} else {
|
||||
glide.load(R.drawable.subreddit_default_icon).into(((DataViewHolder) holder).subredditIconCircleImageView);
|
||||
}
|
||||
@ -115,7 +115,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
canStartActivity = false;
|
||||
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
((DataViewHolder) holder).subredditNameTextView.setText(subredditName);
|
||||
((DataViewHolder) holder).postTimeTextView.setText(postTime);
|
||||
((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) {
|
||||
((DataViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE);
|
||||
@ -141,17 +141,17 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
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).progressBar.setVisibility(View.VISIBLE);
|
||||
((DataViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
switch (mBestPostData.get(position).getPostType()) {
|
||||
case BestPostData.IMAGE_TYPE:
|
||||
switch (mPostData.get(position).getPostType()) {
|
||||
case PostData.IMAGE_TYPE:
|
||||
((DataViewHolder) holder).typeTextView.setText("IMAGE");
|
||||
final String previewImageUrl = mBestPostData.get(position).getPreviewUrl();
|
||||
final String imageUrl = mBestPostData.get(position).getUrl();
|
||||
final String previewImageUrl = mPostData.get(position).getPreviewUrl();
|
||||
final String imageUrl = mPostData.get(position).getUrl();
|
||||
glide.load(previewImageUrl).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
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;
|
||||
case BestPostData.LINK_TYPE:
|
||||
case PostData.LINK_TYPE:
|
||||
((DataViewHolder) holder).typeTextView.setText("LINK");
|
||||
String linkPreviewUrl = mBestPostData.get(position).getPreviewUrl();
|
||||
String linkPreviewUrl = mPostData.get(position).getPreviewUrl();
|
||||
glide.load(linkPreviewUrl).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}).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() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -204,9 +204,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.GIF_VIDEO_TYPE:
|
||||
case PostData.GIF_VIDEO_TYPE:
|
||||
((DataViewHolder) holder).typeTextView.setText("GIF");
|
||||
String gifVideoPreviewUrl = mBestPostData.get(position).getPreviewUrl();
|
||||
String gifVideoPreviewUrl = mPostData.get(position).getPreviewUrl();
|
||||
glide.load(gifVideoPreviewUrl).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
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);
|
||||
|
||||
String gifVideoUrl = mBestPostData.get(position).getVideoUrl();
|
||||
String gifVideoUrl = mPostData.get(position).getVideoUrl();
|
||||
final Uri gifVideoUri = Uri.parse(gifVideoUrl);
|
||||
|
||||
((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.setData(gifVideoUri);
|
||||
intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
|
||||
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mBestPostData.get(position).isDashVideo());
|
||||
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mBestPostData.get(position).isDownloadableGifOrVideo());
|
||||
if(mBestPostData.get(position).isDownloadableGifOrVideo()) {
|
||||
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mBestPostData.get(position).getGifOrVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
|
||||
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
|
||||
if(mPostData.get(position).isDownloadableGifOrVideo()) {
|
||||
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
|
||||
intent.putExtra(ViewVideoActivity.ID_KEY, id);
|
||||
}
|
||||
@ -240,9 +240,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.VIDEO_TYPE:
|
||||
case PostData.VIDEO_TYPE:
|
||||
((DataViewHolder) holder).typeTextView.setText("VIDEO");
|
||||
String videoPreviewUrl = mBestPostData.get(position).getPreviewUrl();
|
||||
String videoPreviewUrl = mPostData.get(position).getPreviewUrl();
|
||||
glide.load(videoPreviewUrl).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
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);
|
||||
|
||||
String videoUrl = mBestPostData.get(position).getVideoUrl();
|
||||
String videoUrl = mPostData.get(position).getVideoUrl();
|
||||
final Uri videoUri = Uri.parse(videoUrl);
|
||||
|
||||
((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.setData(videoUri);
|
||||
intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
|
||||
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mBestPostData.get(position).isDashVideo());
|
||||
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mBestPostData.get(position).isDownloadableGifOrVideo());
|
||||
if(mBestPostData.get(position).isDownloadableGifOrVideo()) {
|
||||
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mBestPostData.get(position).getGifOrVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
|
||||
intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
|
||||
if(mPostData.get(position).isDownloadableGifOrVideo()) {
|
||||
intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
|
||||
intent.putExtra(ViewVideoActivity.ID_KEY, id);
|
||||
}
|
||||
@ -276,9 +276,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.NO_PREVIEW_LINK_TYPE:
|
||||
case PostData.NO_PREVIEW_LINK_TYPE:
|
||||
((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.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -307,19 +307,19 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
|
||||
((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
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 {
|
||||
((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() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mBestPostData.get(position).setVoteType(1);
|
||||
mPostData.get(position).setVoteType(1);
|
||||
if(isDownvotedBefore) {
|
||||
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() + 2);
|
||||
mPostData.get(position).setScore(mPostData.get(position).getScore() + 2);
|
||||
} 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) {
|
||||
Toast.makeText(mContext, "Cannot upvote this post", Toast.LENGTH_SHORT).show();
|
||||
((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);
|
||||
}
|
||||
}, id, RedditUtils.DIR_UPVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1);
|
||||
} else {
|
||||
//Upvoted before
|
||||
((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() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mBestPostData.get(position).setVoteType(0);
|
||||
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() - 1);
|
||||
mPostData.get(position).setVoteType(0);
|
||||
mPostData.get(position).setScore(mPostData.get(position).getScore() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
@ -365,19 +365,19 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
|
||||
((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
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 {
|
||||
((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() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mBestPostData.get(position).setVoteType(-1);
|
||||
mPostData.get(position).setVoteType(-1);
|
||||
if(isUpvotedBefore) {
|
||||
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() - 2);
|
||||
mPostData.get(position).setScore(mPostData.get(position).getScore() - 2);
|
||||
} 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) {
|
||||
Toast.makeText(mContext, "Cannot downvote this post", Toast.LENGTH_SHORT).show();
|
||||
((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);
|
||||
}
|
||||
}, id, RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
|
||||
} else {
|
||||
//Down voted before
|
||||
((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() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mBestPostData.get(position).setVoteType(0);
|
||||
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore());
|
||||
mPostData.get(position).setVoteType(0);
|
||||
mPostData.get(position).setScore(mPostData.get(position).getScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
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).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore()));
|
||||
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore());
|
||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
|
||||
mPostData.get(position).setScore(mPostData.get(position).getScore());
|
||||
}
|
||||
}, id, RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1);
|
||||
}
|
||||
@ -459,12 +459,12 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mBestPostData.size() + 1;
|
||||
return mPostData.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
@ -45,7 +45,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
private String orientationState = "OS";
|
||||
|
||||
private int mMoreCommentCount;
|
||||
private BestPostData mPostData;
|
||||
private PostData mPostData;
|
||||
|
||||
private CoordinatorLayout mCoordinatorLayout;
|
||||
private ProgressBar mCommentProgressbar;
|
||||
@ -144,7 +144,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
switch (mPostData.getPostType()) {
|
||||
case BestPostData.IMAGE_TYPE:
|
||||
case PostData.IMAGE_TYPE:
|
||||
typeTextView.setText("IMAGE");
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
Glide.with(this).load(mPostData.getPreviewUrl()).listener(new RequestListener<Drawable>() {
|
||||
@ -172,7 +172,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.LINK_TYPE:
|
||||
case PostData.LINK_TYPE:
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
typeTextView.setText("LINK");
|
||||
String linkPreviewUrl = mPostData.getPreviewUrl();
|
||||
@ -201,7 +201,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.GIF_VIDEO_TYPE:
|
||||
case PostData.GIF_VIDEO_TYPE:
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
typeTextView.setText("VIDEO");
|
||||
String gifVideoPreviewUrl = mPostData.getPreviewUrl();
|
||||
@ -238,7 +238,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.VIDEO_TYPE:
|
||||
case PostData.VIDEO_TYPE:
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
typeTextView.setText("VIDEO");
|
||||
String videoPreviewUrl = mPostData.getPreviewUrl();
|
||||
@ -275,7 +275,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.NO_PREVIEW_LINK_TYPE:
|
||||
case PostData.NO_PREVIEW_LINK_TYPE:
|
||||
typeTextView.setText("LINK");
|
||||
noPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@ -290,7 +290,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case BestPostData.TEXT_TYPE:
|
||||
case PostData.TEXT_TYPE:
|
||||
typeTextView.setText("TEXT");
|
||||
if(!mPostData.getSelfText().equals("")) {
|
||||
contentTextView.setVisibility(View.VISIBLE);
|
||||
|
@ -7,6 +7,8 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
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.widget.Toolbar;
|
||||
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
|
||||
|
@ -1,17 +1,10 @@
|
||||
<?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:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/frame_layout_view_subreddit_detail_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".ViewSubredditDetailActivity"
|
||||
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>
|
||||
tools:showIn="@layout/activity_view_subreddit_detail" />
|
||||
|
@ -2,7 +2,8 @@
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
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">
|
||||
|
||||
<LinearLayout
|
||||
|
Loading…
Reference in New Issue
Block a user