diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-12 14:05:12 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-12 14:05:12 +0000 |
commit | ee048b25dd0d2a412271a17e954619702dcfae53 (patch) | |
tree | eb377dd5ccfc18ee857a05f6d10cff77cac49520 /app/src/main/java/ml | |
parent | 6921d720d21eb2862d377cc0cd80f41e4150d6a9 (diff) | |
download | infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar.gz infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar.bz2 infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar.lz infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar.xz infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.tar.zst infinity-for-reddit-ee048b25dd0d2a412271a17e954619702dcfae53.zip |
Fix bugs related to favoriting multireddits. Add some fonts.
Diffstat (limited to 'app/src/main/java/ml')
7 files changed, 31 insertions, 18 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java index 4be79e91..51939d7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java @@ -125,7 +125,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, false, multiReddit, + mAccessToken, false, multiReddit, new FavoriteMultiReddit.FavoriteMultiRedditListener() { @Override public void success() { @@ -151,7 +151,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, true, multiReddit, + mAccessToken, true, multiReddit, new FavoriteMultiReddit.FavoriteMultiRedditListener() { @Override public void success() { @@ -213,7 +213,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, false, multiReddit, + mAccessToken, false, multiReddit, new FavoriteMultiReddit.FavoriteMultiRedditListener() { @Override public void success() { @@ -239,7 +239,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, true, multiReddit, + mAccessToken, true, multiReddit, new FavoriteMultiReddit.FavoriteMultiRedditListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java index 2c15fa33..2c49eccb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.AsyncTask; import android.os.AsyncTask; -import android.util.Log; import java.util.ArrayList; import java.util.Collections; @@ -14,6 +13,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> { private MultiRedditDao multiRedditDao; private ArrayList<MultiReddit> multiReddits; + private MultiReddit multiReddit; private String accountName; private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener; @@ -26,15 +26,27 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> { this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener; } + public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, + MultiReddit multiReddit, + InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) { + multiRedditDao = redditDataRoomDatabase.multiRedditDao(); + this.multiReddit = multiReddit; + this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener; + } + @Override protected Void doInBackground(Void... voids) { + if (multiReddit != null) { + multiRedditDao.insert(multiReddit); + return null; + } + List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName); Collections.sort(multiReddits, (multiReddit, t1) -> multiReddit.getName().compareToIgnoreCase(t1.getName())); List<String> deletedMultiredditNames = new ArrayList<>(); compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames); for (String deleted : deletedMultiredditNames) { - Log.i("asdfasdfs", "s " + deleted + accountName); multiRedditDao.deleteMultiReddit(deleted, accountName); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java index 8b43545f..cad7a532 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java @@ -9,7 +9,9 @@ public enum ContentFontFamily { RobotoCondensed(R.style.ContentFontFamily_RobotoCondensed, "RobotoCondensed"), HarmoniaSans(R.style.ContentFontFamily_HarmoniaSans, "HarmoniaSans"), Selawk(R.style.ContentFontFamily_Selawk, "Selawk"), - Inter(R.style.ContentFontFamily_Inter, "Inter"); + Inter(R.style.ContentFontFamily_Inter, "Inter"), + Manrope(R.style.ContentFontFamily_Manrope, "Manrope"), + Rubik(R.style.ContentFontFamily_Rubik, "Rubik"); private int resId; private String title; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java index 40540060..88e89660 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java @@ -9,7 +9,9 @@ public enum FontFamily { RobotoCondensed(R.style.FontFamily_RobotoCondensed, "RobotoCondensed"), HarmoniaSans(R.style.FontFamily_HarmoniaSans, "HarmoniaSans"), Selawk(R.style.FontFamily_Selawk, "Selawk"), - Inter(R.style.FontFamily_Inter, "Inter"); + Inter(R.style.FontFamily_Inter, "Inter"), + Manrope(R.style.FontFamily_Manrope, "Manrope"), + Rubik(R.style.FontFamily_Rubik, "Rubik"); private int resId; private String title; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java index 9e348bec..17ebf3bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java @@ -9,7 +9,9 @@ public enum TitleFontFamily { RobotoCondensed(R.style.TitleFontFamily_RobotoCondensed, "RobotoCondensed"), HarmoniaSans(R.style.TitleFontFamily_HarmoniaSans, "HarmoniaSans"), Selawk(R.style.TitleFontFamily_Selawk, "Selawk"), - Inter(R.style.TitleFontFamily_Inter, "Inter"); + Inter(R.style.TitleFontFamily_Inter, "Inter"), + Manrope(R.style.TitleFontFamily_Manrope, "Manrope"), + Rubik(R.style.TitleFontFamily_Rubik, "Rubik"); private int resId; private String title; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java index 89311f15..1a58e526 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java @@ -49,7 +49,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm public static final String EXTRA_ACCOUNT_NAME = "EAN"; public static final String EXTRA_ACCESS_TOKEN = "EAT"; - private static final String INSERT_MULTI_REDDIT_STATE = "ISSS"; @BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment) SwipeRefreshLayout mSwipeRefreshLayout; @@ -78,7 +77,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm private AppCompatActivity mActivity; private RequestManager mGlide; private LinearLayoutManager mLinearLayoutManager; - private boolean mInsertSuccess = false; public MultiRedditListingFragment() { // Required empty public constructor 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 54142d08..8c976245 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java @@ -2,12 +2,11 @@ package ml.docilealligator.infinityforreddit.MultiReddit; import androidx.annotation.NonNull; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.API.RedditAPI; +import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.APIUtils; import retrofit2.Call; @@ -22,7 +21,7 @@ public class FavoriteMultiReddit { } public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, String accountName, boolean makeFavorite, + String accessToken, boolean makeFavorite, MultiReddit multiReddit, FavoriteMultiRedditListener favoriteMultiRedditListener) { Map<String, String> params = new HashMap<>(); params.put(APIUtils.MULTIPATH_KEY, multiReddit.getPath()); @@ -33,10 +32,8 @@ public class FavoriteMultiReddit { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { - multiReddit.setFavorite(true); - ArrayList<MultiReddit> singleMultiRedditList = new ArrayList<>(); - singleMultiRedditList.add(multiReddit); - new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList, accountName, + multiReddit.setFavorite(makeFavorite); + new InsertMultiRedditAsyncTask(redditDataRoomDatabase, multiReddit, favoriteMultiRedditListener::success).execute(); } else { favoriteMultiRedditListener.failed(); |