mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Add a time option to some sort types. Remember the last sort type.
This commit is contained in:
parent
d82b1e6305
commit
fdca23fa14
@ -31,15 +31,16 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
|
|||||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
|
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
import ml.docilealligator.infinityforreddit.PostDataSource;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
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";
|
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.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, mUserWhere);
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
@ -255,12 +255,17 @@ public class AccountPostsActivity extends BaseActivity implements UserThingSortT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userThingSortTypeSelected(String sortType) {
|
public void sortTypeSelected(SortType sortType) {
|
||||||
if (mFragment != null) {
|
if (mFragment != null) {
|
||||||
((PostFragment) mFragment).changeSortType(sortType);
|
((PostFragment) mFragment).changeSortType(sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sortTypeSelected(String sortType) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
||||||
finish();
|
finish();
|
||||||
|
@ -294,7 +294,6 @@ public class AccountSavedThingActivity extends BaseActivity {
|
|||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
|
@ -31,6 +31,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
|
|||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
@ -40,15 +41,15 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
|
|
||||||
public class FilteredThingActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback {
|
||||||
SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback {
|
|
||||||
|
|
||||||
public static final String EXTRA_NAME = "ESN";
|
public static final String EXTRA_NAME = "ESN";
|
||||||
public static final String EXTRA_QUERY = "EQ";
|
public static final String EXTRA_QUERY = "EQ";
|
||||||
public static final String EXTRA_FILTER = "EF";
|
public static final String EXTRA_FILTER = "EF";
|
||||||
public static final String EXTRA_POST_TYPE = "EPT";
|
public static final String EXTRA_POST_TYPE = "EPT";
|
||||||
public static final String EXTRA_SORT_TYPE = "EST";
|
|
||||||
public static final String EXTRA_USER_WHERE = "EUW";
|
public static final String EXTRA_USER_WHERE = "EUW";
|
||||||
|
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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 SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment;
|
||||||
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
|
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
|
||||||
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
||||||
|
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -142,7 +144,6 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
|
|||||||
name = getIntent().getStringExtra(EXTRA_NAME);
|
name = getIntent().getStringExtra(EXTRA_NAME);
|
||||||
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
||||||
int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE);
|
int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE);
|
||||||
String sortType = getIntent().getStringExtra(EXTRA_SORT_TYPE);
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
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();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
if (!mNullAccessToken && mAccessToken == null) {
|
||||||
getCurrentAccountAndBindView(filter, sortType);
|
getCurrentAccountAndBindView(filter);
|
||||||
} else {
|
} else {
|
||||||
/*mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
bindView(filter, false);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();*/
|
|
||||||
bindView(filter, sortType, false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccountAndBindView(filter, sortType);
|
getCurrentAccountAndBindView(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,18 +168,18 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
|
|||||||
return mSharedPreferences;
|
return mSharedPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView(int filter, String sortType) {
|
private void getCurrentAccountAndBindView(int filter) {
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = account.getAccessToken();
|
mAccessToken = account.getAccessToken();
|
||||||
}
|
}
|
||||||
bindView(filter, sortType, true);
|
bindView(filter, true);
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView(int filter, String sortType, boolean initializeFragment) {
|
private void bindView(int filter, boolean initializeFragment) {
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostDataSource.TYPE_FRONT_PAGE:
|
case PostDataSource.TYPE_FRONT_PAGE:
|
||||||
getSupportActionBar().setTitle(name);
|
getSupportActionBar().setTitle(name);
|
||||||
@ -223,6 +222,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
|
||||||
|
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case Post.NSFW_TYPE:
|
case Post.NSFW_TYPE:
|
||||||
toolbar.setSubtitle(R.string.nsfw);
|
toolbar.setSubtitle(R.string.nsfw);
|
||||||
@ -249,7 +250,6 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
|
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, filter);
|
bundle.putInt(PostFragment.EXTRA_FILTER, filter);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
if (postType == PostDataSource.TYPE_USER) {
|
if (postType == PostDataSource.TYPE_USER) {
|
||||||
@ -350,18 +350,16 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void searchSortTypeSelected(String sortType) {
|
public void sortTypeSelected(SortType sortType) {
|
||||||
((PostFragment) mFragment).changeSortType(sortType);
|
((PostFragment) mFragment).changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortTypeSelected(String sortType) {
|
public void sortTypeSelected(String sortType) {
|
||||||
((PostFragment) mFragment).changeSortType(sortType);
|
Bundle bundle = new Bundle();
|
||||||
}
|
bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
|
||||||
|
sortTimeBottomSheetFragment.setArguments(bundle);
|
||||||
@Override
|
sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
|
||||||
public void userThingSortTypeSelected(String sortType) {
|
|
||||||
((PostFragment) mFragment).changeSortType(sortType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -74,6 +74,7 @@ import ml.docilealligator.infinityforreddit.FetchMyInfo;
|
|||||||
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
|
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
@ -84,13 +85,15 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.ReadMessage;
|
import ml.docilealligator.infinityforreddit.ReadMessage;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
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.SubredditDatabase.SubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
|
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
|
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
||||||
|
|
||||||
static final String EXTRA_POST_TYPE = "EPT";
|
static final String EXTRA_POST_TYPE = "EPT";
|
||||||
@ -177,6 +180,7 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
|
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
|
||||||
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
|
||||||
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
|
||||||
|
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||||
private boolean mNullAccessToken = false;
|
private boolean mNullAccessToken = false;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
@ -278,6 +282,8 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
|
popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
|
||||||
popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
|
popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
|
||||||
|
|
||||||
|
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
drawer = findViewById(R.id.drawer_layout);
|
drawer = findViewById(R.id.drawer_layout);
|
||||||
@ -877,10 +883,18 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortTypeSelected(String sortType) {
|
public void sortTypeSelected(SortType sortType) {
|
||||||
sectionsPagerAdapter.changeSortType(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
|
@Override
|
||||||
public void postTypeSelected(int postType) {
|
public void postTypeSelected(int postType) {
|
||||||
Intent intent;
|
Intent intent;
|
||||||
@ -946,7 +960,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
@ -956,7 +969,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
@ -968,7 +980,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
PostFragment fragment = new PostFragment();
|
PostFragment fragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
@ -978,7 +989,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
@ -988,7 +998,6 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
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 (mAccessToken == null) {
|
||||||
if (viewPager.getCurrentItem() == 0) {
|
if (viewPager.getCurrentItem() == 0) {
|
||||||
popularPostFragment.changeSortType(sortType);
|
popularPostFragment.changeSortType(sortType);
|
||||||
@ -1184,12 +1193,27 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra
|
|||||||
} else {
|
} else {
|
||||||
switch (viewPager.getCurrentItem()) {
|
switch (viewPager.getCurrentItem()) {
|
||||||
case 0:
|
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);
|
frontPagePostFragment.changeSortType(sortType);
|
||||||
break;
|
break;
|
||||||
case 1:
|
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);
|
popularPostFragment.changeSortType(sortType);
|
||||||
break;
|
break;
|
||||||
case 2:
|
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);
|
allPostFragment.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
@ -45,9 +46,10 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
|
|
||||||
public class SearchResultActivity extends BaseActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback,
|
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback {
|
||||||
SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback {
|
|
||||||
static final String EXTRA_QUERY = "QK";
|
static final String EXTRA_QUERY = "QK";
|
||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
|
|
||||||
@ -73,6 +75,7 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
|
|||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
||||||
|
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||||
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
|
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,6 +149,8 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
searchPostSortTypeBottomSheetFragment.setArguments(bundle);
|
searchPostSortTypeBottomSheetFragment.setArguments(bundle);
|
||||||
|
|
||||||
|
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
|
||||||
|
|
||||||
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
|
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
|
||||||
|
|
||||||
// Get the intent, verify the action and get the query
|
// Get the intent, verify the action and get the query
|
||||||
@ -240,12 +245,20 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void searchSortTypeSelected(String sortType) {
|
public void sortTypeSelected(SortType sortType) {
|
||||||
sectionsPagerAdapter.changeSortType(sortType, 0);
|
sectionsPagerAdapter.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition) {
|
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(SortType sortType, int fragmentPosition) {
|
||||||
sectionsPagerAdapter.changeSortType(sortType, fragmentPosition);
|
sectionsPagerAdapter.changeSortType(sortType, fragmentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +290,6 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
|
|||||||
PostFragment mFragment = new PostFragment();
|
PostFragment mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
|
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_NAME, mSubredditName);
|
||||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
@ -343,15 +355,23 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort
|
|||||||
return fragment;
|
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) {
|
switch (fragmentPosition) {
|
||||||
case 0:
|
|
||||||
postFragment.changeSortType(sortType);
|
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
|
mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply();
|
||||||
subredditListingFragment.changeSortType(sortType);
|
subredditListingFragment.changeSortType(sortType);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply();
|
||||||
userListingFragment.changeSortType(sortType);
|
userListingFragment.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.FetchSubredditData;
|
import ml.docilealligator.infinityforreddit.FetchSubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
@ -57,6 +58,8 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.ReadMessage;
|
import ml.docilealligator.infinityforreddit.ReadMessage;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
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.SubredditDao;
|
||||||
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
|
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
|
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
|
||||||
@ -64,7 +67,7 @@ import ml.docilealligator.infinityforreddit.SubredditSubscription;
|
|||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
||||||
|
|
||||||
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
|
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 AppBarLayout.LayoutParams params;
|
||||||
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
|
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
|
||||||
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
|
||||||
|
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||||
private SubredditViewModel mSubredditViewModel;
|
private SubredditViewModel mSubredditViewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -210,8 +214,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
getCurrentAccountAndBindView();
|
getCurrentAccountAndBindView();
|
||||||
} else {
|
} else {
|
||||||
bindView(false);
|
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) {
|
if (mFetchSubredditInfoSuccess) {
|
||||||
@ -228,6 +230,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
|
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
|
||||||
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
|
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
|
||||||
|
|
||||||
|
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
|
||||||
|
|
||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
|
|
||||||
//Get status bar height
|
//Get status bar height
|
||||||
@ -459,7 +463,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
@ -569,10 +572,23 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
((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
|
@Override
|
||||||
public void postTypeSelected(int postType) {
|
public void postTypeSelected(int postType) {
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.FetchUserData;
|
import ml.docilealligator.infinityforreddit.FetchUserData;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
@ -63,6 +64,8 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.ReadMessage;
|
import ml.docilealligator.infinityforreddit.ReadMessage;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
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.SubscribedUserDatabase.SubscribedUserDao;
|
||||||
import ml.docilealligator.infinityforreddit.User.UserDao;
|
import ml.docilealligator.infinityforreddit.User.UserDao;
|
||||||
import ml.docilealligator.infinityforreddit.User.UserData;
|
import ml.docilealligator.infinityforreddit.User.UserData;
|
||||||
@ -71,7 +74,7 @@ import ml.docilealligator.infinityforreddit.UserFollowing;
|
|||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
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_USER_NAME_KEY = "EUNK";
|
||||||
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
|
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
|
||||||
@ -122,6 +125,7 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
|
|||||||
private Menu mMenu;
|
private Menu mMenu;
|
||||||
private AppBarLayout.LayoutParams params;
|
private AppBarLayout.LayoutParams params;
|
||||||
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
|
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
|
||||||
|
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||||
private boolean mNullAccessToken = false;
|
private boolean mNullAccessToken = false;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
@ -385,6 +389,7 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
|
|||||||
});
|
});
|
||||||
|
|
||||||
userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
|
userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
|
||||||
|
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -610,10 +615,15 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userThingSortTypeSelected(String sortType) {
|
public void sortTypeSelected(SortType sortType) {
|
||||||
sectionsPagerAdapter.changeSortType(sortType);
|
sectionsPagerAdapter.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sortTypeSelected(String sortType) {
|
||||||
|
sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
||||||
if (!getClass().getName().equals(event.excludeActivityClassName)) {
|
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.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
|
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED);
|
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.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
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 (viewPager.getCurrentItem() == 0) {
|
||||||
if (postFragment != null) {
|
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);
|
postFragment.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (commentsListingFragment != null) {
|
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);
|
commentsListingFragment.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
|
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
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);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
});
|
});
|
||||||
@ -407,7 +406,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
|
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
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());
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType());
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
|
|
||||||
|
@ -328,7 +328,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
Intent intent = new Intent(mContext, FilteredThingActivity.class);
|
Intent intent = new Intent(mContext, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2));
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2));
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
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);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
|
|||||||
@Nullable
|
@Nullable
|
||||||
private String accessToken;
|
private String accessToken;
|
||||||
private String username;
|
private String username;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private boolean areSavedComments;
|
private boolean areSavedComments;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
@ -36,7 +36,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
|
|||||||
private LoadParams<String> params;
|
private LoadParams<String> params;
|
||||||
private LoadCallback<String, CommentData> callback;
|
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) {
|
boolean areSavedComments) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -72,14 +72,30 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
|
|||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> commentsCall;
|
Call<String> commentsCall;
|
||||||
if (areSavedComments) {
|
if (areSavedComments) {
|
||||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
|
if (sortType.getTime() != null) {
|
||||||
null, sortType, RedditUtils.getOAuthHeader(accessToken));
|
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 {
|
} else {
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken), username,
|
if (sortType.getTime() != null) {
|
||||||
null, sortType);
|
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>() {
|
commentsCall.enqueue(new Callback<String>() {
|
||||||
@ -135,14 +151,29 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
|
|||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> commentsCall;
|
Call<String> commentsCall;
|
||||||
if (areSavedComments) {
|
if (areSavedComments) {
|
||||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
|
if (sortType.getTime() != null) {
|
||||||
sortType, RedditUtils.getOAuthHeader(accessToken));
|
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 {
|
} else {
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
commentsCall = api.getUserCommentsOauth(RedditUtils.getOAuthHeader(accessToken),
|
if (sortType.getTime() != null) {
|
||||||
username, params.key, sortType);
|
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>() {
|
commentsCall.enqueue(new Callback<String>() {
|
||||||
|
@ -14,14 +14,14 @@ class CommentDataSourceFactory extends DataSource.Factory {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private String accessToken;
|
private String accessToken;
|
||||||
private String username;
|
private String username;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private boolean areSavedComments;
|
private boolean areSavedComments;
|
||||||
|
|
||||||
private CommentDataSource commentDataSource;
|
private CommentDataSource commentDataSource;
|
||||||
private MutableLiveData<CommentDataSource> commentDataSourceLiveData;
|
private MutableLiveData<CommentDataSource> commentDataSourceLiveData;
|
||||||
|
|
||||||
CommentDataSourceFactory(Retrofit retrofit, Locale locale, @Nullable String accessToken,
|
CommentDataSourceFactory(Retrofit retrofit, Locale locale, @Nullable String accessToken,
|
||||||
String username, String sortType,
|
String username, SortType sortType,
|
||||||
boolean areSavedComments) {
|
boolean areSavedComments) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -49,7 +49,7 @@ class CommentDataSourceFactory extends DataSource.Factory {
|
|||||||
return commentDataSource;
|
return commentDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSortType(String sortType) {
|
void changeSortType(SortType sortType) {
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ public class CommentViewModel extends ViewModel {
|
|||||||
private LiveData<NetworkState> initialLoadingState;
|
private LiveData<NetworkState> initialLoadingState;
|
||||||
private LiveData<Boolean> hasCommentLiveData;
|
private LiveData<Boolean> hasCommentLiveData;
|
||||||
private LiveData<PagedList<CommentData>> comments;
|
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) {
|
boolean areSavedComments) {
|
||||||
commentDataSourceFactory = new CommentDataSourceFactory(retrofit, locale, accessToken, username, sortType,
|
commentDataSourceFactory = new CommentDataSourceFactory(retrofit, locale, accessToken, username, sortType,
|
||||||
areSavedComments);
|
areSavedComments);
|
||||||
@ -72,7 +72,7 @@ public class CommentViewModel extends ViewModel {
|
|||||||
commentDataSourceFactory.getCommentDataSource().retryLoadingMore();
|
commentDataSourceFactory.getCommentDataSource().retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +81,11 @@ public class CommentViewModel extends ViewModel {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private String accessToken;
|
private String accessToken;
|
||||||
private String username;
|
private String username;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private boolean areSavedComments;
|
private boolean areSavedComments;
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, Locale locale, String accessToken, String username,
|
public Factory(Retrofit retrofit, Locale locale, String accessToken, String username,
|
||||||
String sortType, boolean areSavedComments) {
|
SortType sortType, boolean areSavedComments) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
|
@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -36,9 +37,10 @@ import ml.docilealligator.infinityforreddit.CommentViewModel;
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +78,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
private boolean mNullAccessToken = false;
|
private boolean mNullAccessToken = false;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
@ -144,6 +148,14 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
() -> mCommentViewModel.retryLoadingMore());
|
() -> mCommentViewModel.retryLoadingMore());
|
||||||
|
|
||||||
String username = getArguments().getString(EXTRA_USERNAME);
|
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);
|
mCommentRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
@ -151,11 +163,11 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
|
|
||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
factory = new CommentViewModel.Factory(mRetrofit,
|
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));
|
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||||
} else {
|
} else {
|
||||||
factory = new CommentViewModel.Factory(mOauthRetrofit,
|
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));
|
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));
|
mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
mCommentViewModel.changeSortType(sortType);
|
mCommentViewModel.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ import ml.docilealligator.infinityforreddit.PostViewModel;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import retrofit2.Retrofit;
|
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_USER_WHERE = "EUW";
|
||||||
public static final String EXTRA_QUERY = "EQ";
|
public static final String EXTRA_QUERY = "EQ";
|
||||||
public static final String EXTRA_POST_TYPE = "EPT";
|
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 String EXTRA_FILTER = "EF";
|
||||||
public static final int EXTRA_NO_FILTER = -2;
|
public static final int EXTRA_NO_FILTER = -2;
|
||||||
public static final String EXTRA_ACCESS_TOKEN = "EAT";
|
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);
|
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);
|
int filter = getArguments().getInt(EXTRA_FILTER);
|
||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
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 subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
String query = getArguments().getString(EXTRA_QUERY);
|
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,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
||||||
new PostRecyclerViewAdapter.Callback() {
|
new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -297,7 +301,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
|
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
|
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@ -314,8 +317,36 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||||
String subredditName = getArguments().getString(EXTRA_NAME);
|
String subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
|
String sort;
|
||||||
|
String sortTime = null;
|
||||||
|
SortType sortType;
|
||||||
|
|
||||||
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
|
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,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, displaySubredditName, needBlurNsfw, needBlurSpoiler,
|
accessToken, postType, displaySubredditName, needBlurNsfw, needBlurSpoiler,
|
||||||
new PostRecyclerViewAdapter.Callback() {
|
new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -329,7 +360,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
|
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@ -353,6 +383,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mFetchPostInfoLinearLayout.setLayoutParams(params);
|
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,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
||||||
new PostRecyclerViewAdapter.Callback() {
|
new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -366,7 +405,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
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_USER_WHERE, where);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -383,6 +421,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
filter, nsfw);
|
filter, nsfw);
|
||||||
}
|
}
|
||||||
} else {
|
} 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,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
|
||||||
new PostRecyclerViewAdapter.Callback() {
|
new PostRecyclerViewAdapter.Callback() {
|
||||||
@ -396,7 +443,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
Intent intent = new Intent(activity, FilteredThingActivity.class);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
|
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType);
|
|
||||||
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@ -444,7 +490,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
mPostViewModel.changeSortType(sortType);
|
mPostViewModel.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -10,14 +11,16 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
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;
|
TextView newTypeTextView;
|
||||||
@BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment)
|
@BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||||
TextView commentsTypeTextView;
|
TextView commentsTypeTextView;
|
||||||
|
private Activity activity;
|
||||||
public SearchPostSortTypeBottomSheetFragment() {
|
public SearchPostSortTypeBottomSheetFragment() {
|
||||||
// Required empty public constructor
|
// 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);
|
View rootView = inflater.inflate(R.layout.fragment_search_post_sort_type_bottom_sheet, container, false);
|
||||||
ButterKnife.bind(this, rootView);
|
ButterKnife.bind(this, rootView);
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
||||||
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
relevanceTypeTextView.setOnClickListener(view -> {
|
relevanceTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.RELEVANCE.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
hotTypeTextView.setOnClickListener(view -> {
|
hotTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_HOT);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.HOT.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
topTypeTextView.setOnClickListener(view -> {
|
topTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_TOP);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
newTypeTextView.setOnClickListener(view -> {
|
newTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_NEW);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
commentsTypeTextView.setOnClickListener(view -> {
|
commentsTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_COMMENTS);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.COMMENTS.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public interface SearchSortTypeSelectionCallback {
|
public void onAttach(@NonNull Context context) {
|
||||||
void searchSortTypeSelected(String sortType);
|
super.onAttach(context);
|
||||||
|
this.activity = (Activity) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -10,14 +11,16 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
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;
|
TextView relevanceTypeTextView;
|
||||||
@BindView(R.id.activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment)
|
@BindView(R.id.activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment)
|
||||||
TextView activityTypeTextView;
|
TextView activityTypeTextView;
|
||||||
|
private Activity activity;
|
||||||
public SearchUserAndSubredditSortTypeBottomSheetFragment() {
|
public SearchUserAndSubredditSortTypeBottomSheetFragment() {
|
||||||
// Required empty public constructor
|
// 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);
|
View rootView = inflater.inflate(R.layout.fragment_search_user_and_subreddit_sort_type_bottom_sheet, container, false);
|
||||||
ButterKnife.bind(this, rootView);
|
ButterKnife.bind(this, rootView);
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
||||||
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
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 -> {
|
relevanceTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE, position);
|
((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.RELEVANCE), position);
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
activityTypeTextView.setOnClickListener(view -> {
|
activityTypeTextView.setOnClickListener(view -> {
|
||||||
((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_HOT, position);
|
((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.ACTIVITY), position);
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public interface SearchUserAndSubredditSortTypeSelectionCallback {
|
public void onAttach(@NonNull Context context) {
|
||||||
void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition);
|
super.onAttach(context);
|
||||||
|
this.activity = (Activity) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -17,8 +18,9 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
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;
|
TextView topTypeTextView;
|
||||||
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment)
|
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment)
|
||||||
TextView controversialTypeTextView;
|
TextView controversialTypeTextView;
|
||||||
|
private Activity activity;
|
||||||
public SortTypeBottomSheetFragment() {
|
public SortTypeBottomSheetFragment() {
|
||||||
// Required empty public constructor
|
// 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);
|
View rootView = inflater.inflate(R.layout.fragment_sort_type_bottom_sheet, container, false);
|
||||||
ButterKnife.bind(this, rootView);
|
ButterKnife.bind(this, rootView);
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
&& (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
||||||
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
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);
|
bestTypeTextView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
bestTypeTextView.setOnClickListener(view -> {
|
bestTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_BEST);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.BEST));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hotTypeTextView.setOnClickListener(view -> {
|
hotTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_HOT);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.HOT));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
newTypeTextView.setOnClickListener(view -> {
|
newTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_NEW);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
randomTypeTextView.setOnClickListener(view -> {
|
randomTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RANDOM);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RANDOM));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
risingTypeTextView.setOnClickListener(view -> {
|
risingTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_RISING);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RISING));
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
topTypeTextView.setOnClickListener(view -> {
|
topTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_TOP);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
controversialTypeTextView.setOnClickListener(view -> {
|
controversialTypeTextView.setOnClickListener(view -> {
|
||||||
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.CONTROVERSIAL.name());
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public interface SortTypeSelectionCallback {
|
public void onAttach(@NonNull Context context) {
|
||||||
void sortTypeSelected(String sortType);
|
super.onAttach(context);
|
||||||
|
this.activity = (Activity) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -35,9 +36,10 @@ import ml.docilealligator.infinityforreddit.Adapter.SubredditListingRecyclerView
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SubredditListingViewModel;
|
import ml.docilealligator.infinityforreddit.SubredditListingViewModel;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -72,7 +74,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private SubredditListingRecyclerViewAdapter mAdapter;
|
private SubredditListingRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
@ -112,8 +116,11 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
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,
|
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
||||||
accessToken, accountName, redditDataRoomDatabase,
|
accessToken, accountName, mRedditDataRoomDatabase,
|
||||||
new SubredditListingRecyclerViewAdapter.Callback() {
|
new SubredditListingRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -134,8 +141,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
|
|
||||||
mSubredditListingRecyclerView.setAdapter(mAdapter);
|
mSubredditListingRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
|
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query, sortType);
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE);
|
|
||||||
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
|
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
|
||||||
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
|
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);
|
mSubredditListingViewModel.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit.Fragment;
|
package ml.docilealligator.infinityforreddit.Fragment;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -30,9 +31,10 @@ import ml.docilealligator.infinityforreddit.Adapter.UserListingRecyclerViewAdapt
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.UserListingViewModel;
|
import ml.docilealligator.infinityforreddit.UserListingViewModel;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -66,7 +68,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private UserListingRecyclerViewAdapter mAdapter;
|
private UserListingRecyclerViewAdapter mAdapter;
|
||||||
@ -103,15 +107,17 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
mQuery = getArguments().getString(EXTRA_QUERY);
|
mQuery = getArguments().getString(EXTRA_QUERY);
|
||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
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,
|
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
|
||||||
accessToken, accountName, redditDataRoomDatabase.subscribedUserDao(),
|
accessToken, accountName, mRedditDataRoomDatabase.subscribedUserDao(),
|
||||||
() -> mUserListingViewModel.retryLoadingMore());
|
() -> mUserListingViewModel.retryLoadingMore());
|
||||||
|
|
||||||
mUserListingRecyclerView.setAdapter(mAdapter);
|
mUserListingRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE);
|
sortType);
|
||||||
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
|
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
|
||||||
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
|
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);
|
mUserListingViewModel.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.PostDataSource;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
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 {
|
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)
|
@BindView(R.id.new_type_text_view_user_thing_sort_type_bottom_sheet_fragment)
|
||||||
TextView newTypeTextView;
|
TextView newTypeTextView;
|
||||||
@BindView(R.id.hot_type_text_view_user_thing_sort_type_bottom_sheet_fragment)
|
@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 -> {
|
newTypeTextView.setOnClickListener(view -> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_NEW);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
hotTypeTextView.setOnClickListener(view -> {
|
hotTypeTextView.setOnClickListener(view -> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_HOT);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.HOT));
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
topTypeTextView.setOnClickListener(view -> {
|
topTypeTextView.setOnClickListener(view -> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_TOP);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
controversialTypeTextView.setOnClickListener(view -> {
|
controversialTypeTextView.setOnClickListener(view -> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL);
|
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.CONTROVERSIAL.name());
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface UserThingSortTypeSelectionCallback {
|
|
||||||
void userThingSortTypeSelected(String sortType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,6 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
public static final int TYPE_USER = 2;
|
public static final int TYPE_USER = 2;
|
||||||
public static final int TYPE_SEARCH = 3;
|
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_SUBMITTED = "submitted";
|
||||||
public static final String USER_WHERE_UPVOTED = "upvoted";
|
public static final String USER_WHERE_UPVOTED = "upvoted";
|
||||||
public static final String USER_WHERE_DOWNVOTED = "downvoted";
|
public static final String USER_WHERE_DOWNVOTED = "downvoted";
|
||||||
@ -41,7 +31,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private String subredditOrUserName;
|
private String subredditOrUserName;
|
||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private boolean nsfw;
|
private boolean nsfw;
|
||||||
private int filter;
|
private int filter;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
@ -53,7 +43,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private LoadParams<String> params;
|
private LoadParams<String> params;
|
||||||
private LoadCallback<String, Post> callback;
|
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) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -62,13 +52,13 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
initialLoadStateLiveData = new MutableLiveData<>();
|
initialLoadStateLiveData = new MutableLiveData<>();
|
||||||
hasPostLiveData = new MutableLiveData<>();
|
hasPostLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
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.filter = filter;
|
||||||
this.nsfw = nsfw;
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -79,9 +69,9 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
if (sortType == null) {
|
if (sortType == null) {
|
||||||
if (subredditOrUserName.equals("popular") || subredditOrUserName.equals("all")) {
|
if (subredditOrUserName.equals("popular") || subredditOrUserName.equals("all")) {
|
||||||
this.sortType = PostDataSource.SORT_TYPE_HOT;
|
this.sortType = new SortType(SortType.Type.HOT);
|
||||||
} else {
|
} else {
|
||||||
this.sortType = PostDataSource.SORT_TYPE_BEST;
|
this.sortType = new SortType(SortType.Type.BEST);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.sortType = sortType;
|
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,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -100,14 +90,14 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
initialLoadStateLiveData = new MutableLiveData<>();
|
initialLoadStateLiveData = new MutableLiveData<>();
|
||||||
hasPostLiveData = new MutableLiveData<>();
|
hasPostLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType == null ? PostDataSource.SORT_TYPE_NEW : sortType;
|
this.sortType = sortType == null ? new SortType(SortType.Type.NEW) : sortType;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.nsfw = nsfw;
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, String query,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -117,7 +107,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
initialLoadStateLiveData = new MutableLiveData<>();
|
initialLoadStateLiveData = new MutableLiveData<>();
|
||||||
hasPostLiveData = new MutableLiveData<>();
|
hasPostLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
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.filter = filter;
|
||||||
this.nsfw = nsfw;
|
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) {
|
private void loadBestPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback, String lastItem) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
Call<String> bestPost;
|
||||||
Call<String> bestPost = api.getBestPosts(sortType, lastItem, RedditUtils.getOAuthHeader(accessToken));
|
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>() {
|
bestPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
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() {
|
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
@ -260,7 +255,13 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
String after = lastItem == null ? params.key : lastItem;
|
String after = lastItem == null ? params.key : lastItem;
|
||||||
|
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
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>() {
|
bestPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -301,15 +302,25 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
Call<String> getPost;
|
Call<String> getPost;
|
||||||
if (accessToken == null) {
|
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 {
|
} 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>() {
|
getPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
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() {
|
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
@ -377,10 +388,21 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> getPost;
|
Call<String> getPost;
|
||||||
if (accessToken == null) {
|
if (accessToken != null) {
|
||||||
getPost = api.getSubredditBestPosts(subredditOrUserName, sortType, after);
|
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 {
|
} 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>() {
|
getPost.enqueue(new Callback<String>() {
|
||||||
@ -422,10 +444,20 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
Call<String> getPost;
|
Call<String> getPost;
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, lastItem, sortType,
|
if (sortType.getTime() != null) {
|
||||||
RedditUtils.getOAuthHeader(accessToken));
|
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>() {
|
getPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -480,10 +512,20 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
Call<String> getPost;
|
Call<String> getPost;
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
getPost = api.getUserPostsOauth(subredditOrUserName, userWhere, after, sortType,
|
if (sortType.getTime() != null) {
|
||||||
RedditUtils.getOAuthHeader(accessToken));
|
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>() {
|
getPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -525,16 +567,39 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
if (subredditOrUserName == null) {
|
if (subredditOrUserName == null) {
|
||||||
if (accessToken == 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 {
|
} 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 {
|
} else {
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
|
if (sortType.getTime() != null) {
|
||||||
RedditUtils.getOAuthHeader(accessToken));
|
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 (subredditOrUserName == null) {
|
||||||
if (accessToken == 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 {
|
} 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 {
|
} else {
|
||||||
if (accessToken == null) {
|
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 {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after,
|
if (sortType.getTime() != null) {
|
||||||
RedditUtils.getOAuthHeader(accessToken));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
private String subredditName;
|
private String subredditName;
|
||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private int filter;
|
private int filter;
|
||||||
private boolean nsfw;
|
private boolean nsfw;
|
||||||
@ -23,7 +23,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
private PostDataSource postDataSource;
|
private PostDataSource postDataSource;
|
||||||
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
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) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -36,7 +36,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -49,7 +49,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -63,7 +63,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -105,11 +105,11 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
return postDataSource;
|
return postDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSortType(String sortType) {
|
void changeSortType(SortType sortType) {
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeNSFWAndSortType(boolean nsfw, String sortType) {
|
void changeNSFWAndSortType(boolean nsfw, SortType sortType) {
|
||||||
this.nsfw = nsfw;
|
this.nsfw = nsfw;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ public class PostViewModel extends ViewModel {
|
|||||||
private LiveData<Boolean> hasPostLiveData;
|
private LiveData<Boolean> hasPostLiveData;
|
||||||
private LiveData<PagedList<Post>> posts;
|
private LiveData<PagedList<Post>> posts;
|
||||||
private MutableLiveData<Boolean> nsfwLiveData;
|
private MutableLiveData<Boolean> nsfwLiveData;
|
||||||
private MutableLiveData<String> sortTypeLiveData;
|
private MutableLiveData<SortType> sortTypeLiveData;
|
||||||
private NSFWAndSortTypeLiveData nsfwAndSortTypeLiveData;
|
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) {
|
int filter, boolean nsfw) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType,
|
||||||
sortType, filter, nsfw);
|
sortType, filter, nsfw);
|
||||||
@ -57,7 +57,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
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,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
postType, sortType, filter, nsfw);
|
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,
|
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,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
postType, sortType, where, filter, nsfw);
|
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,
|
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,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
query, postType, sortType, filter, nsfw);
|
query, postType, sortType, filter, nsfw);
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
postDataSourceFactory.getPostDataSource().retryLoadingMore();
|
postDataSourceFactory.getPostDataSource().retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,12 +188,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
private String subredditName;
|
private String subredditName;
|
||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private int filter;
|
private int filter;
|
||||||
private boolean nsfw;
|
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) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -205,7 +205,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -217,7 +217,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -230,7 +230,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
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.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -261,8 +261,8 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, String>> {
|
private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, SortType>> {
|
||||||
public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<String> sortType) {
|
public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<SortType> sortType) {
|
||||||
addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
|
addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
|
||||||
addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1)));
|
addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1)));
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,44 @@ public interface RedditAPI {
|
|||||||
@GET("{sortType}?raw_json=1")
|
@GET("{sortType}?raw_json=1")
|
||||||
Call<String> getBestPosts(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
|
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")
|
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
|
||||||
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
|
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
|
||||||
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
|
@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")
|
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25")
|
||||||
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
|
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
|
||||||
@Query("after") String lastItem);
|
@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")
|
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
|
||||||
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
|
Call<String> getUserPostsOauth(@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=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")
|
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
|
||||||
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
|
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
|
||||||
@Query("sort") String sortType);
|
@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")
|
@GET("user/{username}/about.json?raw_json=1")
|
||||||
Call<String> getUserData(@Path("username") String username);
|
Call<String> getUserData(@Path("username") String username);
|
||||||
|
|
||||||
@ -66,13 +88,28 @@ public interface RedditAPI {
|
|||||||
Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
|
Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
|
||||||
@Query("sort") String sortType);
|
@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")
|
@GET("user/{username}/comments.json?raw_json=1")
|
||||||
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
|
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
|
||||||
@Query("after") String after, @Query("sort") String sortType);
|
@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")
|
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
|
||||||
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
|
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
|
@FormUrlEncoded
|
||||||
@POST("api/subscribe")
|
@POST("api/subscribe")
|
||||||
@ -97,18 +134,40 @@ public interface RedditAPI {
|
|||||||
@Query("sort") String sort,
|
@Query("sort") String sort,
|
||||||
@HeaderMap Map<String, String> headers);
|
@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")
|
@GET("search.json?include_over_18=1&raw_json=1&type=link")
|
||||||
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
||||||
@Query("sort") String sort);
|
@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")
|
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
|
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);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
|
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
|
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
|
||||||
@Query("q") String query, @Query("after") String after);
|
@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("sort") String sort,
|
||||||
|
@Query("t") String sortTime, @Query("after") String after);
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("api/comment")
|
@POST("api/comment")
|
||||||
|
@ -29,4 +29,20 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String CONTENT_FONT_SIZE_KEY = "content_font_size";
|
public static final String CONTENT_FONT_SIZE_KEY = "content_font_size";
|
||||||
public static final String AMOLED_DARK_KEY = "amoled_dark";
|
public static final String AMOLED_DARK_KEY = "amoled_dark";
|
||||||
public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface";
|
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";
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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){}
|
||||||
|
}
|
@ -13,7 +13,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
|
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||||
@ -22,7 +22,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
private LoadParams<String> params;
|
private LoadParams<String> params;
|
||||||
private LoadCallback<String, SubredditData> callback;
|
private LoadCallback<String, SubredditData> callback;
|
||||||
|
|
||||||
SubredditListingDataSource(Retrofit retrofit, String query, String sortType) {
|
SubredditListingDataSource(Retrofit retrofit, String query, SortType sortType) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
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) {
|
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, SubredditData> callback) {
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType,
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType.getType().value,
|
||||||
new FetchSubredditData.FetchSubredditListingDataListener() {
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
@ -82,7 +82,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType,
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType.getType().value,
|
||||||
new FetchSubredditData.FetchSubredditListingDataListener() {
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
|
@ -9,12 +9,12 @@ import retrofit2.Retrofit;
|
|||||||
public class SubredditListingDataSourceFactory extends DataSource.Factory {
|
public class SubredditListingDataSourceFactory extends DataSource.Factory {
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
|
|
||||||
private SubredditListingDataSource subredditListingDataSource;
|
private SubredditListingDataSource subredditListingDataSource;
|
||||||
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
|
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
|
||||||
|
|
||||||
SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
SubredditListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
@ -37,7 +37,7 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
|
|||||||
return subredditListingDataSource;
|
return subredditListingDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSortType(String sortType) {
|
void changeSortType(SortType sortType) {
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ public class SubredditListingViewModel extends ViewModel {
|
|||||||
private LiveData<NetworkState> initialLoadingState;
|
private LiveData<NetworkState> initialLoadingState;
|
||||||
private LiveData<Boolean> hasSubredditLiveData;
|
private LiveData<Boolean> hasSubredditLiveData;
|
||||||
private LiveData<PagedList<SubredditData>> subreddits;
|
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);
|
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
||||||
@ -69,16 +69,16 @@ public class SubredditListingViewModel extends ViewModel {
|
|||||||
subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore();
|
subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
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.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
@ -13,7 +13,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
|
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||||
@ -22,7 +22,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
private PageKeyedDataSource.LoadParams<String> params;
|
private PageKeyedDataSource.LoadParams<String> params;
|
||||||
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
|
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
|
||||||
|
|
||||||
UserListingDataSource(Retrofit retrofit, String query, String sortType) {
|
UserListingDataSource(Retrofit retrofit, String query, SortType sortType) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
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) {
|
public void loadInitial(@NonNull PageKeyedDataSource.LoadInitialParams<String> params, @NonNull PageKeyedDataSource.LoadInitialCallback<String, UserData> callback) {
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, null, sortType,
|
FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType().value,
|
||||||
new FetchUserData.FetchUserListingDataListener() {
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
@ -82,7 +82,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType,
|
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType().value,
|
||||||
new FetchUserData.FetchUserListingDataListener() {
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
|
@ -9,12 +9,12 @@ import retrofit2.Retrofit;
|
|||||||
public class UserListingDataSourceFactory extends DataSource.Factory {
|
public class UserListingDataSourceFactory extends DataSource.Factory {
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private SortType sortType;
|
||||||
|
|
||||||
private UserListingDataSource userListingDataSource;
|
private UserListingDataSource userListingDataSource;
|
||||||
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
|
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
|
||||||
|
|
||||||
UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
UserListingDataSourceFactory(Retrofit retrofit, String query, SortType sortType) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
@ -37,7 +37,7 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
|
|||||||
return userListingDataSource;
|
return userListingDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSortType(String sortType) {
|
void changeSortType(SortType sortType) {
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ public class UserListingViewModel extends ViewModel {
|
|||||||
private LiveData<NetworkState> initialLoadingState;
|
private LiveData<NetworkState> initialLoadingState;
|
||||||
private LiveData<Boolean> hasUserLiveData;
|
private LiveData<Boolean> hasUserLiveData;
|
||||||
private LiveData<PagedList<UserData>> users;
|
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);
|
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
||||||
@ -69,16 +69,16 @@ public class UserListingViewModel extends ViewModel {
|
|||||||
userListingDataSourceFactory.getUserListingDataSource().retryLoadingMore();
|
userListingDataSourceFactory.getUserListingDataSource().retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(String sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
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.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
100
app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml
Normal file
100
app/src/main/res/layout/fragment_sort_time_bottom_sheet.xml
Normal file
@ -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>
|
@ -188,6 +188,12 @@
|
|||||||
<string name="sort_relevance">Relevance</string>
|
<string name="sort_relevance">Relevance</string>
|
||||||
<string name="sort_comments">Comments</string>
|
<string name="sort_comments">Comments</string>
|
||||||
<string name="sort_activity">Activity</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="open_link_with">Open link with</string>
|
||||||
<string name="no_browser_found">No browser found</string>
|
<string name="no_browser_found">No browser found</string>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
<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:hint="@string/search_hint"
|
||||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
|
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
|
||||||
</searchable>
|
</searchable>
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
Loading…
Reference in New Issue
Block a user