diff options
author | Alex Ning <chineseperson5@gmail.com> | 2018-08-26 06:51:13 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2018-08-26 06:51:13 +0000 |
commit | 41b243be7d48e141b082a48e601d2b05a83ea26c (patch) | |
tree | 12af1b5af096f61148bd6b4b1e47095f04ce205e /app/src/main/java/ml | |
parent | d83ded01933d653ac7ea62e9f5f9c4915263a5ca (diff) | |
download | infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar.gz infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar.bz2 infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar.lz infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar.xz infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.tar.zst infinity-for-reddit-41b243be7d48e141b082a48e601d2b05a83ea26c.zip |
Display the number of gold given to the post.
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 41 insertions, 44 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java index 97795c54..957e52ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java @@ -33,17 +33,5 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl); - /*Context context = contextWeakReference.get(); - CircleImageView circleImageView = circleImageViewWeakReference.get(); - - if(context != null && circleImageView != null) { - if(!iconImageUrl.equals("")) { - Glide.with(context).load(iconImageUrl).into(circleImageView); - } else { - Glide.with(context).load(R.drawable.subreddit_default_icon).into(circleImageView); - } - } - - postData.setSubredditIconUrl(iconImageUrl);*/ } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index ffc2be9b..5ef4aab3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -65,7 +65,7 @@ class ParsePost { JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); String id = data.getString(JSONUtils.ID_KEY); String fullName = data.getString(JSONUtils.NAME_KEY); - String subredditName = data.getString(JSONUtils.SUBREDDIT_NAME_PREFIX_KEY); + String subredditNamePrefixed = data.getString(JSONUtils.SUBREDDIT_NAME_PREFIX_KEY); long postTime = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; String title = data.getString(JSONUtils.TITLE_KEY); int score = data.getInt(JSONUtils.SCORE_KEY); @@ -94,10 +94,10 @@ class ParsePost { if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) { //Cross post data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); - parseData(data, permalink, newPostData, id, fullName, subredditName, + parseData(data, permalink, newPostData, id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, score, voteType, gilded, nsfw, stickied, i); } else { - parseData(data, permalink, newPostData, id, fullName, subredditName, + parseData(data, permalink, newPostData, id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, score, voteType, gilded, nsfw, stickied, i); } } @@ -121,7 +121,7 @@ class ParsePost { } private void parseData(JSONObject data, String permalink, ArrayList<PostData> bestPostData, - String id, String fullName, String subredditName, String formattedPostTime, + String id, String fullName, String subredditNamePrefixed, String formattedPostTime, String title, String previewUrl, int score, int voteType, int gilded, boolean nsfw, boolean stickied, int i) throws JSONException { boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); @@ -132,7 +132,7 @@ class ParsePost { //Text post Log.i("text", Integer.toString(i)); int postType = PostData.TEXT_TYPE; - PostData postData = new PostData(id, fullName, subredditName, formattedPostTime, + PostData postData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, permalink, score, postType, voteType, gilded, nsfw, stickied); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { postData.setSelfText(""); @@ -144,7 +144,7 @@ class ParsePost { //No preview link post Log.i("no preview link", Integer.toString(i)); int postType = PostData.NO_PREVIEW_LINK_TYPE; - PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, + PostData linkPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { linkPostData.setSelfText(""); @@ -160,7 +160,7 @@ class ParsePost { int postType = PostData.VIDEO_TYPE; String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY); - PostData videoPostData = new PostData(id, fullName, subredditName, formattedPostTime, + PostData videoPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, true); videoPostData.setVideoUrl(videoUrl); @@ -175,7 +175,7 @@ class ParsePost { 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); - PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, + PostData post = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, false); post.setVideoUrl(videoUrl); @@ -190,7 +190,7 @@ class ParsePost { String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY) .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY); - PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, + PostData post = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, true); post.setVideoUrl(videoUrl); @@ -202,13 +202,13 @@ class ParsePost { //Image post Log.i("image", Integer.toString(i)); int postType = PostData.IMAGE_TYPE; - bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, + bestPostData.add(new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, url, url, permalink, score, postType, voteType, gilded, nsfw, stickied)); } else { //Link post Log.i("link", Integer.toString(i)); int postType = PostData.LINK_TYPE; - PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, + PostData linkPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { linkPostData.setSelfText(""); @@ -223,13 +223,13 @@ class ParsePost { //Image post Log.i("CP no preview image", Integer.toString(i)); int postType = PostData.IMAGE_TYPE; - bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, + bestPostData.add(new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, url, url, permalink, score, postType, voteType, gilded, nsfw, stickied)); } else { //Link post Log.i("CP no preview link", Integer.toString(i)); int postType = PostData.LINK_TYPE; - PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, + PostData linkPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied); bestPostData.add(linkPostData); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java index 0626088f..93b8d832 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java @@ -17,7 +17,7 @@ class PostData implements Parcelable { private String id; private String fullName; - private String subredditName; + private String subredditNamePrefixed; private String subredditIconUrl; private String postTime; private String title; @@ -36,12 +36,12 @@ class PostData implements Parcelable { private boolean isDashVideo; private boolean isDownloadableGifOrVideo; - PostData(String id, String fullName, String subredditName, String postTime, String title, + PostData(String id, String fullName, String subredditNamePrefixed, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, int gilded, boolean nsfw, boolean stickied, boolean isDashVideo) { this.id = id; this.fullName = fullName; - this.subredditName = subredditName; + this.subredditNamePrefixed = subredditNamePrefixed; this.postTime = postTime; this.title = title; this.previewUrl = previewUrl; @@ -55,12 +55,12 @@ class PostData implements Parcelable { this.isDashVideo = isDashVideo; } - PostData(String id, String fullName, String subredditName, String postTime, String title, + PostData(String id, String fullName, String subredditNamePrefixed, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, int gilded, boolean nsfw, boolean stickied) { this.id = id; this.fullName = fullName; - this.subredditName = subredditName; + this.subredditNamePrefixed = subredditNamePrefixed; this.postTime = postTime; this.title = title; this.previewUrl = previewUrl; @@ -74,12 +74,12 @@ class PostData implements Parcelable { this.stickied = stickied; } - PostData(String id, String fullName, String subredditName, String postTime, String title, + PostData(String id, String fullName, String subredditNamePrefixed, String postTime, String title, String permalink, int score, int postType, int voteType, int gilded, boolean nsfw, boolean stickied) { this.id = id; this.fullName = fullName; - this.subredditName = subredditName; + this.subredditNamePrefixed = subredditNamePrefixed; this.postTime = postTime; this.title = title; this.permalink = RedditUtils.API_BASE_URI + permalink; @@ -94,7 +94,7 @@ class PostData implements Parcelable { protected PostData(Parcel in) { id = in.readString(); fullName = in.readString(); - subredditName = in.readString(); + subredditNamePrefixed = in.readString(); subredditIconUrl = in.readString(); postTime = in.readString(); title = in.readString(); @@ -134,8 +134,8 @@ class PostData implements Parcelable { return fullName; } - public String getSubredditName() { - return subredditName; + public String getSubredditNamePrefixed() { + return subredditNamePrefixed; } public String getSubredditIconUrl() { @@ -247,7 +247,7 @@ class PostData implements Parcelable { public void writeToParcel(Parcel parcel, int i) { parcel.writeString(id); parcel.writeString(fullName); - parcel.writeString(subredditName); + parcel.writeString(subredditNamePrefixed); parcel.writeString(subredditIconUrl); parcel.writeString(postTime); parcel.writeString(title); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 724fb753..7dc95034 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -92,7 +92,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold Log.i("is null", Integer.toString(position)); } else { final String id = mPostData.get(holder.getAdapterPosition()).getFullName(); - final String subredditName = mPostData.get(holder.getAdapterPosition()).getSubredditName(); + final String subredditName = mPostData.get(holder.getAdapterPosition()).getSubredditNamePrefixed(); final String postTime = mPostData.get(holder.getAdapterPosition()).getPostTime(); final String title = mPostData.get(holder.getAdapterPosition()).getTitle(); final String permalink = mPostData.get(holder.getAdapterPosition()).getPermalink(); @@ -135,6 +135,15 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold } }); + ((DataViewHolder) holder).subredditIconCircleImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME, + mPostData.get(holder.getAdapterPosition()).getSubredditNamePrefixed().substring(2)); + } + }); + ((DataViewHolder) holder).subredditNameTextView.setText(subredditName); ((DataViewHolder) holder).postTimeTextView.setText(postTime); ((DataViewHolder) holder).titleTextView.setText(title); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 8ebb175e..14323edf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -105,7 +105,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { if(mPostData.getSubredditIconUrl() == null) { mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask( - SubredditRoomDatabase.getDatabase(this).subredditDao(), mPostData.getSubredditName(), + SubredditRoomDatabase.getDatabase(this).subredditDao(), mPostData.getSubredditNamePrefixed(), new LoadSubredditIconAsyncTask.LoadSubredditIconAsyncTaskListener() { @Override public void loadIconSuccess(String iconImageUrl) { @@ -145,7 +145,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mAcquireAccessTokenRequestQueue = Volley.newRequestQueue(this); mCommentQueue = Volley.newRequestQueue(this); - subredditTextView.setText(mPostData.getSubredditName()); + subredditTextView.setText(mPostData.getSubredditNamePrefixed()); postTimeTextView.setText(mPostData.getPostTime()); if(mPostData.getGilded() > 0) { @@ -195,7 +195,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { Intent intent = new Intent(ViewPostDetailActivity.this, ViewImageActivity.class); intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPostData.getUrl()); intent.putExtra(ViewImageActivity.TITLE_KEY, mPostData.getTitle()); - intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPostData.getSubredditName().substring(2) + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPostData.getSubredditNamePrefixed().substring(2) + "-" + mPostData.getId().substring(3)); startActivity(intent); } @@ -264,7 +264,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.isDownloadableGifOrVideo()); if(mPostData.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPostData.getSubredditName()); + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPostData.getSubredditNamePrefixed()); intent.putExtra(ViewVideoActivity.ID_KEY, mPostData.getId()); } startActivity(intent); @@ -301,7 +301,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.isDownloadableGifOrVideo()); if(mPostData.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPostData.getSubredditName()); + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPostData.getSubredditNamePrefixed()); intent.putExtra(ViewVideoActivity.ID_KEY, mPostData.getId()); } startActivity(intent); @@ -494,7 +494,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { private void queryComment() { mCommentProgressbar.setVisibility(View.VISIBLE); mNoCommentWrapperLinearLayout.setVisibility(View.GONE); - new FetchComment(mCommentQueue, mPostData.getSubredditName(), mPostData.getId()).queryComment(new FetchComment.FetchCommentListener() { + new FetchComment(mCommentQueue, mPostData.getSubredditNamePrefixed(), mPostData.getId()).queryComment(new FetchComment.FetchCommentListener() { @Override public void onFetchCommentSuccess(String response) { new ParseComment().parseComment(ViewPostDetailActivity.this, response, new ArrayList<CommentData>(), new ParseComment.ParseCommentListener() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index 99fcc56e..3cced2cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -40,7 +40,6 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - String id = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ID); final String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); final String title = "r/" + subredditName; @@ -75,6 +74,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { final TextView descriptionTextView = findViewById(R.id.description_text_view_view_subreddit_detail_activity); final RequestManager glide = Glide.with(ViewSubredditDetailActivity.this); + String id = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ID); SubredditViewModel.Factory factory = new SubredditViewModel.Factory(getApplication(), id); mSubredditViewModel = ViewModelProviders.of(this, factory).get(SubredditViewModel.class); mSubredditViewModel.getSubredditLiveData().observe(this, new Observer<SubredditData>() { |