From 74f17d4db510bd1fe9ab5c3aff02f45e95184c81 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:02:52 -0400 Subject: Fix NullPointerException in ParseSubredditData. --- .../infinityforreddit/activities/MainActivity.java | 18 +- .../activities/SearchActivity.java | 26 +-- .../activities/SearchResultActivity.java | 24 +-- .../activities/ViewMultiRedditDetailActivity.java | 20 ++- .../activities/ViewSubredditDetailActivity.java | 57 ++++--- .../activities/ViewUserDetailActivity.java | 24 +-- .../asynctasks/LoadSubredditIcon.java | 32 ++-- .../fragments/SidebarFragment.java | 29 ++-- .../fragments/SubredditListingFragment.java | 2 +- .../fragments/ViewPostDetailFragment.java | 4 +- .../subreddit/FetchSubredditData.java | 99 +++++------ .../subreddit/ParseSubredditData.java | 190 +++++++++------------ .../subreddit/SubredditListingDataSource.java | 21 ++- .../SubredditListingDataSourceFactory.java | 12 +- .../subreddit/SubredditListingViewModel.java | 16 +- .../subreddit/SubredditSubscription.java | 50 +++--- 16 files changed, 312 insertions(+), 312 deletions(-) (limited to 'app/src/main/java/ml') 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 b07f7a92..7a1bd74d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -1381,6 +1381,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); + Handler handler = new Handler(); thingEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -1403,16 +1404,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - adapter.setSubreddits(subredditData); - } + ParseSubredditData.parseSubredditListingData(mExecutor, handler, + response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + adapter.setSubreddits(subredditData); + } - @Override - public void onParseSubredditListingDataFail() { + @Override + public void onParseSubredditListingDataFail() { - } + } }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index 21fe403b..714948b8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -166,6 +166,7 @@ public class SearchActivity extends BaseActivity { binding.searchEditTextSearchActivity.setImeOptions(binding.searchEditTextSearchActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); } + Handler handler = new Handler(); binding.searchEditTextSearchActivity.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -190,18 +191,19 @@ public class SearchActivity extends BaseActivity { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - subredditAutocompleteRecyclerViewAdapter.setSubreddits(subredditData); - binding.recyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); - } - - @Override - public void onParseSubredditListingDataFail() { - - } - }); + ParseSubredditData.parseSubredditListingData(executor, handler, + response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + subredditAutocompleteRecyclerViewAdapter.setSubreddits(subredditData); + binding.recyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); + } + + @Override + public void onParseSubredditListingDataFail() { + + } + }); } } 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 a100e7a4..fe7bec33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -587,6 +587,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect return false; }); + Handler handler = new Handler(); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); thingEditText.addTextChangedListener(new TextWatcher() { @Override @@ -610,17 +611,18 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - adapter.setSubreddits(subredditData); - } - - @Override - public void onParseSubredditListingDataFail() { - - } - }); + ParseSubredditData.parseSubredditListingData(executor, handler, response.body(), + nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + adapter.setSubreddits(subredditData); + } + + @Override + public void onParseSubredditListingDataFail() { + + } + }); } } 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 82346029..cf582fa9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -594,6 +594,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT return false; }); + Handler handler = new Handler(); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); thingEditText.addTextChangedListener(new TextWatcher() { @Override @@ -617,17 +618,18 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - adapter.setSubreddits(subredditData); - } + ParseSubredditData.parseSubredditListingData(mExecutor, handler, response.body(), + nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + adapter.setSubreddits(subredditData); + } - @Override - public void onParseSubredditListingDataFail() { + @Override + public void onParseSubredditListingDataFail() { - } - }); + } + }); } } 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 202967e8..48898f00 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -544,21 +544,24 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp private void fetchSubredditData() { if (!mFetchSubredditInfoSuccess) { - FetchSubredditData.fetchSubredditData(accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; - binding.onlineSubscriberCountTextViewViewSubredditDetailActivity.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); - InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, - subredditData, () -> mFetchSubredditInfoSuccess = true); - } + Handler handler = new Handler(); + FetchSubredditData.fetchSubredditData(mExecutor, handler, + accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, + subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { + mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; + binding.onlineSubscriberCountTextViewViewSubredditDetailActivity.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); + InsertSubredditData.insertSubredditData(mExecutor, handler, mRedditDataRoomDatabase, + subredditData, () -> mFetchSubredditInfoSuccess = true); + } - @Override - public void onFetchSubredditDataFail(boolean isQuarantined) { - makeSnackbar(R.string.cannot_fetch_subreddit_info, true); - mFetchSubredditInfoSuccess = false; - } - }); + @Override + public void onFetchSubredditDataFail(boolean isQuarantined) { + makeSnackbar(R.string.cannot_fetch_subreddit_info, true); + mFetchSubredditInfoSuccess = false; + } + }); } } @@ -1396,6 +1399,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp return false; }); + Handler handler = new Handler(); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); thingEditText.addTextChangedListener(new TextWatcher() { @Override @@ -1415,21 +1419,22 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } subredditAutocompleteCall = mOauthRetrofit.create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(accessToken), editable.toString(), nsfw); - subredditAutocompleteCall.enqueue(new Callback() { + subredditAutocompleteCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - adapter.setSubreddits(subredditData); - } - - @Override - public void onParseSubredditListingDataFail() { - - } - }); + ParseSubredditData.parseSubredditListingData(mExecutor, handler, response.body(), + nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + adapter.setSubreddits(subredditData); + } + + @Override + public void onParseSubredditListingDataFail() { + + } + }); } } 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 fe0a49c6..e1876da3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -1337,6 +1337,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele return false; }); + Handler handler = new Handler(); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); thingEditText.addTextChangedListener(new TextWatcher() { @Override @@ -1360,17 +1361,18 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - adapter.setSubreddits(subredditData); - } - - @Override - public void onParseSubredditListingDataFail() { - - } - }); + ParseSubredditData.parseSubredditListingData(mExecutor, handler, + response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { + @Override + public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + adapter.setSubreddits(subredditData); + } + + @Override + public void onParseSubredditListingDataFail() { + + } + }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java index bf0121fd..892c91d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java @@ -27,21 +27,23 @@ public class LoadSubredditIcon { String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl(); handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl)); } else { - handler.post(() -> FetchSubredditData.fetchSubredditData(accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) { - ArrayList singleSubredditDataList = new ArrayList<>(); - singleSubredditDataList.add(subredditData1); - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, accountName, - null, null, singleSubredditDataList, - () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData1.getIconUrl())); - } - - @Override - public void onFetchSubredditDataFail(boolean isQuarantined) { - loadSubredditIconAsyncTaskListener.loadIconSuccess(null); - } - })); + handler.post(() -> FetchSubredditData.fetchSubredditData(executor, handler, + accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : oauthRetrofit, retrofit, + subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) { + ArrayList singleSubredditDataList = new ArrayList<>(); + singleSubredditDataList.add(subredditData1); + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, accountName, + null, null, singleSubredditDataList, + () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData1.getIconUrl())); + } + + @Override + public void onFetchSubredditDataFail(boolean isQuarantined) { + loadSubredditIconAsyncTaskListener.loadIconSuccess(null); + } + })); } }); } 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 11b9dae3..e23c4610 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -238,20 +238,23 @@ public class SidebarFragment extends Fragment { public void fetchSubredditData() { binding.swipeRefreshLayoutSidebarFragment.setRefreshing(true); - FetchSubredditData.fetchSubredditData(activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, subredditName, activity.accessToken, new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); - InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, - subredditData, () -> binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false)); - } + Handler handler = new Handler(); + FetchSubredditData.fetchSubredditData(mExecutor, handler, + activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, + subredditName, activity.accessToken, new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { + binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); + InsertSubredditData.insertSubredditData(mExecutor, handler, mRedditDataRoomDatabase, + subredditData, () -> binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false)); + } - @Override - public void onFetchSubredditDataFail(boolean isQuarantined) { - binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); - Toast.makeText(activity, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show(); - } - }); + @Override + public void onFetchSubredditDataFail(boolean isQuarantined) { + binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); + Toast.makeText(activity, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show(); + } + }); } public void goBackToTop() { 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 5d3fd223..70067f27 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -156,7 +156,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun }); } - SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory( + SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mExecutor, mOauthRetrofit, query, sortType, mActivity.accessToken, mActivity.accountName, nsfw); mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class); mSubredditListingViewModel.getSubreddits().observe(getViewLifecycleOwner(), subredditData -> mAdapter.submitList(subredditData)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 87ac594c..52042a64 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -1413,7 +1413,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic e.printStackTrace(); } } - FetchSubredditData.fetchSubredditData(activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, mPost.getSubredditName(), activity.accessToken, + FetchSubredditData.fetchSubredditData(mExecutor, new Handler(), + activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, + mRetrofit, mPost.getSubredditName(), activity.accessToken, new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java index d59c14c6..45806447 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java @@ -1,91 +1,72 @@ package ml.docilealligator.infinityforreddit.subreddit; +import android.os.Handler; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.APIUtils; import retrofit2.Call; -import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; public class FetchSubredditData { - public static void fetchSubredditData(Retrofit oauthRetrofit, Retrofit retrofit, String subredditName, String accessToken, final FetchSubredditDataListener fetchSubredditDataListener) { - RedditAPI api = retrofit.create(RedditAPI.class); + public static void fetchSubredditData(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit retrofit, + String subredditName, String accessToken, + final FetchSubredditDataListener fetchSubredditDataListener) { + executor.execute(() -> { + RedditAPI api = retrofit.create(RedditAPI.class); - Call subredditData; - if (oauthRetrofit == null) { - subredditData = api.getSubredditData(subredditName); - } else { - RedditAPI oauthApi = oauthRetrofit.create(RedditAPI.class); - subredditData = oauthApi.getSubredditDataOauth(subredditName, APIUtils.getOAuthHeader(accessToken)); - } - subredditData.enqueue(new Callback<>() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { + Call subredditData; + if (oauthRetrofit == null) { + subredditData = api.getSubredditData(subredditName); + } else { + RedditAPI oauthApi = oauthRetrofit.create(RedditAPI.class); + subredditData = oauthApi.getSubredditDataOauth(subredditName, APIUtils.getOAuthHeader(accessToken)); + } + try { + Response response = subredditData.execute(); if (response.isSuccessful()) { - ParseSubredditData.parseSubredditData(response.body(), new ParseSubredditData.ParseSubredditDataListener() { - @Override - public void onParseSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - fetchSubredditDataListener.onFetchSubredditDataSuccess(subredditData, nCurrentOnlineSubscribers); - } - - @Override - public void onParseSubredditDataFail() { - fetchSubredditDataListener.onFetchSubredditDataFail(false); - } - }); + ParseSubredditData.parseSubredditDataSync(handler, response.body(), fetchSubredditDataListener); } else { - fetchSubredditDataListener.onFetchSubredditDataFail(response.code() == 403); + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataFail(response.code() == 403)); } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchSubredditDataListener.onFetchSubredditDataFail(false); + } catch (IOException e) { + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataFail(false)); } }); } - static void fetchSubredditListingData(Retrofit retrofit, String query, String after, SortType.Type sortType, @Nullable String accessToken, - @NonNull String accountName, boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { - RedditAPI api = retrofit.create(RedditAPI.class); + static void fetchSubredditListingData(Executor executor, Handler handler, Retrofit retrofit, String query, + String after, SortType.Type sortType, @Nullable String accessToken, + @NonNull String accountName, boolean nsfw, + final FetchSubredditListingDataListener fetchSubredditListingDataListener) { + executor.execute(() -> { + RedditAPI api = retrofit.create(RedditAPI.class); - Map map = new HashMap<>(); - Map headers = accountName.equals(Account.ANONYMOUS_ACCOUNT) ? Collections.unmodifiableMap(map) : APIUtils.getOAuthHeader(accessToken); - Call subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers); - subredditDataCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { + Map map = new HashMap<>(); + Map headers = accountName.equals(Account.ANONYMOUS_ACCOUNT) ? map : APIUtils.getOAuthHeader(accessToken); + Call subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers); + try { + Response response = subredditDataCall.execute(); if (response.isSuccessful()) { - ParseSubredditData.parseSubredditListingData(response.body(), nsfw, - new ParseSubredditData.ParseSubredditListingDataListener() { - @Override - public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { - fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditData, after); - } - - @Override - public void onParseSubredditListingDataFail() { - fetchSubredditListingDataListener.onFetchSubredditListingDataFail(); - } - }); + ParseSubredditData.parseSubredditListingDataSync(handler, response.body(), nsfw, + fetchSubredditListingDataListener); } else { - fetchSubredditListingDataListener.onFetchSubredditListingDataFail(); + handler.post(fetchSubredditListingDataListener::onFetchSubredditListingDataFail); } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchSubredditListingDataListener.onFetchSubredditListingDataFail(); + } catch (IOException e) { + e.printStackTrace(); + handler.post(fetchSubredditListingDataListener::onFetchSubredditListingDataFail); } }); } @@ -96,7 +77,7 @@ public class FetchSubredditData { void onFetchSubredditDataFail(boolean isQuarantined); } - interface FetchSubredditListingDataListener { + public interface FetchSubredditListingDataListener { void onFetchSubredditListingDataSuccess(ArrayList subredditData, String after); void onFetchSubredditListingDataFail(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/ParseSubredditData.java index 1739557f..ad409d85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/ParseSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/ParseSubredditData.java @@ -1,6 +1,6 @@ package ml.docilealligator.infinityforreddit.subreddit; -import android.os.AsyncTask; +import android.os.Handler; import androidx.annotation.Nullable; @@ -9,21 +9,98 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class ParseSubredditData { - public static void parseSubredditData(String response, ParseSubredditDataListener parseSubredditDataListener) { - new ParseSubredditDataAsyncTask(response, parseSubredditDataListener).execute(); + public static void parseSubredditDataSync(Handler handler, @Nullable String response, + FetchSubredditData.FetchSubredditDataListener fetchSubredditDataListener) { + if (response == null) { + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataFail(false)); + return; + } + + try { + JSONObject data = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY); + + int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY); + SubredditData subredditData = parseSubredditDataSync(data, true); + + if (subredditData == null) { + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataFail(false)); + } else { + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataSuccess(subredditData, nCurrentOnlineSubscribers)); + } + } catch (JSONException e) { + e.printStackTrace(); + handler.post(() -> fetchSubredditDataListener.onFetchSubredditDataFail(false)); + } } - public static void parseSubredditListingData(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) { - new ParseSubredditListingDataAsyncTask(response, nsfw, parseSubredditListingDataListener).execute(); + public static void parseSubredditListingDataSync(Handler handler, @Nullable String response, boolean nsfw, + FetchSubredditData.FetchSubredditListingDataListener fetchSubredditListingDataListener) { + if (response == null) { + handler.post(fetchSubredditListingDataListener::onFetchSubredditListingDataFail); + return; + } + + try { + JSONObject jsonObject = new JSONObject(response); + JSONArray children = jsonObject.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); + + ArrayList subredditListingData = new ArrayList<>(); + for (int i = 0; i < children.length(); i++) { + JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); + SubredditData subredditData = parseSubredditDataSync(data, nsfw); + if (subredditData != null) { + subredditListingData.add(subredditData); + } + } + + String after = jsonObject.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); + + handler.post(() -> fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditListingData, after)); + } catch (JSONException e) { + e.printStackTrace(); + handler.post(fetchSubredditListingDataListener::onFetchSubredditListingDataFail); + } + } + + public static void parseSubredditListingData(Executor executor, Handler handler, @Nullable String response, boolean nsfw, + ParseSubredditListingDataListener parseSubredditListingDataListener) { + if (response == null) { + parseSubredditListingDataListener.onParseSubredditListingDataFail(); + return; + } + + executor.execute(() -> { + try { + JSONObject jsonObject = new JSONObject(response); + JSONArray children = jsonObject.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); + + ArrayList subredditListingData = new ArrayList<>(); + for (int i = 0; i < children.length(); i++) { + JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); + SubredditData subredditData = parseSubredditDataSync(data, nsfw); + if (subredditData != null) { + subredditListingData.add(subredditData); + } + } + + String after = jsonObject.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); + + handler.post(() -> parseSubredditListingDataListener.onParseSubredditListingDataSuccess(subredditListingData, after)); + } catch (JSONException e) { + e.printStackTrace(); + handler.post(parseSubredditListingDataListener::onParseSubredditListingDataFail); + } + }); } @Nullable - private static SubredditData parseSubredditData(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException { + private static SubredditData parseSubredditDataSync(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException { boolean isNSFW = !subredditDataJsonObject.isNull(JSONUtils.OVER18_KEY) && subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY); if (!nsfw && isNSFW) { return null; @@ -64,110 +141,9 @@ public class ParseSubredditData { sidebarDescription, nSubscribers, createdUTC, suggestedCommentSort, isNSFW); } - interface ParseSubredditDataListener { - void onParseSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers); - - void onParseSubredditDataFail(); - } - public interface ParseSubredditListingDataListener { void onParseSubredditListingDataSuccess(ArrayList subredditData, String after); void onParseSubredditListingDataFail(); } - - private static class ParseSubredditDataAsyncTask extends AsyncTask { - private JSONObject jsonResponse; - private boolean parseFailed; - private final ParseSubredditDataListener parseSubredditDataListener; - private SubredditData subredditData; - private int mNCurrentOnlineSubscribers; - - ParseSubredditDataAsyncTask(String response, ParseSubredditDataListener parseSubredditDataListener) { - this.parseSubredditDataListener = parseSubredditDataListener; - try { - jsonResponse = new JSONObject(response); - parseFailed = false; - } catch (JSONException e) { - e.printStackTrace(); - parseSubredditDataListener.onParseSubredditDataFail(); - } - } - - @Override - protected Void doInBackground(Void... voids) { - try { - JSONObject data = jsonResponse.getJSONObject(JSONUtils.DATA_KEY); - mNCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY); - subredditData = parseSubredditData(data, true); - } catch (JSONException e) { - parseFailed = true; - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!parseFailed) { - parseSubredditDataListener.onParseSubredditDataSuccess(subredditData, mNCurrentOnlineSubscribers); - } else { - parseSubredditDataListener.onParseSubredditDataFail(); - } - } - } - - private static class ParseSubredditListingDataAsyncTask extends AsyncTask { - private JSONObject jsonResponse; - private boolean nsfw; - private boolean parseFailed; - private final ParseSubredditListingDataListener parseSubredditListingDataListener; - private ArrayList subredditListingData; - private String after; - - ParseSubredditListingDataAsyncTask(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) { - this.parseSubredditListingDataListener = parseSubredditListingDataListener; - try { - jsonResponse = new JSONObject(response); - this.nsfw = nsfw; - parseFailed = false; - subredditListingData = new ArrayList<>(); - } catch (JSONException e) { - e.printStackTrace(); - parseFailed = true; - } - } - - @Override - protected Void doInBackground(Void... voids) { - try { - if (!parseFailed) { - JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY) - .getJSONArray(JSONUtils.CHILDREN_KEY); - for (int i = 0; i < children.length(); i++) { - JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); - SubredditData subredditData = parseSubredditData(data, nsfw); - if (subredditData != null) { - subredditListingData.add(subredditData); - } - } - after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); - } - } catch (JSONException e) { - e.printStackTrace(); - parseFailed = true; - parseSubredditListingDataListener.onParseSubredditListingDataFail(); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!parseFailed) { - parseSubredditListingDataListener.onParseSubredditListingDataSuccess(subredditListingData, after); - } else { - parseSubredditListingDataListener.onParseSubredditListingDataFail(); - } - } - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java index 813dd71b..0846fe5b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java @@ -1,11 +1,14 @@ package ml.docilealligator.infinityforreddit.subreddit; +import android.os.Handler; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.MutableLiveData; import androidx.paging.PageKeyedDataSource; import java.util.ArrayList; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.SortType; @@ -13,6 +16,7 @@ import retrofit2.Retrofit; public class SubredditListingDataSource extends PageKeyedDataSource { + private final Executor executor; private final Retrofit retrofit; private final String query; private final SortType sortType; @@ -21,6 +25,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource paginationNetworkStateLiveData; private final MutableLiveData initialLoadStateLiveData; @@ -29,14 +34,16 @@ public class SubredditListingDataSource extends PageKeyedDataSource params; private LoadCallback callback; - SubredditListingDataSource(Retrofit retrofit, String query, SortType sortType, @Nullable String accessToken, - @NonNull String accountName, boolean nsfw) { + SubredditListingDataSource(Executor executor, Retrofit retrofit, String query, SortType sortType, + @Nullable String accessToken, @NonNull String accountName, boolean nsfw) { + this.executor = executor; this.retrofit = retrofit; this.query = query; this.sortType = sortType; this.accessToken = accessToken; this.accountName = accountName; this.nsfw = nsfw; + handler = new Handler(); paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasSubredditLiveData = new MutableLiveData<>(); @@ -58,8 +65,9 @@ public class SubredditListingDataSource extends PageKeyedDataSource params, @NonNull LoadInitialCallback callback) { initialLoadStateLiveData.postValue(NetworkState.LOADING); - FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType.getType(), accessToken, - accountName, nsfw, new FetchSubredditData.FetchSubredditListingDataListener() { + FetchSubredditData.fetchSubredditListingData(executor, handler, retrofit, query, null, + sortType.getType(), accessToken, accountName, nsfw, + new FetchSubredditData.FetchSubredditListingDataListener() { @Override public void onFetchSubredditListingDataSuccess(ArrayList subredditData, String after) { if (subredditData.size() == 0) { @@ -93,8 +101,9 @@ public class SubredditListingDataSource extends PageKeyedDataSource subredditData, String after) { callback.onResult(subredditData, after); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java index fadf484a..9150eef0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java @@ -5,10 +5,13 @@ import androidx.annotation.Nullable; import androidx.lifecycle.MutableLiveData; import androidx.paging.DataSource; +import java.util.concurrent.Executor; + import ml.docilealligator.infinityforreddit.SortType; import retrofit2.Retrofit; public class SubredditListingDataSourceFactory extends DataSource.Factory { + private final Executor executor; private final Retrofit retrofit; private final String query; private SortType sortType; @@ -21,8 +24,9 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory { private SubredditListingDataSource subredditListingDataSource; private final MutableLiveData subredditListingDataSourceMutableLiveData; - SubredditListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType, @Nullable String accessToken, - @NonNull String accountName, boolean nsfw) { + SubredditListingDataSourceFactory(Executor executor, Retrofit retrofit, String query, SortType sortType, + @Nullable String accessToken, @NonNull String accountName, boolean nsfw) { + this.executor = executor; this.retrofit = retrofit; this.query = query; this.sortType = sortType; @@ -35,8 +39,8 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory { @NonNull @Override public DataSource create() { - subredditListingDataSource = new SubredditListingDataSource(retrofit, query, sortType, accessToken, - accountName, nsfw); + subredditListingDataSource = new SubredditListingDataSource(executor, retrofit, query, sortType, + accessToken, accountName, nsfw); subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource); return subredditListingDataSource; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java index 79d9b217..bfd4f126 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java @@ -10,6 +10,8 @@ import androidx.lifecycle.ViewModelProvider; import androidx.paging.LivePagedListBuilder; import androidx.paging.PagedList; +import java.util.concurrent.Executor; + import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.SortType; import retrofit2.Retrofit; @@ -22,8 +24,10 @@ public class SubredditListingViewModel extends ViewModel { private final LiveData> subreddits; private final MutableLiveData sortTypeLiveData; - public SubredditListingViewModel(Retrofit retrofit, String query, SortType sortType, @Nullable String accessToken, @NonNull String accountName, boolean nsfw) { - subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType, accessToken, accountName, nsfw); + public SubredditListingViewModel(Executor executor, Retrofit retrofit, String query, SortType sortType, + @Nullable String accessToken, @NonNull String accountName, boolean nsfw) { + subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(executor, retrofit, query, + sortType, accessToken, accountName, nsfw); initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(), SubredditListingDataSource::getInitialLoadStateLiveData); @@ -75,6 +79,7 @@ public class SubredditListingViewModel extends ViewModel { } public static class Factory extends ViewModelProvider.NewInstanceFactory { + private final Executor executor; private final Retrofit retrofit; private final String query; private final SortType sortType; @@ -84,8 +89,9 @@ public class SubredditListingViewModel extends ViewModel { private final String accountName; private final boolean nsfw; - public Factory(Retrofit retrofit, String query, SortType sortType, @Nullable String accessToken, - @NonNull String accountName, boolean nsfw) { + public Factory(Executor executor, Retrofit retrofit, String query, SortType sortType, + @Nullable String accessToken, @NonNull String accountName, boolean nsfw) { + this.executor = executor; this.retrofit = retrofit; this.query = query; this.sortType = sortType; @@ -97,7 +103,7 @@ public class SubredditListingViewModel extends ViewModel { @NonNull @Override public T create(@NonNull Class modelClass) { - return (T) new SubredditListingViewModel(retrofit, query, sortType, accessToken, accountName, nsfw); + return (T) new SubredditListingViewModel(executor, retrofit, query, sortType, accessToken,accountName, nsfw); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java index e8073caf..f6880b2f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java @@ -30,18 +30,19 @@ public class SubredditSubscription { RedditDataRoomDatabase redditDataRoomDatabase, String subredditName, SubredditSubscriptionListener subredditSubscriptionListener) { - FetchSubredditData.fetchSubredditData(null, retrofit, subredditName, "", new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - insertSubscription(executor, handler, redditDataRoomDatabase, - subredditData, Account.ANONYMOUS_ACCOUNT, subredditSubscriptionListener); - } + FetchSubredditData.fetchSubredditData(executor, handler, null, retrofit, subredditName, + "", new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { + insertSubscription(executor, handler, redditDataRoomDatabase, + subredditData, Account.ANONYMOUS_ACCOUNT, subredditSubscriptionListener); + } - @Override - public void onFetchSubredditDataFail(boolean isQuarantined) { - subredditSubscriptionListener.onSubredditSubscriptionFail(); - } - }); + @Override + public void onFetchSubredditDataFail(boolean isQuarantined) { + subredditSubscriptionListener.onSubredditSubscriptionFail(); + } + }); } public static void unsubscribeToSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, @@ -71,23 +72,24 @@ public class SubredditSubscription { params.put(APIUtils.SR_NAME_KEY, subredditName); Call subredditSubscriptionCall = api.subredditSubscription(APIUtils.getOAuthHeader(accessToken), params); - subredditSubscriptionCall.enqueue(new Callback() { + subredditSubscriptionCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { if (action.equals("sub")) { - FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { - @Override - public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - insertSubscription(executor, handler, redditDataRoomDatabase, - subredditData, accountName, subredditSubscriptionListener); - } - - @Override - public void onFetchSubredditDataFail(boolean isQuarantined) { - - } - }); + FetchSubredditData.fetchSubredditData(executor, handler, oauthRetrofit, retrofit, + subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() { + @Override + public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { + insertSubscription(executor, handler, redditDataRoomDatabase, + subredditData, accountName, subredditSubscriptionListener); + } + + @Override + public void onFetchSubredditDataFail(boolean isQuarantined) { + + } + }); } else { removeSubscription(executor, handler, redditDataRoomDatabase, subredditName, accountName, subredditSubscriptionListener); -- cgit v1.2.3