aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java87
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java90
2 files changed, 126 insertions, 51 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
index 8cc218b5..46987335 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
@@ -39,6 +39,7 @@ import java.util.Locale;
import CustomView.AspectRatioGifImageView;
import SubredditDatabase.SubredditRoomDatabase;
+import User.UserRoomDatabase;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation;
@@ -161,13 +162,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
if(holder.getItemViewType() == VIEW_TYPE_POST_DETAIL) {
((PostDetailViewHolder) holder).mTitleTextView.setText(mPost.getTitle());
- if(mPost.getSubredditIconUrl() == null) {
- if(mLoadSubredditIconAsyncTask != null) {
- mLoadSubredditIconAsyncTask.cancel(true);
- }
- mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
- SubredditRoomDatabase.getDatabase(mActivity).subredditDao(), mPost.getSubredditNamePrefixed().substring(2),
- iconImageUrl -> {
+ if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) {
+ if(mPost.getAuthorIconUrl() == null) {
+ new LoadUserDataAsyncTask(UserRoomDatabase.getDatabase(mActivity).userDao(), mPost.getAuthor(), mOauthRetrofit, iconImageUrl -> {
+ if(mActivity != null && getItemCount() > 0) {
if(!iconImageUrl.equals("")) {
mGlide.load(iconImageUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@@ -180,20 +178,57 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
.into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
}
- mPost.setSubredditIconUrl(iconImageUrl);
- });
-
- mLoadSubredditIconAsyncTask.execute();
- } else if(!mPost.getSubredditIconUrl().equals("")) {
- mGlide.load(mPost.getSubredditIconUrl())
- .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);
+ if(holder.getAdapterPosition() >= 0) {
+ mPost.setAuthorIconUrl(iconImageUrl);
+ }
+ }
+ }).execute();
+ } else if(!mPost.getAuthorIconUrl().equals("")) {
+ mGlide.load(mPost.getAuthorIconUrl())
+ .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);
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ }
} else {
- mGlide.load(R.drawable.subreddit_default_icon)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ if(mPost.getSubredditIconUrl() == null) {
+ if(mLoadSubredditIconAsyncTask != null) {
+ mLoadSubredditIconAsyncTask.cancel(true);
+ }
+ mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
+ SubredditRoomDatabase.getDatabase(mActivity).subredditDao(), mPost.getSubredditNamePrefixed().substring(2),
+ iconImageUrl -> {
+ if(!iconImageUrl.equals("")) {
+ mGlide.load(iconImageUrl)
+ .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);
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ }
+
+ mPost.setSubredditIconUrl(iconImageUrl);
+ });
+
+ mLoadSubredditIconAsyncTask.execute();
+ } else if(!mPost.getSubredditIconUrl().equals("")) {
+ mGlide.load(mPost.getSubredditIconUrl())
+ .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);
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView);
+ }
}
switch (mPost.getVoteType()) {
@@ -659,9 +694,15 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
ButterKnife.bind(this, itemView);
mSubredditIconNameLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
- intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY,
- mPost.getSubredditNamePrefixed().substring(2));
+ Intent intent;
+ if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) {
+ intent = new Intent(mActivity, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mPost.getAuthor());
+ } else {
+ intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY,
+ mPost.getSubredditNamePrefixed().substring(2));
+ }
mActivity.startActivity(intent);
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index bb63a905..09c87319 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -152,37 +152,71 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
if(postType != PostDataSource.TYPE_SUBREDDIT) {
- if(post.getSubredditIconUrl() == null) {
- new LoadSubredditIconAsyncTask(subredditDao, subredditName,
- iconImageUrl -> {
- if(mContext != null && getItemCount() > 0) {
- if(!iconImageUrl.equals("")) {
- glide.load(iconImageUrl)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .error(glide.load(R.drawable.subreddit_default_icon)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((DataViewHolder) holder).subredditIconGifImageView);
- } else {
- glide.load(R.drawable.subreddit_default_icon)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((DataViewHolder) holder).subredditIconGifImageView);
- }
+ if(author.equals(subredditNamePrefixed)) {
+ if(post.getAuthorIconUrl() == null) {
+ new LoadUserDataAsyncTask(userDao, post.getAuthor(), mOauthRetrofit, iconImageUrl -> {
+ if(mContext != null && getItemCount() > 0) {
+ if(!iconImageUrl.equals("")) {
+ glide.load(iconImageUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ }
- if(holder.getAdapterPosition() >= 0) {
- post.setSubredditIconUrl(iconImageUrl);
- }
+ if(holder.getAdapterPosition() >= 0) {
+ post.setAuthorIconUrl(iconImageUrl);
}
- }).execute();
- } else if(!post.getSubredditIconUrl().equals("")) {
- glide.load(post.getSubredditIconUrl())
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .error(glide.load(R.drawable.subreddit_default_icon)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(((DataViewHolder) holder).subredditIconGifImageView);
+ }
+ }).execute();
+ } else if(!post.getAuthorIconUrl().equals("")) {
+ glide.load(post.getAuthorIconUrl())
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ }
} else {
- glide.load(R.drawable.subreddit_default_icon)
- .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(((DataViewHolder) holder).subredditIconGifImageView);
+ if(post.getSubredditIconUrl() == null) {
+ new LoadSubredditIconAsyncTask(subredditDao, subredditName,
+ iconImageUrl -> {
+ if(mContext != null && getItemCount() > 0) {
+ if(!iconImageUrl.equals("")) {
+ glide.load(iconImageUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ }
+
+ if(holder.getAdapterPosition() >= 0) {
+ post.setSubredditIconUrl(iconImageUrl);
+ }
+ }
+ }).execute();
+ } else if(!post.getSubredditIconUrl().equals("")) {
+ glide.load(post.getSubredditIconUrl())
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ } else {
+ glide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(((DataViewHolder) holder).subredditIconGifImageView);
+ }
}
((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));