From d7928436fea370395f389563f7c89e67e6853819 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 11 Nov 2019 15:27:11 +0800 Subject: Changing post layout in other activities is available. Show username in card layout posts. --- .../Activity/AccountPostsActivity.java | 17 +++++++++++- .../Activity/FilteredThingActivity.java | 30 +++++++++++++++++++++- .../Activity/SearchResultActivity.java | 22 +++++++++++++++- .../Activity/ViewSubredditDetailActivity.java | 7 ++--- .../Activity/ViewUserDetailActivity.java | 21 ++++++++++++++- .../Adapter/PostRecyclerViewAdapter.java | 29 ++++++++++++++------- app/src/main/res/layout/item_post.xml | 18 ++++++++++++- app/src/main/res/menu/account_posts_activity.xml | 6 +++++ app/src/main/res/menu/filtered_posts_activity.xml | 6 +++++ app/src/main/res/menu/search_result_activity.xml | 6 +++++ .../main/res/menu/view_user_detail_activity.xml | 6 +++++ 11 files changed, 151 insertions(+), 17 deletions(-) (limited to 'app') 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 96c2af3a..c760160e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -31,6 +31,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; +import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; @@ -40,7 +41,7 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; -public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback { +public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { static final String EXTRA_USER_WHERE = "EUW"; @@ -68,6 +69,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect private Fragment mFragment; private Menu mMenu; private AppBarLayout.LayoutParams params; + private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -139,6 +141,8 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); + postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + if (savedInstanceState != null) { mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); @@ -229,6 +233,9 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect } } return true; + case R.id.action_change_post_layout_account_posts_activity: + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + return true; case android.R.id.home: finish(); return true; @@ -275,4 +282,12 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) { ((FragmentCommunicator) mFragment).changeNSFW(changeNSFWEvent.nsfw); } + + @Override + public void postLayoutSelected(int postLayout) { + if (mFragment != null) { + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, 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 1f6fc1e3..e797ab33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -30,6 +30,7 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; +import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; @@ -44,7 +45,8 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; -public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback { +public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback, + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_QUERY = "EQ"; @@ -82,6 +84,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; + private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -169,6 +172,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec } else { getCurrentAccountAndBindView(filter); } + + postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); } @Override @@ -344,6 +349,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec } } return true; + case R.id.action_change_post_layout_filtered_post_activity: + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + return true; } return false; } @@ -368,6 +376,26 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec ((PostFragment) mFragment).changeSortType(sortType); } + @Override + public void postLayoutSelected(int postLayout) { + if (mFragment != null) { + switch (postType) { + case PostDataSource.TYPE_FRONT_PAGE: + 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(); + break; + case PostDataSource.TYPE_USER: + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply(); + break; + case PostDataSource.TYPE_SEARCH: + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); + } + ((FragmentCommunicator) mFragment).changePostLayout(postLayout); + } + } + @Override public void sortTypeSelected(String sortType) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index 1d43edd0..458506de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; +import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment; @@ -49,7 +50,8 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; -public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback { +public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback, + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { static final String EXTRA_QUERY = "QK"; static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -77,6 +79,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment; + private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -153,6 +156,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment(); + postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + // Get the intent, verify the action and get the query Intent intent = getIntent(); String query = intent.getStringExtra(EXTRA_QUERY); @@ -226,6 +231,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect case R.id.action_refresh_search_result_activity: sectionsPagerAdapter.refresh(); return true; + case R.id.action_change_post_layout_search_result_activity: + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + return true; } return super.onOptionsItemSelected(item); } @@ -262,6 +270,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect sectionsPagerAdapter.changeSortType(sortType, fragmentPosition); } + @Override + public void postLayoutSelected(int postLayout) { + sectionsPagerAdapter.changePostLayout(postLayout); + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { finish(); @@ -395,5 +408,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect postFragment.changeNSFW(nsfw); } } + + void changePostLayout(int postLayout) { + if (postFragment != null) { + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); + ((FragmentCommunicator) postFragment).changePostLayout(postLayout); + } + } } } 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 4d0e7fab..45731b52 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -507,7 +507,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, false); intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false); startActivity(intent); - break; + return true; case R.id.action_refresh_view_subreddit_detail_activity: if (mMenu != null) { mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode); @@ -517,7 +517,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp mFetchSubredditInfoSuccess = false; fetchSubredditData(); } - break; + return true; case R.id.action_lazy_mode_view_subreddit_detail_activity: MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity); if (isInLazyMode) { @@ -538,9 +538,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp isInLazyMode = false; } } - break; + return true; case R.id.action_change_post_layout_view_subreddit_detail_activity: postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + return true; } return false; } 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 9bd6788e..de6cbd9a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchUserData; import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; +import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.FragmentCommunicator; @@ -74,7 +75,8 @@ import ml.docilealligator.infinityforreddit.UserFollowing; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback { +public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback, + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { public static final String EXTRA_USER_NAME_KEY = "EUNK"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -126,6 +128,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele private AppBarLayout.LayoutParams params; private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; + private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private boolean mNullAccessToken = false; private String mAccessToken; private String mAccountName; @@ -390,6 +393,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); + postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); } @Override @@ -579,6 +583,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } return true; + case R.id.action_change_post_layout_view_user_detail_activity: + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + return true; } return false; } @@ -627,6 +634,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag()); } + @Override + public void postLayoutSelected(int postLayout) { + sectionsPagerAdapter.changePostLayout(postLayout); + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { if (!getClass().getName().equals(event.excludeActivityClassName)) { @@ -793,5 +805,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele postFragment.changeNSFW(nsfw); } } + + void changePostLayout(int postLayout) { + if (postFragment != null) { + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, 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 b2d03d13..09a5bcad 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -181,6 +181,17 @@ 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 (mDisplaySubredditName) { if (authorPrefixed.equals(subredditNamePrefixed)) { if (post.getAuthorIconUrl() == null) { @@ -249,10 +260,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + ((PostViewHolder) holder).subredditTextView.setOnClickListener(view -> { if (canStartActivity) { canStartActivity = false; if (post.getSubredditNamePrefixed().startsWith("u/")) { @@ -270,7 +280,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter - ((PostViewHolder) holder).nameTextView.performClick()); + ((PostViewHolder) holder).subredditTextView.performClick()); } else { if (post.getAuthorIconUrl() == null) { String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor(); @@ -305,10 +315,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + ((PostViewHolder) holder).subredditTextView.setOnClickListener(view -> { if (canStartActivity) { canStartActivity = false; Intent intent = new Intent(mContext, ViewUserDetailActivity.class); @@ -318,7 +327,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter - ((PostViewHolder) holder).nameTextView.performClick()); + ((PostViewHolder) holder).subredditTextView.performClick()); } ((PostViewHolder) holder).postTimeTextView.setText(postTime); @@ -1392,7 +1401,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/filtered_posts_activity.xml b/app/src/main/res/menu/filtered_posts_activity.xml index d918f896..3cebab6c 100644 --- a/app/src/main/res/menu/filtered_posts_activity.xml +++ b/app/src/main/res/menu/filtered_posts_activity.xml @@ -20,4 +20,10 @@ android:orderInCategory="3" android:title="@string/action_start_lazy_mode" app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/search_result_activity.xml b/app/src/main/res/menu/search_result_activity.xml index 0fc7a1fe..b6c9dd3f 100644 --- a/app/src/main/res/menu/search_result_activity.xml +++ b/app/src/main/res/menu/search_result_activity.xml @@ -20,4 +20,10 @@ android:orderInCategory="3" android:title="@string/action_refresh" app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/view_user_detail_activity.xml b/app/src/main/res/menu/view_user_detail_activity.xml index 51db8d2f..51d2f61e 100644 --- a/app/src/main/res/menu/view_user_detail_activity.xml +++ b/app/src/main/res/menu/view_user_detail_activity.xml @@ -26,4 +26,10 @@ android:orderInCategory="4" android:title="@string/action_start_lazy_mode" app:showAsAction="never" /> + + -- cgit v1.2.3