diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index dfaad6f7..7bdc04b0 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 946bd4f8..4dd39fc5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,4 +56,5 @@ dependencies { implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.0' implementation 'org.sufficientlysecure:html-textview:3.6' + implementation 'com.squareup.retrofit2:retrofit:2.4.0' } 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 { 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 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 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(), 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() {