aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-06-04 19:00:53 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-06-04 19:00:53 +0000
commit43f389f12fe5159d428769a7520e3340f8df5eaa (patch)
tree09add80062267af70e6afda9eda049b0ecbc1b93
parentd278bd873debaf4bdaf9f5183b013286383d3e71 (diff)
downloadinfinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar.gz
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar.bz2
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar.lz
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar.xz
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.tar.zst
infinity-for-reddit-43f389f12fe5159d428769a7520e3340f8df5eaa.zip
Fix RuntimeException related to Handler in SubredditListingDataSource.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java12
4 files changed, 18 insertions, 9 deletions
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 70067f27..ca7255f5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
@@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -157,7 +158,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
}
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mExecutor,
- mOauthRetrofit, query, sortType, mActivity.accessToken, mActivity.accountName, nsfw);
+ new Handler(), 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/subreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java
index 0846fe5b..0ba14106 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java
@@ -34,7 +34,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
private LoadParams<String> params;
private LoadCallback<String, SubredditData> callback;
- SubredditListingDataSource(Executor executor, Retrofit retrofit, String query, SortType sortType,
+ SubredditListingDataSource(Executor executor, Handler handler, Retrofit retrofit, String query, SortType sortType,
@Nullable String accessToken, @NonNull String accountName, boolean nsfw) {
this.executor = executor;
this.retrofit = retrofit;
@@ -43,7 +43,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
this.accessToken = accessToken;
this.accountName = accountName;
this.nsfw = nsfw;
- handler = new Handler();
+ this.handler = handler;
paginationNetworkStateLiveData = new MutableLiveData<>();
initialLoadStateLiveData = new MutableLiveData<>();
hasSubredditLiveData = new MutableLiveData<>();
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 9150eef0..5f7ecc94 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.subreddit;
+import android.os.Handler;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.MutableLiveData;
@@ -12,6 +14,7 @@ import retrofit2.Retrofit;
public class SubredditListingDataSourceFactory extends DataSource.Factory {
private final Executor executor;
+ private final Handler handler;
private final Retrofit retrofit;
private final String query;
private SortType sortType;
@@ -24,9 +27,10 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
private SubredditListingDataSource subredditListingDataSource;
private final MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
- SubredditListingDataSourceFactory(Executor executor, Retrofit retrofit, String query, SortType sortType,
+ SubredditListingDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String query, SortType sortType,
@Nullable String accessToken, @NonNull String accountName, boolean nsfw) {
this.executor = executor;
+ this.handler = handler;
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -39,7 +43,7 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
@NonNull
@Override
public DataSource create() {
- subredditListingDataSource = new SubredditListingDataSource(executor, retrofit, query, sortType,
+ subredditListingDataSource = new SubredditListingDataSource(executor, handler, 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 bfd4f126..491de480 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.subreddit;
+import android.os.Handler;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
@@ -24,9 +26,9 @@ public class SubredditListingViewModel extends ViewModel {
private final LiveData<PagedList<SubredditData>> subreddits;
private final MutableLiveData<SortType> sortTypeLiveData;
- public SubredditListingViewModel(Executor executor, Retrofit retrofit, String query, SortType sortType,
+ public SubredditListingViewModel(Executor executor, Handler handler, Retrofit retrofit, String query, SortType sortType,
@Nullable String accessToken, @NonNull String accountName, boolean nsfw) {
- subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(executor, retrofit, query,
+ subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(executor, handler, retrofit, query,
sortType, accessToken, accountName, nsfw);
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
@@ -80,6 +82,7 @@ public class SubredditListingViewModel extends ViewModel {
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final Executor executor;
+ private final Handler handler;
private final Retrofit retrofit;
private final String query;
private final SortType sortType;
@@ -89,9 +92,10 @@ public class SubredditListingViewModel extends ViewModel {
private final String accountName;
private final boolean nsfw;
- public Factory(Executor executor, Retrofit retrofit, String query, SortType sortType,
+ public Factory(Executor executor, Handler handler, Retrofit retrofit, String query, SortType sortType,
@Nullable String accessToken, @NonNull String accountName, boolean nsfw) {
this.executor = executor;
+ this.handler = handler;
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -103,7 +107,7 @@ public class SubredditListingViewModel extends ViewModel {
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
- return (T) new SubredditListingViewModel(executor, retrofit, query, sortType, accessToken,accountName, nsfw);
+ return (T) new SubredditListingViewModel(executor, handler, retrofit, query, sortType, accessToken,accountName, nsfw);
}
}
}