mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Start adding anonymous subscriptions.
This commit is contained in:
parent
7bd60c907f
commit
e8cb0d329c
@ -1,31 +0,0 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
|
||||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
|
||||||
|
|
||||||
public class FetchPostFilterAndReadPosts {
|
|
||||||
public interface FetchPostFilterAndReadPostsListener {
|
|
||||||
void success(PostFilter postFilter, ArrayList<ReadPost> readPostList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fetchPostFilterAndReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
|
|
||||||
Handler handler, String accountName, int postFilterUsage,
|
|
||||||
String nameOfUsage, FetchPostFilterAndReadPostsListener fetchPostFilterAndReadPostsListener) {
|
|
||||||
executor.execute(() -> {
|
|
||||||
List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage);
|
|
||||||
PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters);
|
|
||||||
if (accountName != null) {
|
|
||||||
ArrayList<ReadPost> readPosts = (ArrayList<ReadPost>) redditDataRoomDatabase.readPostDao().getAllReadPosts(accountName);
|
|
||||||
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, readPosts));
|
|
||||||
} else {
|
|
||||||
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, null));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,58 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||||
|
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||||
|
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
|
||||||
|
|
||||||
|
public class FetchPostFilterReadPostsAndConcatenatedSubredditNames {
|
||||||
|
public interface FetchPostFilterAndReadPostsListener {
|
||||||
|
void success(PostFilter postFilter, ArrayList<ReadPost> readPostList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface FetchPostFilterAndConcatenatecSubredditNamesListener {
|
||||||
|
void success(PostFilter postFilter, String concatenatedSubredditNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fetchPostFilterAndReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
|
||||||
|
Handler handler, String accountName, int postFilterUsage,
|
||||||
|
String nameOfUsage, FetchPostFilterAndReadPostsListener fetchPostFilterAndReadPostsListener) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage);
|
||||||
|
PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters);
|
||||||
|
if (accountName != null) {
|
||||||
|
ArrayList<ReadPost> readPosts = (ArrayList<ReadPost>) redditDataRoomDatabase.readPostDao().getAllReadPosts(accountName);
|
||||||
|
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, readPosts));
|
||||||
|
} else {
|
||||||
|
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, null));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fetchPostFilterAndConcatenatedSubredditNames(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
|
||||||
|
Handler handler, int postFilterUsage, String nameOfUsage,
|
||||||
|
FetchPostFilterAndConcatenatecSubredditNamesListener fetchPostFilterAndConcatenatecSubredditNamesListener) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage);
|
||||||
|
PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters);
|
||||||
|
List<SubscribedSubredditData> anonymousSubscribedSubreddits = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList("-");
|
||||||
|
if (anonymousSubscribedSubreddits != null && !anonymousSubscribedSubreddits.isEmpty()) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (SubscribedSubredditData s : anonymousSubscribedSubreddits) {
|
||||||
|
stringBuilder.append(s).append("+");
|
||||||
|
}
|
||||||
|
if (stringBuilder.length() > 0) {
|
||||||
|
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
handler.post(() -> fetchPostFilterAndConcatenatecSubredditNamesListener.success(mergedPostFilter, stringBuilder.toString()));
|
||||||
|
} else {
|
||||||
|
handler.post(() -> fetchPostFilterAndConcatenatecSubredditNamesListener.success(mergedPostFilter, null));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.user.UserData;
|
|||||||
|
|
||||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
||||||
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
|
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
|
||||||
ReadPost.class, PostFilter.class, PostFilterUsage.class}, version = 18)
|
ReadPost.class, PostFilter.class, PostFilterUsage.class}, version = 19)
|
||||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||||
private static RedditDataRoomDatabase INSTANCE;
|
private static RedditDataRoomDatabase INSTANCE;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
|||||||
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
|
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
|
||||||
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
|
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
|
||||||
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
|
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
|
||||||
MIGRATION_17_18)
|
MIGRATION_17_18, MIGRATION_18_19)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,4 +325,11 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
|||||||
database.execSQL("ALTER TABLE custom_themes ADD COLUMN upvote_ratio_icon_tint INTEGER DEFAULT " + Color.parseColor("#0256EE") + " NOT NULL");
|
database.execSQL("ALTER TABLE custom_themes ADD COLUMN upvote_ratio_icon_tint INTEGER DEFAULT " + Color.parseColor("#0256EE") + " NOT NULL");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Migration MIGRATION_18_19 = new Migration(18, 19) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("INSERT INTO accounts(username, karma, is_current_user) VALUES (\"-\", 0, false)");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,19 @@ public interface AccountDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insert(Account account);
|
void insert(Account account);
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts")
|
@Query("SELECT * FROM accounts WHERE username != '-'")
|
||||||
List<Account> getAllAccounts();
|
List<Account> getAllAccounts();
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE is_current_user = 0")
|
@Query("SELECT * FROM accounts WHERE is_current_user = 0 AND username != '-'")
|
||||||
List<Account> getAllNonCurrentAccounts();
|
List<Account> getAllNonCurrentAccounts();
|
||||||
|
|
||||||
@Query("UPDATE accounts SET is_current_user = 0 WHERE is_current_user = 1")
|
@Query("UPDATE accounts SET is_current_user = 0 WHERE is_current_user = 1 AND username != '-'")
|
||||||
void markAllAccountsNonCurrent();
|
void markAllAccountsNonCurrent();
|
||||||
|
|
||||||
@Query("DELETE FROM accounts WHERE is_current_user = 1")
|
@Query("DELETE FROM accounts WHERE is_current_user = 1 AND username != '-'")
|
||||||
void deleteCurrentAccount();
|
void deleteCurrentAccount();
|
||||||
|
|
||||||
@Query("DELETE FROM accounts")
|
@Query("DELETE FROM accounts WHERE username != '-'")
|
||||||
void deleteAllAccounts();
|
void deleteAllAccounts();
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE username = :username COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE username = :username COLLATE NOCASE LIMIT 1")
|
||||||
@ -34,17 +34,17 @@ public interface AccountDao {
|
|||||||
@Query("SELECT * FROM accounts WHERE username = :username COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE username = :username COLLATE NOCASE LIMIT 1")
|
||||||
Account getAccountData(String username);
|
Account getAccountData(String username);
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE is_current_user = 1 AND username != '-' LIMIT 1")
|
||||||
Account getCurrentAccount();
|
Account getCurrentAccount();
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE is_current_user = 1 AND username != '-' LIMIT 1")
|
||||||
LiveData<Account> getCurrentAccountLiveData();
|
LiveData<Account> getCurrentAccountLiveData();
|
||||||
|
|
||||||
@Query("UPDATE accounts SET profile_image_url = :profileImageUrl, banner_image_url = :bannerImageUrl, " +
|
@Query("UPDATE accounts SET profile_image_url = :profileImageUrl, banner_image_url = :bannerImageUrl, " +
|
||||||
"karma = :karma WHERE username = :username")
|
"karma = :karma WHERE username = :username")
|
||||||
void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma);
|
void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma);
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE is_current_user = 0 ORDER BY username COLLATE NOCASE ASC")
|
@Query("SELECT * FROM accounts WHERE is_current_user = 0 AND username != '-' ORDER BY username COLLATE NOCASE ASC")
|
||||||
LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData();
|
LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData();
|
||||||
|
|
||||||
@Query("UPDATE accounts SET is_current_user = 1 WHERE username = :username")
|
@Query("UPDATE accounts SET is_current_user = 1 WHERE username = :username")
|
||||||
|
@ -792,9 +792,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 0:
|
case 0:
|
||||||
tab.setText(R.string.popular);
|
tab.setText(R.string.home);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
tab.setText(R.string.popular);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
tab.setText(R.string.all);
|
tab.setText(R.string.all);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1352,6 +1355,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
public Fragment createFragment(int position) {
|
public Fragment createFragment(int position) {
|
||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
|
PostFragment fragment = new PostFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE);
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
return fragment;
|
||||||
|
} 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, PostDataSource.TYPE_SUBREDDIT);
|
||||||
@ -1499,7 +1508,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
return tabCount + favoriteSubscribedSubreddits.size() + subscribedSubreddits.size();
|
return tabCount + favoriteSubscribedSubreddits.size() + subscribedSubreddits.size();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ import im.ene.toro.exoplayer.ExoCreator;
|
|||||||
import im.ene.toro.media.PlaybackInfo;
|
import im.ene.toro.media.PlaybackInfo;
|
||||||
import im.ene.toro.media.VolumeInfo;
|
import im.ene.toro.media.VolumeInfo;
|
||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
import ml.docilealligator.infinityforreddit.FetchPostFilterAndReadPosts;
|
import ml.docilealligator.infinityforreddit.FetchPostFilterReadPostsAndConcatenatedSubredditNames;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
@ -146,6 +146,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private static final String READ_POST_LIST_STATE = "RPLS";
|
private static final String READ_POST_LIST_STATE = "RPLS";
|
||||||
private static final String HIDE_READ_POSTS_INDEX_STATE = "HRPIS";
|
private static final String HIDE_READ_POSTS_INDEX_STATE = "HRPIS";
|
||||||
private static final String POST_FILTER_STATE = "PFS";
|
private static final String POST_FILTER_STATE = "PFS";
|
||||||
|
private static final String CONCATENATED_SUBREDDIT_NAMES_STATE = "CSNS";
|
||||||
private static final String POST_FRAGMENT_ID_STATE = "PFIS";
|
private static final String POST_FRAGMENT_ID_STATE = "PFIS";
|
||||||
|
|
||||||
@BindView(R.id.swipe_refresh_layout_post_fragment)
|
@BindView(R.id.swipe_refresh_layout_post_fragment)
|
||||||
@ -221,6 +222,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private String query;
|
private String query;
|
||||||
private String where;
|
private String where;
|
||||||
private String multiRedditPath;
|
private String multiRedditPath;
|
||||||
|
private String concatenatedSubredditNames;
|
||||||
private int maxPosition = -1;
|
private int maxPosition = -1;
|
||||||
private int postLayout;
|
private int postLayout;
|
||||||
private SortType sortType;
|
private SortType sortType;
|
||||||
@ -381,6 +383,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE);
|
readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE);
|
||||||
hideReadPostsIndex = savedInstanceState.getInt(HIDE_READ_POSTS_INDEX_STATE, 0);
|
hideReadPostsIndex = savedInstanceState.getInt(HIDE_READ_POSTS_INDEX_STATE, 0);
|
||||||
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
|
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
|
||||||
|
concatenatedSubredditNames = savedInstanceState.getString(CONCATENATED_SUBREDDIT_NAMES_STATE);
|
||||||
postFragmentId = savedInstanceState.getLong(POST_FRAGMENT_ID_STATE);
|
postFragmentId = savedInstanceState.getLong(POST_FRAGMENT_ID_STATE);
|
||||||
} else {
|
} else {
|
||||||
postFilter = getArguments().getParcelable(EXTRA_FILTER);
|
postFilter = getArguments().getParcelable(EXTRA_FILTER);
|
||||||
@ -673,6 +676,60 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delayTransition() {
|
||||||
|
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
|
usage = PostFilterUsage.HOME_TYPE;
|
||||||
|
nameOfUsage = PostFilterUsage.NO_USAGE;
|
||||||
|
|
||||||
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
|
||||||
|
if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
|
||||||
|
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
|
||||||
|
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
||||||
|
} else {
|
||||||
|
sortType = new SortType(SortType.Type.valueOf(sort));
|
||||||
|
}
|
||||||
|
|
||||||
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
|
mRedgifsRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, accountName, postType, postLayout, true,
|
||||||
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
|
||||||
|
mExoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
|
@Override
|
||||||
|
public void retryLoadingMore() {
|
||||||
|
mPostViewModel.retryLoadingMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void typeChipClicked(int filter) {
|
||||||
|
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best));
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nsfwChipClicked() {
|
||||||
|
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best));
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||||
|
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void currentlyBindItem(int position) {
|
||||||
|
if (maxPosition < position) {
|
||||||
|
maxPosition = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delayTransition() {
|
public void delayTransition() {
|
||||||
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
|
||||||
@ -752,15 +809,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
((ActivityToolbarInterface) activity).displaySortType();
|
((ActivityToolbarInterface) activity).displaySortType();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountName != null && !accountName.equals("")) {
|
if (accessToken != null && !accessToken.equals("")) {
|
||||||
if (mPostHistorySharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false) && readPosts == null) {
|
if (mPostHistorySharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false) && readPosts == null) {
|
||||||
if (getArguments().getBoolean(EXTRA_DISABLE_READ_POSTS, false)) {
|
if (getArguments().getBoolean(EXTRA_DISABLE_READ_POSTS, false)) {
|
||||||
if (postFilter == null) {
|
if (postFilter == null) {
|
||||||
FetchPostFilterAndReadPosts.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
||||||
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
initializeAndBindPostViewModel(accessToken);
|
initializeAndBindPostViewModel(accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -768,12 +825,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
initializeAndBindPostViewModel(accessToken);
|
initializeAndBindPostViewModel(accessToken);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FetchPostFilterAndReadPosts.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
||||||
new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> {
|
new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> {
|
||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
if (this.postFilter == null) {
|
if (this.postFilter == null) {
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
}
|
}
|
||||||
this.readPosts = readPostList;
|
this.readPosts = readPostList;
|
||||||
initializeAndBindPostViewModel(accessToken);
|
initializeAndBindPostViewModel(accessToken);
|
||||||
@ -782,11 +839,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (postFilter == null) {
|
if (postFilter == null) {
|
||||||
FetchPostFilterAndReadPosts.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
||||||
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
initializeAndBindPostViewModel(accessToken);
|
initializeAndBindPostViewModel(accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -796,16 +853,56 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (postFilter == null) {
|
if (postFilter == null) {
|
||||||
FetchPostFilterAndReadPosts.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
if (concatenatedSubredditNames == null) {
|
||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
|
||||||
this.postFilter = postFilter;
|
(postFilter, concatenatedSubredditNames) -> {
|
||||||
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
initializeAndBindPostViewModelForAnonymous(accessToken);
|
this.postFilter = postFilter;
|
||||||
}
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
});
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
|
if (concatenatedSubredditNames == null) {
|
||||||
|
showErrorView(R.string.anonymous_front_page_no_subscriptions);
|
||||||
|
} else {
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
|
||||||
|
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
|
this.postFilter = postFilter;
|
||||||
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
|
initializeAndBindPostViewModelForAnonymous(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
initializeAndBindPostViewModelForAnonymous(accessToken);
|
if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
|
if (concatenatedSubredditNames == null) {
|
||||||
|
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
|
||||||
|
(postFilter, concatenatedSubredditNames) -> {
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
|
this.postFilter = postFilter;
|
||||||
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
|
if (concatenatedSubredditNames == null) {
|
||||||
|
showErrorView(R.string.anonymous_front_page_no_subscriptions);
|
||||||
|
} else {
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initializeAndBindPostViewModelForAnonymous(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,32 +1067,32 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
bindPostViewModel();
|
bindPostViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAndBindPostViewModelForAnonymous(String accessToken) {
|
private void initializeAndBindPostViewModelForAnonymous(String concatenatedSubredditNames) {
|
||||||
//For anonymous user
|
//For anonymous user
|
||||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mRetrofit, null,
|
||||||
accountName, mSharedPreferences,
|
accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
|
mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
|
||||||
postFilter, readPosts)).get(PostViewModel.class);
|
postFilter, readPosts)).get(PostViewModel.class);
|
||||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mRetrofit, null,
|
||||||
accountName, mSharedPreferences,
|
accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
||||||
postFilter, readPosts)).get(PostViewModel.class);
|
postFilter, readPosts)).get(PostViewModel.class);
|
||||||
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mRetrofit, null,
|
||||||
accountName, mSharedPreferences,
|
accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter,
|
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter,
|
||||||
readPosts)).get(PostViewModel.class);
|
readPosts)).get(PostViewModel.class);
|
||||||
} else if (postType == PostDataSource.TYPE_USER) {
|
} else if (postType == PostDataSource.TYPE_USER) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mRetrofit, null,
|
||||||
accountName, mSharedPreferences,
|
accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
|
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
|
||||||
where, readPosts)).get(PostViewModel.class);
|
where, readPosts)).get(PostViewModel.class);
|
||||||
} else {
|
} else {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
//Anonymous Front Page
|
||||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mRetrofit,
|
||||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)).get(PostViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindPostViewModel();
|
bindPostViewModel();
|
||||||
@ -1014,8 +1111,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
stopLazyMode();
|
stopLazyMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
mFetchPostInfoLinearLayout.setOnClickListener(view -> {
|
mFetchPostInfoLinearLayout.setOnClickListener(null);
|
||||||
});
|
|
||||||
showErrorView(R.string.no_posts);
|
showErrorView(R.string.no_posts);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1036,51 +1132,53 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(SortType sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
switch (postType) {
|
if (mPostViewModel != null) {
|
||||||
case PostDataSource.TYPE_FRONT_PAGE:
|
switch (postType) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
|
case PostDataSource.TYPE_FRONT_PAGE:
|
||||||
if (sortType.getTime() != null) {
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
|
if (sortType.getTime() != null) {
|
||||||
}
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
|
||||||
break;
|
}
|
||||||
case PostDataSource.TYPE_SUBREDDIT:
|
break;
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
|
case PostDataSource.TYPE_SUBREDDIT:
|
||||||
if (sortType.getTime() != null) {
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
|
if (sortType.getTime() != null) {
|
||||||
}
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
|
||||||
break;
|
}
|
||||||
case PostDataSource.TYPE_USER:
|
break;
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
|
case PostDataSource.TYPE_USER:
|
||||||
if (sortType.getTime() != null) {
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
|
if (sortType.getTime() != null) {
|
||||||
}
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
|
||||||
break;
|
}
|
||||||
case PostDataSource.TYPE_SEARCH:
|
break;
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
|
case PostDataSource.TYPE_SEARCH:
|
||||||
if (sortType.getTime() != null) {
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
|
if (sortType.getTime() != null) {
|
||||||
}
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
|
||||||
break;
|
}
|
||||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
break;
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||||
sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
if (sortType.getTime() != null) {
|
sortType.getType().name()).apply();
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
if (sortType.getTime() != null) {
|
||||||
sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
}
|
sortType.getTime().name()).apply();
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) {
|
||||||
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
|
mGlide.clear(mFetchPostInfoImageView);
|
||||||
|
}
|
||||||
|
mAdapter.removeFooter();
|
||||||
|
hasPost = false;
|
||||||
|
if (isInLazyMode) {
|
||||||
|
stopLazyMode();
|
||||||
|
}
|
||||||
|
this.sortType = sortType;
|
||||||
|
mPostViewModel.changeSortType(sortType);
|
||||||
}
|
}
|
||||||
if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) {
|
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
|
||||||
mGlide.clear(mFetchPostInfoImageView);
|
|
||||||
}
|
|
||||||
mAdapter.removeFooter();
|
|
||||||
hasPost = false;
|
|
||||||
if (isInLazyMode) {
|
|
||||||
stopLazyMode();
|
|
||||||
}
|
|
||||||
this.sortType = sortType;
|
|
||||||
mPostViewModel.changeSortType(sortType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSwipeActionDrawable() {
|
private void initializeSwipeActionDrawable() {
|
||||||
@ -1127,6 +1225,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]);
|
mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]);
|
||||||
}
|
}
|
||||||
outState.putParcelable(POST_FILTER_STATE, postFilter);
|
outState.putParcelable(POST_FILTER_STATE, postFilter);
|
||||||
|
outState.putString(CONCATENATED_SUBREDDIT_NAMES_STATE, concatenatedSubredditNames);
|
||||||
outState.putLong(POST_FRAGMENT_ID_STATE, postFragmentId);
|
outState.putLong(POST_FRAGMENT_ID_STATE, postFragmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1150,14 +1249,18 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mAdapter.removeFooter();
|
if (mPostViewModel != null) {
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mAdapter.removeFooter();
|
||||||
hasPost = false;
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
if (isInLazyMode) {
|
hasPost = false;
|
||||||
stopLazyMode();
|
if (isInLazyMode) {
|
||||||
|
stopLazyMode();
|
||||||
|
}
|
||||||
|
saveCache();
|
||||||
|
mPostViewModel.refresh();
|
||||||
|
} else {
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
saveCache();
|
|
||||||
mPostViewModel.refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorView(int stringResId) {
|
private void showErrorView(int stringResId) {
|
||||||
@ -1321,7 +1424,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
@Override
|
@Override
|
||||||
public void changePostFilter(PostFilter postFilter) {
|
public void changePostFilter(PostFilter postFilter) {
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null || accountName.equals("-") ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
if (mPostViewModel != null) {
|
if (mPostViewModel != null) {
|
||||||
mPostViewModel.changePostFilter(postFilter);
|
mPostViewModel.changePostFilter(postFilter);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
public static final int TYPE_USER = 2;
|
public static final int TYPE_USER = 2;
|
||||||
public static final int TYPE_SEARCH = 3;
|
public static final int TYPE_SEARCH = 3;
|
||||||
public static final int TYPE_MULTI_REDDIT = 4;
|
public static final int TYPE_MULTI_REDDIT = 4;
|
||||||
|
public static final int TYPE_ANONYMOUS_FRONT_PAGE = 5;
|
||||||
|
|
||||||
public static final String USER_WHERE_SUBMITTED = "submitted";
|
public static final String USER_WHERE_SUBMITTED = "submitted";
|
||||||
public static final String USER_WHERE_UPVOTED = "upvoted";
|
public static final String USER_WHERE_UPVOTED = "upvoted";
|
||||||
@ -86,7 +87,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
if (postType == TYPE_SUBREDDIT) {
|
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
this.subredditOrUserName = path;
|
this.subredditOrUserName = path;
|
||||||
} else {
|
} else {
|
||||||
if (sortType != null) {
|
if (sortType != null) {
|
||||||
@ -196,6 +197,8 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
case TYPE_MULTI_REDDIT:
|
case TYPE_MULTI_REDDIT:
|
||||||
loadMultiRedditPostsInitial(callback, null);
|
loadMultiRedditPostsInitial(callback, null);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +234,8 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
case TYPE_MULTI_REDDIT:
|
case TYPE_MULTI_REDDIT:
|
||||||
loadMultiRedditPostsAfter(params, callback, null);
|
loadMultiRedditPostsAfter(params, callback, null);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -918,6 +923,120 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadAnonymousFrontPagePostsInitial(@NonNull final LoadInitialCallback<String, Post> callback, String lastItem) {
|
||||||
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
|
Call<String> getPost;
|
||||||
|
if (sortType.getTime() != null) {
|
||||||
|
getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, sortType.getTime().value, lastItem);
|
||||||
|
} else {
|
||||||
|
getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, lastItem);
|
||||||
|
}
|
||||||
|
getPost.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
ParsePost.parsePosts(response.body(), -1, postFilter, null,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
|
@Override
|
||||||
|
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
|
||||||
|
String nextPageKey;
|
||||||
|
if (lastItem == null || lastItem.equals("") || lastItem.equals("null")) {
|
||||||
|
nextPageKey = null;
|
||||||
|
} else {
|
||||||
|
nextPageKey = lastItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPosts.size() != 0) {
|
||||||
|
postLinkedHashSet.addAll(newPosts);
|
||||||
|
callback.onResult(new ArrayList<>(newPosts), null, nextPageKey);
|
||||||
|
hasPostLiveData.postValue(true);
|
||||||
|
} else if (nextPageKey != null) {
|
||||||
|
loadAnonymousFrontPagePostsInitial(callback, nextPageKey);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
postLinkedHashSet.addAll(newPosts);
|
||||||
|
callback.onResult(new ArrayList<>(newPosts), null, nextPageKey);
|
||||||
|
hasPostLiveData.postValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onParsePostsListingFail() {
|
||||||
|
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED,
|
||||||
|
"code: " + response + " message: " + response.message()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
String errorMessage = t.getMessage();
|
||||||
|
initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED,
|
||||||
|
errorMessage + " " + call.request().url().toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAnonymousFrontPagePostsAfter(@NonNull LoadParams<String> params, @NonNull final LoadCallback<String, Post> callback, String lastItem) {
|
||||||
|
String after = lastItem == null ? params.key : lastItem;
|
||||||
|
|
||||||
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
|
Call<String> getPost;
|
||||||
|
if (sortType.getTime() != null) {
|
||||||
|
getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value,
|
||||||
|
sortType.getTime().value, after);
|
||||||
|
} else {
|
||||||
|
getPost = api.getSubredditBestPosts(subredditOrUserName, sortType.getType().value, after);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPost.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
ParsePost.parsePosts(response.body(), -1, postFilter, null,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
|
@Override
|
||||||
|
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
|
||||||
|
if (newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
||||||
|
loadAnonymousFrontPagePostsAfter(params, callback, lastItem);
|
||||||
|
} else {
|
||||||
|
int currentPostsSize = postLinkedHashSet.size();
|
||||||
|
postLinkedHashSet.addAll(newPosts);
|
||||||
|
if (currentPostsSize == postLinkedHashSet.size()) {
|
||||||
|
loadAnonymousFrontPagePostsAfter(params, callback, lastItem);
|
||||||
|
} else {
|
||||||
|
List<Post> newPostsList = new ArrayList<>(postLinkedHashSet).subList(currentPostsSize, postLinkedHashSet.size());
|
||||||
|
callback.onResult(newPostsList, lastItem);
|
||||||
|
}
|
||||||
|
paginationNetworkStateLiveData.postValue(NetworkState.LOADED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onParsePostsListingFail() {
|
||||||
|
paginationNetworkStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
paginationNetworkStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
String errorMessage = t.getMessage();
|
||||||
|
paginationNetworkStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, errorMessage));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void retryLoadingMore() {
|
void retryLoadingMore() {
|
||||||
loadAfter(params, callback);
|
loadAfter(params, callback);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
private String accountName;
|
private String accountName;
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||||
private String subredditName;
|
private String name;
|
||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private SortType sortType;
|
private SortType sortType;
|
||||||
@ -49,14 +49,14 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String subredditName, int postType, SortType sortType, PostFilter postFilter,
|
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||||
List<ReadPost> readPostList) {
|
List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = name;
|
||||||
postDataSourceLiveData = new MutableLiveData<>();
|
postDataSourceLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
@ -66,14 +66,14 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String subredditName, int postType, SortType sortType, PostFilter postFilter,
|
String name, int postType, SortType sortType, PostFilter postFilter,
|
||||||
String where, List<ReadPost> readPostList) {
|
String where, List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = name;
|
||||||
postDataSourceLiveData = new MutableLiveData<>();
|
postDataSourceLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
@ -84,14 +84,14 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String subredditName, String query, int postType, SortType sortType, PostFilter postFilter,
|
String name, String query, int postType, SortType sortType, PostFilter postFilter,
|
||||||
List<ReadPost> readPostList) {
|
List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = name;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
postDataSourceLiveData = new MutableLiveData<>();
|
postDataSourceLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
@ -109,16 +109,20 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
postFilter, readPostList);
|
postFilter, readPostList);
|
||||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, query,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query,
|
||||||
postType, sortType, postFilter, readPostList);
|
postType, sortType, postFilter, readPostList);
|
||||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||||
Log.i("asdasfd", "s5 " + (postFilter == null));
|
Log.i("asdasfd", "s5 " + (postFilter == null));
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||||
sortType, postFilter, readPostList);
|
sortType, postFilter, readPostList);
|
||||||
|
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
|
postDataSource = new PostDataSource(retrofit, null, null,
|
||||||
|
sharedPreferences, null, name, postType,
|
||||||
|
sortType, postFilter, null);
|
||||||
} else {
|
} else {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
postDataSource = new PostDataSource(retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||||
sortType, postFilter, userWhere, readPostList);
|
sortType, postFilter, userWhere, readPostList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, String accountName,
|
public PostViewModel(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
|
SharedPreferences sharedPreferences, SharedPreferences cache, String username,
|
||||||
int postType, SortType sortType, PostFilter postFilter, String where,
|
int postType, SortType sortType, PostFilter postFilter, String where,
|
||||||
List<ReadPost> readPostList) {
|
List<ReadPost> readPostList) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName,
|
||||||
sharedPreferences, cache, subredditName, postType, sortType, postFilter, where, readPostList);
|
sharedPreferences, cache, username, postType, sortType, postFilter, where, readPostList);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::getInitialLoadStateLiveData);
|
PostDataSource::getInitialLoadStateLiveData);
|
||||||
@ -205,7 +205,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
private String accountName;
|
private String accountName;
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||||
private String subredditName;
|
private String name;
|
||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private SortType sortType;
|
private SortType sortType;
|
||||||
@ -229,14 +229,14 @@ public class PostViewModel extends ViewModel {
|
|||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences,
|
SharedPreferences sharedPreferences,
|
||||||
SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
|
SharedPreferences postFeedScrolledPositionSharedPreferences, String name,
|
||||||
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = name;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
@ -245,14 +245,14 @@ public class PostViewModel extends ViewModel {
|
|||||||
|
|
||||||
//User posts
|
//User posts
|
||||||
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String username,
|
||||||
int postType, SortType sortType, PostFilter postFilter, String where, List<ReadPost> readPostList) {
|
int postType, SortType sortType, PostFilter postFilter, String where, List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = username;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
@ -261,14 +261,14 @@ public class PostViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
public Factory(Retrofit retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String name,
|
||||||
String query, int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
String query, int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
this.subredditName = subredditName;
|
this.name = name;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
@ -276,6 +276,17 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Anonymous Front Page
|
||||||
|
public Factory(Retrofit retrofit, SharedPreferences sharedPreferences, String concatenatedSubredditNames,
|
||||||
|
int postType, SortType sortType, PostFilter postFilter) {
|
||||||
|
this.retrofit = retrofit;
|
||||||
|
this.sharedPreferences = sharedPreferences;
|
||||||
|
this.name = concatenatedSubredditNames;
|
||||||
|
this.postType = postType;
|
||||||
|
this.sortType = sortType;
|
||||||
|
this.postFilter = postFilter;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
@ -284,15 +295,19 @@ public class PostViewModel extends ViewModel {
|
|||||||
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
|
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
|
||||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
|
postFeedScrolledPositionSharedPreferences, name, query, postType, sortType,
|
||||||
postFilter, readPostList);
|
postFilter, readPostList);
|
||||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||||
postFilter, readPostList);
|
postFilter, readPostList);
|
||||||
|
} else if (postType == PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
|
return (T) new PostViewModel(retrofit, null, null, sharedPreferences,
|
||||||
|
null, name, postType, sortType,
|
||||||
|
postFilter, null);
|
||||||
} else {
|
} else {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
|
postFeedScrolledPositionSharedPreferences, name, postType, sortType,
|
||||||
postFilter, userWhere, readPostList);
|
postFilter, userWhere, readPostList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1035,4 +1035,6 @@
|
|||||||
|
|
||||||
<string name="vote">Vote</string>
|
<string name="vote">Vote</string>
|
||||||
|
|
||||||
|
<string name="anonymous_front_page_no_subscriptions">Start by joining a subreddit!</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user