aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-07-29 16:30:45 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-07-29 16:30:45 +0000
commitf07f01ce63eb24d86be6969f1d56548a8dd93c8c (patch)
tree15e6ab489417791b3b0b2939fa4cb11fa047ad51 /app/src/main
parent453501b1ba4fd32458abe4b5a008130f74a86ff3 (diff)
downloadinfinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar.gz
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar.bz2
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar.lz
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar.xz
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.tar.zst
infinity-for-reddit-f07f01ce63eb24d86be6969f1d56548a8dd93c8c.zip
Display both the subreddit and the user name in ViewPostDetailActivity.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java6
-rw-r--r--app/src/main/res/layout/item_post_detail.xml27
5 files changed, 58 insertions, 25 deletions
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<RecyclerVie
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
}
if(holder.getAdapterPosition() >= 0) {
@@ -188,11 +188,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
}
} else {
if(mPost.getSubredditIconUrl() == null) {
@@ -207,11 +207,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
}
mPost.setSubredditIconUrl(iconImageUrl);
@@ -223,11 +223,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ .into(((PostDetailViewHolder) holder).mIconGifImageView);
}
}
@@ -260,6 +260,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
((PostDetailViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
+ ((PostDetailViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed());
((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime());
@@ -643,9 +644,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
class PostDetailViewHolder extends RecyclerView.ViewHolder {
- @BindView(R.id.subreddit_icon_name_linear_layout_item_post_detail) LinearLayout mSubredditIconNameLinearLayout;
- @BindView(R.id.subreddit_icon_gif_image_view_item_post_detail) AspectRatioGifImageView mSubredditIconGifImageView;
+ @BindView(R.id.icon_gif_image_view_item_post_detail) AspectRatioGifImageView mIconGifImageView;
@BindView(R.id.subreddit_text_view_item_post_detail) TextView mSubredditTextView;
+ @BindView(R.id.user_text_view_item_post_detail) TextView mUserTextView;
@BindView(R.id.post_time_text_view_item_post_detail) TextView mPostTimeTextView;
@BindView(R.id.title_text_view_item_post_detail) TextView mTitleTextView;
@BindView(R.id.content_markdown_view_item_post_detail) CustomMarkwonView mContentMarkdownView;
@@ -673,7 +674,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
super(itemView);
ButterKnife.bind(this, itemView);
- mSubredditIconNameLinearLayout.setOnClickListener(view -> {
+ 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<RecyclerVie
mActivity.startActivity(intent);
});
+ mUserTextView.setOnClickListener(view -> {
+ 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<Post, RecyclerView.ViewHo
private UserDao userDao;
private boolean canStartActivity = true;
private int postType;
+ private boolean displaySubredditName;
private static final int VIEW_TYPE_DATA = 0;
private static final int VIEW_TYPE_ERROR = 1;
@@ -78,13 +79,14 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, SharedPreferences sharedPreferences, int postType,
- RetryLoadingMoreCallback retryLoadingMoreCallback) {
+ boolean displaySubredditName, RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
if(context != null) {
mContext = context;
mOauthRetrofit = oauthRetrofit;
mSharedPreferences = sharedPreferences;
this.postType = postType;
+ this.displaySubredditName = displaySubredditName;
glide = Glide.with(mContext.getApplicationContext());
subredditDao = SubredditRoomDatabase.getDatabase(mContext.getApplicationContext()).subredditDao();
userDao = UserRoomDatabase.getDatabase(mContext.getApplicationContext()).userDao();
@@ -154,7 +156,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
});
- if(postType != PostDataSource.TYPE_SUBREDDIT) {
+ if(displaySubredditName) {
if(author.equals(subredditNamePrefixed)) {
if(post.getAuthorIconUrl() == null) {
new LoadUserDataAsyncTask(userDao, post.getAuthor(), mOauthRetrofit, iconImageUrl -> {
diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml
index fade8588..7d85466f 100644
--- a/app/src/main/res/layout/item_post_detail.xml
+++ b/app/src/main/res/layout/item_post_detail.xml
@@ -14,8 +14,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <LinearLayout
- android:id="@+id/subreddit_icon_name_linear_layout_item_post_detail"
+ <RelativeLayout
+ android:id="@+id/subreddit_icon_name_relative_layout_item_post_detail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="16dp"
@@ -26,20 +26,31 @@
app:layout_constraintTop_toTopOf="parent">
<CustomView.AspectRatioGifImageView
- android:id="@+id/subreddit_icon_gif_image_view_item_post_detail"
+ android:id="@+id/icon_gif_image_view_item_post_detail"
android:layout_width="24dp"
android:layout_height="24dp"
- android:layout_gravity="center"/>
+ android:layout_centerVertical="true" />
<TextView
android:id="@+id/subreddit_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
- android:layout_gravity="center"
- android:textColor="#E91E63" />
+ android:layout_alignParentTop="true"
+ android:layout_toEndOf="@id/icon_gif_image_view_item_post_detail"
+ android:textColor="@color/colorAccent" />
- </LinearLayout>
+ <TextView
+ android:id="@+id/user_text_view_item_post_detail"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_alignParentBottom="true"
+ android:layout_below="@id/subreddit_text_view_item_post_detail"
+ android:layout_toEndOf="@id/icon_gif_image_view_item_post_detail"
+ android:textColor="@color/textColorPrimaryDark" />
+
+ </RelativeLayout>
<TextView
android:id="@+id/post_time_text_view_item_post_detail"
@@ -48,7 +59,7 @@
android:layout_gravity="center"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toEndOf="@id/subreddit_icon_name_linear_layout_item_post_detail"
+ app:layout_constraintStart_toEndOf="@id/subreddit_icon_name_relative_layout_item_post_detail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>