mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-06 18:57:26 +01:00
Fix loading community and user images
This commit resolves two issues: 1. Loading community icons on the homepage sometimes showed the wrong community icon 2. Loading user avatars failed before when tried them in the comments
This commit is contained in:
parent
2020172b56
commit
a8d63c7480
@ -392,12 +392,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
if (authorName.equals(comment.getAuthorQualifiedName())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
|
||||
Comment currentComment = getCurrentComment(holder);
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthor())) {
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthorQualifiedName())) {
|
||||
mGlide.load(iconUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@ -537,12 +537,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
if (authorName.equals(comment.getAuthorQualifiedName())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
|
||||
Comment currentComment = getCurrentComment(holder);
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthor())) {
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthorQualifiedName())) {
|
||||
mGlide.load(iconUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||
|
@ -98,6 +98,7 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import eu.toldi.infinityforlemmy.videoautoplay.CacheManager;
|
||||
@ -475,8 +476,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
((PostDetailBaseViewHolder) holder).mTitleTextView.setText(mPost.getTitle());
|
||||
if (mPost.getSubredditNamePrefixed().startsWith("u/")) {
|
||||
if (mPost.getAuthorIconUrl() == null) {
|
||||
String authorName = mPost.isAuthorDeleted() ? mPost.getSubredditNamePrefixed().substring(2) : mPost.getAuthor();
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mOauthRetrofit, iconImageUrl -> {
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, LemmyUtils.qualifiedUserName2ActorId(mPost.getAuthorNamePrefixed()), mOauthRetrofit, iconImageUrl -> {
|
||||
if (mActivity != null && getItemCount() > 0) {
|
||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
|
@ -574,7 +574,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
} else {
|
||||
if (post.getSubredditIconUrl() == null) {
|
||||
mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(post.getSubredditNamePrefixed(), true, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@ -1141,7 +1141,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
} else {
|
||||
if (post.getSubredditIconUrl() == null) {
|
||||
mFragment.loadIcon(subredditName, true, (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(subredditNamePrefixed, true, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && subredditName.equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
|
@ -9,6 +9,7 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditDao;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class LoadSubredditIcon {
|
||||
@ -18,9 +19,9 @@ public class LoadSubredditIcon {
|
||||
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
|
||||
executor.execute(() -> {
|
||||
SubredditDao subredditDao = redditDataRoomDatabase.subredditDao();
|
||||
SubredditData subredditData = subredditDao.getSubredditData(subredditName);
|
||||
SubredditData subredditData = subredditDao.getSubredditDataByActorId(LemmyUtils.qualifiedCommunityName2ActorId(subredditName));
|
||||
if (subredditData != null) {
|
||||
String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
|
||||
String iconImageUrl = subredditDao.getSubredditDataByActorId(LemmyUtils.qualifiedCommunityName2ActorId(subredditName)).getIconUrl();
|
||||
handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
|
@ -8,6 +8,7 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.user.FetchUserData;
|
||||
import eu.toldi.infinityforlemmy.user.UserDao;
|
||||
import eu.toldi.infinityforlemmy.user.UserData;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class LoadUserData {
|
||||
@ -16,8 +17,9 @@ public class LoadUserData {
|
||||
Retrofit retrofit, LoadUserDataAsyncTaskListener loadUserDataAsyncTaskListener) {
|
||||
executor.execute(() -> {
|
||||
UserDao userDao = redditDataRoomDatabase.userDao();
|
||||
if (userDao.getUserData(userName) != null) {
|
||||
String iconImageUrl = userDao.getUserData(userName).getIconUrl();
|
||||
UserData userData= userDao.getUserDataByActorId(LemmyUtils.qualifiedUserName2ActorId(userName));
|
||||
if (userData != null) {
|
||||
String iconImageUrl = userData.getIconUrl();
|
||||
handler.post(() -> loadUserDataAsyncTaskListener.loadUserDataSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchUserData.fetchUserData(retrofit, userName, new FetchUserData.FetchUserDataListener() {
|
||||
|
@ -285,6 +285,12 @@ public class ParseComment {
|
||||
String author = creatorObj.getString("name");
|
||||
String authorQualifiedName = LemmyUtils.actorID2FullName(creatorObj.getString("actor_id"));
|
||||
String linkAuthor = creatorObj.getString("actor_id");
|
||||
|
||||
|
||||
String authorAvatar = null;
|
||||
if(creatorObj.has("avatar")){
|
||||
authorAvatar = creatorObj.getString("avatar");
|
||||
}
|
||||
long commentTimeMillis = 0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
commentTimeMillis = ZonedDateTime.parse(commentObj.getString("published"),
|
||||
@ -335,6 +341,7 @@ public class ParseComment {
|
||||
score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, deleted, edited, path);
|
||||
int child_count = countsObj.getInt("child_count");
|
||||
comment.setChildCount(child_count);
|
||||
comment.setAuthorIconUrl(authorAvatar);
|
||||
return comment;
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,7 @@ import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.post.PostViewModel;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import eu.toldi.infinityforlemmy.videoautoplay.ExoCreator;
|
||||
@ -1756,7 +1757,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
|
||||
});
|
||||
} else {
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditOrUserName,
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, LemmyUtils.qualifiedUserName2ActorId(subredditOrUserName),
|
||||
mRetrofit.getRetrofit(), iconImageUrl -> {
|
||||
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
|
||||
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
|
||||
|
@ -114,6 +114,7 @@ import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import eu.toldi.infinityforlemmy.videoautoplay.ExoCreator;
|
||||
|
@ -213,6 +213,8 @@ public class ParsePost {
|
||||
|
||||
|
||||
String url = (!data.getJSONObject("post").isNull("url")) ? data.getJSONObject("post").getString("url") : "";
|
||||
String communityURL = (!data.getJSONObject("community").isNull("icon")) ? data.getJSONObject("community").getString("icon") : "";
|
||||
|
||||
Uri uri = Uri.parse(url);
|
||||
String path = uri.getPath();
|
||||
boolean isVideo = path.endsWith(".mp4") || path.endsWith(".webm") || path.endsWith(".gifv");
|
||||
@ -660,6 +662,7 @@ public class ParsePost {
|
||||
post.setSelfTextPlain(body);
|
||||
post.setSelfTextPlainTrimmed(body.trim());
|
||||
}
|
||||
post.setSubredditIconUrl(communityURL);
|
||||
return post;
|
||||
}
|
||||
|
||||
|
@ -22,4 +22,7 @@ public interface SubredditDao {
|
||||
|
||||
@Query("SELECT * from subreddits WHERE name = :namePrefixed COLLATE NOCASE LIMIT 1")
|
||||
SubredditData getSubredditData(String namePrefixed);
|
||||
|
||||
@Query("SELECT * from subreddits WHERE actor_id = :actorId COLLATE NOCASE LIMIT 1")
|
||||
SubredditData getSubredditDataByActorId(String actorId);
|
||||
}
|
||||
|
@ -25,4 +25,7 @@ public interface UserDao {
|
||||
|
||||
@Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
||||
UserData getUserData(String userName);
|
||||
|
||||
@Query("SELECT * FROM users WHERE actor_id = :actorId COLLATE NOCASE LIMIT 1")
|
||||
UserData getUserDataByActorId(String actorId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user