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