aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-06-05 12:52:53 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-06-05 12:52:53 +0000
commit2cd86c7ffa4f475fed064842e472cdd9c26f03b2 (patch)
tree2fbb99470f0c0dbcbb56db1cd833e0d87ac7d01f /app/src/main/java/ml/docilealligator/infinityforreddit
parent8311507acd0e96a537c6d540a066a06895bbcfff (diff)
downloadinfinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar.gz
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar.bz2
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar.lz
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar.xz
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.tar.zst
infinity-for-reddit-2cd86c7ffa4f475fed064842e472cdd9c26f03b2.zip
Show sort type in toolbar.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java13
13 files changed, 223 insertions, 41 deletions
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 4a88fa6a..f5232d7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -92,6 +92,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
@@ -601,6 +602,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter.pauseLazyMode();
}
}
+ sectionsPagerAdapter.displaySortTypeInToolbar();
}
@Override
@@ -931,6 +933,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
+ @Override
+ public void displaySortType() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.displaySortTypeInToolbar();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment tab1;
private PostFragment tab2;
@@ -1092,6 +1101,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tab3 = (PostFragment) fragment;
}
}
+ displaySortTypeInToolbar();
return fragment;
}
@@ -1271,6 +1281,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tab3.changeSortType(sortType);
}
}
+ displaySortTypeInToolbar();
}
public void refresh() {
@@ -1361,5 +1372,27 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tab3.goBackToTop();
}
}
+ void displaySortTypeInToolbar() {
+ switch (viewPager.getCurrentItem()) {
+ case 0:
+ if (tab1 != null) {
+ SortType sortType = tab1.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ case 1:
+ if (tab2 != null) {
+ SortType sortType = tab2.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ case 2:
+ if (tab3 != null) {
+ SortType sortType = tab3.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
index 9dc8941b..3bda986c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -50,6 +50,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
@@ -200,6 +201,20 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2);
+ viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ sectionsPagerAdapter.displaySortTypeInToolbar();
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ }
+ });
tabLayout.setupWithViewPager(viewPager);
}
@@ -304,6 +319,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
}
+ @Override
+ public void displaySortType() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.displaySortTypeInToolbar();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
@@ -384,6 +406,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
userListingFragment = (UserListingFragment) fragment;
break;
}
+ displaySortTypeInToolbar();
return fragment;
}
@@ -398,6 +421,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
postFragment.changeSortType(sortType);
+ displaySortTypeInToolbar();
}
void changeSortType(SortType sortType, int fragmentPosition) {
@@ -410,6 +434,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply();
userListingFragment.changeSortType(sortType);
}
+ displaySortTypeInToolbar();
}
public void refresh() {
@@ -448,5 +473,28 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
userListingFragment.goBackToTop();
}
}
+
+ void displaySortTypeInToolbar() {
+ switch (viewPager.getCurrentItem()) {
+ case 0:
+ if (postFragment != null) {
+ SortType sortType = postFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ case 1:
+ if (subredditListingFragment != null) {
+ SortType sortType = subredditListingFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ case 2:
+ if (userListingFragment != null) {
+ SortType sortType = userListingFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ }
+ }
}
}
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 52162d5a..da94b78e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
@@ -44,6 +44,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
@@ -306,6 +307,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
}
((PostFragment) mFragment).changeSortType(sortType);
+ displaySortType();
}
@Override
@@ -346,4 +348,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
((PostFragment) mFragment).goBackToTop();
}
}
+
+ @Override
+ public void displaySortType() {
+ if (mFragment != null) {
+ SortType sortType = ((PostFragment) mFragment).getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index d18aba55..387867de 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -55,6 +55,7 @@ import butterknife.ButterKnife;
import im.ene.toro.exoplayer.ExoCreator;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo;
+import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
@@ -81,7 +82,6 @@ import ml.docilealligator.infinityforreddit.Post.ParsePost;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
-import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.SortType;
@@ -181,6 +181,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private int orientation;
private int postListPosition = -1;
private String mSingleCommentId;
+ private String sortType;
private boolean showToast = false;
private boolean isSortingComments = false;
private boolean mVolumeKeysNavigateComments;
@@ -344,6 +345,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
};
mSingleCommentId = getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID);
+ sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value);
+ mToolbar.setTitle(new SortType(SortType.Type.valueOf(sortType)).getType().fullName);
+ sortType = sortType.toLowerCase();
if (savedInstanceState == null) {
if (mSingleCommentId != null) {
isSingleCommentThreadMode = true;
@@ -569,9 +573,6 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mSwipeRefreshLayout.setRefreshing(true);
mGlide.clear(mFetchPostInfoImageView);
- String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase();
-
-
Call<String> postAndComments;
if (mAccessToken == null) {
if (isSingleCommentThreadMode && mSingleCommentId != null) {
@@ -847,8 +848,6 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
private void fetchComments(boolean changeRefreshState) {
- String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT,
- SortType.Type.BEST.value).toLowerCase();
fetchComments(changeRefreshState, true, sortType);
}
@@ -1618,6 +1617,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
fetchComments(false, false, sortType.getType().value);
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
+
+ mToolbar.setTitle(sortType.getType().fullName);
}
public void lockSwipeRightToGoBack() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index c0d3357a..a026456a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -78,6 +78,7 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import ml.docilealligator.infinityforreddit.SubredditSubscription;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -642,6 +643,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sectionsPagerAdapter.pauseLazyMode();
}
}
+
+ sectionsPagerAdapter.displaySortTypeInToolbar();
}
@Override
@@ -853,6 +856,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
+ @Override
+ public void displaySortType() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.displaySortTypeInToolbar();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private SidebarFragment sidebarFragment;
@@ -904,6 +914,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
switch (position) {
case 0:
postFragment = (PostFragment) fragment;
+ displaySortTypeInToolbar();
break;
case 1:
sidebarFragment = (SidebarFragment) fragment;
@@ -960,6 +971,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
postFragment.changeSortType(sortType);
+ displaySortTypeInToolbar();
}
}
@@ -987,5 +999,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
}
+
+ void displaySortTypeInToolbar() {
+ if (viewPager.getCurrentItem() == 0) {
+ if (postFragment != null) {
+ SortType sortType = postFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index 8cd8202e..36f3c203 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -78,6 +78,7 @@ import ml.docilealligator.infinityforreddit.User.UserData;
import ml.docilealligator.infinityforreddit.User.UserViewModel;
import ml.docilealligator.infinityforreddit.UserFollowing;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -510,6 +511,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sectionsPagerAdapter.pauseLazyMode();
}
}
+ sectionsPagerAdapter.displaySortTypeInToolbar();
}
@Override
@@ -720,6 +722,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
+ @Override
+ public void displaySortType() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.displaySortTypeInToolbar();
+ }
+ }
+
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
private UserDao userDao;
@@ -807,6 +816,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
case 1:
commentsListingFragment = (CommentsListingFragment) fragment;
}
+ displaySortTypeInToolbar();
return fragment;
}
@@ -871,6 +881,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
commentsListingFragment.changeSortType(sortType);
}
}
+ displaySortTypeInToolbar();
}
public void changeNSFW(boolean nsfw) {
@@ -897,5 +908,22 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
}
+
+ void displaySortTypeInToolbar() {
+ switch (viewPager.getCurrentItem()) {
+ case 0:
+ if (postFragment != null) {
+ SortType sortType = postFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ case 1:
+ if (commentsListingFragment != null) {
+ SortType sortType = commentsListingFragment.getSortType();
+ Utils.displaySortTypeInToolbar(sortType, toolbar);
+ }
+ break;
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java
index 42a9870b..04f0bcb5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java
@@ -2,4 +2,5 @@ package ml.docilealligator.infinityforreddit;
public interface ActivityToolbarInterface {
void onLongPress();
+ default void displaySortType() {};
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
index 4abc1701..11faaa49 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -42,7 +43,6 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
@@ -97,6 +97,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private Activity mActivity;
private LinearLayoutManager mLinearLayoutManager;
private CommentsListingRecyclerViewAdapter mAdapter;
+ private SortType sortType;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
@@ -173,10 +174,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
() -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME);
- String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
- SortType sortType;
- if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
- String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value);
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.name());
+ if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
} else {
sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
@@ -230,6 +230,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
public void changeSortType(SortType sortType) {
mCommentViewModel.changeSortType(sortType);
+ this.sortType = sortType;
}
@Override
@@ -273,4 +274,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public SortType getSortType() {
+ return sortType;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index 29b4ffa2..37888f9a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -49,11 +49,11 @@ import butterknife.ButterKnife;
import im.ene.toro.exoplayer.ExoCreator;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo;
-import im.ene.toro.widget.Container;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.MainActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
@@ -151,6 +151,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private CountDownTimer resumeLazyModeCountDownTimer;
private float lazyModeInterval;
private int postLayout;
+ private SortType sortType;
public PostFragment() {
// Required empty public constructor
@@ -348,7 +349,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name());
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
- SortType sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
+ sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
@@ -383,7 +384,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_NAME);
String sort;
String sortTime = null;
- SortType sortType;
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
if(displaySubredditName) {
@@ -445,7 +445,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String multiRedditPath = getArguments().getString(EXTRA_NAME);
String sort;
String sortTime = null;
- SortType sortType;
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Type.HOT.name());
@@ -499,7 +498,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name());
- SortType sortType;
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
@@ -538,7 +536,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
} else {
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
- SortType sortType;
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
@@ -569,6 +566,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
getResources().getConfiguration().locale, postType, sortType, filter, nsfw)).get(PostViewModel.class);
}
+ if (activity instanceof ActivityToolbarInterface) {
+ ((ActivityToolbarInterface) activity).displaySortType();
+ }
+
mPostRecyclerView.setAdapter(mAdapter);
mPostRecyclerView.setCacheManager(mAdapter);
mPostRecyclerView.setPlayerInitializer(order -> {
@@ -621,6 +622,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (isInLazyMode) {
stopLazyMode();
}
+ this.sortType = sortType;
mPostViewModel.changeSortType(sortType);
}
@@ -937,6 +939,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ public SortType getSortType() {
+ return sortType;
+ }
+
@Override
public void onPause() {
super.onPause();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
index afb3013f..80cb6541 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
@@ -89,6 +89,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
private LinearLayoutManager mLinearLayoutManager;
private SubredditListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
+ private SortType sortType;
public SubredditListingFragment() {
// Required empty public constructor
@@ -128,7 +129,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value);
- SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mRetrofit,
customThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase,
@@ -206,6 +207,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
public void changeSortType(SortType sortType) {
mSubredditListingViewModel.changeSortType(sortType);
+ this.sortType = sortType;
}
@Override
@@ -227,4 +229,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public SortType getSortType() {
+ return sortType;
+ }
}
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 21c2c154..532346c5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
@@ -86,6 +86,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
private String mQuery;
private UserListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
+ private SortType sortType;
public UserListingFragment() {
// Required empty public constructor
@@ -123,7 +124,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value);
- SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
customThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase.subscribedUserDao(),
@@ -186,6 +187,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
public void changeSortType(SortType sortType) {
mUserListingViewModel.changeSortType(sortType);
+ this.sortType = sortType;
}
@Override
@@ -207,4 +209,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public SortType getSortType() {
+ return sortType;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java
index fe50d884..83d45f57 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java
@@ -23,40 +23,44 @@ public class SortType {
}
public enum Type {
- BEST("best"),
- HOT("hot"),
- NEW("new"),
- RANDOM("random"),
- RISING("rising"),
- TOP("top"),
- CONTROVERSIAL("controversial"),
- RELEVANCE("relevance"),
- COMMENTS("comments"),
- ACTIVITY("activity"),
- CONFIDENCE("confidence"),
- OLD("old"),
- QA("qa"),
- LIVE("live");
+ BEST("best", "Best"),
+ HOT("hot", "Hot"),
+ NEW("new", "New"),
+ RANDOM("random", "Random"),
+ RISING("rising", "Rising"),
+ TOP("top", "Top"),
+ CONTROVERSIAL("controversial", "Controversial"),
+ RELEVANCE("relevance", "Relevance"),
+ COMMENTS("comments", "Comments"),
+ ACTIVITY("activity", "Activity"),
+ CONFIDENCE("confidence", "Confidence"),
+ OLD("old", "Old"),
+ QA("qa", "QA"),
+ LIVE("live", "Live");
public final String value;
+ public final String fullName;
- Type(String value) {
+ Type(String value, String fullName) {
this.value = value;
+ this.fullName = fullName;
}
}
public enum Time {
- HOUR("hour"),
- DAY("day"),
- WEEK("week"),
- MONTH("month"),
- YEAR("year"),
- ALL("all");
+ HOUR("hour", "Hour"),
+ DAY("day", "Day"),
+ WEEK("week", "Week"),
+ MONTH("month", "Month"),
+ YEAR("year", "Year"),
+ ALL("all", "All Time");
public final String value;
+ public final String fullName;
- Time(String value) {
+ Time(String value, String fullName) {
this.value = value;
+ this.fullName = fullName;
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
index e6726cbb..5bbb2e73 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
@@ -8,9 +8,12 @@ import android.text.Html;
import android.text.Spannable;
import android.widget.TextView;
+import androidx.appcompat.widget.Toolbar;
+
import java.util.Locale;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
public class Utils {
private static final long SECOND_MILLIS = 1000;
@@ -104,4 +107,14 @@ public class Utils {
return false;
}
+
+ public static void displaySortTypeInToolbar(SortType sortType, Toolbar toolbar) {
+ if (sortType != null) {
+ if (sortType.getTime() != null) {
+ toolbar.setSubtitle(sortType.getType().fullName + " " + sortType.getTime().fullName);
+ } else {
+ toolbar.setSubtitle(sortType.getType().fullName);
+ }
+ }
+ }
}