diff options
Diffstat (limited to '')
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); } } } |