diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-09-26 12:45:01 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-09-26 12:45:01 +0000 |
commit | 39835c587abab4cdfe08d30a9546b8df1fb2ed26 (patch) | |
tree | e0feebd443eee705947fa3917c4cee54bd7deb18 | |
parent | 9a0067d71407a840f3db68cf2c7bb6b1150ea117 (diff) | |
download | infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar.gz infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar.bz2 infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar.lz infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar.xz infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.tar.zst infinity-for-reddit-39835c587abab4cdfe08d30a9546b8df1fb2ed26.zip |
Favorite anonymous multireddits.
Diffstat (limited to '')
2 files changed, 113 insertions, 76 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java index 038f1744..bb8f1420 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java @@ -25,6 +25,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -129,55 +130,69 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(multiReddit.isFavorite()) { ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); - FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, false, multiReddit, - new FavoriteMultiReddit.FavoriteMultiRedditListener() { - @Override - public void success() { - int position = holder.getBindingAdapterPosition() - offset; - if(position >= 0 && mMultiReddits.size() > position) { - mMultiReddits.get(position).setFavorite(false); + if (mAccessToken == null) { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, + () -> { + //Do nothing + }); + } else { + FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, false, multiReddit, + new FavoriteMultiReddit.FavoriteMultiRedditListener() { + @Override + public void success() { + int position = holder.getBindingAdapterPosition() - offset; + if(position >= 0 && mMultiReddits.size() > position) { + mMultiReddits.get(position).setFavorite(false); + } + ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); - } - @Override - public void failed() { - Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); - int position = holder.getBindingAdapterPosition() - offset; - if(position >= 0 && mMultiReddits.size() > position) { - mMultiReddits.get(position).setFavorite(true); + @Override + public void failed() { + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + int position = holder.getBindingAdapterPosition() - offset; + if(position >= 0 && mMultiReddits.size() > position) { + mMultiReddits.get(position).setFavorite(true); + } + ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - } - ); + ); + } } else { ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); - FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, true, multiReddit, - new FavoriteMultiReddit.FavoriteMultiRedditListener() { - @Override - public void success() { - int position = holder.getBindingAdapterPosition() - offset; - if(position >= 0 && mMultiReddits.size() > position) { - mMultiReddits.get(position).setFavorite(true); + if (mAccessToken == null) { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, + () -> { + //Do nothing + }); + } else { + FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, true, multiReddit, + new FavoriteMultiReddit.FavoriteMultiRedditListener() { + @Override + public void success() { + int position = holder.getBindingAdapterPosition() - offset; + if(position >= 0 && mMultiReddits.size() > position) { + mMultiReddits.get(position).setFavorite(true); + } + ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); - } - @Override - public void failed() { - Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); - int position = holder.getBindingAdapterPosition() - offset; - if(position >= 0 && mMultiReddits.size() > position) { - mMultiReddits.get(position).setFavorite(false); + @Override + public void failed() { + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + int position = holder.getBindingAdapterPosition() - offset; + if(position >= 0 && mMultiReddits.size() > position) { + mMultiReddits.get(position).setFavorite(false); + } + ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - } - ); + ); + } } }); holder.itemView.setOnClickListener(view -> { @@ -215,55 +230,69 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(multiReddit.isFavorite()) { ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); - FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, false, multiReddit, - new FavoriteMultiReddit.FavoriteMultiRedditListener() { - @Override - public void success() { - int position = holder.getBindingAdapterPosition() - 1; - if(position >= 0 && mFavoriteMultiReddits.size() > position) { - mFavoriteMultiReddits.get(position).setFavorite(false); + if (mAccessToken == null) { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, + () -> { + //Do nothing + }); + } else { + FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, false, multiReddit, + new FavoriteMultiReddit.FavoriteMultiRedditListener() { + @Override + public void success() { + int position = holder.getBindingAdapterPosition() - 1; + if(position >= 0 && mFavoriteMultiReddits.size() > position) { + mFavoriteMultiReddits.get(position).setFavorite(false); + } + ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); - } - @Override - public void failed() { - Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); - int position = holder.getBindingAdapterPosition() - 1; - if(position >= 0 && mFavoriteMultiReddits.size() > position) { - mFavoriteMultiReddits.get(position).setFavorite(true); + @Override + public void failed() { + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + int position = holder.getBindingAdapterPosition() - 1; + if(position >= 0 && mFavoriteMultiReddits.size() > position) { + mFavoriteMultiReddits.get(position).setFavorite(true); + } + ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - } - ); + ); + } } else { ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); - FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, true, multiReddit, - new FavoriteMultiReddit.FavoriteMultiRedditListener() { - @Override - public void success() { - int position = holder.getBindingAdapterPosition() - 1; - if(position >= 0 && mFavoriteMultiReddits.size() > position) { - mFavoriteMultiReddits.get(position).setFavorite(true); + if (mAccessToken == null) { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, + () -> { + //Do nothing + }); + } else { + FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, true, multiReddit, + new FavoriteMultiReddit.FavoriteMultiRedditListener() { + @Override + public void success() { + int position = holder.getBindingAdapterPosition() - 1; + if(position >= 0 && mFavoriteMultiReddits.size() > position) { + mFavoriteMultiReddits.get(position).setFavorite(true); + } + ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); - } - @Override - public void failed() { - Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); - int position = holder.getBindingAdapterPosition() - 1; - if(position >= 0 && mFavoriteMultiReddits.size() > position) { - mFavoriteMultiReddits.get(position).setFavorite(false); + @Override + public void failed() { + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + int position = holder.getBindingAdapterPosition() - 1; + if(position >= 0 && mFavoriteMultiReddits.size() > position) { + mFavoriteMultiReddits.get(position).setFavorite(false); + } + ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); } - } - ); + ); + } } }); holder.itemView.setOnClickListener(view -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java index 227b7665..53e1a980 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java @@ -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); + } } |