From f07f01ce63eb24d86be6969f1d56548a8dd93c8c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 30 Jul 2019 00:30:45 +0800 Subject: Display both the subreddit and the user name in ViewPostDetailActivity. --- .../CommentAndPostRecyclerViewAdapter.java | 31 ++++++++++++++-------- .../ml/docilealligator/infinityforreddit/Post.java | 10 +++++++ .../infinityforreddit/PostFragment.java | 9 ++++--- .../infinityforreddit/PostRecyclerViewAdapter.java | 6 +++-- 4 files changed, 39 insertions(+), 17 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index d6af8c03..d3f4c9ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -171,11 +171,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0) { @@ -188,11 +188,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + mIconGifImageView.setOnClickListener(view -> mSubredditTextView.performClick()); + + mSubredditTextView.setOnClickListener(view -> { Intent intent; if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) { intent = new Intent(mActivity, ViewUserDetailActivity.class); @@ -686,6 +689,12 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mPost.getAuthor()); + mActivity.startActivity(intent); + }); + mShareButton.setOnClickListener(view -> { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 71847ae5..f6159533 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -20,6 +20,7 @@ class Post implements Parcelable { private String subredditNamePrefixed; private String subredditIconUrl; private String author; + private String authorNamePrefixed; private String authorIconUrl; private String postTime; private String title; @@ -51,6 +52,7 @@ class Post implements Parcelable { this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; + this.authorNamePrefixed = "u/" + author; this.postTime = postTime; this.title = title; this.previewUrl = previewUrl; @@ -75,6 +77,7 @@ class Post implements Parcelable { this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; + this.authorNamePrefixed = "u/" + author; this.postTime = postTime; this.title = title; this.previewUrl = previewUrl; @@ -98,6 +101,7 @@ class Post implements Parcelable { this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; + this.authorNamePrefixed = "u/" + author; this.postTime = postTime; this.title = title; this.permalink = RedditUtils.API_BASE_URI + permalink; @@ -118,6 +122,7 @@ class Post implements Parcelable { subredditNamePrefixed = in.readString(); subredditIconUrl = in.readString(); author = in.readString(); + authorNamePrefixed = in.readString(); authorIconUrl = in.readString(); postTime = in.readString(); title = in.readString(); @@ -178,6 +183,10 @@ class Post implements Parcelable { return author; } + String getAuthorNamePrefixed() { + return authorNamePrefixed; + } + String getAuthorIconUrl() { return authorIconUrl; } @@ -318,6 +327,7 @@ class Post implements Parcelable { parcel.writeString(subredditNamePrefixed); parcel.writeString(subredditIconUrl); parcel.writeString(author); + parcel.writeString(authorNamePrefixed); parcel.writeString(authorIconUrl); parcel.writeString(postTime); parcel.writeString(title); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index f78d00b6..60b42726 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -179,7 +179,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String query = getArguments().getString(EXTRA_QUERY); mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit, - mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore()); + mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore()); factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, getResources().getConfiguration().locale, subredditName, query, postType, sortType, new PostDataSource.OnPostFetchedCallback() { @Override @@ -198,8 +198,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else if(postType == PostDataSource.TYPE_SUBREDDIT) { String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME); + boolean displaySubredditName = subredditName.equals("popular"); mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit, - mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore()); + mSharedPreferences, postType, displaySubredditName, () -> mPostViewModel.retryLoadingMore()); factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, getResources().getConfiguration().locale, subredditName, postType, sortType, new PostDataSource.OnPostFetchedCallback() { @@ -224,7 +225,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME); mAdapter = new PostRecyclerViewAdapter(activity, mRetrofit, - mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore()); + mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore()); factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, getResources().getConfiguration().locale, subredditName, postType, sortType, @@ -244,7 +245,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { }); } else { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, - mSharedPreferences, postType, () -> mPostViewModel.retryLoadingMore()); + mSharedPreferences, postType, true, () -> mPostViewModel.retryLoadingMore()); factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, getResources().getConfiguration().locale, postType, sortType, new PostDataSource.OnPostFetchedCallback() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index ad6e59e3..2342fcd1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -65,6 +65,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter { -- cgit v1.2.3