aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-10-13 16:08:21 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-10-13 16:08:21 +0000
commitfdca23fa14c5f42b028a0598e9fb2c4ae6a696f2 (patch)
tree276b3e1b0a87d5df9c86da4e8c926a5a06a1f6a6
parentd82b1e63051465fa45578884ef9bc17314d89af8 (diff)
downloadinfinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar.gz
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar.bz2
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar.lz
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar.xz
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.tar.zst
infinity-for-reddit-fdca23fa14c5f42b028a0598e9fb2c4ae6a696f2.zip
Add a time option to some sort types. Remember the last sort type.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java38
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java40
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java40
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java55
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSourceFactory.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java60
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchPostSortTypeBottomSheetFragment.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchUserAndSubredditSortTypeBottomSheetFragment.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTimeBottomSheetFragment.java112
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserThingSortTypeBottomSheetFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java178
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java65
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSourceFactory.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSourceFactory.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java10
-rw-r--r--app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml100
-rw-r--r--app/src/main/res/values/strings.xml6
-rw-r--r--app/src/main/res/xml/searchable.xml2
-rw-r--r--build.gradle2
38 files changed, 869 insertions, 241 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
index 56e03233..96c2af3a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
@@ -31,15 +31,16 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
-import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
-public class AccountPostsActivity extends BaseActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback {
+public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback {
static final String EXTRA_USER_WHERE = "EUW";
@@ -177,7 +178,6 @@ public class AccountPostsActivity extends BaseActivity implements UserThingSortT
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, mUserWhere);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_NEW);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
mFragment.setArguments(bundle);
@@ -255,12 +255,17 @@ public class AccountPostsActivity extends BaseActivity implements UserThingSortT
}
@Override
- public void userThingSortTypeSelected(String sortType) {
+ public void sortTypeSelected(SortType sortType) {
if (mFragment != null) {
((PostFragment) mFragment).changeSortType(sortType);
}
}
+ @Override
+ public void sortTypeSelected(String sortType) {
+
+ }
+
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
index 1cc7e09f..87e8131e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
@@ -294,7 +294,6 @@ public class AccountSavedThingActivity extends BaseActivity {
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_NEW);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
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 52f370b2..b5412522 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
@@ -31,6 +31,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@@ -40,15 +41,15 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
-public class FilteredThingActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
- SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback {
+public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback {
public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ";
public static final String EXTRA_FILTER = "EF";
public static final String EXTRA_POST_TYPE = "EPT";
- public static final String EXTRA_SORT_TYPE = "EST";
public static final String EXTRA_USER_WHERE = "EUW";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
@@ -79,6 +80,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment;
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
+ private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -142,7 +144,6 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
name = getIntent().getStringExtra(EXTRA_NAME);
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE);
- String sortType = getIntent().getStringExtra(EXTRA_SORT_TYPE);
if (savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
@@ -153,14 +154,12 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
if (!mNullAccessToken && mAccessToken == null) {
- getCurrentAccountAndBindView(filter, sortType);
+ getCurrentAccountAndBindView(filter);
} else {
- /*mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
- getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();*/
- bindView(filter, sortType, false);
+ bindView(filter, false);
}
} else {
- getCurrentAccountAndBindView(filter, sortType);
+ getCurrentAccountAndBindView(filter);
}
}
@@ -169,18 +168,18 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
return mSharedPreferences;
}
- private void getCurrentAccountAndBindView(int filter, String sortType) {
+ private void getCurrentAccountAndBindView(int filter) {
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
if (account == null) {
mNullAccessToken = true;
} else {
mAccessToken = account.getAccessToken();
}
- bindView(filter, sortType, true);
+ bindView(filter, true);
}).execute();
}
- private void bindView(int filter, String sortType, boolean initializeFragment) {
+ private void bindView(int filter, boolean initializeFragment) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
getSupportActionBar().setTitle(name);
@@ -223,6 +222,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
break;
}
+ sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
+
switch (filter) {
case Post.NSFW_TYPE:
toolbar.setSubtitle(R.string.nsfw);
@@ -249,7 +250,6 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
bundle.putInt(PostFragment.EXTRA_FILTER, filter);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
if (postType == PostDataSource.TYPE_USER) {
@@ -350,18 +350,16 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
}
@Override
- public void searchSortTypeSelected(String sortType) {
+ public void sortTypeSelected(SortType sortType) {
((PostFragment) mFragment).changeSortType(sortType);
}
@Override
public void sortTypeSelected(String sortType) {
- ((PostFragment) mFragment).changeSortType(sortType);
- }
-
- @Override
- public void userThingSortTypeSelected(String sortType) {
- ((PostFragment) mFragment).changeSortType(sortType);
+ Bundle bundle = new Bundle();
+ bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
+ sortTimeBottomSheetFragment.setArguments(bundle);
+ sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
}
@Subscribe
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 f48fc2b1..823a8e2f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -74,6 +74,7 @@ import ml.docilealligator.infinityforreddit.FetchMyInfo;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -84,13 +85,15 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class MainActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
+public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
static final String EXTRA_POST_TYPE = "EPT";
@@ -177,6 +180,7 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
+ private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
@@ -278,6 +282,8 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
+ sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
+
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
@@ -877,11 +883,19 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
}
@Override
- public void sortTypeSelected(String sortType) {
+ public void sortTypeSelected(SortType sortType) {
sectionsPagerAdapter.changeSortType(sortType);
}
@Override
+ public void sortTypeSelected(String sortType) {
+ Bundle bundle = new Bundle();
+ bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
+ sortTimeBottomSheetFragment.setArguments(bundle);
+ sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
+ }
+
+ @Override
public void postTypeSelected(int postType) {
Intent intent;
switch (postType) {
@@ -946,7 +960,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, "popular");
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -956,7 +969,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, "all");
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -968,7 +980,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
PostFragment fragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -978,7 +989,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, "popular");
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -988,7 +998,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, "all");
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -1174,7 +1183,7 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
}
}
- void changeSortType(String sortType) {
+ void changeSortType(SortType sortType) {
if (mAccessToken == null) {
if (viewPager.getCurrentItem() == 0) {
popularPostFragment.changeSortType(sortType);
@@ -1184,12 +1193,27 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
} else {
switch (viewPager.getCurrentItem()) {
case 0:
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
+ }
+
frontPagePostFragment.changeSortType(sortType);
break;
case 1:
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply();
+ }
+
popularPostFragment.changeSortType(sortType);
break;
case 2:
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply();
+ }
+
allPostFragment.changeSortType(sortType);
}
}
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 9d2c8ca2..1d43edd0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -37,6 +37,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@@ -45,9 +46,10 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
-public class SearchResultActivity extends BaseActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback,
- SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback {
+public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback {
static final String EXTRA_QUERY = "QK";
static final String EXTRA_SUBREDDIT_NAME = "ESN";
@@ -73,6 +75,7 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
private String mSubredditName;
private SectionsPagerAdapter sectionsPagerAdapter;
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
+ private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
@Override
@@ -146,6 +149,8 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
Bundle bundle = new Bundle();
searchPostSortTypeBottomSheetFragment.setArguments(bundle);
+ sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
+
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
// Get the intent, verify the action and get the query
@@ -240,12 +245,20 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
}
@Override
- public void searchSortTypeSelected(String sortType) {
- sectionsPagerAdapter.changeSortType(sortType, 0);
+ public void sortTypeSelected(SortType sortType) {
+ sectionsPagerAdapter.changeSortType(sortType);
+ }
+
+ @Override
+ public void sortTypeSelected(String sortType) {
+ Bundle bundle = new Bundle();
+ bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
+ sortTimeBottomSheetFragment.setArguments(bundle);
+ sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
}
@Override
- public void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition) {
+ public void searchUserAndSubredditSortTypeSelected(SortType sortType, int fragmentPosition) {
sectionsPagerAdapter.changeSortType(sortType, fragmentPosition);
}
@@ -277,7 +290,6 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
PostFragment mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_RELEVANCE);
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
@@ -343,15 +355,23 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
return fragment;
}
- void changeSortType(String sortType, int fragmentPosition) {
+ void changeSortType(SortType sortType) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
+ }
+
+ postFragment.changeSortType(sortType);
+ }
+
+ void changeSortType(SortType sortType, int fragmentPosition) {
switch (fragmentPosition) {
- case 0:
- postFragment.changeSortType(sortType);
- break;
case 1:
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply();
subredditListingFragment.changeSortType(sortType);
break;
case 2:
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply();
userListingFragment.changeSortType(sortType);
}
}
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 bf5bd92d..7ab828f0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -49,6 +49,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -57,6 +58,8 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
@@ -64,7 +67,7 @@ import ml.docilealligator.infinityforreddit.SubredditSubscription;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
+public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
@@ -132,6 +135,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private AppBarLayout.LayoutParams params;
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
+ private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private SubredditViewModel mSubredditViewModel;
@Override
@@ -210,8 +214,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
getCurrentAccountAndBindView();
} else {
bindView(false);
- /*mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
- getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();*/
}
if (mFetchSubredditInfoSuccess) {
@@ -228,6 +230,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
+ sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
+
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
//Get status bar height
@@ -459,7 +463,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
mFragment.setArguments(bundle);
@@ -569,11 +572,24 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
@Override
- public void sortTypeSelected(String sortType) {
+ public void sortTypeSelected(SortType sortType) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, sortType.getTime().name()).apply();
+ }
+
((PostFragment) mFragment).changeSortType(sortType);
}
@Override
+ public void sortTypeSelected(String sortType) {
+ Bundle bundle = new Bundle();
+ bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
+ sortTimeBottomSheetFragment.setArguments(bundle);
+ sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
+ }
+
+ @Override
public void postTypeSelected(int postType) {
Intent intent;
switch (postType) {
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 ec574dec..a92ffc4b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchUserData;
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
+import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -63,6 +64,8 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
import ml.docilealligator.infinityforreddit.User.UserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
@@ -71,7 +74,7 @@ import ml.docilealligator.infinityforreddit.UserFollowing;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class ViewUserDetailActivity extends BaseActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback {
+public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback {
public static final String EXTRA_USER_NAME_KEY = "EUNK";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@@ -122,6 +125,7 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
+ private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
@@ -385,6 +389,7 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
});
userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
+ sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
}
@Override
@@ -610,10 +615,15 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
}
@Override
- public void userThingSortTypeSelected(String sortType) {
+ public void sortTypeSelected(SortType sortType) {
sectionsPagerAdapter.changeSortType(sortType);
}
+ @Override
+ public void sortTypeSelected(String sortType) {
+ sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
+ }
+
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
if (!getClass().getName().equals(event.excludeActivityClassName)) {
@@ -671,7 +681,6 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED);
- bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_NEW);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
@@ -754,13 +763,23 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
}
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST, sortType.getTime().name()).apply();
+ }
+
postFragment.changeSortType(sortType);
}
} else {
if (commentsListingFragment != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, sortType.getType().name()).apply();
+ if(sortType.getTime() != null) {
+ mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, sortType.getTime().name()).apply();
+ }
+
commentsListingFragment.changeSortType(sortType);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index e2e72171..904ad0a3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -391,7 +391,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
mActivity.startActivity(intent);
});
@@ -407,7 +406,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType());
mActivity.startActivity(intent);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index a0dbe900..41ca7800 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -328,7 +328,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Intent intent = new Intent(mContext, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
mContext.startActivity(intent);
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
index d405e7d2..163a8e56 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
@@ -26,7 +26,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
@Nullable
private String accessToken;
private String username;
- private String sortType;
+ private SortType sortType;
private boolean areSavedComments;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
@@ -36,7 +36,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
private LoadParams<String> params;
private LoadCallback<String, CommentData> callback;
- CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, String sortType,
+ CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, SortType sortType,
boolean areSavedComments) {
this.retrofit = retrofit;
this.locale = locale;
@@ -72,14 +72,30 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> commentsCall;
if (areSavedComments) {
- commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
- null, sortType, RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
+ null, sortType.getType().value, sortType.getTime().value,
+ RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
+ null, sortType.getType().value, RedditUtils.getOAuthHeader(accessToken));
+ }
} else {
if (accessToken == null) {
- commentsCall = api.getUserComments(username, null, sortType);
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserComments(username, null, sortType.getType().value,
+ sortType.getTime().value);
+ } else {
+ commentsCall = api.getUserComments(username, null, sortType.getType().value);
+ }
} else {
- commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken), username,
- null, sortType);
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken), username,
+ null, sortType.getType().value, sortType.getTime().value);
+ } else {
+ commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken), username,
+ null, sortType.getType().value);
+ }
}
}
commentsCall.enqueue(new Callback<String>() {
@@ -135,14 +151,29 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> commentsCall;
if (areSavedComments) {
- commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
- sortType, RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
+ sortType.getType().value, sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
+ sortType.getType().value, RedditUtils.getOAuthHeader(accessToken));
+ }
} else {
if (accessToken == null) {
- commentsCall = api.getUserComments(username, params.key, sortType);
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserComments(username, params.key, sortType.getType().value,
+ sortType.getTime().value);
+ } else {
+ commentsCall = api.getUserComments(username, params.key, sortType.getType().value);
+ }
} else {
- commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken),
- username, params.key, sortType);
+ if (sortType.getTime() != null) {
+ commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken),
+ username, params.key, sortType.getType().value, sortType.getTime().value);
+ } else {
+ commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken),
+ username, params.key, sortType.getType().value);
+ }
}
}
commentsCall.enqueue(new Callback<String>() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSourceFactory.java
index 2a586d2f..34d24b8a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSourceFactory.java
@@ -14,14 +14,14 @@ class CommentDataSourceFactory extends DataSource.Factory {
private Locale locale;
private String accessToken;
private String username;
- private String sortType;
+ private SortType sortType;
private boolean areSavedComments;
private CommentDataSource commentDataSource;
private MutableLiveData<CommentDataSource> commentDataSourceLiveData;
CommentDataSourceFactory(Retrofit retrofit, Locale locale, @Nullable String accessToken,
- String username, String sortType,
+ String username, SortType sortType,
boolean areSavedComments) {
this.retrofit = retrofit;
this.locale = locale;
@@ -49,7 +49,7 @@ class CommentDataSourceFactory extends DataSource.Factory {
return commentDataSource;
}
- void changeSortType(String sortType) {
+ void changeSortType(SortType sortType) {
this.sortType = sortType;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
index 6fc2d1c7..3753ba9f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
@@ -19,9 +19,9 @@ public class CommentViewModel extends ViewModel {
private LiveData<NetworkState> initialLoadingState;
private LiveData<Boolean> hasCommentLiveData;
private LiveData<PagedList<CommentData>> comments;
- private MutableLiveData<String> sortTypeLiveData;
+ private MutableLiveData<SortType> sortTypeLiveData;
- public CommentViewModel(Retrofit retrofit, Locale locale, String accessToken, String username, String sortType,
+ public CommentViewModel(Retrofit retrofit, Locale locale, String accessToken, String username, SortType sortType,
boolean areSavedComments) {
commentDataSourceFactory = new CommentDataSourceFactory(retrofit, locale, accessToken, username, sortType,
areSavedComments);
@@ -72,7 +72,7 @@ public class CommentViewModel extends ViewModel {
commentDataSourceFactory.getCommentDataSource().retryLoadingMore();
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
sortTypeLiveData.postValue(sortType);
}
@@ -81,11 +81,11 @@ public class CommentViewModel extends ViewModel {
private Locale locale;
private String accessToken;
private String username;
- private String sortType;
+ private SortType sortType;
private boolean areSavedComments;
public Factory(Retrofit retrofit, Locale locale, String accessToken, String username,
- String sortType, boolean areSavedComments) {
+ SortType sortType, boolean areSavedComments) {
this.retrofit = retrofit;
this.locale = locale;
this.accessToken = accessToken;
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 81af278a..48823b32 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
@@ -36,9 +37,10 @@ import ml.docilealligator.infinityforreddit.CommentViewModel;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
@@ -76,6 +78,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
Retrofit mOauthRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ SharedPreferences mSharedPreferences;
private boolean mNullAccessToken = false;
private String mAccessToken;
private RequestManager mGlide;
@@ -144,6 +148,14 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
() -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME);
+ String sort = mSharedPreferences.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 = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value);
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+ } else {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ }
mCommentRecyclerView.setAdapter(mAdapter);
@@ -151,11 +163,11 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
if (mAccessToken == null) {
factory = new CommentViewModel.Factory(mRetrofit,
- resources.getConfiguration().locale, mAccessToken, username, PostDataSource.SORT_TYPE_NEW,
+ resources.getConfiguration().locale, null, username, sortType,
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
} else {
factory = new CommentViewModel.Factory(mOauthRetrofit,
- resources.getConfiguration().locale, mAccessToken, username, PostDataSource.SORT_TYPE_NEW,
+ resources.getConfiguration().locale, mAccessToken, username, sortType,
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
}
@@ -189,7 +201,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
mCommentViewModel.changeSortType(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 83dce165..0a4ee79d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -61,6 +61,7 @@ import ml.docilealligator.infinityforreddit.PostViewModel;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit;
@@ -74,7 +75,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public static final String EXTRA_USER_WHERE = "EUW";
public static final String EXTRA_QUERY = "EQ";
public static final String EXTRA_POST_TYPE = "EPT";
- public static final String EXTRA_SORT_TYPE = "EST";
public static final String EXTRA_FILTER = "EF";
public static final int EXTRA_NO_FILTER = -2;
public static final String EXTRA_ACCESS_TOKEN = "EAT";
@@ -269,7 +269,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
int postType = getArguments().getInt(EXTRA_POST_TYPE);
- String sortType = getArguments().getString(EXTRA_SORT_TYPE);
+ //String sortType = getArguments().getString(EXTRA_SORT_TYPE);
int filter = getArguments().getInt(EXTRA_FILTER);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
@@ -283,6 +283,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_NAME);
String query = getArguments().getString(EXTRA_QUERY);
+ String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.value);
+ String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.value);
+ SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
new PostRecyclerViewAdapter.Callback() {
@@ -297,7 +301,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@@ -314,8 +317,36 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
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) {
+ if(subredditName.equals("popular")) {
+ sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, SortType.Type.HOT.value);
+ if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
+ sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.value);
+ }
+ } else {
+ sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.value);
+ if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
+ sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.value);
+ }
+ }
+ } else {
+ sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST, SortType.Type.HOT.value);
+ if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
+ sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, SortType.Time.ALL.value);
+ }
+ }
+
+ if(sortTime != null) {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+ } else {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ }
+
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, displaySubredditName, needBlurNsfw, needBlurSpoiler,
new PostRecyclerViewAdapter.Callback() {
@@ -329,7 +360,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@@ -353,6 +383,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mFetchPostInfoLinearLayout.setLayoutParams(params);
}
+ String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST, SortType.Type.NEW.value);
+ SortType sortType;
+ if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
+ String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST, SortType.Time.ALL.value);
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+ } else {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ }
+
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
new PostRecyclerViewAdapter.Callback() {
@@ -366,7 +405,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
startActivity(intent);
@@ -383,6 +421,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
filter, nsfw);
}
} else {
+ String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.value);
+ SortType sortType;
+ if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
+ String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.value);
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+ } else {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ }
+
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
new PostRecyclerViewAdapter.Callback() {
@@ -396,7 +443,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
- intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@@ -444,7 +490,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return rootView;
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
mPostViewModel.changeSortType(sortType);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchPostSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchPostSortTypeBottomSheetFragment.java
index f03b1e5e..9973b1af 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchPostSortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchPostSortTypeBottomSheetFragment.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
+import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
@@ -10,14 +11,16 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
/**
@@ -35,6 +38,7 @@ public class SearchPostSortTypeBottomSheetFragment extends RoundedBottomSheetDia
TextView newTypeTextView;
@BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment)
TextView commentsTypeTextView;
+ private Activity activity;
public SearchPostSortTypeBottomSheetFragment() {
// Required empty public constructor
}
@@ -45,44 +49,42 @@ public class SearchPostSortTypeBottomSheetFragment extends RoundedBottomSheetDia
View rootView = inflater.inflate(R.layout.fragment_search_post_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
- Activity activity = getActivity();
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
relevanceTypeTextView.setOnClickListener(view -> {
- ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.RELEVANCE.name());
dismiss();
});
hotTypeTextView.setOnClickListener(view -> {
- ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_HOT);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.HOT.name());
dismiss();
});
topTypeTextView.setOnClickListener(view -> {
- ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_TOP);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
dismiss();
});
newTypeTextView.setOnClickListener(view -> {
- ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_NEW);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
dismiss();
});
commentsTypeTextView.setOnClickListener(view -> {
- ((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_COMMENTS);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.COMMENTS.name());
dismiss();
});
return rootView;
}
-
- public interface SearchSortTypeSelectionCallback {
- void searchSortTypeSelected(String sortType);
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (Activity) context;
}
-
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchUserAndSubredditSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchUserAndSubredditSortTypeBottomSheetFragment.java
index 41c3fd13..bd40b263 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchUserAndSubredditSortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SearchUserAndSubredditSortTypeBottomSheetFragment.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
+import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
@@ -10,14 +11,16 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
/**
@@ -30,6 +33,7 @@ public class SearchUserAndSubredditSortTypeBottomSheetFragment extends RoundedBo
TextView relevanceTypeTextView;
@BindView(R.id.activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment)
TextView activityTypeTextView;
+ private Activity activity;
public SearchUserAndSubredditSortTypeBottomSheetFragment() {
// Required empty public constructor
}
@@ -40,31 +44,33 @@ public class SearchUserAndSubredditSortTypeBottomSheetFragment extends RoundedBo
View rootView = inflater.inflate(R.layout.fragment_search_user_and_subreddit_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
- Activity activity = getActivity();
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
- int position = getArguments().getInt(EXTRA_FRAGMENT_POSITION);
+ int position = getArguments() != null ? getArguments().getInt(EXTRA_FRAGMENT_POSITION) : -1;
+ if(position < 0) {
+ dismiss();
+ return rootView;
+ }
relevanceTypeTextView.setOnClickListener(view -> {
- ((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE, position);
+ ((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.RELEVANCE), position);
dismiss();
});
activityTypeTextView.setOnClickListener(view -> {
- ((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_HOT, position);
+ ((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.ACTIVITY), position);
dismiss();
});
return rootView;
}
-
- public interface SearchUserAndSubredditSortTypeSelectionCallback {
- void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition);
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (Activity) context;
}
-
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTimeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTimeBottomSheetFragment.java
new file mode 100644
index 00000000..10cfdde7
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTimeBottomSheetFragment.java
@@ -0,0 +1,112 @@
+package ml.docilealligator.infinityforreddit.Fragment;
+
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class SortTimeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+
+ public static final String EXTRA_SORT_TYPE = "EST";
+
+ @BindView(R.id.hour_text_view_sort_time_bottom_sheet_fragment)
+ TextView hourTextView;
+ @BindView(R.id.day_text_view_sort_time_bottom_sheet_fragment)
+ TextView dayTextView;
+ @BindView(R.id.week_text_view_sort_time_bottom_sheet_fragment)
+ TextView weekTextView;
+ @BindView(R.id.month_text_view_sort_time_bottom_sheet_fragment)
+ TextView monthTextView;
+ @BindView(R.id.year_text_view_sort_time_bottom_sheet_fragment)
+ TextView yearTextView;
+ @BindView(R.id.all_time_text_view_sort_time_bottom_sheet_fragment)
+ TextView allTimeTextView;
+ private Activity activity;
+ public SortTimeBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_sort_time_bottom_sheet, container, false);
+
+ ButterKnife.bind(this, rootView);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
+ rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
+ }
+
+ String sortType = getArguments() != null ? getArguments().getString(EXTRA_SORT_TYPE) : null;
+ if(sortType == null) {
+ dismiss();
+ return rootView;
+ }
+
+ hourTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.HOUR));
+ dismiss();
+ });
+
+ dayTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.DAY));
+ dismiss();
+ });
+
+ weekTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.WEEK));
+ dismiss();
+ });
+
+ monthTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.MONTH));
+ dismiss();
+ });
+
+ yearTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.YEAR));
+ dismiss();
+ });
+
+ allTimeTextView.setOnClickListener(view -> {
+ ((SortTypeSelectionCallback) activity)
+ .sortTypeSelected(new SortType(SortType.Type.valueOf(sortType), SortType.Time.ALL));
+ dismiss();
+ });
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (Activity) context;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
index 22e96462..4f9d67b7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
+import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
@@ -17,8 +18,9 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
/**
@@ -41,6 +43,7 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
TextView topTypeTextView;
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment)
TextView controversialTypeTextView;
+ private Activity activity;
public SortTypeBottomSheetFragment() {
// Required empty public constructor
}
@@ -51,58 +54,56 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
View rootView = inflater.inflate(R.layout.fragment_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
- Activity activity = getActivity();
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
- if (getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) {
+ if (getArguments() == null || getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) {
bestTypeTextView.setVisibility(View.GONE);
} else {
bestTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_BEST);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.BEST));
dismiss();
});
}
hotTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_HOT);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.HOT));
dismiss();
});
newTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_NEW);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
dismiss();
});
randomTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RANDOM);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RANDOM));
dismiss();
});
risingTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RISING);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RISING));
dismiss();
});
topTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_TOP);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
dismiss();
});
controversialTypeTextView.setOnClickListener(view -> {
- ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.CONTROVERSIAL.name());
dismiss();
});
return rootView;
}
-
- public interface SortTypeSelectionCallback {
- void sortTypeSelected(String sortType);
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (Activity) context;
}
-
}
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 49123504..572bbf61 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
@@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
@@ -35,9 +36,10 @@ import ml.docilealligator.infinityforreddit.Adapter.SubredditListingRecyclerView
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SubredditListingViewModel;
import retrofit2.Retrofit;
@@ -72,7 +74,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
- RedditDataRoomDatabase redditDataRoomDatabase;
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ SharedPreferences mSharedPreferences;
private LinearLayoutManager mLinearLayoutManager;
private SubredditListingRecyclerViewAdapter mAdapter;
@@ -112,8 +116,11 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
+ String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value);
+ SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
- accessToken, accountName, redditDataRoomDatabase,
+ accessToken, accountName, mRedditDataRoomDatabase,
new SubredditListingRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@@ -134,8 +141,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSubredditListingRecyclerView.setAdapter(mAdapter);
- SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
- PostDataSource.SORT_TYPE_RELEVANCE);
+ SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query, sortType);
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
@@ -179,7 +185,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
}
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
mSubredditListingViewModel.changeSortType(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 02a1624e..af14afc8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.Fragment;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
@@ -30,9 +31,10 @@ import ml.docilealligator.infinityforreddit.Adapter.UserListingRecyclerViewAdapt
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.UserListingViewModel;
import retrofit2.Retrofit;
@@ -66,7 +68,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
- RedditDataRoomDatabase redditDataRoomDatabase;
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ SharedPreferences mSharedPreferences;
private LinearLayoutManager mLinearLayoutManager;
private String mQuery;
private UserListingRecyclerViewAdapter mAdapter;
@@ -103,15 +107,17 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mQuery = getArguments().getString(EXTRA_QUERY);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
+ String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value);
+ SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
- accessToken, accountName, redditDataRoomDatabase.subscribedUserDao(),
+ accessToken, accountName, mRedditDataRoomDatabase.subscribedUserDao(),
() -> mUserListingViewModel.retryLoadingMore());
mUserListingRecyclerView.setAdapter(mAdapter);
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
- PostDataSource.SORT_TYPE_RELEVANCE);
+ sortType);
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
@@ -155,7 +161,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
}
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
mUserListingViewModel.changeSortType(sortType);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserThingSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserThingSortTypeBottomSheetFragment.java
index d1afa8e4..59e099c4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserThingSortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserThingSortTypeBottomSheetFragment.java
@@ -17,8 +17,9 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
/**
@@ -26,7 +27,6 @@ import ml.docilealligator.infinityforreddit.R;
*/
public class UserThingSortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
- static final String EXTRA_NO_BEST_TYPE = "ENBT";
@BindView(R.id.new_type_text_view_user_thing_sort_type_bottom_sheet_fragment)
TextView newTypeTextView;
@BindView(R.id.hot_type_text_view_user_thing_sort_type_bottom_sheet_fragment)
@@ -55,38 +55,32 @@ public class UserThingSortTypeBottomSheetFragment extends RoundedBottomSheetDial
newTypeTextView.setOnClickListener(view -> {
if (activity != null) {
- ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_NEW);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
}
dismiss();
});
hotTypeTextView.setOnClickListener(view -> {
if (activity != null) {
- ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_HOT);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.HOT));
}
dismiss();
});
topTypeTextView.setOnClickListener(view -> {
if (activity != null) {
- ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_TOP);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
}
dismiss();
});
controversialTypeTextView.setOnClickListener(view -> {
if (activity != null) {
- ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL);
+ ((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.CONTROVERSIAL.name());
}
dismiss();
});
return rootView;
}
-
-
- public interface UserThingSortTypeSelectionCallback {
- void userThingSortTypeSelected(String sortType);
- }
-
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
index 83c7a072..3ee4c20f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
@@ -18,16 +18,6 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
public static final int TYPE_USER = 2;
public static final int TYPE_SEARCH = 3;
- public static final String SORT_TYPE_BEST = "best";
- public static final String SORT_TYPE_HOT = "hot";
- public static final String SORT_TYPE_NEW = "new";
- public static final String SORT_TYPE_RANDOM = "random";
- public static final String SORT_TYPE_RISING = "rising";
- public static final String SORT_TYPE_TOP = "top";
- public static final String SORT_TYPE_CONTROVERSIAL = "controversial";
- public static final String SORT_TYPE_RELEVANCE = "relevance";
- public static final String SORT_TYPE_COMMENTS = "comments";
-
public static final String USER_WHERE_SUBMITTED = "submitted";
public static final String USER_WHERE_UPVOTED = "upvoted";
public static final String USER_WHERE_DOWNVOTED = "downvoted";
@@ -41,7 +31,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private String subredditOrUserName;
private String query;
private int postType;
- private String sortType;
+ private SortType sortType;
private boolean nsfw;
private int filter;
private String userWhere;
@@ -53,7 +43,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private LoadParams<String> params;
private LoadCallback<String, Post> callback;
- PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
+ PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, SortType sortType,
int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
@@ -62,13 +52,13 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
initialLoadStateLiveData = new MutableLiveData<>();
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
- this.sortType = sortType == null ? PostDataSource.SORT_TYPE_BEST : sortType;
+ this.sortType = sortType == null ? new SortType(SortType.Type.BEST) : sortType;
this.filter = filter;
this.nsfw = nsfw;
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
- String sortType, int filter, boolean nsfw) {
+ SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -79,9 +69,9 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
this.postType = postType;
if (sortType == null) {
if (subredditOrUserName.equals("popular") || subredditOrUserName.equals("all")) {
- this.sortType = PostDataSource.SORT_TYPE_HOT;
+ this.sortType = new SortType(SortType.Type.HOT);
} else {
- this.sortType = PostDataSource.SORT_TYPE_BEST;
+ this.sortType = new SortType(SortType.Type.BEST);
}
} else {
this.sortType = sortType;
@@ -91,7 +81,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
- String sortType, String where, int filter, boolean nsfw) {
+ SortType sortType, String where, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -100,14 +90,14 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
initialLoadStateLiveData = new MutableLiveData<>();
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
- this.sortType = sortType == null ? PostDataSource.SORT_TYPE_NEW : sortType;
+ this.sortType = sortType == null ? new SortType(SortType.Type.NEW) : sortType;
userWhere = where;
this.filter = filter;
this.nsfw = nsfw;
}
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, String query,
- int postType, String sortType, int filter, boolean nsfw) {
+ int postType, SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -117,7 +107,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
initialLoadStateLiveData = new MutableLiveData<>();
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
- this.sortType = sortType == null ? PostDataSource.SORT_TYPE_RELEVANCE : sortType;
+ this.sortType = sortType == null ? new SortType(SortType.Type.RELEVANCE) : sortType;
this.filter = filter;
this.nsfw = nsfw;
}
@@ -188,13 +178,18 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private void loadBestPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback, String lastItem) {
RedditAPI api = retrofit.create(RedditAPI.class);
-
- Call<String> bestPost = api.getBestPosts(sortType, lastItem, RedditUtils.getOAuthHeader(accessToken));
+ Call<String> bestPost;
+ if(sortType.getTime() != null) {
+ bestPost = api.getBestPosts(sortType.getType().value, sortType.getTime().value, lastItem,
+ RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ bestPost = api.getBestPosts(sortType.getType().value, lastItem, RedditUtils.getOAuthHeader(accessToken));
+ }
bestPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- if (sortType.equals(SORT_TYPE_RANDOM)) {
+ if (sortType.getType().value.equals(SortType.Type.RANDOM.value)) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
public void onParsePostSuccess(Post post) {
@@ -260,7 +255,13 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
String after = lastItem == null ? params.key : lastItem;
RedditAPI api = retrofit.create(RedditAPI.class);
- Call<String> bestPost = api.getBestPosts(sortType, after, RedditUtils.getOAuthHeader(accessToken));
+ Call<String> bestPost;
+ if(sortType.getTime() != null) {
+ bestPost = api.getBestPosts(sortType.getType().value, sortType.getTime().value, after,
+ RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ bestPost = api.getBestPosts(sortType.getType().value, after, RedditUtils.getOAuthHeader(accessToken));
+ }
bestPost.enqueue(new Callback<String>() {
@Override
@@ -301,15 +302,25 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
Call<String> getPost;
if (accessToken == null) {
- getPost = api.getSubredditBestPosts(subredditOrUserName, sortType, lastItem);
+ if (sortType.getTime() != null) {
+ getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, sortType.getTime().value, lastItem);
+ } else {
+ getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, lastItem);
+ }
} else {
- getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType, lastItem, RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType.getType().value,
+ sortType.getTime().value, lastItem, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType.getType().value,
+ lastItem, RedditUtils.getOAuthHeader(accessToken));
+ }
}
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- if (sortType.equals(SORT_TYPE_RANDOM)) {
+ if (sortType.getType().value.equals(SortType.Type.RANDOM.value)) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
public void onParsePostSuccess(Post post) {
@@ -377,10 +388,21 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> getPost;
- if (accessToken == null) {
- getPost = api.getSubredditBestPosts(subredditOrUserName, sortType, after);
+ if (accessToken != null) {
+ if (sortType.getTime() != null) {
+ getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value,
+ sortType.getTime().value, after);
+ } else {
+ getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, after);
+ }
} else {
- getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType, after, RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType.getType().value,
+ sortType.getTime().value, after, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.getSubredditBestPostsOauth(subredditOrUserName, sortType.getType().value,
+ after, RedditUtils.getOAuthHeader(accessToken));
+ }
}
getPost.enqueue(new Callback<String>() {
@@ -422,10 +444,20 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
Call<String> getPost;
if (accessToken == null) {
- getPost = api.getUserPosts(subredditOrUserName, lastItem, sortType);
+ if (sortType.getTime() != null) {
+ getPost = api.getUserPosts(subredditOrUserName, lastItem, sortType.getType().value,
+ sortType.getTime().value);
+ } else {
+ getPost = api.getUserPosts(subredditOrUserName, lastItem, sortType.getType().value);
+ }
} else {
- getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, lastItem, sortType,
- RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, lastItem, sortType.getType().value,
+ sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, lastItem, sortType.getType().value,
+ RedditUtils.getOAuthHeader(accessToken));
+ }
}
getPost.enqueue(new Callback<String>() {
@Override
@@ -480,10 +512,20 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
Call<String> getPost;
if (accessToken == null) {
- getPost = api.getUserPosts(subredditOrUserName, after, sortType);
+ if (sortType.getTime() != null) {
+ getPost = api.getUserPosts(subredditOrUserName, after, sortType.getType().value,
+ sortType.getTime().value);
+ } else {
+ getPost = api.getUserPosts(subredditOrUserName, after, sortType.getType().value);
+ }
} else {
- getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, after, sortType,
- RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, after, sortType.getType().value,
+ sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, after, sortType.getType().value,
+ RedditUtils.getOAuthHeader(accessToken));
+ }
}
getPost.enqueue(new Callback<String>() {
@Override
@@ -525,16 +567,39 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
if (subredditOrUserName == null) {
if (accessToken == null) {
- getPost = api.searchPosts(query, lastItem, sortType);
+ if (sortType.getTime() != null) {
+ getPost = api.searchPosts(query, lastItem, sortType.getType().value, sortType.getTime().value);
+ } else {
+ getPost = api.searchPosts(query, lastItem, sortType.getType().value);
+ }
} else {
- getPost = api.searchPostsOauth(query, lastItem, sortType, RedditUtils.getOAuthHeader(accessToken));
+ if(sortType.getTime() != null) {
+ getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
+ sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
+ RedditUtils.getOAuthHeader(accessToken));
+ }
}
} else {
if (accessToken == null) {
- getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, lastItem);
+ if (sortType.getTime() != null) {
+ getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query,
+ sortType.getType().value, sortType.getTime().value, lastItem);
+ } else {
+ getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query,
+ sortType.getType().value, lastItem);
+ }
} else {
- getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
- RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query,
+ sortType.getType().value, sortType.getTime().value, lastItem,
+ RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query,
+ sortType.getType().value, lastItem,
+ RedditUtils.getOAuthHeader(accessToken));
+ }
}
}
@@ -592,16 +657,37 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
if (subredditOrUserName == null) {
if (accessToken == null) {
- getPost = api.searchPosts(query, after, sortType);
+ if (sortType.getTime() != null) {
+ getPost = api.searchPosts(query, after, sortType.getType().value, sortType.getTime().value);
+ } else {
+ getPost = api.searchPosts(query, after, sortType.getType().value);
+ }
} else {
- getPost = api.searchPostsOauth(query, after, sortType, RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.searchPostsOauth(query, after, sortType.getType().value,
+ sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.searchPostsOauth(query, after, sortType.getType().value, RedditUtils.getOAuthHeader(accessToken));
+ }
}
} else {
if (accessToken == null) {
- getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, after);
+ if (sortType.getTime() != null) {
+ getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query,
+ sortType.getType().value, sortType.getTime().value, after);
+ } else {
+ getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query,
+ sortType.getType().value, after);
+ }
} else {
- getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after,
- RedditUtils.getOAuthHeader(accessToken));
+ if (sortType.getTime() != null) {
+ getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query,
+ sortType.getType().value, sortType.getTime().value, after,
+ RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query,
+ sortType.getType().value, after, RedditUtils.getOAuthHeader(accessToken));
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
index 0b2f9d50..77b5199d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
@@ -15,7 +15,7 @@ class PostDataSourceFactory extends DataSource.Factory {
private String subredditName;
private String query;
private int postType;
- private String sortType;
+ private SortType sortType;
private String userWhere;
private int filter;
private boolean nsfw;
@@ -23,7 +23,7 @@ class PostDataSourceFactory extends DataSource.Factory {
private PostDataSource postDataSource;
private MutableLiveData<PostDataSource> postDataSourceLiveData;
- PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
+ PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType, SortType sortType,
int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
@@ -36,7 +36,7 @@ class PostDataSourceFactory extends DataSource.Factory {
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
- int postType, String sortType, int filter, boolean nsfw) {
+ int postType, SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -49,7 +49,7 @@ class PostDataSourceFactory extends DataSource.Factory {
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
- int postType, String sortType, String where, int filter, boolean nsfw) {
+ int postType, SortType sortType, String where, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -63,7 +63,7 @@ class PostDataSourceFactory extends DataSource.Factory {
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
- String query, int postType, String sortType, int filter, boolean nsfw) {
+ String query, int postType, SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -105,11 +105,11 @@ class PostDataSourceFactory extends DataSource.Factory {
return postDataSource;
}
- void changeSortType(String sortType) {
+ void changeSortType(SortType sortType) {
this.sortType = sortType;
}
- void changeNSFWAndSortType(boolean nsfw, String sortType) {
+ void changeNSFWAndSortType(boolean nsfw, SortType sortType) {
this.nsfw = nsfw;
this.sortType = sortType;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
index ea2758ca..16ad30f0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
@@ -22,10 +22,10 @@ public class PostViewModel extends ViewModel {
private LiveData<Boolean> hasPostLiveData;
private LiveData<PagedList<Post>> posts;
private MutableLiveData<Boolean> nsfwLiveData;
- private MutableLiveData<String> sortTypeLiveData;
+ private MutableLiveData<SortType> sortTypeLiveData;
private NSFWAndSortTypeLiveData nsfwAndSortTypeLiveData;
- public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
+ public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, SortType sortType,
int filter, boolean nsfw) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType,
sortType, filter, nsfw);
@@ -57,7 +57,7 @@ public class PostViewModel extends ViewModel {
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
- String sortType, int filter, boolean nsfw) {
+ SortType sortType, int filter, boolean nsfw) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
postType, sortType, filter, nsfw);
@@ -88,7 +88,7 @@ public class PostViewModel extends ViewModel {
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
- String sortType, String where, int filter, boolean nsfw) {
+ SortType sortType, String where, int filter, boolean nsfw) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
postType, sortType, where, filter, nsfw);
@@ -119,7 +119,7 @@ public class PostViewModel extends ViewModel {
}
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
- int postType, String sortType, int filter, boolean nsfw) {
+ int postType, SortType sortType, int filter, boolean nsfw) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
query, postType, sortType, filter, nsfw);
@@ -173,7 +173,7 @@ public class PostViewModel extends ViewModel {
postDataSourceFactory.getPostDataSource().retryLoadingMore();
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
sortTypeLiveData.postValue(sortType);
}
@@ -188,12 +188,12 @@ public class PostViewModel extends ViewModel {
private String subredditName;
private String query;
private int postType;
- private String sortType;
+ private SortType sortType;
private String userWhere;
private int filter;
private boolean nsfw;
- public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
+ public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, SortType sortType,
int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
@@ -205,7 +205,7 @@ public class PostViewModel extends ViewModel {
}
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
- String sortType, int filter, boolean nsfw) {
+ SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -217,7 +217,7 @@ public class PostViewModel extends ViewModel {
}
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
- String sortType, String where, int filter, boolean nsfw) {
+ SortType sortType, String where, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -230,7 +230,7 @@ public class PostViewModel extends ViewModel {
}
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
- int postType, String sortType, int filter, boolean nsfw) {
+ int postType, SortType sortType, int filter, boolean nsfw) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.locale = locale;
@@ -261,8 +261,8 @@ public class PostViewModel extends ViewModel {
}
}
- private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, String>> {
- public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<String> sortType) {
+ private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, SortType>> {
+ public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<SortType> sortType) {
addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1)));
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
index 2a326228..a5fd0844 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
@@ -43,22 +43,44 @@ public interface RedditAPI {
@GET("{sortType}?raw_json=1")
Call<String> getBestPosts(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
+ @GET("{sortType}?raw_json=1")
+ Call<String> getBestPosts(@Path("sortType") String sortType, @Query("t") String sortTime,
+ @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
+
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
+ Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
+ @Query("t") String sortTime, @Query("after") String lastItem,
+ @HeaderMap Map<String, String> headers);
+
+ @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
@Query("after") String lastItem);
+ @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
+ Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
+ @Query("t") String sortTime, @Query("after") String lastItem);
+
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") String sortType, @HeaderMap Map<String, String> headers);
+ @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
+ Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
+ @Query("after") String lastItem, @Query("sort") String sortType,
+ @Query("t") String sortTime, @HeaderMap Map<String, String> headers);
+
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") String sortType);
+ @GET("user/{username}/submitted.json?raw_json=1&limit=25")
+ Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
+ @Query("sort") String sortType, @Query("t") String sortTime);
+
@GET("user/{username}/about.json?raw_json=1")
Call<String> getUserData(@Path("username") String username);
@@ -67,12 +89,27 @@ public interface RedditAPI {
@Query("sort") String sortType);
@GET("user/{username}/comments.json?raw_json=1")
+ Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
+ @Query("sort") String sortType, @Query("t") String sortTime);
+
+ @GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") String sortType);
+ @GET("user/{username}/comments.json?raw_json=1")
+ Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
+ @Query("after") String after, @Query("sort") String sortType,
+ @Query("t") String sortTime);
+
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
- @Query("after") String lastItem, @Query("sort") String sortType, @HeaderMap Map<String, String> headers);
+ @Query("after") String lastItem, @Query("sort") String sortType,
+ @HeaderMap Map<String, String> headers);
+
+ @GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
+ Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
+ @Query("after") String lastItem, @Query("sort") String sortType,
+ @Query("t") String sortTime, @HeaderMap Map<String, String> headers);
@FormUrlEncoded
@POST("api/subscribe")
@@ -98,17 +135,39 @@ public interface RedditAPI {
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
+ Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
+ @Query("sort") String sort, @Query("t") String sortTime,
+ @HeaderMap Map<String, String> headers);
+
+ @GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort);
+ @GET("search.json?include_over_18=1&raw_json=1&type=link")
+ Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
+ @Query("sort") String sort, @Query("t") String sortTime);
+
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
- @Query("q") String query, @Query("after") String after,
+ @Query("q") String query, @Query("sort") String sort,
+ @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
+ Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
+ @Query("q") String query, @Query("sort") String sort,
+ @Query("t") String sortTime, @Query("after") String after,
+ @HeaderMap Map<String, String> headers);
+
+ @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
+ Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
+ @Query("q") String query, @Query("sort") String sort,
+ @Query("after") String after);
+
+ @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
- @Query("q") String query, @Query("after") String after);
+ @Query("q") String query, @Query("sort") String sort,
+ @Query("t") String sortTime, @Query("after") String after);
@FormUrlEncoded
@POST("api/comment")
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
index 69c717b0..372eaabb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
@@ -29,4 +29,20 @@ public class SharedPreferencesUtils {
public static final String CONTENT_FONT_SIZE_KEY = "content_font_size";
public static final String AMOLED_DARK_KEY = "amoled_dark";
public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface";
+ public static final String SORT_TYPE_BEST_POST = "sort_type_best_post";
+ public static final String SORT_TIME_BEST_POST = "sort_time_best_post";
+ public static final String SORT_TYPE_ALL_POST = "sort_type_all_post";
+ public static final String SORT_TIME_ALL_POST = "sort_time_all_post";
+ public static final String SORT_TYPE_POPULAR_POST = "sort_type_popular_post";
+ public static final String SORT_TIME_POPULAR_POST = "sort_time_popular_post";
+ public static final String SORT_TYPE_SEARCH_POST = "sort_type_search_post";
+ public static final String SORT_TIME_SEARCH_POST = "sort_time_search_post";
+ public static final String SORT_TYPE_SUBREDDIT_POST = "sort_type_subreddit_post";
+ public static final String SORT_TIME_SUBREDDIT_POST = "sort_time_subreddit_post";
+ public static final String SORT_TYPE_USER_POST = "sort_type_user_post";
+ public static final String SORT_TIME_USER_POST = "sort_time_user_post";
+ public static final String SORT_TYPE_USER_COMMENT = "sort_type_user_comment";
+ public static final String SORT_TIME_USER_COMMENT = "sort_time_user_comment";
+ public static final String SORT_TYPE_SEARCH_SUBREDDIT = "sort_type_search_subreddit";
+ public static final String SORT_TYPE_SEARCH_USER = "sort_type_search_user";
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java
new file mode 100644
index 00000000..39502a2d
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java
@@ -0,0 +1,58 @@
+package ml.docilealligator.infinityforreddit;
+
+public class SortType {
+
+ private Type type;
+ private Time time;
+
+ public SortType(Type type) {
+ this.type = type;
+ }
+
+ public SortType(Type type, Time time) {
+ this.type = type;
+ this.time = time;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public Time getTime() {
+ return time;
+ }
+
+ public enum Type {
+ BEST("best"),
+ HOT("hot"),
+ NEW("new"),
+ RANDOM("random"),
+ RISING("rising"),
+ TOP("top"),
+ CONTROVERSIAL("controversial"),
+ RELEVANCE("relevance"),
+ COMMENTS("comments"),
+ ACTIVITY("activity");
+
+ public final String value;
+
+ Type(String value) {
+ this.value = value;
+ }
+ }
+
+ public enum Time {
+ HOUR("hour"),
+ DAY("day"),
+ WEEK("week"),
+ MONTH("month"),
+ YEAR("year"),
+ ALL("all");
+
+ public final String value;
+
+ Time(String value) {
+ this.value = value;
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java
new file mode 100644
index 00000000..6585c3a4
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit;
+
+public interface SortTypeSelectionCallback {
+ default void sortTypeSelected(SortType sortType){}
+
+ default void sortTypeSelected(String sortType){}
+
+ default void searchUserAndSubredditSortTypeSelected(SortType sortType, int fragmentPosition){}
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
index 0cbb63cd..32bde86d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
@@ -13,7 +13,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
private MutableLiveData<NetworkState> initialLoadStateLiveData;
@@ -22,7 +22,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
private LoadParams<String> params;
private LoadCallback<String, SubredditData> callback;
- SubredditListingDataSource(Retrofit retrofit, String query, String sortType) {
+ SubredditListingDataSource(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -47,7 +47,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, SubredditData> callback) {
initialLoadStateLiveData.postValue(NetworkState.LOADING);
- FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType,
+ FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType.getType().value,
new FetchSubredditData.FetchSubredditListingDataListener() {
@Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
@@ -82,7 +82,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
return;
}
- FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType,
+ FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType.getType().value,
new FetchSubredditData.FetchSubredditListingDataListener() {
@Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSourceFactory.java
index f67218db..fa683f47 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSourceFactory.java
@@ -9,12 +9,12 @@ import retrofit2.Retrofit;
public class SubredditListingDataSourceFactory extends DataSource.Factory {
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
private SubredditListingDataSource subredditListingDataSource;
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
- SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
+ SubredditListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -37,7 +37,7 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
return subredditListingDataSource;
}
- void changeSortType(String sortType) {
+ void changeSortType(SortType sortType) {
this.sortType = sortType;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
index bf68dd82..b2023541 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
@@ -18,9 +18,9 @@ public class SubredditListingViewModel extends ViewModel {
private LiveData<NetworkState> initialLoadingState;
private LiveData<Boolean> hasSubredditLiveData;
private LiveData<PagedList<SubredditData>> subreddits;
- private MutableLiveData<String> sortTypeLiveData;
+ private MutableLiveData<SortType> sortTypeLiveData;
- public SubredditListingViewModel(Retrofit retrofit, String query, String sortType) {
+ public SubredditListingViewModel(Retrofit retrofit, String query, SortType sortType) {
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
@@ -69,16 +69,16 @@ public class SubredditListingViewModel extends ViewModel {
subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore();
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
sortTypeLiveData.postValue(sortType);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
- public Factory(Retrofit retrofit, String query, String sortType) {
+ public Factory(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
index 39a36a2f..0d181035 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
@@ -13,7 +13,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
private MutableLiveData<NetworkState> initialLoadStateLiveData;
@@ -22,7 +22,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
private PageKeyedDataSource.LoadParams<String> params;
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
- UserListingDataSource(Retrofit retrofit, String query, String sortType) {
+ UserListingDataSource(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -47,7 +47,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,
+ FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType().value,
new FetchUserData.FetchUserListingDataListener() {
@Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
@@ -82,7 +82,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
return;
}
- FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType,
+ FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType().value,
new FetchUserData.FetchUserListingDataListener() {
@Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSourceFactory.java
index db5da25d..d391514f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSourceFactory.java
@@ -9,12 +9,12 @@ import retrofit2.Retrofit;
public class UserListingDataSourceFactory extends DataSource.Factory {
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
private UserListingDataSource userListingDataSource;
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
- UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
+ UserListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
@@ -37,7 +37,7 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
return userListingDataSource;
}
- void changeSortType(String sortType) {
+ void changeSortType(SortType sortType) {
this.sortType = sortType;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
index 70f53ebc..abe3cef2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
@@ -18,9 +18,9 @@ public class UserListingViewModel extends ViewModel {
private LiveData<NetworkState> initialLoadingState;
private LiveData<Boolean> hasUserLiveData;
private LiveData<PagedList<UserData>> users;
- private MutableLiveData<String> sortTypeLiveData;
+ private MutableLiveData<SortType> sortTypeLiveData;
- public UserListingViewModel(Retrofit retrofit, String query, String sortType) {
+ public UserListingViewModel(Retrofit retrofit, String query, SortType sortType) {
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
@@ -69,16 +69,16 @@ public class UserListingViewModel extends ViewModel {
userListingDataSourceFactory.getUserListingDataSource().retryLoadingMore();
}
- public void changeSortType(String sortType) {
+ public void changeSortType(SortType sortType) {
sortTypeLiveData.postValue(sortType);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit;
private String query;
- private String sortType;
+ private SortType sortType;
- public Factory(Retrofit retrofit, String query, String sortType) {
+ public Factory(Retrofit retrofit, String query, SortType sortType) {
this.retrofit = retrofit;
this.query = query;
this.sortType = sortType;
diff --git a/app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml b/app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml
new file mode 100644
index 00000000..d08066e0
--- /dev/null
+++ b/app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:paddingBottom="8dp"
+ tools:context=".Fragment.SortTimeBottomSheetFragment">
+
+ <TextView
+ android:id="@+id/hour_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_hour"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/day_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_day"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/week_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_week"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/month_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_month"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/year_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_year"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/all_time_text_view_sort_time_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/sort_time_all_time"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bcd99f75..f37430d3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -188,6 +188,12 @@
<string name="sort_relevance">Relevance</string>
<string name="sort_comments">Comments</string>
<string name="sort_activity">Activity</string>
+ <string name="sort_time_hour">Hour</string>
+ <string name="sort_time_day">Day</string>
+ <string name="sort_time_week">Week</string>
+ <string name="sort_time_month">Month</string>
+ <string name="sort_time_year">Year</string>
+ <string name="sort_time_all_time">All Time</string>
<string name="open_link_with">Open link with</string>
<string name="no_browser_found">No browser found</string>
diff --git a/app/src/main/res/xml/searchable.xml b/app/src/main/res/xml/searchable.xml
index 9b87146c..4512198f 100644
--- a/app/src/main/res/xml/searchable.xml
+++ b/app/src/main/res/xml/searchable.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
- android:label="@string/app_label"
+ android:value="@string/app_label"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
</searchable> \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 0dee177b..a42fdab1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.0'
+ classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong