diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-11-11 07:27:11 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-11-11 07:27:11 +0000 |
commit | d7928436fea370395f389563f7c89e67e6853819 (patch) | |
tree | efd187d5b84badcf1d84e864e35210d9ff25228e /app/src/main/java/ml | |
parent | a3ae945e3937b4bba6201f7088a805b9cc8b6629 (diff) | |
download | infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar.gz infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar.bz2 infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar.lz infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar.xz infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.tar.zst infinity-for-reddit-d7928436fea370395f389563f7c89e67e6853819.zip |
Changing post layout in other activities is available. Show username in card layout posts.
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 110 insertions, 16 deletions
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; } @@ -369,6 +377,26 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec } @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(); bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType); 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<Post, RecyclerView } }); + ((PostViewHolder) holder).subredditTextView.setText(subredditNamePrefixed); + ((PostViewHolder) holder).userTextView.setText(authorPrefixed); + ((PostViewHolder) holder).userTextView.setOnClickListener(view -> { + 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<Post, RecyclerView } } - ((PostViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent)); - ((PostViewHolder) holder).nameTextView.setText(subredditNamePrefixed); + ((PostViewHolder) holder).subredditTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent)); - ((PostViewHolder) holder).nameTextView.setOnClickListener(view -> { + ((PostViewHolder) holder).subredditTextView.setOnClickListener(view -> { if (canStartActivity) { canStartActivity = false; if (post.getSubredditNamePrefixed().startsWith("u/")) { @@ -270,7 +280,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView }); ((PostViewHolder) holder).iconGifImageView.setOnClickListener(view -> - ((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<Post, RecyclerView .into(((PostViewHolder) holder).iconGifImageView); } - ((PostViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme)); - ((PostViewHolder) holder).nameTextView.setText(authorPrefixed); + ((PostViewHolder) holder).subredditTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme)); - ((PostViewHolder) holder).nameTextView.setOnClickListener(view -> { + ((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<Post, RecyclerView }); ((PostViewHolder) holder).iconGifImageView.setOnClickListener(view -> - ((PostViewHolder) holder).nameTextView.performClick()); + ((PostViewHolder) holder).subredditTextView.performClick()); } ((PostViewHolder) holder).postTimeTextView.setText(postTime); @@ -1392,7 +1401,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView @BindView(R.id.icon_gif_image_view_item_post) AspectRatioGifImageView iconGifImageView; @BindView(R.id.name_text_view_item_post) - TextView nameTextView; + TextView subredditTextView; + @BindView(R.id.user_text_view_item_post) + TextView userTextView; @BindView(R.id.stickied_post_image_view_item_post) ImageView stickiedPostImageView; @BindView(R.id.post_time_text_view_best_item_post) |