From 7ca511d3f18e6bb626db413d5d249da4502ef862 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 25 Jan 2021 00:08:07 +0800 Subject: [PATCH] Rewrite all the AsyncTasks in the asynctasks package using Executor and Handler. --- .../infinityforreddit/AppComponent.java | 6 + .../infinityforreddit/FavoriteThing.java | 41 +++-- .../infinityforreddit/WallpaperSetter.java | 10 +- .../CustomThemeListingActivity.java | 11 +- .../activities/LoginActivity.java | 14 +- .../activities/MainActivity.java | 8 +- .../MultiredditSelectionActivity.java | 8 +- .../activities/PostImageActivity.java | 7 +- .../activities/PostLinkActivity.java | 8 +- .../activities/PostTextActivity.java | 8 +- .../activities/PostVideoActivity.java | 8 +- .../activities/ReportActivity.java | 3 - .../activities/SearchResultActivity.java | 4 - .../SearchSubredditsResultActivity.java | 7 - .../activities/SelectUserFlairActivity.java | 6 - .../SendPrivateMessageActivity.java | 7 - .../activities/SettingsActivity.java | 7 - .../activities/SubmitCrosspostActivity.java | 8 +- .../SubredditMultiselectionActivity.java | 3 - .../SubredditSelectionActivity.java | 9 +- .../SubscribedThingListingActivity.java | 17 +- .../activities/ViewImageOrGifActivity.java | 121 +++++++------- .../activities/ViewImgurMediaActivity.java | 10 +- .../ViewMultiRedditDetailActivity.java | 3 +- .../activities/ViewPostDetailActivity.java | 4 +- .../ViewPrivateMessagesActivity.java | 14 +- .../activities/ViewRedditGalleryActivity.java | 10 +- .../ViewSubredditDetailActivity.java | 14 +- .../activities/ViewUserDetailActivity.java | 14 +- .../CommentAndPostRecyclerViewAdapter.java | 18 ++- .../FollowedUsersRecyclerViewAdapter.java | 22 ++- ...MultiRedditListingRecyclerViewAdapter.java | 14 +- .../adapters/PostRecyclerViewAdapter.java | 41 ++--- .../SubredditListingRecyclerViewAdapter.java | 16 +- ...bscribedSubredditsRecyclerViewAdapter.java | 19 ++- .../UserListingRecyclerViewAdapter.java | 25 +-- .../asynctasks/ChangeThemeName.java | 14 ++ .../asynctasks/ChangeThemeNameAsyncTask.java | 23 --- .../asynctasks/CheckIsFollowingUser.java | 31 ++++ .../CheckIsFollowingUserAsyncTask.java | 44 ------ .../CheckIsSubscribedToSubreddit.java | 32 ++++ ...CheckIsSubscribedToSubredditAsyncTask.java | 46 ------ .../asynctasks/DeleteAllPostLayouts.java | 44 ++++++ .../DeleteAllPostLayoutsAsyncTask.java | 57 ------- .../asynctasks/DeleteAllReadPosts.java | 23 +++ .../DeleteAllReadPostsAsyncTask.java | 33 ---- .../asynctasks/DeleteAllSortTypes.java | 46 ++++++ .../DeleteAllSortTypesAsyncTask.java | 58 ------- .../asynctasks/DeleteAllSubreddits.java | 22 +++ .../DeleteAllSubredditsAsyncTask.java | 33 ---- .../asynctasks/DeleteAllThemes.java | 30 ++++ .../asynctasks/DeleteAllThemesAsyncTask.java | 45 ------ .../asynctasks/DeleteAllUsers.java | 22 +++ .../asynctasks/DeleteAllUsersAsyncTask.java | 33 ---- .../DeleteMultiredditInDatabase.java | 23 +++ .../DeleteMultiredditInDatabaseAsyncTask.java | 37 ----- .../asynctasks/DeleteTheme.java | 32 ++++ .../asynctasks/DeleteThemeAsyncTask.java | 44 ------ .../InsertMultiRedditAsyncTask.java | 94 ----------- .../asynctasks/InsertMultireddit.java | 76 +++++++++ .../asynctasks/InsertSubredditData.java | 24 +++ .../InsertSubredditDataAsyncTask.java | 35 ---- ...cTask.java => InsertSubscribedThings.java} | 131 +++++++-------- .../asynctasks/InsertUserData.java | 25 +++ .../asynctasks/InsertUserDataAsyncTask.java | 36 ----- .../asynctasks/LoadSubredditIcon.java | 48 ++++++ .../LoadSubredditIconAsyncTask.java | 71 --------- .../asynctasks/LoadUserData.java | 42 +++++ .../asynctasks/LoadUserDataAsyncTask.java | 58 ------- .../asynctasks/ParseAndInsertNewAccount.java | 29 ++++ .../ParseAndInsertNewAccountAsyncTask.java | 50 ------ .../asynctasks/SaveBitmapImageToFile.java | 35 ++++ .../SaveBitmapImageToFileAsyncTask.java | 55 ------- .../asynctasks/SaveGIFToFile.java | 40 +++++ .../asynctasks/SaveGIFToFileAsyncTask.java | 59 ------- .../asynctasks/SetAsWallpaper.java | 77 +++++++++ .../asynctasks/SetAsWallpaperAsyncTask.java | 95 ----------- .../FollowedUsersListingFragment.java | 26 +-- .../fragments/MultiRedditListingFragment.java | 7 +- .../fragments/PostFragment.java | 10 +- .../fragments/SidebarFragment.java | 10 +- .../fragments/SubredditListingFragment.java | 16 +- .../SubscribedSubredditsListingFragment.java | 24 +-- .../fragments/UserListingFragment.java | 16 +- .../fragments/ViewImgurImageFragment.java | 149 ++++++++++-------- .../ViewRedditGalleryImageOrGifFragment.java | 25 ++- .../multireddit/DeleteMultiReddit.java | 14 +- .../multireddit/FavoriteMultiReddit.java | 12 +- .../settings/AdvancedPreferenceFragment.java | 47 +++--- .../infinityforreddit/user/UserFollowing.java | 9 +- app/src/main/res/values-zh-rCN/strings.xml | 4 +- 91 files changed, 1289 insertions(+), 1477 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ChangeThemeName.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ChangeThemeNameAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUserAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubredditAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayouts.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayoutsAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPosts.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypes.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypesAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubreddits.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubredditsAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemes.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemesAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsers.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsersAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabaseAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteTheme.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteThemeAsyncTask.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultiRedditAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditDataAsyncTask.java rename app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/{InsertSubscribedThingsAsyncTask.java => InsertSubscribedThings.java} (51%) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserDataAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIconAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserDataAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccount.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccountAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFile.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFileAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFile.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFileAsyncTask.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaper.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaperAsyncTask.java diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 9db681e3..05aa69fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -62,7 +62,9 @@ import ml.docilealligator.infinityforreddit.fragments.SidebarFragment; import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment; import ml.docilealligator.infinityforreddit.fragments.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.fragments.UserListingFragment; +import ml.docilealligator.infinityforreddit.fragments.ViewImgurImageFragment; import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment; +import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryImageOrGifFragment; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.services.DownloadRedditVideoService; @@ -242,4 +244,8 @@ public interface AppComponent { void inject(SearchUsersResultActivity searchUsersResultActivity); void inject(MultiredditSelectionActivity multiredditSelectionActivity); + + void inject(ViewImgurImageFragment viewImgurImageFragment); + + void inject(ViewRedditGalleryImageOrGifFragment viewRedditGalleryImageOrGifFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java index 1bc7b002..8a041e3b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java @@ -1,12 +1,15 @@ package ml.docilealligator.infinityforreddit; +import android.os.Handler; + import androidx.annotation.NonNull; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -16,7 +19,8 @@ import retrofit2.Response; import retrofit2.Retrofit; public class FavoriteThing { - public static void favoriteSubreddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, + public static void favoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, SubscribedSubredditData subscribedSubredditData, FavoriteThingListener favoriteThingListener) { Map params = new HashMap<>(); @@ -26,8 +30,8 @@ public class FavoriteThing { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedSubredditData, - favoriteThingListener::success).execute(); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, + favoriteThingListener::success); } else { favoriteThingListener.failed(); } @@ -40,7 +44,8 @@ public class FavoriteThing { }); } - public static void unfavoriteSubreddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, + public static void unfavoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, SubscribedSubredditData subscribedSubredditData, FavoriteThingListener favoriteThingListener) { Map params = new HashMap<>(); @@ -50,8 +55,8 @@ public class FavoriteThing { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedSubredditData, - favoriteThingListener::success).execute(); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedSubredditData, favoriteThingListener::success); } else { favoriteThingListener.failed(); } @@ -64,9 +69,10 @@ public class FavoriteThing { }); } - public static void favoriteUser(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedUserData subscribedUserData, - FavoriteThingListener favoriteThingListener) { + public static void favoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + String accessToken, SubscribedUserData subscribedUserData, + FavoriteThingListener favoriteThingListener) { Map params = new HashMap<>(); params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); @@ -74,8 +80,8 @@ public class FavoriteThing { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedUserData, - favoriteThingListener::success).execute(); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); } else { favoriteThingListener.failed(); } @@ -88,9 +94,10 @@ public class FavoriteThing { }); } - public static void unfavoriteUser(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedUserData subscribedUserData, - FavoriteThingListener favoriteThingListener) { + public static void unfavoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + String accessToken, SubscribedUserData subscribedUserData, + FavoriteThingListener favoriteThingListener) { Map params = new HashMap<>(); params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); @@ -98,8 +105,8 @@ public class FavoriteThing { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedUserData, - favoriteThingListener::success).execute(); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); } else { favoriteThingListener.failed(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java index e121ffcb..fbbf05ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java @@ -4,6 +4,7 @@ import android.app.WallpaperManager; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.os.Handler; import android.view.WindowManager; import android.widget.Toast; @@ -14,14 +15,16 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; -import ml.docilealligator.infinityforreddit.asynctasks.SetAsWallpaperAsyncTask; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.asynctasks.SetAsWallpaper; public class WallpaperSetter { public static final int HOME_SCREEN = 0; public static final int LOCK_SCREEN = 1; public static final int BOTH_SCREENS = 2; - public static void set(String url, int setTo, Context context, SetWallpaperListener setWallpaperListener) { + public static void set(Executor executor, Handler handler, String url, int setTo, Context context, SetWallpaperListener setWallpaperListener) { Toast.makeText(context, R.string.save_image_first, Toast.LENGTH_SHORT).show(); WallpaperManager wallpaperManager = WallpaperManager.getInstance(context); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); @@ -29,7 +32,8 @@ public class WallpaperSetter { Glide.with(context).asBitmap().load(url).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - new SetAsWallpaperAsyncTask(resource, setTo, wallpaperManager, windowManager, setWallpaperListener).execute(); + SetAsWallpaper.setAsWallpaper(executor, handler, resource, setTo, wallpaperManager, + windowManager, setWallpaperListener); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java index 3a8ffae1..9f9207e5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -38,8 +38,8 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.adapters.CustomThemeListingRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.asynctasks.ChangeThemeNameAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteThemeAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.ChangeThemeName; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteTheme; import ml.docilealligator.infinityforreddit.asynctasks.GetCustomTheme; import ml.docilealligator.infinityforreddit.asynctasks.InsertCustomTheme; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CreateThemeBottomSheetFragment; @@ -175,7 +175,8 @@ public class CustomThemeListingActivity extends BaseActivity implements if (imm != null) { imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); } - new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldThemeName, themeNameEditText.getText().toString()).execute(); + ChangeThemeName.changeThemeName(executor, redditDataRoomDatabase, oldThemeName, + themeNameEditText.getText().toString()); }) .setNegativeButton(R.string.cancel, null) .setOnDismissListener(dialogInterface -> { @@ -212,7 +213,7 @@ public class CustomThemeListingActivity extends BaseActivity implements .setTitle(R.string.delete_theme) .setMessage(getString(R.string.delete_theme_dialog_message, themeName)) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteThemeAsyncTask(redditDataRoomDatabase, themeName, (isLightTheme, isDarkTheme, isAmoledTheme) -> { + -> DeleteTheme.deleteTheme(executor, new Handler(), redditDataRoomDatabase, themeName, (isLightTheme, isDarkTheme, isAmoledTheme) -> { if (isLightTheme) { CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences( CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), lightThemeSharedPreferences); @@ -226,7 +227,7 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomThemeWrapper.getIndigoAmoled(CustomThemeListingActivity.this), amoledThemeSharedPreferences); } EventBus.getDefault().post(new RecreateActivityEvent()); - }).execute()) + })) .setNegativeButton(R.string.no, null) .show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 210a81c7..3fb9010e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -7,6 +7,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.util.Log; import android.view.InflateException; import android.view.MenuItem; @@ -28,19 +29,20 @@ import org.json.JSONObject; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.asynctasks.ParseAndInsertNewAccountAsyncTask; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.asynctasks.ParseAndInsertNewAccount; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -77,6 +79,8 @@ public class LoginActivity extends BaseActivity { SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private String authCode; @Override @@ -163,13 +167,13 @@ public class LoginActivity extends BaseActivity { mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, accessToken) .putString(SharedPreferencesUtils.ACCOUNT_NAME, name) .putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, profileImageUrl).apply(); - new ParseAndInsertNewAccountAsyncTask(name, accessToken, refreshToken, profileImageUrl, bannerImageUrl, + ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name, accessToken, refreshToken, profileImageUrl, bannerImageUrl, karma, authCode, mRedditDataRoomDatabase.accountDao(), () -> { Intent resultIntent = new Intent(); setResult(Activity.RESULT_OK, resultIntent); finish(); - }).execute(); + }); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index a2d8ac7f..5dfc00d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -80,7 +80,7 @@ import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.AccountViewModel; import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.asynctasks.SwitchToAnonymousMode; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; @@ -897,13 +897,15 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, ArrayList subscribedUserData, ArrayList subredditData) { - new InsertSubscribedThingsAsyncTask( + InsertSubscribedThings.insertSubscribedThings( + mExecutor, + new Handler(), mRedditDataRoomDatabase, mAccountName, subscribedSubredditData, subscribedUserData, subredditData, - () -> mFetchSubscriptionsSuccess = true).execute(); + () -> mFetchSubscriptionsSuccess = true); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java index e84534b1..0e189274 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.MenuItem; import android.view.View; import android.view.Window; @@ -34,7 +35,7 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.MultiRedditListingFragment; @@ -167,10 +168,11 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { @Override public void success(ArrayList multiReddits) { - new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, + multiReddits, mAccountName, () -> { mInsertSuccess = true; ((MultiRedditListingFragment) mFragment).stopRefreshProgressbar(); - }).execute(); + }); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index 5e0d1d6e..cbab1914 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; @@ -51,7 +52,7 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitImagePostEvent; @@ -423,11 +424,11 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } private void loadSubredditIcon() { - new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { + LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { iconUrl = iconImageUrl; displaySubredditIcon(); loadSubredditIconSuccessful = true; - }).execute(); + }); } private void promptAlertDialog(int titleResId, int messageResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 51369282..48e012a4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -6,6 +6,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -42,7 +43,7 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent; @@ -354,11 +355,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr } private void loadSubredditIcon() { - new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { + LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, + mRetrofit, iconImageUrl -> { iconUrl = iconImageUrl; displaySubredditIcon(); loadSubredditIconSuccessful = true; - }).execute(); + }); } private void promptAlertDialog(int titleResId, int messageResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 131baa39..7d93fef7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -6,6 +6,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -45,7 +46,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent; @@ -371,11 +372,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr } private void loadSubredditIcon() { - new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { + LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, + mRetrofit, iconImageUrl -> { iconUrl = iconImageUrl; displaySubredditIcon(); loadSubredditIconSuccessful = true; - }).execute(); + }); } private void promptAlertDialog(int titleResId, int messageResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index cfb747a4..420477ff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -7,6 +7,7 @@ import android.content.res.Resources; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; @@ -54,7 +55,7 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent; @@ -431,11 +432,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } private void loadSubredditIcon() { - new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { + LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, + mRetrofit, iconImageUrl -> { iconUrl = iconImageUrl; displaySubredditIcon(); loadSubredditIconSuccessful = true; - }).execute(); + }); } private void promptAlertDialog(int titleResId, int messageResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index 7e273b09..0c88bcb4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -18,7 +18,6 @@ import com.google.android.material.snackbar.Snackbar; import com.r0adkll.slidr.Slidr; import java.util.ArrayList; -import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -68,8 +67,6 @@ public class ReportActivity extends BaseActivity { RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; private String mAccessToken; private String mFullname; private String mSubredditName; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 44cae730..35d6c66e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -35,8 +35,6 @@ import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.concurrent.Executor; - import javax.inject.Inject; import javax.inject.Named; @@ -110,8 +108,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; private String mAccessToken; private String mAccountName; private String mQuery; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java index 4f417ca0..b6882196 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java @@ -21,8 +21,6 @@ import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.concurrent.Executor; - import javax.inject.Inject; import javax.inject.Named; @@ -31,7 +29,6 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment; @@ -53,8 +50,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti Toolbar toolbar; Fragment mFragment; @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject @Named("default") SharedPreferences mSharedPreferences; @Inject @@ -62,8 +57,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; private String mAccessToken; private String mAccountName; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java index 6da07407..84db322c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java @@ -22,7 +22,6 @@ import com.google.android.material.snackbar.Snackbar; import com.r0adkll.slidr.Slidr; import java.util.ArrayList; -import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -33,7 +32,6 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.FetchUserFlairs; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SelectUserFlair; import ml.docilealligator.infinityforreddit.UserFlair; import ml.docilealligator.infinityforreddit.adapters.UserFlairRecyclerViewAdapter; @@ -58,8 +56,6 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo @Named("oauth") Retrofit mOauthRetrofit; @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject @Named("default") SharedPreferences mSharedPreferences; @Inject @@ -67,8 +63,6 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; private LinearLayoutManager mLinearLayoutManager; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java index 61d44645..216dd2ae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java @@ -16,8 +16,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.snackbar.Snackbar; -import java.util.concurrent.Executor; - import javax.inject.Inject; import javax.inject.Named; @@ -25,7 +23,6 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.ComposeMessage; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -53,8 +50,6 @@ public class SendPrivateMessageActivity extends BaseActivity { @Named("oauth") Retrofit mOauthRetrofit; @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject @Named("default") SharedPreferences mSharedPreferences; @Inject @@ -62,8 +57,6 @@ public class SendPrivateMessageActivity extends BaseActivity { SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; private String mAccessToken; private boolean isSubmitting = false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java index 0831bf44..e19b5fa9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java @@ -17,8 +17,6 @@ import com.google.android.material.appbar.AppBarLayout; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.concurrent.Executor; - import javax.inject.Inject; import javax.inject.Named; @@ -26,7 +24,6 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.settings.AboutPreferenceFragment; @@ -58,11 +55,7 @@ public class SettingsActivity extends BaseActivity implements @Named("current_account") SharedPreferences mCurrentAccountSharedPreferences; @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java index 366edda0..7e97c0a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java @@ -8,6 +8,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -51,7 +52,7 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitCrosspostEvent; @@ -424,11 +425,12 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom } private void loadSubredditIcon() { - new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> { + LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, + mRetrofit, iconImageUrl -> { iconUrl = iconImageUrl; displaySubredditIcon(); loadSubredditIconSuccessful = true; - }).execute(); + }); } private void promptAlertDialog(int titleResId, int messageResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index 32f6f4a0..23efef58 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -29,7 +29,6 @@ import com.google.android.material.appbar.AppBarLayout; import com.r0adkll.slidr.Slidr; import java.util.ArrayList; -import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -81,8 +80,6 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - @Inject - Executor mExecutor; public SubscribedSubredditViewModel mSubscribedSubredditViewModel; private String mAccessToken; private String mAccountName; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java index a28b8903..1029469d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -36,7 +37,7 @@ import ml.docilealligator.infinityforreddit.FetchSubscribedThing; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.SubscribedSubredditsListingFragment; @@ -187,13 +188,15 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity public void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, ArrayList subscribedUserData, ArrayList subredditData) { - new InsertSubscribedThingsAsyncTask( + InsertSubscribedThings.insertSubscribedThings( + mExecutor, + new Handler(), mRedditDataRoomDatabase, mAccountName, subscribedSubredditData, subscribedUserData, subredditData, - () -> mInsertSuccess = true).execute(); + () -> mInsertSuccess = true); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 775e434c..c4a90904 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -43,8 +44,8 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent; @@ -246,7 +247,9 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti public void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, ArrayList subscribedUserData, ArrayList subredditData) { - new InsertSubscribedThingsAsyncTask( + InsertSubscribedThings.insertSubscribedThings( + mExecutor, + new Handler(), mRedditDataRoomDatabase, mAccountName, subscribedSubredditData, @@ -255,7 +258,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti () -> { mInsertSuccess = true; sectionsPagerAdapter.stopRefreshProgressbar(); - }).execute(); + }); } @Override @@ -277,10 +280,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { @Override public void success(ArrayList multiReddits) { - new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { mInsertMultiredditSuccess = true; sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); - }).execute(); + }); } @Override @@ -297,7 +300,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti .setTitle(R.string.delete) .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) - -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + -> DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index 1a5a8c38..e82ea47a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.text.Html; import android.view.Menu; import android.view.MenuItem; @@ -46,6 +47,7 @@ import com.r0adkll.slidr.model.SlidrConfig; import com.r0adkll.slidr.model.SlidrPosition; import java.io.File; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -57,8 +59,8 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; import ml.docilealligator.infinityforreddit.WallpaperSetter; -import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFileAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFileAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; +import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontStyle; @@ -86,6 +88,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Inject @Named("default") SharedPreferences mSharedPreferences; + @Inject + Executor mExecutor; private boolean isActionBarHidden = false; private boolean isDownloading = false; private RequestManager glide; @@ -273,62 +277,62 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.action_download_view_image_or_gif_activity: - if (isDownloading) { - return false; - } + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + finish(); + return true; + } else if (itemId == R.id.action_download_view_image_or_gif_activity) { + if (isDownloading) { + return false; + } - isDownloading = true; + isDownloading = true; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (ContextCompat.checkSelfPermission(this, - Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { - // Permission is not granted - // No explanation needed; request the permission - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); - } else { - // Permission has already been granted - download(); - } + // Permission is not granted + // No explanation needed; request the permission + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); } else { + // Permission has already been granted download(); } + } else { + download(); + } - return true; - case R.id.action_share_view_image_or_gif_activity: - if (isGif) - shareGif(); - else - shareImage(); - return true; - case R.id.action_set_wallpaper_view_image_or_gif_activity: - if (!isGif) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); - setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); - } else { - WallpaperSetter.set(mImageUrl, WallpaperSetter.BOTH_SCREENS, this, - new WallpaperSetter.SetWallpaperListener() { - @Override - public void success() { - Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show(); - } + return true; + } else if (itemId == R.id.action_share_view_image_or_gif_activity) { + if (isGif) + shareGif(); + else + shareImage(); + return true; + } else if (itemId == R.id.action_set_wallpaper_view_image_or_gif_activity) { + if (!isGif) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); + setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); + } else { + WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this, + new WallpaperSetter.SetWallpaperListener() { + @Override + public void success() { + Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show(); + } - @Override - public void failed() { - Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show(); - } - }); - } + @Override + public void failed() { + Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show(); + } + }); } - return true; + } + return true; } return false; @@ -353,8 +357,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { if (getExternalCacheDir() != null) { Toast.makeText(ViewImageOrGifActivity.this, R.string.save_image_first, Toast.LENGTH_SHORT).show(); - new SaveBitmapImageToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName, - new SaveBitmapImageToFileAsyncTask.SaveBitmapImageToFileAsyncTaskListener() { + SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, + getExternalCacheDir().getPath(), mImageFileName, + new SaveBitmapImageToFile.SaveBitmapImageToFileListener() { @Override public void saveSuccess(File imageFile) { Uri uri = FileProvider.getUriForFile(ViewImageOrGifActivity.this, @@ -372,7 +377,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa Toast.makeText(ViewImageOrGifActivity.this, R.string.cannot_save_image, Toast.LENGTH_SHORT).show(); } - }).execute(); + }); } else { Toast.makeText(ViewImageOrGifActivity.this, R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); @@ -397,8 +402,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public boolean onResourceReady(GifDrawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { if (getExternalCacheDir() != null) { - new SaveGIFToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName, - new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() { + SaveGIFToFile.saveGifToFile(mExecutor, new Handler(), resource, getExternalCacheDir().getPath(), mImageFileName, + new SaveGIFToFile.SaveGIFToFileAsyncTaskListener() { @Override public void saveSuccess(File imageFile) { Uri uri = FileProvider.getUriForFile(ViewImageOrGifActivity.this, @@ -416,7 +421,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa Toast.makeText(ViewImageOrGifActivity.this, R.string.cannot_save_gif, Toast.LENGTH_SHORT).show(); } - }).execute(); + }); } else { Toast.makeText(ViewImageOrGifActivity.this, R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); @@ -440,7 +445,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public void setToHomeScreen(int viewPagerPosition) { - WallpaperSetter.set(mImageUrl, WallpaperSetter.HOME_SCREEN, this, + WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.HOME_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -456,7 +461,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public void setToLockScreen(int viewPagerPosition) { - WallpaperSetter.set(mImageUrl, WallpaperSetter.LOCK_SCREEN, this, + WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.LOCK_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -472,7 +477,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public void setToBoth(int viewPagerPosition) { - WallpaperSetter.set(mImageUrl, WallpaperSetter.BOTH_SCREENS, this, + WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java index 58898098..10866770 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java @@ -5,6 +5,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -28,6 +29,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -81,6 +83,8 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa @Inject @Named("default") SharedPreferences sharedPreferences; + @Inject + Executor executor; @Override protected void onCreate(Bundle savedInstanceState) { @@ -301,7 +305,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa @Override public void setToHomeScreen(int viewPagerPosition) { if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) { - WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.HOME_SCREEN, this, + WallpaperSetter.set(executor, new Handler(), images.get(viewPagerPosition).getLink(), WallpaperSetter.HOME_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -319,7 +323,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa @Override public void setToLockScreen(int viewPagerPosition) { if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) { - WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.LOCK_SCREEN, this, + WallpaperSetter.set(executor, new Handler(), images.get(viewPagerPosition).getLink(), WallpaperSetter.LOCK_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -337,7 +341,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa @Override public void setToBoth(int viewPagerPosition) { if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) { - WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.BOTH_SCREENS, this, + WallpaperSetter.set(executor, new Handler(), images.get(viewPagerPosition).getLink(), WallpaperSetter.BOTH_SCREENS, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index e1bdf079..4c673726 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -264,7 +265,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT .setTitle(R.string.delete) .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) - -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + -> DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 30100d86..a9e83270 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -639,7 +639,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS setupMenu(); mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, - mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, + mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator, @@ -802,7 +802,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS setupMenu(); mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, - mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, + mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java index 6867125b..b7f914b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.MenuItem; import android.view.View; import android.widget.EditText; @@ -36,7 +37,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.adapters.PrivateMessagesDetailRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.asynctasks.LoadUserDataAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent; import ml.docilealligator.infinityforreddit.message.Message; @@ -93,7 +94,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit private String mAccountName; private String mUserAvatar; private ArrayList mProvideUserAvatarCallbacks; - private LoadUserDataAsyncTask mLoadUserDataAsyncTask; + private boolean isLoadingUserAvatar = false; private boolean isSendingMessage = false; private int mSecondaryTextColor; private int mSendMessageIconColor; @@ -234,15 +235,16 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit public void fetchUserAvatar(String username, ProvideUserAvatarCallback provideUserAvatarCallback) { if (mUserAvatar == null) { mProvideUserAvatarCallbacks.add(provideUserAvatarCallback); - if (mLoadUserDataAsyncTask == null) { - mLoadUserDataAsyncTask = new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), username, mRetrofit, iconImageUrl -> { - mUserAvatar = iconImageUrl; + if (!isLoadingUserAvatar) { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, + username, mRetrofit, iconImageUrl -> { + isLoadingUserAvatar = false; + mUserAvatar = iconImageUrl == null ? "" : iconImageUrl; for (ProvideUserAvatarCallback provideUserAvatarCallbackInArrayList : mProvideUserAvatarCallbacks) { provideUserAvatarCallbackInArrayList.fetchAvatarSuccess(iconImageUrl); } mProvideUserAvatarCallbacks.clear(); }); - mLoadUserDataAsyncTask.execute(); } } else { provideUserAvatarCallback.fetchAvatarSuccess(mUserAvatar); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 0eaa24c9..6bcccfa3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -4,6 +4,7 @@ import android.content.SharedPreferences; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; @@ -20,6 +21,7 @@ import com.thefuntasty.hauler.DragDirection; import com.thefuntasty.hauler.HaulerView; import java.util.ArrayList; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -56,6 +58,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA @Inject @Named("default") SharedPreferences sharedPreferences; + @Inject + Executor executor; @Override protected void onCreate(Bundle savedInstanceState) { @@ -152,7 +156,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA @Override public void setToHomeScreen(int viewPagerPosition) { if (gallery != null && viewPagerPosition >= 0 && viewPagerPosition < gallery.size()) { - WallpaperSetter.set(gallery.get(viewPagerPosition).url, WallpaperSetter.HOME_SCREEN, this, + WallpaperSetter.set(executor, new Handler(), gallery.get(viewPagerPosition).url, WallpaperSetter.HOME_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -170,7 +174,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA @Override public void setToLockScreen(int viewPagerPosition) { if (gallery != null && viewPagerPosition >= 0 && viewPagerPosition < gallery.size()) { - WallpaperSetter.set(gallery.get(viewPagerPosition).url, WallpaperSetter.LOCK_SCREEN, this, + WallpaperSetter.set(executor, new Handler(), gallery.get(viewPagerPosition).url, WallpaperSetter.LOCK_SCREEN, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -188,7 +192,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA @Override public void setToBoth(int viewPagerPosition) { if (gallery != null && viewPagerPosition >= 0 && viewPagerPosition < gallery.size()) { - WallpaperSetter.set(gallery.get(viewPagerPosition).url, WallpaperSetter.BOTH_SCREENS, this, + WallpaperSetter.set(executor, new Handler(), gallery.get(viewPagerPosition).url, WallpaperSetter.BOTH_SCREENS, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 3bf7fdf8..af97a15d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -71,8 +71,8 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit; -import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubreddit; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; @@ -515,7 +515,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); - new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> mFetchSubredditInfoSuccess = true).execute(); + InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, + subredditData, () -> mFetchSubredditInfoSuccess = true); } @Override @@ -862,8 +863,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } }); - new CheckIsSubscribedToSubredditAsyncTask(mRedditDataRoomDatabase, subredditName, mAccountName, - new CheckIsSubscribedToSubredditAsyncTask.CheckIsSubscribedToSubredditListener() { + CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(mExecutor, new Handler(), + mRedditDataRoomDatabase, subredditName, mAccountName, + new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() { @Override public void isSubscribed() { subscribeSubredditChip.setText(R.string.unsubscribe); @@ -877,7 +879,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); subscriptionReady = true; } - }).execute(); + }); sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index e3736f1a..c2227455 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -75,7 +75,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit; -import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUserAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUser; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; @@ -94,7 +94,6 @@ import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; import ml.docilealligator.infinityforreddit.user.BlockUser; import ml.docilealligator.infinityforreddit.user.FetchUserData; import ml.docilealligator.infinityforreddit.user.UserDao; @@ -198,7 +197,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele public UserViewModel userViewModel; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; - private SubscribedUserDao subscribedUserDao; private RequestManager glide; private Menu mMenu; private AppBarLayout.LayoutParams params; @@ -358,7 +356,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false); lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); - subscribedUserDao = mRedditDataRoomDatabase.subscribedUserDao(); glide = Glide.with(this); Locale locale = getResources().getConfiguration().locale; @@ -412,7 +409,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele subscriptionReady = false; if (resources.getString(R.string.follow).contentEquals(subscribeUserChip.getText())) { UserFollowing.followUser(mOauthRetrofit, mRetrofit, mAccessToken, - username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() { + username, mAccountName, mRedditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override public void onUserFollowingSuccess() { subscribeUserChip.setText(R.string.unfollow); @@ -429,7 +426,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele }); } else { UserFollowing.unfollowUser(mOauthRetrofit, mRetrofit, mAccessToken, - username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() { + username, mAccountName, mRedditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override public void onUserFollowingSuccess() { subscribeUserChip.setText(R.string.follow); @@ -448,7 +445,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } }); - new CheckIsFollowingUserAsyncTask(subscribedUserDao, username, mAccountName, new CheckIsFollowingUserAsyncTask.CheckIsFollowingUserListener() { + CheckIsFollowingUser.checkIsFollowingUser(mExecutor, new Handler(), mRedditDataRoomDatabase, + username, mAccountName, new CheckIsFollowingUser.CheckIsFollowingUserListener() { @Override public void isSubscribed() { subscribeUserChip.setText(R.string.unfollow); @@ -462,7 +460,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele subscribeUserChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); subscriptionReady = true; } - }).execute(); + }); } else { subscribeUserChip.setVisibility(View.GONE); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 0722da59..0d4569ca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -11,6 +11,7 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; @@ -59,6 +60,7 @@ import org.commonmark.ext.gfm.tables.TableBlock; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -100,8 +102,8 @@ import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity; -import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.LoadUserDataAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CommentMoreBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment; @@ -141,6 +143,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mOauthRetrofit, iconImageUrl -> { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) @@ -749,7 +753,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (iconImageUrl == null || iconImageUrl.equals("")) { @@ -779,7 +783,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mSubscribedUserData; private List mFavoriteSubscribedUserData; private Context mContext; + private Executor mExecutor; private Retrofit mOauthRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; private String mAccessToken; @@ -47,11 +50,12 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, post.getAuthor(), + mRetrofit, iconImageUrl -> { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) @@ -451,7 +455,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { @@ -484,7 +489,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mRetrofit, iconImageUrl -> { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) @@ -518,7 +523,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, post.getAuthor(), mRetrofit, iconImageUrl -> { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) @@ -780,7 +785,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { @@ -813,7 +819,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mRetrofit, iconImageUrl -> { if (mActivity != null && getItemCount() > 0) { if (iconImageUrl == null || iconImageUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) @@ -850,7 +856,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 10_000_000) { - Log.i("afasfasdf", "ssss " + preview.getPreviewUrl()); int divisor = 2; do { preview.setPreviewWidth(preview.getPreviewWidth() / divisor); @@ -1076,8 +1081,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 10_000_000); } - - Log.i("afasfasdf", "s " + preview.getPreviewWidth() * preview.getPreviewHeight() + " " + preview.getPreviewHeight() + " " + preview.getPreviewWidth() + " " + preview.getPreviewUrl()); return preview; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java index cec8041a..1d34c29d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Context; import android.content.res.ColorStateList; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,10 +23,12 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; +import java.util.concurrent.Executor; + import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubreddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -52,6 +55,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter mSubscribedSubredditData; @@ -53,11 +56,12 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte private int primaryTextColor; private int secondaryTextColor; - public SubscribedSubredditsRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, + public SubscribedSubredditsRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken) { mContext = context; + mExecutor = executor; glide = Glide.with(context); mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; @@ -66,12 +70,12 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); } - public SubscribedSubredditsRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, + public SubscribedSubredditsRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken, boolean hasClearSelectionRow, ItemClickListener itemClickListener) { - this(context, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken); + this(context, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken); this.hasClearSelectionRow = hasClearSelectionRow; this.itemClickListener = itemClickListener; } @@ -190,7 +194,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) { ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false); - FavoriteThing.unfavoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), new FavoriteThing.FavoriteThingListener() { @Override @@ -215,7 +219,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte } else { ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true); - FavoriteThing.favoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, + mRedditDataRoomDatabase, accessToken, mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), new FavoriteThing.FavoriteThingListener() { @Override @@ -288,7 +293,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) { ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false); - FavoriteThing.unfavoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), new FavoriteThing.FavoriteThingListener() { @Override @@ -313,7 +318,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte } else { ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true); - FavoriteThing.favoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), new FavoriteThing.FavoriteThingListener() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java index 2fb83bae..f8c9f993 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Context; import android.content.res.ColorStateList; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,14 +23,16 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; +import java.util.concurrent.Executor; + import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUserAsyncTask; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUser; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; import ml.docilealligator.infinityforreddit.user.UserData; import ml.docilealligator.infinityforreddit.user.UserFollowing; import pl.droidsonroids.gif.GifImageView; @@ -52,11 +55,12 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter { UserFollowing.followUser(oauthRetrofit, retrofit, - accessToken, userData.getName(), accountName, subscribedUserDao, + accessToken, userData.getName(), accountName, redditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override public void onUserFollowingSuccess() { @@ -152,7 +157,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter { + redditDataRoomDatabase.customThemeDao().updateName(oldName, newName); + }); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ChangeThemeNameAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ChangeThemeNameAsyncTask.java deleted file mode 100644 index 4bc3bef4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ChangeThemeNameAsyncTask.java +++ /dev/null @@ -1,23 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class ChangeThemeNameAsyncTask extends AsyncTask { - private RedditDataRoomDatabase redditDataRoomDatabase; - private String oldName; - private String newName; - - public ChangeThemeNameAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String oldName, String newName) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.oldName = oldName; - this.newName = newName; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.customThemeDao().updateName(oldName, newName); - return null; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java new file mode 100644 index 00000000..2bf3657e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java @@ -0,0 +1,31 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; + +public class CheckIsFollowingUser { + public static void checkIsFollowingUser(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, String username, + String accountName, CheckIsFollowingUserListener checkIsFollowingUserListener) { + executor.execute(() -> { + SubscribedUserData subscribedUserData = redditDataRoomDatabase.subscribedUserDao().getSubscribedUser(username, accountName); + handler.post(() -> { + if (subscribedUserData != null) { + checkIsFollowingUserListener.isSubscribed(); + } else { + checkIsFollowingUserListener.isNotSubscribed(); + } + }); + }); + } + + public interface CheckIsFollowingUserListener { + void isSubscribed(); + + void isNotSubscribed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUserAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUserAsyncTask.java deleted file mode 100644 index a34bd0a8..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUserAsyncTask.java +++ /dev/null @@ -1,44 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; - -public class CheckIsFollowingUserAsyncTask extends AsyncTask { - private SubscribedUserDao subscribedUserDao; - private String username; - private String accountName; - private SubscribedUserData subscribedUserData; - private CheckIsFollowingUserListener checkIsFollowingUserListener; - - public CheckIsFollowingUserAsyncTask(SubscribedUserDao subscribedUserDao, String username, String accountName, - CheckIsFollowingUserListener checkIsFollowingUserListener) { - this.subscribedUserDao = subscribedUserDao; - this.username = username; - this.accountName = accountName; - this.checkIsFollowingUserListener = checkIsFollowingUserListener; - } - - @Override - protected Void doInBackground(Void... voids) { - subscribedUserData = subscribedUserDao.getSubscribedUser(username, accountName); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (subscribedUserData != null) { - checkIsFollowingUserListener.isSubscribed(); - } else { - checkIsFollowingUserListener.isNotSubscribed(); - } - } - - public interface CheckIsFollowingUserListener { - void isSubscribed(); - - void isNotSubscribed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java new file mode 100644 index 00000000..fed411cc --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java @@ -0,0 +1,32 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; + +public class CheckIsSubscribedToSubreddit { + + public static void checkIsSubscribedToSubreddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + String subredditName, String accountName, + CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener) { + executor.execute(() -> { + SubscribedSubredditData subscribedSubredditData = redditDataRoomDatabase.subscribedSubredditDao().getSubscribedSubreddit(subredditName, accountName); + handler.post(() -> { + if (subscribedSubredditData != null) { + checkIsSubscribedToSubredditListener.isSubscribed(); + } else { + checkIsSubscribedToSubredditListener.isNotSubscribed(); + } + }); + }); + } + + public interface CheckIsSubscribedToSubredditListener { + void isSubscribed(); + + void isNotSubscribed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubredditAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubredditAsyncTask.java deleted file mode 100644 index a7aaddd4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubredditAsyncTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; - -public class CheckIsSubscribedToSubredditAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String subredditName; - private String accountName; - private SubscribedSubredditData subscribedSubredditData; - private CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener; - - public CheckIsSubscribedToSubredditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - String subredditName, String accountName, - CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.subredditName = subredditName; - this.accountName = accountName; - this.checkIsSubscribedToSubredditListener = checkIsSubscribedToSubredditListener; - } - - @Override - protected Void doInBackground(Void... voids) { - subscribedSubredditData = redditDataRoomDatabase.subscribedSubredditDao().getSubscribedSubreddit(subredditName, accountName); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (subscribedSubredditData != null) { - checkIsSubscribedToSubredditListener.isSubscribed(); - } else { - checkIsSubscribedToSubredditListener.isNotSubscribed(); - } - } - - public interface CheckIsSubscribedToSubredditListener { - void isSubscribed(); - - void isNotSubscribed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayouts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayouts.java new file mode 100644 index 00000000..ca20a20d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayouts.java @@ -0,0 +1,44 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.content.SharedPreferences; +import android.os.Handler; + +import java.util.Map; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class DeleteAllPostLayouts { + + public static void deleteAllPostLayouts(Executor executor, Handler handler, SharedPreferences defaultSharedPreferences, + SharedPreferences postLayoutSharedPreferences, + DeleteAllPostLayoutsAsyncTaskListener deleteAllPostLayoutsAsyncTaskListener) { + executor.execute(() -> { + Map keys = defaultSharedPreferences.getAll(); + SharedPreferences.Editor editor = defaultSharedPreferences.edit(); + + for(Map.Entry entry : keys.entrySet()){ + String key = entry.getKey(); + if (key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST_LEGACY) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_ALL_POST_LEGACY) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE) + || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) { + editor.remove(key); + } + } + editor.apply(); + + postLayoutSharedPreferences.edit().clear().apply(); + + handler.post(deleteAllPostLayoutsAsyncTaskListener::success); + }); + } + + public interface DeleteAllPostLayoutsAsyncTaskListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayoutsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayoutsAsyncTask.java deleted file mode 100644 index a4298f10..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllPostLayoutsAsyncTask.java +++ /dev/null @@ -1,57 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.content.SharedPreferences; -import android.os.AsyncTask; - -import java.util.Map; - -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; - -public class DeleteAllPostLayoutsAsyncTask extends AsyncTask { - - private SharedPreferences defaultSharedPreferences; - private SharedPreferences postLayoutSharedPreferences; - private DeleteAllPostLayoutsAsyncTaskListener deleteAllPostLayoutsAsyncTaskListener; - - public interface DeleteAllPostLayoutsAsyncTaskListener { - void success(); - } - - public DeleteAllPostLayoutsAsyncTask(SharedPreferences defaultSharedPreferences, - SharedPreferences postLayoutSharedPreferences, - DeleteAllPostLayoutsAsyncTaskListener deleteAllPostLayoutsAsyncTaskListener) { - this.defaultSharedPreferences = defaultSharedPreferences; - this.postLayoutSharedPreferences = postLayoutSharedPreferences; - this.deleteAllPostLayoutsAsyncTaskListener = deleteAllPostLayoutsAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - Map keys = defaultSharedPreferences.getAll(); - SharedPreferences.Editor editor = defaultSharedPreferences.edit(); - - for(Map.Entry entry : keys.entrySet()){ - String key = entry.getKey(); - if (key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST_LEGACY) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_ALL_POST_LEGACY) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE) - || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) { - editor.remove(key); - } - } - editor.apply(); - - postLayoutSharedPreferences.edit().clear().apply(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllPostLayoutsAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPosts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPosts.java new file mode 100644 index 00000000..996f8f39 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPosts.java @@ -0,0 +1,23 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllReadPosts { + + public static void deleteAllReadPosts(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllReadPostsAsyncTaskListener deleteAllReadPostsAsyncTaskListener) { + executor.execute(() -> { + redditDataRoomDatabase.readPostDao().deleteAllReadPosts(); + handler.post(deleteAllReadPostsAsyncTaskListener::success); + }); + } + + public interface DeleteAllReadPostsAsyncTaskListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java deleted file mode 100644 index 34098ef2..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteAllReadPostsAsyncTask extends AsyncTask { - - public interface DeleteAllReadPostsAsyncTaskListener { - void success(); - } - - private RedditDataRoomDatabase redditDataRoomDatabase; - private DeleteAllReadPostsAsyncTaskListener deleteAllReadPostsAsyncTaskListener; - - public DeleteAllReadPostsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - DeleteAllReadPostsAsyncTaskListener deleteAllReadPostsAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.deleteAllReadPostsAsyncTaskListener = deleteAllReadPostsAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.readPostDao().deleteAllReadPosts(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllReadPostsAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypes.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypes.java new file mode 100644 index 00000000..e077871d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypes.java @@ -0,0 +1,46 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.content.SharedPreferences; +import android.os.Handler; + +import java.util.Map; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class DeleteAllSortTypes { + + public static void deleteAllSortTypes(Executor executor, Handler handler, SharedPreferences defaultSharedPreferences, + SharedPreferences sortTypeSharedPreferences, + DeleteAllSortTypesAsyncTaskListener deleteAllSortTypesAsyncTaskListener) { + executor.execute(() -> { + Map keys = defaultSharedPreferences.getAll(); + SharedPreferences.Editor editor = defaultSharedPreferences.edit(); + + for(Map.Entry entry : keys.entrySet()){ + String key = entry.getKey(); + if (key.contains(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_BEST_POST) + || key.contains(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_ALL_POST_LEGACY) + || key.contains(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_POPULAR_POST_LEGACY) + || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_SEARCH_POST) + || key.contains(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE) + || key.contains(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE) + || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE) + || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_COMMENT) + || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT) || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER) + || key.contains(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT)) { + editor.remove(key); + } + } + editor.apply(); + + sortTypeSharedPreferences.edit().clear().apply(); + + handler.post(deleteAllSortTypesAsyncTaskListener::success); + }); + } + + public interface DeleteAllSortTypesAsyncTaskListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypesAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypesAsyncTask.java deleted file mode 100644 index a0d999b5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSortTypesAsyncTask.java +++ /dev/null @@ -1,58 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.content.SharedPreferences; -import android.os.AsyncTask; - -import java.util.Map; - -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; - -public class DeleteAllSortTypesAsyncTask extends AsyncTask { - private SharedPreferences defaultSharedPreferences; - private SharedPreferences sortTypeSharedPreferences; - private DeleteAllSortTypesAsyncTaskListener deleteAllSortTypesAsyncTaskListener; - - public interface DeleteAllSortTypesAsyncTaskListener { - void success(); - } - - public DeleteAllSortTypesAsyncTask(SharedPreferences defaultSharedPreferences, - SharedPreferences sortTypeSharedPreferences, - DeleteAllSortTypesAsyncTaskListener deleteAllSortTypesAsyncTaskListener) { - this.defaultSharedPreferences = defaultSharedPreferences; - this.sortTypeSharedPreferences = sortTypeSharedPreferences; - this.deleteAllSortTypesAsyncTaskListener = deleteAllSortTypesAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - Map keys = defaultSharedPreferences.getAll(); - SharedPreferences.Editor editor = defaultSharedPreferences.edit(); - - for(Map.Entry entry : keys.entrySet()){ - String key = entry.getKey(); - if (key.contains(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_BEST_POST) - || key.contains(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_ALL_POST_LEGACY) - || key.contains(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_POPULAR_POST_LEGACY) - || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_SEARCH_POST) - || key.contains(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE) - || key.contains(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE) - || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE) - || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_COMMENT) - || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT) || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER) - || key.contains(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT)) { - editor.remove(key); - } - } - editor.apply(); - - sortTypeSharedPreferences.edit().clear().apply(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllSortTypesAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubreddits.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubreddits.java new file mode 100644 index 00000000..84e6ff60 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubreddits.java @@ -0,0 +1,22 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllSubreddits { + + public static void deleteAllSubreddits(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllSubredditsAsyncTaskListener deleteAllSubredditsAsyncTaskListener) { + executor.execute(() -> { + redditDataRoomDatabase.subredditDao().deleteAllSubreddits(); + handler.post(deleteAllSubredditsAsyncTaskListener::success); + }); + } + + public interface DeleteAllSubredditsAsyncTaskListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubredditsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubredditsAsyncTask.java deleted file mode 100644 index f5494224..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllSubredditsAsyncTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteAllSubredditsAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private DeleteAllSubredditsAsyncTaskListener deleteAllSubredditsAsyncTaskListener; - - public interface DeleteAllSubredditsAsyncTaskListener { - void success(); - } - - public DeleteAllSubredditsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - DeleteAllSubredditsAsyncTaskListener deleteAllSubredditsAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.deleteAllSubredditsAsyncTaskListener = deleteAllSubredditsAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.subredditDao().deleteAllSubreddits(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllSubredditsAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemes.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemes.java new file mode 100644 index 00000000..8fbc8cb0 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemes.java @@ -0,0 +1,30 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.content.SharedPreferences; +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllThemes { + + public static void deleteAllThemes(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + SharedPreferences lightThemeSharedPreferences, + SharedPreferences darkThemeSharedPreferences, + SharedPreferences amoledThemeSharedPreferences, + DeleteAllThemesListener deleteAllThemesListener) { + executor.execute(() -> { + redditDataRoomDatabase.customThemeDao().deleteAllCustomThemes(); + lightThemeSharedPreferences.edit().clear().apply(); + darkThemeSharedPreferences.edit().clear().apply(); + amoledThemeSharedPreferences.edit().clear().apply(); + handler.post(deleteAllThemesListener::success); + }); + } + + public interface DeleteAllThemesListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemesAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemesAsyncTask.java deleted file mode 100644 index ccf935fb..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllThemesAsyncTask.java +++ /dev/null @@ -1,45 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.content.SharedPreferences; -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteAllThemesAsyncTask extends AsyncTask { - private RedditDataRoomDatabase redditDataRoomDatabase; - private SharedPreferences lightThemeSharedPreferences; - private SharedPreferences darkThemeSharedPreferences; - private SharedPreferences amoledThemeSharedPreferences; - private DeleteAllThemesAsyncTaskListener deleteAllThemesAsyncTaskListener; - - public interface DeleteAllThemesAsyncTaskListener { - void success(); - } - - public DeleteAllThemesAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - SharedPreferences lightThemeSharedPreferences, - SharedPreferences darkThemeSharedPreferences, - SharedPreferences amoledThemeSharedPreferences, - DeleteAllThemesAsyncTaskListener deleteAllThemesAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.lightThemeSharedPreferences = lightThemeSharedPreferences; - this.darkThemeSharedPreferences = darkThemeSharedPreferences; - this.amoledThemeSharedPreferences = amoledThemeSharedPreferences; - this.deleteAllThemesAsyncTaskListener = deleteAllThemesAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.customThemeDao().deleteAllCustomThemes(); - lightThemeSharedPreferences.edit().clear().apply(); - darkThemeSharedPreferences.edit().clear().apply(); - amoledThemeSharedPreferences.edit().clear().apply(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllThemesAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsers.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsers.java new file mode 100644 index 00000000..ee233614 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsers.java @@ -0,0 +1,22 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllUsers { + + public static void deleteAllUsers(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllUsersListener deleteAllUsersListener) { + executor.execute(() -> { + redditDataRoomDatabase.userDao().deleteAllUsers(); + handler.post(deleteAllUsersListener::success); + }); + } + + public interface DeleteAllUsersListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsersAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsersAsyncTask.java deleted file mode 100644 index 26c20043..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllUsersAsyncTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteAllUsersAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private DeleteAllUsersAsyncTaskListener deleteAllUsersAsyncTaskListener; - - public interface DeleteAllUsersAsyncTaskListener { - void success(); - } - - public DeleteAllUsersAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - DeleteAllUsersAsyncTaskListener deleteAllUsersAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.deleteAllUsersAsyncTaskListener = deleteAllUsersAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.userDao().deleteAllUsers(); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteAllUsersAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java new file mode 100644 index 00000000..d6e2522d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java @@ -0,0 +1,23 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteMultiredditInDatabase { + + public static void deleteMultiredditInDatabase(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + String accountName, String multipath, + DeleteMultiredditInDatabaseListener deleteMultiredditInDatabaseListener) { + executor.execute(() -> { + redditDataRoomDatabase.multiRedditDao().deleteMultiReddit(multipath, accountName); + handler.post(deleteMultiredditInDatabaseListener::success); + }); + } + public interface DeleteMultiredditInDatabaseListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabaseAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabaseAsyncTask.java deleted file mode 100644 index 61e62244..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabaseAsyncTask.java +++ /dev/null @@ -1,37 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteMultiredditInDatabaseAsyncTask extends AsyncTask { - public interface DeleteMultiredditInDatabaseAsyncTaskListener { - void success(); - } - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String accountName; - private String multipath; - private DeleteMultiredditInDatabaseAsyncTaskListener deleteMultiredditInDatabaseAsyncTaskListener; - - public DeleteMultiredditInDatabaseAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - String accountName, String multipath, - DeleteMultiredditInDatabaseAsyncTaskListener deleteMultiredditInDatabaseAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.accountName = accountName; - this.multipath = multipath; - this.deleteMultiredditInDatabaseAsyncTaskListener = deleteMultiredditInDatabaseAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.multiRedditDao().deleteMultiReddit(multipath, accountName); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteMultiredditInDatabaseAsyncTaskListener.success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteTheme.java new file mode 100644 index 00000000..2934e77c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteTheme.java @@ -0,0 +1,32 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; + +public class DeleteTheme { + + public static void deleteTheme(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, String themeName, + DeleteThemeListener deleteThemeListener) { + executor.execute(() -> { + CustomTheme customTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(themeName); + if (customTheme != null) { + boolean isLightTheme = customTheme.isLightTheme; + boolean isDarkTheme = customTheme.isDarkTheme; + boolean isAmoledTheme = customTheme.isAmoledTheme; + redditDataRoomDatabase.customThemeDao().deleteCustomTheme(themeName); + handler.post(() -> deleteThemeListener.success(isLightTheme, isDarkTheme, isAmoledTheme)); + } else { + handler.post(() -> deleteThemeListener.success(false, false, false)); + } + }); + } + + public interface DeleteThemeListener { + void success(boolean isLightTheme, boolean isDarkTheme, boolean isAmoledTheme); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteThemeAsyncTask.java deleted file mode 100644 index e33cdbf5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteThemeAsyncTask.java +++ /dev/null @@ -1,44 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class DeleteThemeAsyncTask extends AsyncTask { - private RedditDataRoomDatabase redditDataRoomDatabase; - private String themeName; - private DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener; - private boolean isLightTheme = false; - private boolean isDarkTheme = false; - private boolean isAmoledTheme = false; - - public interface DeleteThemeAsyncTaskListener { - void success(boolean isLightTheme, boolean isDarkTheme, boolean isAmoledTheme); - } - - public DeleteThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String themeName, - DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.themeName = themeName; - this.deleteThemeAsyncTaskListener = deleteThemeAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - CustomTheme customTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(themeName); - if (customTheme != null) { - isLightTheme = customTheme.isLightTheme; - isDarkTheme = customTheme.isDarkTheme; - isAmoledTheme = customTheme.isAmoledTheme; - redditDataRoomDatabase.customThemeDao().deleteCustomTheme(themeName); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - deleteThemeAsyncTaskListener.success(isLightTheme, isDarkTheme, isAmoledTheme); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultiRedditAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultiRedditAsyncTask.java deleted file mode 100644 index b0351966..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultiRedditAsyncTask.java +++ /dev/null @@ -1,94 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; -import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class InsertMultiRedditAsyncTask extends AsyncTask { - private MultiRedditDao multiRedditDao; - private ArrayList multiReddits; - private MultiReddit multiReddit; - private String accountName; - private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener; - - public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - ArrayList multiReddits, String accountName, - InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) { - multiRedditDao = redditDataRoomDatabase.multiRedditDao(); - this.multiReddits = multiReddits; - this.accountName = accountName; - 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 existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName); - Collections.sort(multiReddits, (multiReddit, t1) -> multiReddit.getName().compareToIgnoreCase(t1.getName())); - List deletedMultiredditNames = new ArrayList<>(); - compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames); - - for (String deleted : deletedMultiredditNames) { - multiRedditDao.deleteMultiReddit(deleted, accountName); - } - - for (MultiReddit multiReddit : multiReddits) { - multiRedditDao.insert(multiReddit); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - insertMultiRedditAsyncTaskListener.success(); - } - - private void compareTwoMultiRedditList(List newMultiReddits, - List oldMultiReddits, - List deletedMultiReddits) { - int newIndex = 0; - for (int oldIndex = 0; oldIndex < oldMultiReddits.size(); oldIndex++) { - if (newIndex >= newMultiReddits.size()) { - for (; oldIndex < oldMultiReddits.size(); oldIndex++) { - deletedMultiReddits.add(oldMultiReddits.get(oldIndex).getName()); - } - return; - } - - MultiReddit old = oldMultiReddits.get(oldIndex); - for (; newIndex < newMultiReddits.size(); newIndex++) { - if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) { - newIndex++; - break; - } - if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) { - deletedMultiReddits.add(old.getName()); - break; - } - } - } - } - - public interface InsertMultiRedditAsyncTaskListener { - void success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java new file mode 100644 index 00000000..99d046c9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java @@ -0,0 +1,76 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; +import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class InsertMultireddit { + + public static void insertMultireddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + ArrayList multiReddits, String accountName, + InsertMultiRedditListener insertMultiRedditListener) { + executor.execute(() -> { + MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao(); + List existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName); + Collections.sort(multiReddits, (multiReddit, t1) -> multiReddit.getName().compareToIgnoreCase(t1.getName())); + List deletedMultiredditNames = new ArrayList<>(); + compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames); + + for (String deleted : deletedMultiredditNames) { + multiRedditDao.deleteMultiReddit(deleted, accountName); + } + + for (MultiReddit multiReddit : multiReddits) { + multiRedditDao.insert(multiReddit); + } + + handler.post(insertMultiRedditListener::success); + }); + } + + public static void insertMultireddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + MultiReddit multiReddit, + InsertMultiRedditListener insertMultiRedditListener) { + executor.execute(() -> { + redditDataRoomDatabase.multiRedditDao().insert(multiReddit); + handler.post(insertMultiRedditListener::success); + }); + } + + private static void compareTwoMultiRedditList(List newMultiReddits, + List oldMultiReddits, + List deletedMultiReddits) { + int newIndex = 0; + for (int oldIndex = 0; oldIndex < oldMultiReddits.size(); oldIndex++) { + if (newIndex >= newMultiReddits.size()) { + for (; oldIndex < oldMultiReddits.size(); oldIndex++) { + deletedMultiReddits.add(oldMultiReddits.get(oldIndex).getName()); + } + return; + } + + MultiReddit old = oldMultiReddits.get(oldIndex); + for (; newIndex < newMultiReddits.size(); newIndex++) { + if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) { + newIndex++; + break; + } + if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) { + deletedMultiReddits.add(old.getName()); + break; + } + } + } + } + + public interface InsertMultiRedditListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditData.java new file mode 100644 index 00000000..5ef4ac2c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditData.java @@ -0,0 +1,24 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.subreddit.SubredditData; + +public class InsertSubredditData { + + public static void insertSubredditData(Executor executor, Handler handler, RedditDataRoomDatabase db, + SubredditData subredditData, + InsertSubredditDataAsyncTaskListener insertSubredditDataAsyncTaskListener) { + executor.execute(() -> { + db.subredditDao().insert(subredditData); + handler.post(insertSubredditDataAsyncTaskListener::insertSuccess); + }); + } + + public interface InsertSubredditDataAsyncTaskListener { + void insertSuccess(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditDataAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditDataAsyncTask.java deleted file mode 100644 index c0085540..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubredditDataAsyncTask.java +++ /dev/null @@ -1,35 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; -import ml.docilealligator.infinityforreddit.subreddit.SubredditData; - -public class InsertSubredditDataAsyncTask extends AsyncTask { - private SubredditDao mSubredditDao; - private SubredditData subredditData; - private InsertSubredditDataAsyncTaskListener insertSubredditDataAsyncTaskListener; - - public InsertSubredditDataAsyncTask(RedditDataRoomDatabase db, SubredditData subredditData, - InsertSubredditDataAsyncTaskListener insertSubredditDataAsyncTaskListener) { - mSubredditDao = db.subredditDao(); - this.subredditData = subredditData; - this.insertSubredditDataAsyncTaskListener = insertSubredditDataAsyncTaskListener; - } - - @Override - protected Void doInBackground(final Void... params) { - mSubredditDao.insert(subredditData); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - insertSubredditDataAsyncTaskListener.insertSuccess(); - } - - public interface InsertSubredditDataAsyncTaskListener { - void insertSuccess(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThingsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java similarity index 51% rename from app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThingsAsyncTask.java rename to app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java index 0d67e183..02ad624d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThingsAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java @@ -1,12 +1,13 @@ package ml.docilealligator.infinityforreddit.asynctasks; -import android.os.AsyncTask; +import android.os.Handler; import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; @@ -16,117 +17,99 @@ import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubred import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; -public class InsertSubscribedThingsAsyncTask extends AsyncTask { +public class InsertSubscribedThings { - private RedditDataRoomDatabase mRedditDataRoomDatabase; - private String mAccountName; - private SubscribedSubredditDao mSubscribedSubredditDao; - private SubscribedUserDao mSubscribedUserDao; - private SubredditDao mSubredditDao; - private SubscribedSubredditData mSingleSubscribedSubredditData; - private SubscribedUserData mSingleSubscribedUserData; - private List subscribedSubredditDataList; - private List subscribedUserDataList; - private List subredditDataList; - private InsertSubscribedThingListener mInsertSubscribedThingListener; + public static void insertSubscribedThings(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName, + List subscribedSubredditDataList, + List subscribedUserDataList, + List subredditDataList, + InsertSubscribedThingListener insertSubscribedThingListener) { + executor.execute(() -> { + if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { + handler.post(insertSubscribedThingListener::insertSuccess); + return; + } - public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName, - List subscribedSubredditDataList, - List subscribedUserDataList, - List subredditDataList, - InsertSubscribedThingListener insertSubscribedThingListener) { - mRedditDataRoomDatabase = redditDataRoomDatabase; - mAccountName = accountName; - mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao(); - mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao(); - mSubredditDao = redditDataRoomDatabase.subredditDao(); + SubscribedSubredditDao subscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao(); + SubscribedUserDao subscribedUserDao = redditDataRoomDatabase.subscribedUserDao(); + SubredditDao subredditDao = redditDataRoomDatabase.subredditDao(); - this.subscribedSubredditDataList = subscribedSubredditDataList; - this.subscribedUserDataList = subscribedUserDataList; - this.subredditDataList = subredditDataList; - mInsertSubscribedThingListener = insertSubscribedThingListener; - } - - public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - SubscribedSubredditData subscribedSubredditDataList, - InsertSubscribedThingListener insertSubscribedThingListener) { - mRedditDataRoomDatabase = redditDataRoomDatabase; - mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao(); - mAccountName = subscribedSubredditDataList.getUsername(); - mSingleSubscribedSubredditData = subscribedSubredditDataList; - mInsertSubscribedThingListener = insertSubscribedThingListener; - } - - public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - SubscribedUserData subscribedUserDataList, - InsertSubscribedThingListener insertSubscribedThingListener) { - mRedditDataRoomDatabase = redditDataRoomDatabase; - mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao(); - mAccountName = subscribedUserDataList.getUsername(); - mSingleSubscribedUserData = subscribedUserDataList; - mInsertSubscribedThingListener = insertSubscribedThingListener; - } - - @Override - protected Void doInBackground(final Void... params) { - if (mAccountName != null && mRedditDataRoomDatabase.accountDao().getAccountData(mAccountName) == null) { - return null; - } - - if (mSingleSubscribedSubredditData != null) { - mSubscribedSubredditDao.insert(mSingleSubscribedSubredditData); - } else if (mSingleSubscribedUserData != null) { - mSubscribedUserDao.insert(mSingleSubscribedUserData); - } else { if (subscribedSubredditDataList != null) { List existingSubscribedSubredditDataList = - mSubscribedSubredditDao.getAllSubscribedSubredditsList(mAccountName); + subscribedSubredditDao.getAllSubscribedSubredditsList(accountName); Collections.sort(subscribedSubredditDataList, (subscribedSubredditData, t1) -> subscribedSubredditData.getName().compareToIgnoreCase(t1.getName())); List unsubscribedSubreddits = new ArrayList<>(); compareTwoSubscribedSubredditList(subscribedSubredditDataList, existingSubscribedSubredditDataList, unsubscribedSubreddits); for (String unsubscribed : unsubscribedSubreddits) { - mSubscribedSubredditDao.deleteSubscribedSubreddit(unsubscribed, mAccountName); + subscribedSubredditDao.deleteSubscribedSubreddit(unsubscribed, accountName); } for (SubscribedSubredditData s : subscribedSubredditDataList) { - mSubscribedSubredditDao.insert(s); + subscribedSubredditDao.insert(s); } } if (subscribedUserDataList != null) { List existingSubscribedUserDataList = - mSubscribedUserDao.getAllSubscribedUsersList(mAccountName); + subscribedUserDao.getAllSubscribedUsersList(accountName); Collections.sort(subscribedUserDataList, (subscribedUserData, t1) -> subscribedUserData.getName().compareToIgnoreCase(t1.getName())); List unsubscribedUsers = new ArrayList<>(); compareTwoSubscribedUserList(subscribedUserDataList, existingSubscribedUserDataList, unsubscribedUsers); for (String unsubscribed : unsubscribedUsers) { - mSubscribedUserDao.deleteSubscribedUser(unsubscribed, mAccountName); + subscribedUserDao.deleteSubscribedUser(unsubscribed, accountName); } for (SubscribedUserData s : subscribedUserDataList) { - mSubscribedUserDao.insert(s); + subscribedUserDao.insert(s); } } if (subredditDataList != null) { for (SubredditData s : subredditDataList) { - mSubredditDao.insert(s); + subredditDao.insert(s); } } - } - return null; + + handler.post(insertSubscribedThingListener::insertSuccess); + }); } - @Override - protected void onPostExecute(Void aVoid) { - mInsertSubscribedThingListener.insertSuccess(); + public static void insertSubscribedThings(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + SubscribedSubredditData singleSubscribedSubredditData, + InsertSubscribedThingListener insertSubscribedThingListener) { + executor.execute(() -> { + String accountName = singleSubscribedSubredditData.getUsername(); + if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { + handler.post(insertSubscribedThingListener::insertSuccess); + return; + } + + redditDataRoomDatabase.subscribedSubredditDao().insert(singleSubscribedSubredditData); + handler.post(insertSubscribedThingListener::insertSuccess); + }); } - private void compareTwoSubscribedSubredditList(List newSubscribedSubreddits, + public static void insertSubscribedThings(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + SubscribedUserData mSingleSubscribedUserData, + InsertSubscribedThingListener insertSubscribedThingListener) { + executor.execute(() -> { + String accountName = mSingleSubscribedUserData.getUsername(); + if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { + handler.post(insertSubscribedThingListener::insertSuccess); + return; + } + + redditDataRoomDatabase.subscribedUserDao().insert(mSingleSubscribedUserData); + handler.post(insertSubscribedThingListener::insertSuccess); + }); + } + + private static void compareTwoSubscribedSubredditList(List newSubscribedSubreddits, List oldSubscribedSubreddits, List unsubscribedSubredditNames) { int newIndex = 0; @@ -152,7 +135,7 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask } } - private void compareTwoSubscribedUserList(List newSubscribedUsers, + private static void compareTwoSubscribedUserList(List newSubscribedUsers, List oldSubscribedUsers, List unsubscribedUserNames) { int newIndex = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserData.java new file mode 100644 index 00000000..0e480315 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserData.java @@ -0,0 +1,25 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.user.UserData; + +public class InsertUserData { + + public static void insertUserData(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + UserData userData, InsertUserDataListener insertUserDataListener) { + executor.execute(() -> { + redditDataRoomDatabase.userDao().insert(userData); + if (insertUserDataListener != null) { + handler.post(insertUserDataListener::insertSuccess); + } + }); + } + + public interface InsertUserDataListener { + void insertSuccess(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserDataAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserDataAsyncTask.java deleted file mode 100644 index caf2f7f1..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertUserDataAsyncTask.java +++ /dev/null @@ -1,36 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.user.UserDao; -import ml.docilealligator.infinityforreddit.user.UserData; - -public class InsertUserDataAsyncTask extends AsyncTask { - private UserDao userDao; - private UserData userData; - private InsertUserDataCallback insertUserDataCallback; - - public InsertUserDataAsyncTask(UserDao userDao, UserData userData, InsertUserDataCallback insertUserDataCallback) { - this.userDao = userDao; - this.userData = userData; - this.insertUserDataCallback = insertUserDataCallback; - } - - @Override - protected Void doInBackground(Void... voids) { - userDao.insert(userData); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (insertUserDataCallback != null) { - insertUserDataCallback.insertSuccess(); - } - } - - public interface InsertUserDataCallback { - void insertSuccess(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java new file mode 100644 index 00000000..1d382255 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java @@ -0,0 +1,48 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.ArrayList; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; +import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; +import ml.docilealligator.infinityforreddit.subreddit.SubredditData; +import retrofit2.Retrofit; + +public class LoadSubredditIcon { + + public static void loadSubredditIcon(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, + String subredditName, Retrofit retrofit, + LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) { + executor.execute(() -> { + SubredditDao subredditDao = redditDataRoomDatabase.subredditDao(); + SubredditData subredditData = subredditDao.getSubredditData(subredditName); + if (subredditData != null) { + String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl(); + handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl)); + } else { + handler.post(() -> FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) { + ArrayList singleSubredditDataList = new ArrayList<>(); + singleSubredditDataList.add(subredditData1); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, null, + null, null, singleSubredditDataList, + () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData1.getIconUrl())); + } + + @Override + public void onFetchSubredditDataFail() { + loadSubredditIconAsyncTaskListener.loadIconSuccess(null); + } + })); + } + }); + } + + public interface LoadSubredditIconAsyncTaskListener { + void loadIconSuccess(String iconImageUrl); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIconAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIconAsyncTask.java deleted file mode 100644 index 7092bae7..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIconAsyncTask.java +++ /dev/null @@ -1,71 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; -import ml.docilealligator.infinityforreddit.subreddit.SubredditData; -import retrofit2.Retrofit; - -public class LoadSubredditIconAsyncTask extends AsyncTask { - private RedditDataRoomDatabase redditDataRoomDatabase; - private SubredditDao subredditDao; - private String subredditName; - private Retrofit retrofit; - private String iconImageUrl; - private boolean hasSubredditInDb; - private LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener; - public LoadSubredditIconAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String subredditName, Retrofit retrofit, - LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.subredditDao = redditDataRoomDatabase.subredditDao(); - this.subredditName = subredditName; - this.retrofit = retrofit; - this.loadSubredditIconAsyncTaskListener = loadSubredditIconAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - SubredditData subredditData = subredditDao.getSubredditData(subredditName); - if (subredditData != null) { - iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl(); - hasSubredditInDb = true; - } else { - hasSubredditInDb = false; - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (!isCancelled()) { - if (hasSubredditInDb) { - loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl); - } else { - FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - ArrayList singleSubredditDataList = new ArrayList<>(); - singleSubredditDataList.add(subredditData); - new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, null, - null, null, singleSubredditDataList, - () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData.getIconUrl())).execute(); - } - - @Override - public void onFetchSubredditDataFail() { - loadSubredditIconAsyncTaskListener.loadIconSuccess(null); - } - }); - } - } - } - - public interface LoadSubredditIconAsyncTaskListener { - void loadIconSuccess(String iconImageUrl); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserData.java new file mode 100644 index 00000000..c6ef0ffc --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserData.java @@ -0,0 +1,42 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.user.FetchUserData; +import ml.docilealligator.infinityforreddit.user.UserDao; +import ml.docilealligator.infinityforreddit.user.UserData; +import retrofit2.Retrofit; + +public class LoadUserData { + + public static void loadUserData(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, String userName, + Retrofit retrofit, LoadUserDataAsyncTaskListener loadUserDataAsyncTaskListener) { + executor.execute(() -> { + UserDao userDao = redditDataRoomDatabase.userDao(); + if (userDao.getUserData(userName) != null) { + String iconImageUrl = userDao.getUserData(userName).getIconUrl(); + handler.post(() -> loadUserDataAsyncTaskListener.loadUserDataSuccess(iconImageUrl)); + } else { + handler.post(() -> FetchUserData.fetchUserData(retrofit, userName, new FetchUserData.FetchUserDataListener() { + @Override + public void onFetchUserDataSuccess(UserData userData) { + InsertUserData.insertUserData(executor, handler, redditDataRoomDatabase, userData, + () -> loadUserDataAsyncTaskListener.loadUserDataSuccess(userData.getIconUrl())); + } + + @Override + public void onFetchUserDataFailed() { + loadUserDataAsyncTaskListener.loadUserDataSuccess(null); + } + })); + } + }); + } + + public interface LoadUserDataAsyncTaskListener { + void loadUserDataSuccess(String iconImageUrl); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserDataAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserDataAsyncTask.java deleted file mode 100644 index 3386965e..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadUserDataAsyncTask.java +++ /dev/null @@ -1,58 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.user.FetchUserData; -import ml.docilealligator.infinityforreddit.user.UserDao; -import ml.docilealligator.infinityforreddit.user.UserData; -import retrofit2.Retrofit; - -public class LoadUserDataAsyncTask extends AsyncTask { - private UserDao userDao; - private String userName; - private String iconImageUrl; - private boolean hasUserInDb; - private Retrofit retrofit; - private LoadUserDataAsyncTaskListener loadUserDataAsyncTaskListener; - public LoadUserDataAsyncTask(UserDao userDao, String userName, Retrofit retrofit, LoadUserDataAsyncTaskListener loadUserDataAsyncTaskListener) { - this.userDao = userDao; - this.userName = userName; - this.retrofit = retrofit; - this.loadUserDataAsyncTaskListener = loadUserDataAsyncTaskListener; - } - - @Override - protected Void doInBackground(Void... voids) { - if (userDao.getUserData(userName) != null) { - iconImageUrl = userDao.getUserData(userName).getIconUrl(); - hasUserInDb = true; - } else { - hasUserInDb = false; - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (hasUserInDb) { - loadUserDataAsyncTaskListener.loadUserDataSuccess(iconImageUrl); - } else { - FetchUserData.fetchUserData(retrofit, userName, new FetchUserData.FetchUserDataListener() { - @Override - public void onFetchUserDataSuccess(UserData userData) { - new InsertUserDataAsyncTask(userDao, userData, () -> loadUserDataAsyncTaskListener.loadUserDataSuccess(userData.getIconUrl())).execute(); - } - - @Override - public void onFetchUserDataFailed() { - loadUserDataAsyncTaskListener.loadUserDataSuccess(null); - } - }); - } - } - - public interface LoadUserDataAsyncTaskListener { - void loadUserDataSuccess(String iconImageUrl); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccount.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccount.java new file mode 100644 index 00000000..b742f983 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccount.java @@ -0,0 +1,29 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.account.AccountDao; + +public class ParseAndInsertNewAccount { + + public static void parseAndInsertNewAccount(Executor executor, Handler handler, String username, + String accessToken, String refreshToken, String profileImageUrl, + String bannerImageUrl, int karma, String code, AccountDao accountDao, + ParseAndInsertAccountListener parseAndInsertAccountListener) { + executor.execute(() -> { + Account account = new Account(username, accessToken, refreshToken, code, profileImageUrl, + bannerImageUrl, karma, true); + accountDao.markAllAccountsNonCurrent(); + accountDao.insert(account); + + handler.post(parseAndInsertAccountListener::success); + }); + } + + public interface ParseAndInsertAccountListener { + void success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccountAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccountAsyncTask.java deleted file mode 100644 index 7563803e..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/ParseAndInsertNewAccountAsyncTask.java +++ /dev/null @@ -1,50 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import ml.docilealligator.infinityforreddit.account.Account; -import ml.docilealligator.infinityforreddit.account.AccountDao; - -public class ParseAndInsertNewAccountAsyncTask extends AsyncTask { - - private String username; - private String accessToken; - private String refreshToken; - private String profileImageUrl; - private String bannerImageUrl; - private int karma; - private String code; - private AccountDao accountDao; - private ParseAndInsertAccountListener parseAndInsertAccountListener; - public ParseAndInsertNewAccountAsyncTask(String username, String accessToken, String refreshToken, String profileImageUrl, String bannerImageUrl, - int karma, String code, AccountDao accountDao, - ParseAndInsertAccountListener parseAndInsertAccountListener) { - this.username = username; - this.accessToken = accessToken; - this.refreshToken = refreshToken; - this.profileImageUrl = profileImageUrl; - this.bannerImageUrl = bannerImageUrl; - this.karma = karma; - this.code = code; - this.accountDao = accountDao; - this.parseAndInsertAccountListener = parseAndInsertAccountListener; - } - - @Override - protected Void doInBackground(Void... voids) { - Account account = new Account(username, accessToken, refreshToken, code, profileImageUrl, - bannerImageUrl, karma, true); - accountDao.markAllAccountsNonCurrent(); - accountDao.insert(account); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - parseAndInsertAccountListener.success(); - } - - public interface ParseAndInsertAccountListener { - void success(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFile.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFile.java new file mode 100644 index 00000000..c5388f08 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFile.java @@ -0,0 +1,35 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.graphics.Bitmap; +import android.os.Handler; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.Executor; + +public class SaveBitmapImageToFile { + + public static void SaveBitmapImageToFile(Executor executor, Handler handler, Bitmap resource, String cacheDirPath, String fileName, + SaveBitmapImageToFileListener saveBitmapImageToFileListener) { + executor.execute(() -> { + try { + File imageFile = new File(cacheDirPath, fileName); + OutputStream outputStream = new FileOutputStream(imageFile); + resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); + outputStream.flush(); + outputStream.close(); + + handler.post(() -> saveBitmapImageToFileListener.saveSuccess(imageFile)); + } catch (IOException e) { + handler.post(saveBitmapImageToFileListener::saveFailed); + } + }); + } + + public interface SaveBitmapImageToFileListener { + void saveSuccess(File imageFile); + void saveFailed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFileAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFileAsyncTask.java deleted file mode 100644 index 7af3fba4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveBitmapImageToFileAsyncTask.java +++ /dev/null @@ -1,55 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.graphics.Bitmap; -import android.os.AsyncTask; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class SaveBitmapImageToFileAsyncTask extends AsyncTask { - private Bitmap resource; - private String cacheDirPath; - private String fileName; - private SaveBitmapImageToFileAsyncTaskListener saveBitmapImageToFileAsyncTaskListener; - private boolean saveSuccess = true; - private File imageFile; - - public SaveBitmapImageToFileAsyncTask(Bitmap resource, String cacheDirPath, String fileName, - SaveBitmapImageToFileAsyncTaskListener saveBitmapImageToFileAsyncTaskListener) { - this.resource = resource; - this.cacheDirPath = cacheDirPath; - this.fileName = fileName; - this.saveBitmapImageToFileAsyncTaskListener = saveBitmapImageToFileAsyncTaskListener; - } - - public interface SaveBitmapImageToFileAsyncTaskListener { - void saveSuccess(File imageFile); - void saveFailed(); - } - - @Override - protected Void doInBackground(Void... voids) { - try { - imageFile = new File(cacheDirPath, fileName); - OutputStream outputStream = new FileOutputStream(imageFile); - resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); - outputStream.flush(); - outputStream.close(); - } catch (IOException e) { - saveSuccess = false; - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (saveSuccess) { - saveBitmapImageToFileAsyncTaskListener.saveSuccess(imageFile); - } else { - saveBitmapImageToFileAsyncTaskListener.saveFailed(); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFile.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFile.java new file mode 100644 index 00000000..e4b61364 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFile.java @@ -0,0 +1,40 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.Handler; + +import com.bumptech.glide.load.resource.gif.GifDrawable; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.concurrent.Executor; + +public class SaveGIFToFile { + + public static void saveGifToFile(Executor executor, Handler handler, GifDrawable resource, + String cacheDirPath, String fileName, + SaveGIFToFileAsyncTaskListener saveImageToFileAsyncTaskListener) { + executor.execute(() -> { + try { + File imageFile = new File(cacheDirPath, fileName); + ByteBuffer byteBuffer = resource.getBuffer(); + OutputStream outputStream = new FileOutputStream(imageFile); + byte[] bytes = new byte[byteBuffer.capacity()]; + ((ByteBuffer) byteBuffer.duplicate().clear()).get(bytes); + outputStream.write(bytes, 0, bytes.length); + outputStream.close(); + + handler.post(() -> saveImageToFileAsyncTaskListener.saveSuccess(imageFile)); + } catch (IOException e) { + handler.post(saveImageToFileAsyncTaskListener::saveFailed); + } + }); + } + + public interface SaveGIFToFileAsyncTaskListener { + void saveSuccess(File imageFile); + void saveFailed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFileAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFileAsyncTask.java deleted file mode 100644 index 52a86e2c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SaveGIFToFileAsyncTask.java +++ /dev/null @@ -1,59 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.os.AsyncTask; - -import com.bumptech.glide.load.resource.gif.GifDrawable; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; - -public class SaveGIFToFileAsyncTask extends AsyncTask { - private GifDrawable resource; - private String cacheDirPath; - private String fileName; - private SaveGIFToFileAsyncTaskListener saveImageToFileAsyncTaskListener; - private boolean saveSuccess = true; - private File imageFile; - - public SaveGIFToFileAsyncTask(GifDrawable resource, String cacheDirPath, String fileName, - SaveGIFToFileAsyncTaskListener saveImageToFileAsyncTaskListener) { - this.resource = resource; - this.cacheDirPath = cacheDirPath; - this.fileName = fileName; - this.saveImageToFileAsyncTaskListener = saveImageToFileAsyncTaskListener; - } - - public interface SaveGIFToFileAsyncTaskListener { - void saveSuccess(File imageFile); - void saveFailed(); - } - - @Override - protected Void doInBackground(Void... voids) { - try { - imageFile = new File(cacheDirPath, fileName); - ByteBuffer byteBuffer = resource.getBuffer(); - OutputStream outputStream = new FileOutputStream(imageFile); - byte[] bytes = new byte[byteBuffer.capacity()]; - ((ByteBuffer) byteBuffer.duplicate().clear()).get(bytes); - outputStream.write(bytes, 0, bytes.length); - outputStream.close(); - } catch (IOException e) { - saveSuccess = false; - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (saveSuccess) { - saveImageToFileAsyncTaskListener.saveSuccess(imageFile); - } else { - saveImageToFileAsyncTaskListener.saveFailed(); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaper.java new file mode 100644 index 00000000..f19a3cdb --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaper.java @@ -0,0 +1,77 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.app.WallpaperManager; +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.media.ThumbnailUtils; +import android.os.Build; +import android.os.Handler; +import android.util.DisplayMetrics; +import android.view.WindowManager; + +import java.io.IOException; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.WallpaperSetter; + +public class SetAsWallpaper { + + public static void setAsWallpaper(Executor executor, Handler handler, Bitmap bitmap, int setTo, + WallpaperManager manager, WindowManager windowManager, + WallpaperSetter.SetWallpaperListener setWallpaperListener) { + executor.execute(new Runnable() { + @Override + public void run() { + DisplayMetrics metrics = new DisplayMetrics(); + Rect rect = null; + Bitmap bitmapFinal = bitmap; + + if (windowManager != null) { + windowManager.getDefaultDisplay().getMetrics(metrics); + int height = metrics.heightPixels; + int width = metrics.widthPixels; + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + bitmapFinal = ThumbnailUtils.extractThumbnail(bitmapFinal, width, height); + } + + float imageAR = (float) bitmapFinal.getWidth() / (float) bitmapFinal.getHeight(); + float screenAR = (float) width / (float) height; + + if (imageAR > screenAR) { + int desiredWidth = (int) (bitmapFinal.getHeight() * screenAR); + rect = new Rect((bitmapFinal.getWidth() - desiredWidth) / 2, 0, bitmapFinal.getWidth(), bitmapFinal.getHeight()); + } else { + int desiredHeight = (int) (bitmapFinal.getWidth() / screenAR); + rect = new Rect(0, (bitmapFinal.getHeight() - desiredHeight) / 2, bitmapFinal.getWidth(), (bitmapFinal.getHeight() + desiredHeight) / 2); + } + } + try { + switch (setTo) { + case WallpaperSetter.HOME_SCREEN: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + manager.setBitmap(bitmapFinal, rect, true, WallpaperManager.FLAG_SYSTEM); + } + break; + case WallpaperSetter.LOCK_SCREEN: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + manager.setBitmap(bitmapFinal, rect, true, WallpaperManager.FLAG_LOCK); + } + break; + case WallpaperSetter.BOTH_SCREENS: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + manager.setBitmap(bitmapFinal, rect, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK); + } else { + manager.setBitmap(bitmapFinal); + } + break; + } + + handler.post(setWallpaperListener::success); + } catch (IOException e) { + handler.post(setWallpaperListener::failed); + } + } + }); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaperAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaperAsyncTask.java deleted file mode 100644 index c613cb9c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/SetAsWallpaperAsyncTask.java +++ /dev/null @@ -1,95 +0,0 @@ -package ml.docilealligator.infinityforreddit.asynctasks; - -import android.app.WallpaperManager; -import android.graphics.Bitmap; -import android.graphics.Rect; -import android.media.ThumbnailUtils; -import android.os.AsyncTask; -import android.os.Build; -import android.util.DisplayMetrics; -import android.view.WindowManager; - -import java.io.IOException; - -import ml.docilealligator.infinityforreddit.WallpaperSetter; - -public class SetAsWallpaperAsyncTask extends AsyncTask { - - private Bitmap bitmap; - private int setTo; - private WallpaperManager manager; - private WindowManager windowManager; - private WallpaperSetter.SetWallpaperListener setWallpaperListener; - private boolean success = true; - - public SetAsWallpaperAsyncTask(Bitmap bitmap, int setTo, WallpaperManager manager, WindowManager windowManager, - WallpaperSetter.SetWallpaperListener setWallpaperListener) { - this.bitmap = bitmap; - this.setTo = setTo; - this.manager = manager; - this.windowManager = windowManager; - this.setWallpaperListener = setWallpaperListener; - } - - @Override - protected Void doInBackground(Void... voids) { - DisplayMetrics metrics = new DisplayMetrics(); - Rect rect = null; - - if (windowManager != null) { - windowManager.getDefaultDisplay().getMetrics(metrics); - int height = metrics.heightPixels; - int width = metrics.widthPixels; - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height); - } - - float imageAR = (float) bitmap.getWidth() / (float) bitmap.getHeight(); - float screenAR = (float) width / (float) height; - - if (imageAR > screenAR) { - int desiredWidth = (int) (bitmap.getHeight() * screenAR); - rect = new Rect((bitmap.getWidth() - desiredWidth) / 2, 0, bitmap.getWidth(), bitmap.getHeight()); - } else { - int desiredHeight = (int) (bitmap.getWidth() / screenAR); - rect = new Rect(0, (bitmap.getHeight() - desiredHeight) / 2, bitmap.getWidth(), (bitmap.getHeight() + desiredHeight) / 2); - } - } - try { - switch (setTo) { - case WallpaperSetter.HOME_SCREEN: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM); - } - break; - case WallpaperSetter.LOCK_SCREEN: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_LOCK); - } - break; - case WallpaperSetter.BOTH_SCREENS: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK); - } else { - manager.setBitmap(bitmap); - } - break; - } - } catch (IOException e) { - success = false; - } - - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (success) { - setWallpaperListener.success(); - } else { - setWallpaperListener.failed(); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java index a740116c..38726cd8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -24,20 +24,22 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.fastscroll.FastScrollerBuilder; -import ml.docilealligator.infinityforreddit.activities.BaseActivity; -import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; -import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; +import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import retrofit2.Retrofit; @@ -70,7 +72,9 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject - CustomThemeWrapper customThemeWrapper; + CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; SubscribedUserViewModel mSubscribedUserViewModel; private Activity mActivity; private RequestManager mGlide; @@ -108,7 +112,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo mLinearLayoutManager = new LinearLayoutManager(mActivity); mRecyclerView.setLayoutManager(mLinearLayoutManager); FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity, - mOauthRetrofit, mRedditDataRoomDatabase, customThemeWrapper, + mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, getArguments().getString(EXTRA_ACCESS_TOKEN)); mRecyclerView.setAdapter(adapter); new FastScrollerBuilder(mRecyclerView).build(); @@ -117,7 +121,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME))) .get(SubscribedUserViewModel.class); - mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> { + mSubscribedUserViewModel.getAllSubscribedUsers().observe(getViewLifecycleOwner(), subscribedUserData -> { mSwipeRefreshLayout.setRefreshing(false); if (subscribedUserData == null || subscribedUserData.size() == 0) { mRecyclerView.setVisibility(View.GONE); @@ -131,7 +135,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo adapter.setSubscribedUsers(subscribedUserData); }); - mSubscribedUserViewModel.getAllFavoriteSubscribedUsers().observe(this, favoriteSubscribedUserData -> { + mSubscribedUserViewModel.getAllFavoriteSubscribedUsers().observe(getViewLifecycleOwner(), favoriteSubscribedUserData -> { mSwipeRefreshLayout.setRefreshing(false); if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { mLinearLayout.setVisibility(View.GONE); @@ -159,12 +163,12 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo public void applyTheme() { if (mActivity instanceof SubscribedThingListingActivity) { mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); } else { mSwipeRefreshLayout.setEnabled(false); } - mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java index 28f9a0bf..9c86135c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -24,6 +24,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -72,6 +74,8 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm Retrofit mOauthRetrofit; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; public MultiRedditViewModel mMultiRedditViewModel; private AppCompatActivity mActivity; @@ -113,7 +117,8 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm mLinearLayoutManager = new LinearLayoutManager(mActivity); mRecyclerView.setLayoutManager(mLinearLayoutManager); MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity, - mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() { + mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, + new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() { @Override public void onClick(MultiReddit multiReddit) { if (mActivity instanceof MultiredditSelectionActivity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 0f1ee2d8..90b1a798 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -437,7 +437,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout); - mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, + mAdapter = new PostRecyclerViewAdapter(activity, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale, windowWidth, accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, @@ -503,7 +503,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { sortType = new SortType(SortType.Type.valueOf(sort)); } - mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, + mAdapter = new PostRecyclerViewAdapter(activity, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale, windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, @@ -567,7 +567,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { sortType = new SortType(SortType.Type.valueOf(sort)); } - mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, + mAdapter = new PostRecyclerViewAdapter(activity, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale, windowWidth, accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, @@ -631,7 +631,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout); - mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, + mAdapter = new PostRecyclerViewAdapter(activity, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale, windowWidth, accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, @@ -686,7 +686,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); - mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, + mAdapter = new PostRecyclerViewAdapter(activity, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale, windowWidth, accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 571350ce..c9550531 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.text.Spanned; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; @@ -23,6 +24,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import org.commonmark.ext.gfm.tables.TableBlock; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -45,7 +48,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; @@ -72,6 +75,8 @@ public class SidebarFragment extends Fragment { RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; public SidebarFragment() { // Required empty public constructor @@ -189,7 +194,8 @@ public class SidebarFragment extends Fragment { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { swipeRefreshLayout.setRefreshing(false); - new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> swipeRefreshLayout.setRefreshing(false)).execute(); + InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, + subredditData, () -> swipeRefreshLayout.setRefreshing(false)); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java index 996739dc..99fc5ec4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -25,6 +25,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -88,7 +90,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Named("nsfw_and_spoiler") SharedPreferences mNsfwAndSpoilerSharedPreferences; @Inject - CustomThemeWrapper customThemeWrapper; + CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private LinearLayoutManager mLinearLayoutManager; private SubredditListingRecyclerViewAdapter mAdapter; private Activity mActivity; @@ -135,8 +139,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); - mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mRetrofit, - customThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase, + mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRetrofit, + mCustomThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase, new SubredditListingRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { @@ -236,9 +240,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); - mFetchSubredditListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + mFetchSubredditListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java index 6279bae5..5275cb87 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -24,6 +24,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -74,7 +76,9 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject - CustomThemeWrapper customThemeWrapper; + CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; public SubscribedSubredditViewModel mSubscribedSubredditViewModel; private Activity mActivity; private RequestManager mGlide; @@ -116,12 +120,12 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra SubscribedSubredditsRecyclerViewAdapter adapter; if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) { - adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mOauthRetrofit, mRedditDataRoomDatabase, - customThemeWrapper, accessToken, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION), + adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, + mCustomThemeWrapper, accessToken, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION), (name, iconUrl, subredditIsUser) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl, subredditIsUser)); } else { - adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mOauthRetrofit, mRedditDataRoomDatabase, - customThemeWrapper, accessToken); + adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, + mCustomThemeWrapper, accessToken); } mRecyclerView.setAdapter(adapter); @@ -130,7 +134,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra mSubscribedSubredditViewModel = new ViewModelProvider(this, new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName)) .get(SubscribedSubredditViewModel.class); - mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> { + mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(getViewLifecycleOwner(), subscribedSubredditData -> { mSwipeRefreshLayout.setRefreshing(false); if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) { mRecyclerView.setVisibility(View.GONE); @@ -146,7 +150,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra adapter.setSubscribedSubreddits(subscribedSubredditData); }); - mSubscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, favoriteSubscribedSubredditData -> { + mSubscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(getViewLifecycleOwner(), favoriteSubscribedSubredditData -> { mSwipeRefreshLayout.setRefreshing(false); if (favoriteSubscribedSubredditData != null && favoriteSubscribedSubredditData.size() > 0) { mLinearLayout.setVisibility(View.GONE); @@ -175,12 +179,12 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra public void applyTheme() { if (mActivity instanceof SubscribedThingListingActivity) { mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); } else { mSwipeRefreshLayout.setEnabled(false); } - mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java index f6d9ceb1..b1c09395 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java @@ -25,6 +25,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -88,7 +90,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Named("nsfw_and_spoiler") SharedPreferences mNsfwAndSpoilerSharedPreferences; @Inject - CustomThemeWrapper customThemeWrapper; + CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private LinearLayoutManager mLinearLayoutManager; private String mQuery; private UserListingRecyclerViewAdapter mAdapter; @@ -135,8 +139,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); - mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit, - customThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase.subscribedUserDao(), + mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mExecutor, mOauthRetrofit, mRetrofit, + mCustomThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase, new UserListingRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { @@ -238,9 +242,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); - mFetchUserListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + mFetchUserListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index df4c01cb..0dcf1f01 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -37,17 +38,21 @@ import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import java.io.File; +import java.util.concurrent.Executor; + +import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; -import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFileAsyncTask; -import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.ImgurMedia; +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; +import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; +import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; +import ml.docilealligator.infinityforreddit.services.DownloadMediaService; public class ViewImgurImageFragment extends Fragment { @@ -60,6 +65,8 @@ public class ViewImgurImageFragment extends Fragment { SubsamplingScaleImageView imageView; @BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment) LinearLayout errorLinearLayout; + @Inject + Executor mExecutor; private ViewImgurMediaActivity activity; private RequestManager glide; @@ -76,6 +83,8 @@ public class ViewImgurImageFragment extends Fragment { Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_view_imgur_images, container, false); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + ButterKnife.bind(this, rootView); setHasOptionsMenu(true); @@ -150,83 +159,83 @@ public class ViewImgurImageFragment extends Fragment { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.action_download_view_imgur_image_fragment: - if (isDownloading) { - return false; - } + int itemId = item.getItemId(); + if (itemId == R.id.action_download_view_imgur_image_fragment) { + if (isDownloading) { + return false; + } - isDownloading = true; + isDownloading = true; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (ContextCompat.checkSelfPermission(activity, - Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(activity, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { - // Permission is not granted - // No explanation needed; request the permission - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); - } else { - // Permission has already been granted - download(); - } + // Permission is not granted + // No explanation needed; request the permission + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); } else { + // Permission has already been granted download(); } + } else { + download(); + } - return true; - case R.id.action_share_view_imgur_image_fragment: - glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget() { + return true; + } else if (itemId == R.id.action_share_view_imgur_image_fragment) { + glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - if (activity.getExternalCacheDir() != null) { - Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show(); - new SaveBitmapImageToFileAsyncTask(resource, activity.getExternalCacheDir().getPath(), - imgurMedia.getFileName(), - new SaveBitmapImageToFileAsyncTask.SaveBitmapImageToFileAsyncTaskListener() { - @Override - public void saveSuccess(File imageFile) { - Uri uri = FileProvider.getUriForFile(activity, - BuildConfig.APPLICATION_ID + ".provider", imageFile); - Intent shareIntent = new Intent(); - shareIntent.setAction(Intent.ACTION_SEND); - shareIntent.putExtra(Intent.EXTRA_STREAM, uri); - shareIntent.setType("image/*"); - shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); - } + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (activity.getExternalCacheDir() != null) { + Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show(); + SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, activity.getExternalCacheDir().getPath(), + imgurMedia.getFileName(), + new SaveBitmapImageToFile.SaveBitmapImageToFileListener() { + @Override + public void saveSuccess(File imageFile) { + Uri uri = FileProvider.getUriForFile(activity, + BuildConfig.APPLICATION_ID + ".provider", imageFile); + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.setType("image/*"); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); + } - @Override - public void saveFailed() { - Toast.makeText(activity, - R.string.cannot_save_image, Toast.LENGTH_SHORT).show(); - } - }).execute(); - } else { - Toast.makeText(activity, - R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); - } + @Override + public void saveFailed() { + Toast.makeText(activity, + R.string.cannot_save_image, Toast.LENGTH_SHORT).show(); + } + }); + } else { + Toast.makeText(activity, + R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - return true; - case R.id.action_set_wallpaper_view_imgur_image_fragment: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition()); - setAsWallpaperBottomSheetFragment.setArguments(bundle); - setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); - } else { - ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition()); } - return true; + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + return true; + } else if (itemId == R.id.action_set_wallpaper_view_imgur_image_fragment) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition()); + setAsWallpaperBottomSheetFragment.setArguments(bundle); + setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); + } else { + ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition()); + } + return true; } return false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 7373279e..75e3b2c6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -42,15 +43,19 @@ import com.github.piasy.biv.view.BigImageView; import com.github.piasy.biv.view.GlideImageViewFactory; import java.io.File; +import java.util.concurrent.Executor; + +import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.BuildConfig; +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; -import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFileAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFileAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; +import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; @@ -67,6 +72,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { BigImageView imageView; @BindView(R.id.load_image_error_linear_layout_view_reddit_gallery_image_or_gif_fragment) LinearLayout errorLinearLayout; + @Inject + Executor mExecutor; private ViewRedditGalleryActivity activity; private RequestManager glide; @@ -86,6 +93,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { View rootView = inflater.inflate(R.layout.fragment_view_reddit_gallery_image_or_gif, container, false); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + ButterKnife.bind(this, rootView); setHasOptionsMenu(true); @@ -283,9 +292,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { if (activity.getExternalCacheDir() != null) { Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show(); - new SaveBitmapImageToFileAsyncTask(resource, activity.getExternalCacheDir().getPath(), + SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, activity.getExternalCacheDir().getPath(), media.fileName, - new SaveBitmapImageToFileAsyncTask.SaveBitmapImageToFileAsyncTaskListener() { + new SaveBitmapImageToFile.SaveBitmapImageToFileListener() { @Override public void saveSuccess(File imageFile) { Uri uri = FileProvider.getUriForFile(activity, @@ -303,7 +312,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { Toast.makeText(activity, R.string.cannot_save_image, Toast.LENGTH_SHORT).show(); } - }).execute(); + }); } else { Toast.makeText(activity, R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); @@ -328,8 +337,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public boolean onResourceReady(GifDrawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { if (activity.getExternalCacheDir() != null) { - new SaveGIFToFileAsyncTask(resource, activity.getExternalCacheDir().getPath(), media.fileName, - new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() { + SaveGIFToFile.saveGifToFile(mExecutor, new Handler(), resource, activity.getExternalCacheDir().getPath(), media.fileName, + new SaveGIFToFile.SaveGIFToFileAsyncTaskListener() { @Override public void saveSuccess(File imageFile) { Uri uri = FileProvider.getUriForFile(activity, @@ -347,7 +356,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { Toast.makeText(activity, R.string.cannot_save_gif, Toast.LENGTH_SHORT).show(); } - }).execute(); + }); } else { Toast.makeText(activity, R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/DeleteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/DeleteMultiReddit.java index 0d6567a1..7fbb3ab7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/DeleteMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/DeleteMultiReddit.java @@ -1,8 +1,12 @@ package ml.docilealligator.infinityforreddit.multireddit; +import android.os.Handler; + import androidx.annotation.NonNull; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteMultiredditInDatabaseAsyncTask; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.asynctasks.DeleteMultiredditInDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -12,12 +16,14 @@ import retrofit2.Response; import retrofit2.Retrofit; public class DeleteMultiReddit { + public interface DeleteMultiRedditListener { void success(); void failed(); } - public static void deleteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, + public static void deleteMultiReddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, String accountName, String multipath, DeleteMultiRedditListener deleteMultiRedditListener) { oauthRetrofit.create(RedditAPI.class).deleteMultiReddit(APIUtils.getOAuthHeader(accessToken), @@ -25,8 +31,8 @@ public class DeleteMultiReddit { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - new DeleteMultiredditInDatabaseAsyncTask(redditDataRoomDatabase, accountName, multipath, - deleteMultiRedditListener::success).execute(); + DeleteMultiredditInDatabase.deleteMultiredditInDatabase(executor, handler, redditDataRoomDatabase, accountName, multipath, + deleteMultiRedditListener::success); } else { deleteMultiRedditListener.failed(); } 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 5d6c7573..227b7665 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java @@ -1,12 +1,15 @@ package ml.docilealligator.infinityforreddit.multireddit; +import android.os.Handler; + import androidx.annotation.NonNull; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.utils.APIUtils; import retrofit2.Call; @@ -20,7 +23,8 @@ public class FavoriteMultiReddit { void failed(); } - public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, + public static void favoriteMultiReddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, boolean makeFavorite, MultiReddit multiReddit, FavoriteMultiRedditListener favoriteMultiRedditListener) { Map params = new HashMap<>(); @@ -33,8 +37,8 @@ public class FavoriteMultiReddit { public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { multiReddit.setFavorite(makeFavorite); - new InsertMultiRedditAsyncTask(redditDataRoomDatabase, multiReddit, - favoriteMultiRedditListener::success).execute(); + InsertMultireddit.insertMultireddit(executor, handler, redditDataRoomDatabase, multiReddit, + favoriteMultiRedditListener::success); } else { favoriteMultiRedditListener.failed(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java index 7b586b5c..cbb6669f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.widget.Toast; import androidx.annotation.NonNull; @@ -16,19 +17,21 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.greenrobot.eventbus.EventBus; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllPostLayoutsAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllReadPostsAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSortTypesAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSubredditsAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllThemesAsyncTask; -import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllUsersAsyncTask; -import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllPostLayouts; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllReadPosts; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSortTypes; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSubreddits; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllThemes; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllUsers; +import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** @@ -65,6 +68,8 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { @Inject @Named("nsfw_and_spoiler") SharedPreferences nsfwAndBlurringSharedPreferences; + @Inject + Executor executor; private Activity activity; @Override @@ -88,8 +93,8 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllSubredditsAsyncTask(mRedditDataRoomDatabase, - () -> Toast.makeText(activity, R.string.delete_all_subreddits_success, Toast.LENGTH_SHORT).show()).execute()) + -> DeleteAllSubreddits.deleteAllSubreddits(executor, new Handler(), mRedditDataRoomDatabase, + () -> Toast.makeText(activity, R.string.delete_all_subreddits_success, Toast.LENGTH_SHORT).show())) .setNegativeButton(R.string.no, null) .show(); return true; @@ -101,8 +106,8 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllUsersAsyncTask(mRedditDataRoomDatabase, - () -> Toast.makeText(activity, R.string.delete_all_users_success, Toast.LENGTH_SHORT).show()).execute()) + -> DeleteAllUsers.deleteAllUsers(executor, new Handler(), mRedditDataRoomDatabase, + () -> Toast.makeText(activity, R.string.delete_all_users_success, Toast.LENGTH_SHORT).show())) .setNegativeButton(R.string.no, null) .show(); return true; @@ -114,10 +119,11 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllSortTypesAsyncTask(mSharedPreferences, mSortTypeSharedPreferences, () -> { + -> DeleteAllSortTypes.deleteAllSortTypes(executor, new Handler(), + mSharedPreferences, mSortTypeSharedPreferences, () -> { Toast.makeText(activity, R.string.delete_all_sort_types_success, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); - }).execute()) + })) .setNegativeButton(R.string.no, null) .show(); return true; @@ -129,10 +135,11 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllPostLayoutsAsyncTask(mSharedPreferences, mPostLayoutSharedPreferences, () -> { + -> DeleteAllPostLayouts.deleteAllPostLayouts(executor, new Handler(), + mSharedPreferences, mPostLayoutSharedPreferences, () -> { Toast.makeText(activity, R.string.delete_all_post_layouts_success, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); - }).execute()) + })) .setNegativeButton(R.string.no, null) .show(); return true; @@ -144,11 +151,12 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllThemesAsyncTask(mRedditDataRoomDatabase, lightThemeSharedPreferences, + -> DeleteAllThemes.deleteAllThemes(executor, new Handler(), + mRedditDataRoomDatabase, lightThemeSharedPreferences, darkThemeSharedPreferences, amoledThemeSharedPreferences, () -> { Toast.makeText(activity, R.string.delete_all_themes_success, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); - }).execute()) + })) .setNegativeButton(R.string.no, null) .show(); return true; @@ -175,9 +183,10 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteAllReadPostsAsyncTask(mRedditDataRoomDatabase, () -> { + -> DeleteAllReadPosts.deleteAllReadPosts(executor, new Handler(), + mRedditDataRoomDatabase, () -> { Toast.makeText(activity, R.string.delete_all_read_posts_success, Toast.LENGTH_SHORT).show(); - }).execute()) + })) .setNegativeButton(R.string.no, null) .show(); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java index 170ec7ed..6edbcf6d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java @@ -7,6 +7,7 @@ import androidx.annotation.NonNull; import java.util.HashMap; import java.util.Map; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; @@ -18,18 +19,18 @@ import retrofit2.Retrofit; public class UserFollowing { public static void followUser(Retrofit oauthRetrofit, Retrofit retrofit, String accessToken, String username, String accountName, - SubscribedUserDao subscribedUserDao, + RedditDataRoomDatabase redditDataRoomDatabase, UserFollowingListener userFollowingListener) { userFollowing(oauthRetrofit, retrofit, accessToken, username, accountName, "sub", - subscribedUserDao, userFollowingListener); + redditDataRoomDatabase.subscribedUserDao(), userFollowingListener); } public static void unfollowUser(Retrofit oauthRetrofit, Retrofit retrofit, String accessToken, String username, String accountName, - SubscribedUserDao subscribedUserDao, + RedditDataRoomDatabase redditDataRoomDatabase, UserFollowingListener userFollowingListener) { userFollowing(oauthRetrofit, retrofit, accessToken, username, accountName, "unsub", - subscribedUserDao, userFollowingListener); + redditDataRoomDatabase.subscribedUserDao(), userFollowingListener); } private static void userFollowing(Retrofit oauthRetrofit, Retrofit retrofit, String accessToken, diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 71bf3538..85441699 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -24,8 +24,8 @@ "编辑版块聚合" "被选中的版块" "报告" - "图片" - "视频" + "图片 %1$d/%2$d" + "视频 %1$d/%2$d" "私信" "图片 %1$d/%2$d "