Favorite anonymous multireddits.

This commit is contained in:
Alex Ning 2021-09-26 20:45:01 +08:00
parent 9a0067d714
commit 39835c587a
2 changed files with 113 additions and 76 deletions

View File

@ -25,6 +25,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider; import me.zhanghai.android.fastscroll.PopupTextProvider;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
@ -129,6 +130,12 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
if(multiReddit.isFavorite()) { if(multiReddit.isFavorite()) {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false); multiReddit.setFavorite(false);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, false, multiReddit, mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() { new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@ -152,9 +159,16 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} }
} }
); );
}
} else { } else {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true); multiReddit.setFavorite(true);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, true, multiReddit, mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() { new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@ -179,6 +193,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} }
); );
} }
}
}); });
holder.itemView.setOnClickListener(view -> { holder.itemView.setOnClickListener(view -> {
mOnItemClickListener.onClick(multiReddit); mOnItemClickListener.onClick(multiReddit);
@ -215,6 +230,12 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
if(multiReddit.isFavorite()) { if(multiReddit.isFavorite()) {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false); multiReddit.setFavorite(false);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, false, multiReddit, mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() { new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@ -238,9 +259,16 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} }
} }
); );
}
} else { } else {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true); multiReddit.setFavorite(true);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, true, multiReddit, mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() { new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@ -265,6 +293,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} }
); );
} }
}
}); });
holder.itemView.setOnClickListener(view -> { holder.itemView.setOnClickListener(view -> {
mOnItemClickListener.onClick(multiReddit); mOnItemClickListener.onClick(multiReddit);

View File

@ -50,4 +50,12 @@ public class FavoriteMultiReddit {
} }
}); });
} }
public static void anonymousFavoriteMultiReddit(Executor executor, Handler handler,
RedditDataRoomDatabase redditDataRoomDatabase,
MultiReddit multiReddit,
FavoriteMultiRedditListener favoriteMultiRedditListener) {
InsertMultireddit.insertMultireddit(executor, handler, redditDataRoomDatabase, multiReddit,
favoriteMultiRedditListener::success);
}
} }