mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Remove PostViewModel, PostDataSource and PostDataSourceFactory. NewPostViewModel is renamed to PostViewModel.
This commit is contained in:
parent
01e1103d3d
commit
ecb891748d
@ -38,7 +38,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
|
||||
public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||
@ -115,13 +115,13 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
||||
}
|
||||
|
||||
mUserWhere = getIntent().getExtras().getString(EXTRA_USER_WHERE);
|
||||
if (mUserWhere.equals(PostDataSource.USER_WHERE_UPVOTED)) {
|
||||
if (mUserWhere.equals(PostPagingSource.USER_WHERE_UPVOTED)) {
|
||||
toolbar.setTitle(R.string.upvoted);
|
||||
} else if (mUserWhere.equals(PostDataSource.USER_WHERE_DOWNVOTED)) {
|
||||
} else if (mUserWhere.equals(PostPagingSource.USER_WHERE_DOWNVOTED)) {
|
||||
toolbar.setTitle(R.string.downvoted);
|
||||
} else if (mUserWhere.equals(PostDataSource.USER_WHERE_HIDDEN)) {
|
||||
} else if (mUserWhere.equals(PostPagingSource.USER_WHERE_HIDDEN)) {
|
||||
toolbar.setTitle(R.string.hidden);
|
||||
} else if (mUserWhere.equals(PostDataSource.USER_WHERE_GILDED)) {
|
||||
} else if (mUserWhere.equals(PostPagingSource.USER_WHERE_GILDED)) {
|
||||
toolbar.setTitle(R.string.gilded);
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
||||
private void initializeFragment() {
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, mUserWhere);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
|
@ -50,7 +50,7 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||
import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment;
|
||||
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
@ -336,9 +336,9 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
if (position == 0) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
|
||||
|
@ -50,7 +50,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
@ -158,7 +158,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||
|
||||
name = getIntent().getStringExtra(EXTRA_NAME);
|
||||
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
||||
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000);
|
||||
PostFilter postFilter = new PostFilter();
|
||||
switch (filter) {
|
||||
@ -220,9 +220,9 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
postFilter.containFlairs = flair;
|
||||
}
|
||||
|
||||
if (postType == PostDataSource.TYPE_USER) {
|
||||
if (postType == PostPagingSource.TYPE_USER) {
|
||||
userWhere = getIntent().getStringExtra(EXTRA_USER_WHERE);
|
||||
if (userWhere != null && !PostDataSource.USER_WHERE_SUBMITTED.equals(userWhere) && mMenu != null) {
|
||||
if (userWhere != null && !PostPagingSource.USER_WHERE_SUBMITTED.equals(userWhere) && mMenu != null) {
|
||||
mMenu.findItem(R.id.action_sort_filtered_thing_activity).setVisible(false);
|
||||
}
|
||||
}
|
||||
@ -268,13 +268,13 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
private void bindView(PostFilter postFilter, boolean initializeFragment) {
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
getSupportActionBar().setTitle(R.string.home);
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
getSupportActionBar().setTitle(R.string.search);
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
if (name.equals("popular") || name.equals("all")) {
|
||||
getSupportActionBar().setTitle(name.substring(0, 1).toUpperCase() + name.substring(1));
|
||||
} else {
|
||||
@ -282,7 +282,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
getSupportActionBar().setTitle(subredditNamePrefixed);
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
String multiRedditName;
|
||||
if (name.endsWith("/")) {
|
||||
multiRedditName = name.substring(0, name.length() - 1);
|
||||
@ -292,7 +292,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
}
|
||||
getSupportActionBar().setTitle(multiRedditName);
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
String usernamePrefixed = "u/" + name;
|
||||
getSupportActionBar().setTitle(usernamePrefixed);
|
||||
break;
|
||||
@ -305,12 +305,12 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
bundle.putParcelable(PostFragment.EXTRA_FILTER, postFilter);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
if (postType == PostDataSource.TYPE_USER) {
|
||||
if (postType == PostPagingSource.TYPE_USER) {
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, userWhere);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
} else if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||
bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getStringExtra(EXTRA_QUERY));
|
||||
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
||||
@ -353,7 +353,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
}
|
||||
|
||||
if (userWhere != null && !PostDataSource.USER_WHERE_SUBMITTED.equals(userWhere)) {
|
||||
if (userWhere != null && !PostPagingSource.USER_WHERE_SUBMITTED.equals(userWhere)) {
|
||||
mMenu.findItem(R.id.action_sort_filtered_thing_activity).setVisible(false);
|
||||
}
|
||||
return true;
|
||||
@ -367,20 +367,20 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
return true;
|
||||
} else if (itemId == R.id.action_sort_filtered_thing_activity) {
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||
Bundle bestBundle = new Bundle();
|
||||
bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false);
|
||||
bestSortTypeBottomSheetFragment.setArguments(bestBundle);
|
||||
bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
|
||||
Bundle searchBundle = new Bundle();
|
||||
searchPostSortTypeBottomSheetFragment.setArguments(searchBundle);
|
||||
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
if (name.equals("popular") || name.equals("all")) {
|
||||
SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||
Bundle popularBundle = new Bundle();
|
||||
@ -395,14 +395,14 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
subredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), subredditSortTypeBottomSheetFragment.getTag());
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
SortTypeBottomSheetFragment multiRedditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||
Bundle multiRedditBundle = new Bundle();
|
||||
multiRedditBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
|
||||
multiRedditSortTypeBottomSheetFragment.setArguments(multiRedditBundle);
|
||||
multiRedditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), multiRedditSortTypeBottomSheetFragment.getTag());
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
|
||||
userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());
|
||||
}
|
||||
@ -472,16 +472,16 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
public void postLayoutSelected(int postLayout) {
|
||||
if (mFragment != null) {
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
|
||||
}
|
||||
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
|
||||
|
@ -111,7 +111,7 @@ import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
|
||||
@ -492,36 +492,34 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
break;
|
||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_UPVOTED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_DOWNVOTED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_HIDDEN: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SAVED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_GILDED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@ -768,18 +766,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
intent = new Intent(MainActivity.this, TrendingActivity.class);
|
||||
} else if (stringId == R.string.upvoted) {
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED);
|
||||
} else if (stringId == R.string.downvoted) {
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED);
|
||||
} else if (stringId == R.string.hidden) {
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN);
|
||||
} else if (stringId == R.string.account_saved_thing_activity_label) {
|
||||
intent = new Intent(MainActivity.this, AccountSavedThingActivity.class);
|
||||
} else if (stringId == R.string.gilded) {
|
||||
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED);
|
||||
} else if (stringId == R.string.light_theme) {
|
||||
mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "0").apply();
|
||||
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
|
||||
@ -1099,7 +1097,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
private void changeSortType() {
|
||||
int currentPostType = sectionsPagerAdapter.getCurrentPostType();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, currentPostType != PostDataSource.TYPE_FRONT_PAGE);
|
||||
bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, currentPostType != PostPagingSource.TYPE_FRONT_PAGE);
|
||||
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||
sortTypeBottomSheetFragment.setArguments(bundle);
|
||||
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
|
||||
@ -1588,13 +1586,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
if (position == 0) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
} else if (position == 1) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@ -1603,7 +1601,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@ -1690,7 +1688,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
@ -1698,7 +1696,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@ -1707,7 +1705,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@ -1717,7 +1715,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_MULTI_REDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_MULTI_REDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
@ -1725,9 +1723,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
@ -1739,22 +1737,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|| postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_GILDED) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
|
||||
|
||||
if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_UPVOTED) {
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED);
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_DOWNVOTED) {
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED);
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HIDDEN) {
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN);
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SAVED) {
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
||||
} else {
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED);
|
||||
}
|
||||
|
||||
fragment.setArguments(bundle);
|
||||
@ -1762,7 +1760,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@ -1823,7 +1821,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
if (currentFragment != null) {
|
||||
return currentFragment.getPostType();
|
||||
}
|
||||
return PostDataSource.TYPE_SUBREDDIT;
|
||||
return PostPagingSource.TYPE_SUBREDDIT;
|
||||
}
|
||||
|
||||
void changeSortType(SortType sortType) {
|
||||
|
@ -69,7 +69,7 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment;
|
||||
import ml.docilealligator.infinityforreddit.fragments.UserListingFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.recentsearchquery.InsertRecentSearchQuery;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
|
||||
@ -771,7 +771,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
case 0: {
|
||||
PostFragment mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
|
||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
||||
|
@ -48,7 +48,7 @@ import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.DeleteMultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
@ -186,7 +186,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
mFragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.EXTRA_NAME, multiPath);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_MULTI_REDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_MULTI_REDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
mFragment.setArguments(bundle);
|
||||
|
@ -107,7 +107,7 @@ import ml.docilealligator.infinityforreddit.fragments.SidebarFragment;
|
||||
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
|
||||
@ -666,35 +666,35 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_UPVOTED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_DOWNVOTED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HIDDEN: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SAVED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SAVED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GILDED: {
|
||||
Intent intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent = new Intent(this, AccountPostsActivity.class);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED);
|
||||
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@ -1583,7 +1583,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
|
@ -99,7 +99,7 @@ import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
|
||||
@ -1446,9 +1446,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
if (position == 0) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED);
|
||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
|
@ -110,7 +110,7 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi
|
||||
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
|
||||
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
@ -1212,7 +1212,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
mTypeTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
|
||||
mActivity.startActivity(intent);
|
||||
});
|
||||
@ -1224,7 +1224,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
mFlairTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair());
|
||||
mActivity.startActivity(intent);
|
||||
});
|
||||
@ -1235,7 +1235,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
mNSFWTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
|
||||
mActivity.startActivity(intent);
|
||||
});
|
||||
|
@ -89,7 +89,7 @@ import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
|
||||
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment;
|
||||
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
@ -639,7 +639,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
break;
|
||||
}
|
||||
|
||||
if (mPostType == PostDataSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
|
||||
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
|
||||
((PostBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
|
||||
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostBaseViewHolder) holder).stickiedPostImageView);
|
||||
}
|
||||
@ -1176,7 +1176,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
}
|
||||
|
||||
if (mPostType == PostDataSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
|
||||
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
|
||||
((PostCompactBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
|
||||
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostCompactBaseViewHolder) holder).stickiedPostImageView);
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
|
||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
@ -79,11 +79,11 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
if (sortType.getTime() != null) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED,
|
||||
null, sortType.getType().value, sortType.getTime().value,
|
||||
APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED,
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED,
|
||||
null, sortType.getType().value, APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
} else {
|
||||
@ -158,10 +158,10 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
if (sortType.getTime() != null) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED, params.key,
|
||||
sortType.getType().value, sortType.getTime().value, APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostDataSource.USER_WHERE_SAVED, params.key,
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED, params.key,
|
||||
sortType.getType().value, APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
} else {
|
||||
|
@ -122,9 +122,9 @@ import ml.docilealligator.infinityforreddit.events.NeedForPostListFromPostFragme
|
||||
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostList;
|
||||
import ml.docilealligator.infinityforreddit.events.ShowDividerInCompactLayoutPreferenceEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.ShowThumbnailOnTheRightInCompactLayoutEvent;
|
||||
import ml.docilealligator.infinityforreddit.post.NewPostViewModel;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostViewModel;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
@ -167,7 +167,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
ImageView mFetchPostInfoImageView;
|
||||
@BindView(R.id.fetch_post_info_text_view_post_fragment)
|
||||
TextView mFetchPostInfoTextView;
|
||||
NewPostViewModel mPostViewModel;
|
||||
PostViewModel mPostViewModel;
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
Retrofit mRetrofit;
|
||||
@ -432,7 +432,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
int usage;
|
||||
String nameOfUsage;
|
||||
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
subredditName = getArguments().getString(EXTRA_NAME);
|
||||
query = getArguments().getString(EXTRA_QUERY);
|
||||
trendingSource = getArguments().getString(EXTRA_TRENDING_SOURCE);
|
||||
@ -498,7 +498,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||
}
|
||||
});
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
subredditName = getArguments().getString(EXTRA_NAME);
|
||||
if (savedInstanceState == null) {
|
||||
postFragmentId += subredditName.hashCode();
|
||||
@ -569,7 +569,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||
}
|
||||
});
|
||||
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
multiRedditPath = getArguments().getString(EXTRA_NAME);
|
||||
if (savedInstanceState == null) {
|
||||
postFragmentId += multiRedditPath.hashCode();
|
||||
@ -640,7 +640,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||
}
|
||||
});
|
||||
} else if (postType == PostDataSource.TYPE_USER) {
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
username = getArguments().getString(EXTRA_USER_NAME);
|
||||
where = getArguments().getString(EXTRA_USER_WHERE);
|
||||
if (savedInstanceState == null) {
|
||||
@ -708,7 +708,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||
}
|
||||
});
|
||||
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
usage = PostFilterUsage.HOME_TYPE;
|
||||
nameOfUsage = PostFilterUsage.NO_USAGE;
|
||||
|
||||
@ -886,7 +886,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
} else {
|
||||
if (postFilter == null) {
|
||||
if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
if (concatenatedSubredditNames == null) {
|
||||
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
|
||||
(postFilter, concatenatedSubredditNames) -> {
|
||||
@ -915,7 +915,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
if (concatenatedSubredditNames == null) {
|
||||
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
|
||||
(postFilter, concatenatedSubredditNames) -> {
|
||||
@ -1078,35 +1078,35 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
private void initializeAndBindPostViewModel(String accessToken) {
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
|
||||
postType, sortType, postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
||||
postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType,
|
||||
postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
|
||||
where, readPosts)).get(NewPostViewModel.class);
|
||||
where, readPosts)).get(PostViewModel.class);
|
||||
} else {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||
postType, sortType, postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
}
|
||||
|
||||
bindPostViewModel();
|
||||
@ -1114,35 +1114,35 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
private void initializeAndBindPostViewModelForAnonymous(String concatenatedSubredditNames) {
|
||||
//For anonymous user
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit, null,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
|
||||
postType, sortType, postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(this, new NewPostViewModel.Factory(mExecutor,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit, null,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
||||
postFilter, readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit, null,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter,
|
||||
readPosts)).get(NewPostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit, null,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
|
||||
where, readPosts)).get(NewPostViewModel.class);
|
||||
where, readPosts)).get(PostViewModel.class);
|
||||
} else {
|
||||
//Anonymous Front Page
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new NewPostViewModel.Factory(mExecutor,
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit,
|
||||
mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)).get(NewPostViewModel.class);
|
||||
mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)).get(PostViewModel.class);
|
||||
}
|
||||
|
||||
bindPostViewModel();
|
||||
@ -1182,31 +1182,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
if (mPostViewModel != null) {
|
||||
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
|
||||
if (sortType.getTime() != null) {
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
|
||||
if (sortType.getTime() != null) {
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
|
||||
if (sortType.getTime() != null) {
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
|
||||
if (sortType.getTime() != null) {
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||
sortType.getType().name()).apply();
|
||||
if (sortType.getTime() != null) {
|
||||
@ -1284,7 +1284,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
private void saveCache() {
|
||||
if (savePostFeedScrolledPosition && postType == PostDataSource.TYPE_FRONT_PAGE && sortType != null && sortType.getType() == SortType.Type.BEST && mAdapter != null) {
|
||||
if (savePostFeedScrolledPosition && postType == PostPagingSource.TYPE_FRONT_PAGE && sortType != null && sortType.getType() == SortType.Type.BEST && mAdapter != null) {
|
||||
Post currentPost = mAdapter.getItemByPosition(maxPosition);
|
||||
if (currentPost != null) {
|
||||
String accountNameForCache = accountName == null ? SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS : accountName;
|
||||
@ -1408,19 +1408,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
public void changePostLayout(int postLayout) {
|
||||
this.postLayout = postLayout;
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, postLayout).apply();
|
||||
break;
|
||||
}
|
||||
@ -1493,24 +1493,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@Override
|
||||
public void filterPosts() {
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
startActivity(intent);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
startActivity(intent);
|
||||
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
startActivity(intent);
|
||||
} else if (postType == PostDataSource.TYPE_USER) {
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
@ -1642,27 +1642,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
Bundle bundle = getArguments();
|
||||
if (bundle != null) {
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
|
||||
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
case PostPagingSource.TYPE_USER:
|
||||
if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) {
|
||||
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
|
||||
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) {
|
||||
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
|
||||
}
|
||||
break;
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) {
|
||||
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
|
||||
}
|
||||
|
@ -1,355 +0,0 @@
|
||||
package ml.docilealligator.infinityforreddit.post;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.util.Pair;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelKt;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.paging.Pager;
|
||||
import androidx.paging.PagingConfig;
|
||||
import androidx.paging.PagingData;
|
||||
import androidx.paging.PagingLiveData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class NewPostViewModel extends ViewModel {
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
|
||||
private LiveData<PagingData<Post>> posts;
|
||||
|
||||
private MutableLiveData<SortType> sortTypeLiveData;
|
||||
private MutableLiveData<PostFilter> postFilterLiveData;
|
||||
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
|
||||
|
||||
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditName, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = subredditName;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, String username,
|
||||
int postType, SortType sortType, PostFilter postFilter, String userWhere,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = username;
|
||||
this.userWhere = userWhere;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditName, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = subredditName;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public LiveData<PagingData<Post>> getPosts() {
|
||||
return posts;
|
||||
}
|
||||
|
||||
public PostPaging3PagingSource returnPagingSoruce() {
|
||||
PostPaging3PagingSource paging3PagingSource;
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
case PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||
paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, readPostList);
|
||||
break;
|
||||
case PostDataSource.TYPE_SEARCH:
|
||||
paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
||||
postType, sortType, postFilter, readPostList);
|
||||
break;
|
||||
default:
|
||||
//User
|
||||
paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, userWhere, readPostList);
|
||||
break;
|
||||
}
|
||||
return paging3PagingSource;
|
||||
}
|
||||
|
||||
private void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
}
|
||||
|
||||
public void changeSortType(SortType sortType) {
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
}
|
||||
|
||||
public void changePostFilter(PostFilter postFilter) {
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
//User posts
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String username, int postType, SortType sortType, PostFilter postFilter, String where,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = username;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
userWhere = where;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
//Anonymous Front Page
|
||||
public Factory(Executor executor, Retrofit retrofit, SharedPreferences sharedPreferences,
|
||||
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.name = concatenatedSubredditNames;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
if (postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||
return (T) new NewPostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
return (T) new NewPostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
return (T) new NewPostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
return (T) new NewPostViewModel(executor, retrofit, null, null, sharedPreferences,
|
||||
null, name, postType, sortType,
|
||||
postFilter, null);
|
||||
} else {
|
||||
return (T) new NewPostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||
postFilter, userWhere, readPostList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class SortTypeAndPostFilterLiveData extends MediatorLiveData<Pair<PostFilter, SortType>> {
|
||||
public SortTypeAndPostFilterLiveData(LiveData<SortType> sortTypeLiveData, LiveData<PostFilter> postFilterLiveData) {
|
||||
addSource(sortTypeLiveData, sortType -> setValue(Pair.create(postFilterLiveData.getValue(), sortType)));
|
||||
addSource(postFilterLiveData, postFilter -> setValue(Pair.create(postFilter, sortTypeLiveData.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,160 +0,0 @@
|
||||
package ml.docilealligator.infinityforreddit.post;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
class PostDataSourceFactory extends DataSource.Factory {
|
||||
private Executor executor;
|
||||
private Handler handler;
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
|
||||
private PostDataSource postDataSource;
|
||||
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
||||
|
||||
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||
String where, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
userWhere = where;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DataSource<String, Post> create() {
|
||||
if (postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
||||
postType, sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
Log.i("asdasfd", "s5 " + (postFilter == null));
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, null, null,
|
||||
sharedPreferences, null, name, postType,
|
||||
sortType, postFilter, null);
|
||||
} else {
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, userWhere, readPostList);
|
||||
}
|
||||
|
||||
postDataSourceLiveData.postValue(postDataSource);
|
||||
return postDataSource;
|
||||
}
|
||||
|
||||
public MutableLiveData<PostDataSource> getPostDataSourceLiveData() {
|
||||
return postDataSourceLiveData;
|
||||
}
|
||||
|
||||
PostDataSource getPostDataSource() {
|
||||
return postDataSource;
|
||||
}
|
||||
|
||||
void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
|
||||
Log.i("asdasfd", "s6 " + (postFilter == null));
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ import retrofit2.HttpException;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostPaging3PagingSource extends ListenableFuturePagingSource<String, Post> {
|
||||
public class PostPagingSource extends ListenableFuturePagingSource<String, Post> {
|
||||
public static final int TYPE_FRONT_PAGE = 0;
|
||||
public static final int TYPE_SUBREDDIT = 1;
|
||||
public static final int TYPE_USER = 2;
|
||||
@ -60,7 +60,7 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
|
||||
private String multiRedditPath;
|
||||
private LinkedHashSet<Post> postLinkedHashSet;
|
||||
|
||||
PostPaging3PagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
@ -77,7 +77,7 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPaging3PagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String path, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
@ -115,7 +115,7 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPaging3PagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
|
||||
String where, List<ReadPost> readPostList) {
|
||||
@ -134,7 +134,7 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPaging3PagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, String query, String trendingSource, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
@ -1,7 +1,6 @@
|
||||
package ml.docilealligator.infinityforreddit.post;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.util.Pair;
|
||||
@ -10,201 +9,23 @@ import androidx.lifecycle.MediatorLiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelKt;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.paging.Pager;
|
||||
import androidx.paging.PagingConfig;
|
||||
import androidx.paging.PagingData;
|
||||
import androidx.paging.PagingLiveData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostViewModel extends ViewModel {
|
||||
private PostDataSourceFactory postDataSourceFactory;
|
||||
private LiveData<NetworkState> paginationNetworkState;
|
||||
private LiveData<NetworkState> initialLoadingState;
|
||||
private LiveData<Boolean> hasPostLiveData;
|
||||
private LiveData<PagedList<Post>> posts;
|
||||
private MutableLiveData<SortType> sortTypeLiveData;
|
||||
private MutableLiveData<PostFilter> postFilterLiveData;
|
||||
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
|
||||
|
||||
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences cache, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, cache, postType, sortType, postFilter, readPostList);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getInitialLoadStateLiveData);
|
||||
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getPaginationNetworkStateLiveData);
|
||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::hasPostLiveData);
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(false)
|
||||
.setPageSize(25)
|
||||
.build();
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
postDataSourceFactory.changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
|
||||
int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, cache, subredditName, postType, sortType, postFilter,
|
||||
readPostList);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getInitialLoadStateLiveData);
|
||||
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getPaginationNetworkStateLiveData);
|
||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::hasPostLiveData);
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(false)
|
||||
.setPageSize(25)
|
||||
.build();
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
postDataSourceFactory.changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences cache, String username,
|
||||
int postType, SortType sortType, PostFilter postFilter, String where,
|
||||
List<ReadPost> readPostList) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, cache, username, postType, sortType, postFilter, where, readPostList);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getInitialLoadStateLiveData);
|
||||
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getPaginationNetworkStateLiveData);
|
||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::hasPostLiveData);
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(false)
|
||||
.setPageSize(25)
|
||||
.build();
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
postDataSourceFactory.changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
|
||||
String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, cache, subredditName, query, trendingSource, postType, sortType, postFilter,
|
||||
readPostList);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getInitialLoadStateLiveData);
|
||||
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::getPaginationNetworkStateLiveData);
|
||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
PostDataSource::hasPostLiveData);
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(false)
|
||||
.setPageSize(25)
|
||||
.build();
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
postDataSourceFactory.changeSortTypeAndPostFilter(sortTypeLiveData.getValue(),
|
||||
postFilterLiveData.getValue());
|
||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||
});
|
||||
}
|
||||
|
||||
public LiveData<PagedList<Post>> getPosts() {
|
||||
return posts;
|
||||
}
|
||||
|
||||
public LiveData<NetworkState> getPaginationNetworkState() {
|
||||
return paginationNetworkState;
|
||||
}
|
||||
|
||||
public LiveData<NetworkState> getInitialLoadingState() {
|
||||
return initialLoadingState;
|
||||
}
|
||||
|
||||
public LiveData<Boolean> hasPost() {
|
||||
return hasPostLiveData;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
postDataSourceFactory.getPostDataSource().invalidate();
|
||||
}
|
||||
|
||||
public void retryLoadingMore() {
|
||||
postDataSourceFactory.getPostDataSource().retryLoadingMore();
|
||||
}
|
||||
|
||||
public void changeSortType(SortType sortType) {
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
}
|
||||
|
||||
public void changePostFilter(PostFilter postFilter) {
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private Executor executor;
|
||||
private Handler handler;
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
@ -219,11 +40,209 @@ public class PostViewModel extends ViewModel {
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
private LiveData<PagingData<Post>> posts;
|
||||
|
||||
private MutableLiveData<SortType> sortTypeLiveData;
|
||||
private MutableLiveData<PostFilter> postFilterLiveData;
|
||||
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditName, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = subredditName;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, String username,
|
||||
int postType, SortType sortType, PostFilter postFilter, String userWhere,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = username;
|
||||
this.userWhere = userWhere;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditName, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
this.readPostList = readPostList;
|
||||
this.name = subredditName;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
|
||||
sortTypeLiveData = new MutableLiveData<>();
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
postFilterLiveData = new MutableLiveData<>();
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
|
||||
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
|
||||
|
||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||
|
||||
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
|
||||
changeSortTypeAndPostFilter(
|
||||
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
|
||||
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
|
||||
});
|
||||
}
|
||||
|
||||
public LiveData<PagingData<Post>> getPosts() {
|
||||
return posts;
|
||||
}
|
||||
|
||||
public PostPagingSource returnPagingSoruce() {
|
||||
PostPagingSource paging3PagingSource;
|
||||
switch (postType) {
|
||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
break;
|
||||
case PostPagingSource.TYPE_SUBREDDIT:
|
||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, readPostList);
|
||||
break;
|
||||
case PostPagingSource.TYPE_SEARCH:
|
||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
||||
postType, sortType, postFilter, readPostList);
|
||||
break;
|
||||
default:
|
||||
//User
|
||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||
sortType, postFilter, userWhere, readPostList);
|
||||
break;
|
||||
}
|
||||
return paging3PagingSource;
|
||||
}
|
||||
|
||||
private void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
}
|
||||
|
||||
public void changeSortType(SortType sortType) {
|
||||
sortTypeLiveData.postValue(sortType);
|
||||
}
|
||||
|
||||
public void changePostFilter(PostFilter postFilter) {
|
||||
postFilterLiveData.postValue(postFilter);
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
@ -235,11 +254,10 @@ public class PostViewModel extends ViewModel {
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
@ -253,12 +271,11 @@ public class PostViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
//User posts
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String username, int postType, SortType sortType, PostFilter postFilter, String where,
|
||||
List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
@ -272,12 +289,11 @@ public class PostViewModel extends ViewModel {
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
this.accountName = accountName;
|
||||
@ -293,10 +309,9 @@ public class PostViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
//Anonymous Front Page
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, SharedPreferences sharedPreferences,
|
||||
public Factory(Executor executor, Retrofit retrofit, SharedPreferences sharedPreferences,
|
||||
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
this.sharedPreferences = sharedPreferences;
|
||||
this.name = concatenatedSubredditNames;
|
||||
@ -308,23 +323,23 @@ public class PostViewModel extends ViewModel {
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
if (postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
|
||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
} else if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, null, null, sharedPreferences,
|
||||
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
|
||||
null, name, postType, sortType,
|
||||
postFilter, null);
|
||||
} else {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||
postFilter, userWhere, readPostList);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user