From 50de0d84c68b6b0375f8afca3b4e2bccc2ba454e Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 18 Aug 2020 16:31:30 +0800 Subject: Remove code related to post sorty type Random. --- .../Activity/FilteredThingActivity.java | 1 - .../infinityforreddit/Activity/MainActivity.java | 1 - .../Activity/ViewMultiRedditDetailActivity.java | 1 - .../SortTypeBottomSheetFragment.java | 12 -- .../infinityforreddit/Post/PostDataSource.java | 152 ++++++++------------- .../res/layout/fragment_sort_type_bottom_sheet.xml | 19 --- 6 files changed, 58 insertions(+), 128 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index f97944c3..1a3bfa31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -252,7 +252,6 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec multiRedditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); Bundle multiRedditBundle = new Bundle(); multiRedditBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - multiRedditBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_RANDOM_TYPE, true); multiRedditSortTypeBottomSheetFragment.setArguments(multiRedditBundle); break; case PostDataSource.TYPE_USER: diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 2272e448..5daee793 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -723,7 +723,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); } - bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_RANDOM_TYPE, true); sortTypeBottomSheetFragment.setArguments(bundle); sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 91c7512a..b2280232 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -164,7 +164,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); Bundle bottomSheetBundle = new Bundle(); bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_RANDOM_TYPE, true); sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SortTypeBottomSheetFragment.java index ee5ba39f..d86bb207 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SortTypeBottomSheetFragment.java @@ -29,15 +29,12 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment { public static final String EXTRA_NO_BEST_TYPE = "ENBT"; - public static final String EXTRA_NO_RANDOM_TYPE = "ENRT"; @BindView(R.id.best_type_text_view_sort_type_bottom_sheet_fragment) TextView bestTypeTextView; @BindView(R.id.hot_type_text_view_sort_type_bottom_sheet_fragment) TextView hotTypeTextView; @BindView(R.id.new_type_text_view_sort_type_bottom_sheet_fragment) TextView newTypeTextView; - @BindView(R.id.random_type_text_view_sort_type_bottom_sheet_fragment) - TextView randomTypeTextView; @BindView(R.id.rising_type_text_view_sort_type_bottom_sheet_fragment) TextView risingTypeTextView; @BindView(R.id.top_type_text_view_sort_type_bottom_sheet_fragment) @@ -79,15 +76,6 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen dismiss(); }); - if (getArguments() == null || (getArguments().containsKey(EXTRA_NO_RANDOM_TYPE) && getArguments().getBoolean(EXTRA_NO_RANDOM_TYPE))) { - randomTypeTextView.setVisibility(View.GONE); - } else { - randomTypeTextView.setOnClickListener(view -> { - ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RANDOM)); - dismiss(); - }); - } - risingTypeTextView.setOnClickListener(view -> { ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RISING)); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java index e0c4a9a3..d444a0b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java @@ -247,56 +247,38 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - if (sortType.getType().value.equals(SortType.Type.RANDOM.value)) { - ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() { - @Override - public void onParsePostSuccess(Post post) { - ArrayList singlePostList = new ArrayList<>(); - singlePostList.add(post); - callback.onResult(singlePostList, null, null); - hasPostLiveData.postValue(true); - initialLoadStateLiveData.postValue(NetworkState.LOADED); - } - - @Override - public void onParsePostFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data")); - } - }); - } else { - ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw, - new ParsePost.ParsePostsListingListener() { - @Override - public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { - String nextPageKey; - if (lastItem == null || lastItem.equals("") || lastItem.equals("null")) { - nextPageKey = null; - } else { - nextPageKey = lastItem; - } - - if (newPosts.size() != 0) { - postLinkedHashSet.addAll(newPosts); - callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); - hasPostLiveData.postValue(true); - } else if (nextPageKey != null) { - loadBestPostsInitial(callback, nextPageKey); - return; - } else { - postLinkedHashSet.addAll(newPosts); - callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); - hasPostLiveData.postValue(false); - } - - initialLoadStateLiveData.postValue(NetworkState.LOADED); + ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw, + new ParsePost.ParsePostsListingListener() { + @Override + public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { + String nextPageKey; + if (lastItem == null || lastItem.equals("") || lastItem.equals("null")) { + nextPageKey = null; + } else { + nextPageKey = lastItem; } - @Override - public void onParsePostsListingFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); + if (newPosts.size() != 0) { + postLinkedHashSet.addAll(newPosts); + callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); + hasPostLiveData.postValue(true); + } else if (nextPageKey != null) { + loadBestPostsInitial(callback, nextPageKey); + return; + } else { + postLinkedHashSet.addAll(newPosts); + callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); + hasPostLiveData.postValue(false); } - }); - } + + initialLoadStateLiveData.postValue(NetworkState.LOADED); + } + + @Override + public void onParsePostsListingFail() { + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); + } + }); } else { initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "code: " + response.code() + " message: " + response.message())); @@ -388,56 +370,38 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - if (sortType.getType().value.equals(SortType.Type.RANDOM.value)) { - ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() { - @Override - public void onParsePostSuccess(Post post) { - ArrayList singlePostList = new ArrayList<>(); - singlePostList.add(post); - callback.onResult(singlePostList, null, null); - hasPostLiveData.postValue(true); - initialLoadStateLiveData.postValue(NetworkState.LOADED); - } - - @Override - public void onParsePostFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data")); - } - }); - } else { - ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw, - new ParsePost.ParsePostsListingListener() { - @Override - public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { - String nextPageKey; - if (lastItem == null || lastItem.equals("") || lastItem.equals("null")) { - nextPageKey = null; - } else { - nextPageKey = lastItem; - } - - if (newPosts.size() != 0) { - postLinkedHashSet.addAll(newPosts); - callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); - hasPostLiveData.postValue(true); - } else if (nextPageKey != null) { - loadSubredditPostsInitial(callback, nextPageKey); - return; - } else { - postLinkedHashSet.addAll(newPosts); - callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); - hasPostLiveData.postValue(false); - } - - initialLoadStateLiveData.postValue(NetworkState.LOADED); + ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw, + new ParsePost.ParsePostsListingListener() { + @Override + public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { + String nextPageKey; + if (lastItem == null || lastItem.equals("") || lastItem.equals("null")) { + nextPageKey = null; + } else { + nextPageKey = lastItem; } - @Override - public void onParsePostsListingFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); + if (newPosts.size() != 0) { + postLinkedHashSet.addAll(newPosts); + callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); + hasPostLiveData.postValue(true); + } else if (nextPageKey != null) { + loadSubredditPostsInitial(callback, nextPageKey); + return; + } else { + postLinkedHashSet.addAll(newPosts); + callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); + hasPostLiveData.postValue(false); } - }); - } + + initialLoadStateLiveData.postValue(NetworkState.LOADED); + } + + @Override + public void onParsePostsListingFail() { + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); + } + }); } else { initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "code: " + response + " message: " + response.message())); diff --git a/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml b/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml index d5c9e34d..91c0ed62 100644 --- a/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml @@ -68,25 +68,6 @@ android:textSize="?attr/font_default" app:drawableTint="?attr/primaryTextColor" /> - -