From 74ae9a8b683fd1550a01ac6c2e3f1241c80464e9 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 12 Nov 2019 00:24:35 +0800 Subject: Set post layout for subreddit and user posts individually. --- .../Activity/AccountPostsActivity.java | 2 +- .../Activity/FilteredThingActivity.java | 4 ++-- .../Activity/ViewSubredditDetailActivity.java | 2 +- .../Activity/ViewUserDetailActivity.java | 2 +- .../Adapter/PostRecyclerViewAdapter.java | 21 ++++++++++++--------- .../infinityforreddit/Fragment/PostFragment.java | 4 ++-- .../infinityforreddit/SharedPreferencesUtils.java | 4 ++-- app/src/main/res/layout/item_post_compact.xml | 8 ++++---- app/src/main/res/values/attr.xml | 1 + app/src/main/res/values/styles.xml | 4 ++++ 10 files changed, 30 insertions(+), 22 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index c760160e..a2a48e35 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -286,7 +286,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Override public void postLayoutSelected(int postLayout) { if (mFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply(); ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index e797ab33..68ec15d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -384,10 +384,10 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); break; case PostDataSource.TYPE_SUBREDDIT: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply(); break; case PostDataSource.TYPE_USER: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply(); break; case PostDataSource.TYPE_SEARCH: mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index 45731b52..c0628bb4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -626,7 +626,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void postLayoutSelected(int postLayout) { if (mFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply(); ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index de6cbd9a..133e6875 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -808,7 +808,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele void changePostLayout(int postLayout) { if (postFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply(); ((FragmentCommunicator) postFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 09a5bcad..6e6649c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -260,8 +260,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (canStartActivity) { canStartActivity = false; @@ -273,7 +271,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (canStartActivity) { canStartActivity = false; - Intent intent = new Intent(mContext, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor()); - mContext.startActivity(intent); + if (post.getSubredditNamePrefixed().startsWith("u/")) { + Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor()); + mContext.startActivity(intent); + } else { + Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, + post.getSubredditName()); + mContext.startActivity(intent); + } } }); ((PostViewHolder) holder).iconGifImageView.setOnClickListener(view -> - ((PostViewHolder) holder).subredditTextView.performClick()); + ((PostViewHolder) holder).userTextView.performClick()); } ((PostViewHolder) holder).postTimeTextView.setText(postTime); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 5651ac0b..1a3ea761 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -345,7 +345,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, SharedPreferencesUtils.POST_LAYOUT_CARD); } if(sortTime != null) { @@ -398,7 +398,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else { sortType = new SortType(SortType.Type.valueOf(sort)); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, SharedPreferencesUtils.POST_LAYOUT_CARD); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index 1fd5c9f9..f1aa91cd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -50,8 +50,8 @@ public class SharedPreferencesUtils { public static final String POST_LAYOUT_FRONT_PAGE_POST = "post_layout_best_post"; public static final String POST_LAYOUT_POPULAR_POST = "post_layout_popular_post"; public static final String POST_LAYOUT_ALL_POST = "post_layout_all_post"; - public static final String POST_LAYOUT_SUBREDDIT_POST = "post_layout_subreddit_post"; - public static final String POST_LAYOUT_USER_POST = "post_layout_user_post"; + public static final String POST_LAYOUT_SUBREDDIT_POST_BASE = "post_layout_subreddit_post_"; + public static final String POST_LAYOUT_USER_POST_BASE = "post_layout_user_post_"; public static final String POST_LAYOUT_SEARCH_POST = "post_layout_search_post"; public static final int POST_LAYOUT_CARD = 0; public static final int POST_LAYOUT_COMPACT = 1; diff --git a/app/src/main/res/layout/item_post_compact.xml b/app/src/main/res/layout/item_post_compact.xml index dc0f5876..ecef2387 100644 --- a/app/src/main/res/layout/item_post_compact.xml +++ b/app/src/main/res/layout/item_post_compact.xml @@ -113,7 +113,7 @@ android:layout_height="wrap_content" android:padding="4dp" android:textColor="@android:color/white" - android:textSize="?attr/font_12" + android:textSize="?attr/font_10" app:lib_setRadius="3dp" app:lib_setRoundedBGColor="@color/backgroundColorPrimaryDark" app:lib_setRoundedBorderColor="@color/backgroundColorPrimaryDark" @@ -128,7 +128,7 @@ android:padding="4dp" android:text="@string/spoiler" android:textColor="@android:color/white" - android:textSize="?attr/font_12" + android:textSize="?attr/font_10" android:visibility="gone" app:lib_setRadius="3dp" app:lib_setRoundedBGColor="@color/spoilerBackgroundColor" @@ -143,7 +143,7 @@ android:padding="4dp" android:text="@string/nsfw" android:textColor="@android:color/white" - android:textSize="?attr/font_12" + android:textSize="?attr/font_10" android:visibility="gone" app:lib_setRadius="3dp" app:lib_setRoundedBGColor="@color/colorAccent" @@ -158,7 +158,7 @@ android:layout_gravity="center" android:padding="4dp" android:textColor="@android:color/white" - android:textSize="?attr/font_12" + android:textSize="?attr/font_10" android:visibility="gone" app:lib_setRadius="3dp" app:lib_setRoundedBGColor="@color/flairBackgroundColor" diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index bd522e6e..37fc5341 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -4,6 +4,7 @@ + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 698057fd..57a528fd 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -95,6 +95,7 @@