diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-30 15:15:32 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-30 15:15:32 +0000 |
commit | 13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205 (patch) | |
tree | 033a51ba5e4c73ef2343a70690302ae2016f9e74 | |
parent | 773c82a2b7d6860240496b9f184467d675292c0a (diff) | |
download | infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar.gz infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar.bz2 infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar.lz infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar.xz infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.tar.zst infinity-for-reddit-13bed5d234fdf7fe7335eb3cdeb3516b5dc8b205.zip |
Don't search nsfw users when nsfw is off.
Diffstat (limited to '')
6 files changed, 28 insertions, 18 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java index e696ccf2..db5798ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java @@ -128,9 +128,9 @@ public interface RedditAPI { @Query("sort") String sort, @Query("include_over_18") int nsfw, @HeaderMap Map<String, String> headers); - @GET("search.json?include_over_18=1&raw_json=1&type=user") + @GET("search.json?raw_json=1&type=user") Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after, - @Query("sort") String sort); + @Query("sort") String sort, @Query("include_over_18") int nsfw); @GET("search.json?include_over_18=1&raw_json=1&type=link") Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java index 4f0f6720..d39f0d0e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java @@ -80,6 +80,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Named("sort_type") SharedPreferences mSortTypeSharedPreferences; @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; private LinearLayoutManager mLinearLayoutManager; private String mQuery; @@ -124,6 +127,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value); 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(), @@ -132,11 +136,11 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mUserListingRecyclerView.setAdapter(mAdapter); UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery, - sortType); + sortType, nsfw); mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class); - mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData)); + mUserListingViewModel.getUsers().observe(getViewLifecycleOwner(), UserData -> mAdapter.submitList(UserData)); - mUserListingViewModel.hasUser().observe(this, hasUser -> { + mUserListingViewModel.hasUser().observe(getViewLifecycleOwner(), hasUser -> { mSwipeRefreshLayout.setRefreshing(false); if (hasUser) { mFetchUserListingInfoLinearLayout.setVisibility(View.GONE); @@ -148,7 +152,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato } }); - mUserListingViewModel.getInitialLoadingState().observe(this, networkState -> { + mUserListingViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { mSwipeRefreshLayout.setRefreshing(false); } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { @@ -160,7 +164,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato } }); - mUserListingViewModel.getPaginationNetworkState().observe(this, networkState -> { + mUserListingViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> { mAdapter.setNetworkState(networkState); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/FetchUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/FetchUserData.java index 5d9a35d9..f214bec1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/FetchUserData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/FetchUserData.java @@ -41,11 +41,11 @@ public class FetchUserData { }); } - public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType, + public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType, boolean nsfw, FetchUserListingDataListener fetchUserListingDataListener) { RedditAPI api = retrofit.create(RedditAPI.class); - Call<String> userInfo = api.searchUsers(query, after, sortType); + Call<String> userInfo = api.searchUsers(query, after, sortType, nsfw ? 1 : 0); userInfo.enqueue(new Callback<String>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSource.java index a7606588..fc6b1f60 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSource.java @@ -15,6 +15,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData> private Retrofit retrofit; private String query; private SortType sortType; + private boolean nsfw; private MutableLiveData<NetworkState> paginationNetworkStateLiveData; private MutableLiveData<NetworkState> initialLoadStateLiveData; @@ -23,10 +24,11 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData> private PageKeyedDataSource.LoadParams<String> params; private PageKeyedDataSource.LoadCallback<String, UserData> callback; - UserListingDataSource(Retrofit retrofit, String query, SortType sortType) { + UserListingDataSource(Retrofit retrofit, String query, SortType sortType, boolean nsfw) { this.retrofit = retrofit; this.query = query; this.sortType = sortType; + this.nsfw = nsfw; paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasUserLiveData = new MutableLiveData<>(); @@ -48,7 +50,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData> public void loadInitial(@NonNull PageKeyedDataSource.LoadInitialParams<String> params, @NonNull PageKeyedDataSource.LoadInitialCallback<String, UserData> callback) { initialLoadStateLiveData.postValue(NetworkState.LOADING); - FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType().value, + FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType().value, nsfw, new FetchUserData.FetchUserListingDataListener() { @Override public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { @@ -83,7 +85,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData> return; } - FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType().value, + FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType().value, nsfw, new FetchUserData.FetchUserListingDataListener() { @Override public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSourceFactory.java index e0bf6288..ee0a49c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingDataSourceFactory.java @@ -11,21 +11,23 @@ public class UserListingDataSourceFactory extends DataSource.Factory { private Retrofit retrofit; private String query; private SortType sortType; + private boolean nsfw; private UserListingDataSource userListingDataSource; private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData; - UserListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType) { + UserListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType, boolean nsfw) { this.retrofit = retrofit; this.query = query; this.sortType = sortType; + this.nsfw = nsfw; userListingDataSourceMutableLiveData = new MutableLiveData<>(); } @NonNull @Override public DataSource create() { - userListingDataSource = new UserListingDataSource(retrofit, query, sortType); + userListingDataSource = new UserListingDataSource(retrofit, query, sortType, nsfw); userListingDataSourceMutableLiveData.postValue(userListingDataSource); return userListingDataSource; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingViewModel.java index d15bbd62..f2816f3c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserListingViewModel.java @@ -21,8 +21,8 @@ public class UserListingViewModel extends ViewModel { private LiveData<PagedList<UserData>> users; private MutableLiveData<SortType> sortTypeLiveData; - public UserListingViewModel(Retrofit retrofit, String query, SortType sortType) { - userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType); + public UserListingViewModel(Retrofit retrofit, String query, SortType sortType, boolean nsfw) { + userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType, nsfw); initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), UserListingDataSource::getInitialLoadStateLiveData); @@ -78,17 +78,19 @@ public class UserListingViewModel extends ViewModel { private Retrofit retrofit; private String query; private SortType sortType; + private boolean nsfw; - public Factory(Retrofit retrofit, String query, SortType sortType) { + public Factory(Retrofit retrofit, String query, SortType sortType, boolean nsfw) { this.retrofit = retrofit; this.query = query; this.sortType = sortType; + this.nsfw = nsfw; } @NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { - return (T) new UserListingViewModel(retrofit, query, sortType); + return (T) new UserListingViewModel(retrofit, query, sortType, nsfw); } } } |