mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 12:57:12 +01:00
Use PostFragment to handle loading subreddit or user icons for PostRecyclerViewAdapter.
This commit is contained in:
parent
01304ee7dc
commit
56d82d133f
@ -75,7 +75,6 @@ import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
|
|||||||
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
||||||
import ml.docilealligator.infinityforreddit.SaveThing;
|
import ml.docilealligator.infinityforreddit.SaveThing;
|
||||||
import ml.docilealligator.infinityforreddit.VoteThing;
|
import ml.docilealligator.infinityforreddit.VoteThing;
|
||||||
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
|
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
|
||||||
@ -86,8 +85,6 @@ import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity
|
|||||||
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
|
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity;
|
import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
|
import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
|
||||||
@ -134,13 +131,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private SharedPreferences mSharedPreferences;
|
private SharedPreferences mSharedPreferences;
|
||||||
private Executor mExecutor;
|
private Executor mExecutor;
|
||||||
private Retrofit mOauthRetrofit;
|
private Retrofit mOauthRetrofit;
|
||||||
private Retrofit mRetrofit;
|
|
||||||
private Retrofit mGfycatRetrofit;
|
private Retrofit mGfycatRetrofit;
|
||||||
private Retrofit mRedgifsRetrofit;
|
private Retrofit mRedgifsRetrofit;
|
||||||
private int mImageViewWidth;
|
private int mImageViewWidth;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
|
||||||
private Locale mLocale;
|
private Locale mLocale;
|
||||||
private boolean canStartActivity = true;
|
private boolean canStartActivity = true;
|
||||||
private int mPostType;
|
private int mPostType;
|
||||||
@ -218,9 +213,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private ExoCreator mExoCreator;
|
private ExoCreator mExoCreator;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
|
||||||
public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit, Retrofit retrofit,
|
public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit,
|
||||||
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
|
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
|
||||||
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth,
|
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth,
|
||||||
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
|
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences,
|
||||||
@ -233,7 +227,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mSharedPreferences = sharedPreferences;
|
mSharedPreferences = sharedPreferences;
|
||||||
mExecutor = executor;
|
mExecutor = executor;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRetrofit = retrofit;
|
|
||||||
mGfycatRetrofit = gfycatRetrofit;
|
mGfycatRetrofit = gfycatRetrofit;
|
||||||
mRedgifsRetrofit = redgifsRetrofit;
|
mRedgifsRetrofit = redgifsRetrofit;
|
||||||
mImageViewWidth = imageViewWidth;
|
mImageViewWidth = imageViewWidth;
|
||||||
@ -337,7 +330,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
mScale = resources.getDisplayMetrics().density;
|
mScale = resources.getDisplayMetrics().density;
|
||||||
mGlide = Glide.with(mActivity);
|
mGlide = Glide.with(mActivity);
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mExoCreator = exoCreator;
|
mExoCreator = exoCreator;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
@ -500,32 +492,27 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
((PostBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
|
((PostBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
|
||||||
}
|
}
|
||||||
String subredditNamePrefixed = post.getSubredditNamePrefixed();
|
|
||||||
String subredditName = subredditNamePrefixed.substring(2);
|
|
||||||
String authorPrefixed = "u/" + post.getAuthor();
|
String authorPrefixed = "u/" + post.getAuthor();
|
||||||
String flair = post.getFlair();
|
|
||||||
int nAwards = post.getNAwards();
|
|
||||||
|
|
||||||
if (mHideSubredditAndUserPrefix) {
|
if (mHideSubredditAndUserPrefix) {
|
||||||
((PostBaseViewHolder) holder).subredditTextView.setText(subredditName);
|
((PostBaseViewHolder) holder).subredditTextView.setText(post.getSubredditName());
|
||||||
((PostBaseViewHolder) holder).userTextView.setText(post.getAuthor());
|
((PostBaseViewHolder) holder).userTextView.setText(post.getAuthor());
|
||||||
} else {
|
} else {
|
||||||
((PostBaseViewHolder) holder).subredditTextView.setText(subredditNamePrefixed);
|
((PostBaseViewHolder) holder).subredditTextView.setText(post.getSubredditNamePrefixed());
|
||||||
((PostBaseViewHolder) holder).userTextView.setText(authorPrefixed);
|
((PostBaseViewHolder) holder).userTextView.setText(authorPrefixed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDisplaySubredditName) {
|
if (mDisplaySubredditName) {
|
||||||
if (authorPrefixed.equals(subredditNamePrefixed)) {
|
if (authorPrefixed.equals(post.getSubredditNamePrefixed())) {
|
||||||
if (post.getAuthorIconUrl() == null) {
|
if (post.getAuthorIconUrl() == null) {
|
||||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, post.getAuthor(),
|
mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> {
|
||||||
mRetrofit, iconImageUrl -> {
|
if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
if (iconUrl == null || iconUrl.equals("")) {
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -533,7 +520,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setAuthorIconUrl(iconImageUrl);
|
post.setAuthorIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -550,16 +537,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (post.getSubredditIconUrl() == null) {
|
if (post.getSubredditIconUrl() == null) {
|
||||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> {
|
||||||
subredditName, mRetrofit,
|
if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) {
|
||||||
iconImageUrl -> {
|
if (iconUrl == null || iconUrl.equals("")) {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -567,7 +552,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setSubredditIconUrl(iconImageUrl);
|
post.setSubredditIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -586,14 +571,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
} else {
|
} else {
|
||||||
if (post.getAuthorIconUrl() == null) {
|
if (post.getAuthorIconUrl() == null) {
|
||||||
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor();
|
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor();
|
||||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mRetrofit, iconImageUrl -> {
|
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
if (mActivity != null && getItemCount() > 0) {
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) {
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
.into(((PostBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -601,7 +586,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setAuthorIconUrl(iconImageUrl);
|
post.setAuthorIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -644,21 +629,21 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
((PostBaseViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE);
|
((PostBaseViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flair != null && !flair.equals("")) {
|
if (post.getFlair() != null && !post.getFlair().equals("")) {
|
||||||
if (mHidePostFlair) {
|
if (mHidePostFlair) {
|
||||||
((PostBaseViewHolder) holder).flairTextView.setVisibility(View.GONE);
|
((PostBaseViewHolder) holder).flairTextView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
((PostBaseViewHolder) holder).flairTextView.setVisibility(View.VISIBLE);
|
((PostBaseViewHolder) holder).flairTextView.setVisibility(View.VISIBLE);
|
||||||
Utils.setHTMLWithImageToTextView(((PostBaseViewHolder) holder).flairTextView, flair, false);
|
Utils.setHTMLWithImageToTextView(((PostBaseViewHolder) holder).flairTextView, post.getFlair(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nAwards > 0 && !mHideTheNumberOfAwards) {
|
if (post.getNAwards() > 0 && !mHideTheNumberOfAwards) {
|
||||||
((PostBaseViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
((PostBaseViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
||||||
if (nAwards == 1) {
|
if (post.getNAwards() == 1) {
|
||||||
((PostBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.one_award));
|
((PostBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.one_award));
|
||||||
} else {
|
} else {
|
||||||
((PostBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.n_awards, nAwards));
|
((PostBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.n_awards, post.getNAwards()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1011,14 +996,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
if (mDisplaySubredditName) {
|
if (mDisplaySubredditName) {
|
||||||
if (authorPrefixed.equals(subredditNamePrefixed)) {
|
if (authorPrefixed.equals(subredditNamePrefixed)) {
|
||||||
if (post.getAuthorIconUrl() == null) {
|
if (post.getAuthorIconUrl() == null) {
|
||||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, post.getAuthor(), mRetrofit, iconImageUrl -> {
|
mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) {
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
if (iconUrl == null || iconUrl.equals("")) {
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -1026,7 +1011,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setAuthorIconUrl(iconImageUrl);
|
post.setAuthorIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1043,16 +1028,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (post.getSubredditIconUrl() == null) {
|
if (post.getSubredditIconUrl() == null) {
|
||||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
mFragment.loadIcon(subredditName, true, (subredditOrUserName, iconUrl) -> {
|
||||||
subredditName, mRetrofit,
|
if (mActivity != null && getItemCount() > 0 && subredditName.equals(subredditOrUserName)) {
|
||||||
iconImageUrl -> {
|
if (iconUrl == null || iconUrl.equals("")) {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -1060,7 +1043,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setSubredditIconUrl(iconImageUrl);
|
post.setSubredditIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1085,15 +1068,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (post.getAuthorIconUrl() == null) {
|
if (post.getAuthorIconUrl() == null) {
|
||||||
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor();
|
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
|
||||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mRetrofit, iconImageUrl -> {
|
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
|
||||||
if (mActivity != null && getItemCount() > 0) {
|
if (mActivity != null && getItemCount() > 0 && authorName.equals(subredditOrUserName)) {
|
||||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
if (iconUrl == null || iconUrl.equals("")) {
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
.into(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
mGlide.load(iconImageUrl)
|
mGlide.load(iconUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
@ -1101,7 +1084,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getBindingAdapterPosition() >= 0) {
|
if (holder.getBindingAdapterPosition() >= 0) {
|
||||||
post.setAuthorIconUrl(iconImageUrl);
|
post.setAuthorIconUrl(iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -53,7 +53,9 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@ -79,6 +81,8 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
|||||||
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
|
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter;
|
||||||
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon;
|
||||||
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
|
import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
|
||||||
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
|
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
|
||||||
@ -246,6 +250,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private ItemTouchHelper touchHelper;
|
private ItemTouchHelper touchHelper;
|
||||||
private ArrayList<ReadPost> readPosts;
|
private ArrayList<ReadPost> readPosts;
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
private Map<String, String> subredditOrUserIcons = new HashMap<>();
|
||||||
|
|
||||||
public PostFragment() {
|
public PostFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@ -444,8 +449,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, true,
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -526,8 +531,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort));
|
sortType = new SortType(SortType.Type.valueOf(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName,
|
windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -602,8 +607,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort));
|
sortType = new SortType(SortType.Type.valueOf(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, true,
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -672,8 +677,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, true,
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -738,8 +743,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, true,
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -797,8 +802,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mCustomThemeWrapper, locale,
|
||||||
windowWidth, accessToken, accountName, postType, postLayout, true,
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -1578,6 +1583,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadIcon(String subredditOrUserName, boolean isSubreddit, LoadIconListener loadIconListener) {
|
||||||
|
if (subredditOrUserIcons.containsKey(subredditOrUserName)) {
|
||||||
|
loadIconListener.loadIconSuccess(subredditOrUserName, subredditOrUserIcons.get(subredditOrUserName));
|
||||||
|
} else {
|
||||||
|
if (isSubreddit) {
|
||||||
|
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
|
subredditOrUserName, mRetrofit,
|
||||||
|
iconImageUrl -> {
|
||||||
|
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
|
||||||
|
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditOrUserName,
|
||||||
|
mRetrofit, iconImageUrl -> {
|
||||||
|
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
|
||||||
|
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
|
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
|
||||||
PagedList<Post> posts = mAdapter.getCurrentList();
|
PagedList<Post> posts = mAdapter.getCurrentList();
|
||||||
@ -2048,4 +2074,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface LoadIconListener {
|
||||||
|
void loadIconSuccess(String subredditOrUserName, String iconUrl);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user