diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-04-08 08:39:30 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-04-08 08:39:30 +0000 |
commit | e7da8c1f692745255753d30fc74720f8494e576c (patch) | |
tree | 1a01ea77abbc9617db8668c96c5ad9f83a97f248 | |
parent | 8c8dc45f190ac14a71f9210cf2b4db295f7f951b (diff) | |
download | infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar.gz infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar.bz2 infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar.lz infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar.xz infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.tar.zst infinity-for-reddit-e7da8c1f692745255753d30fc74720f8494e576c.zip |
Bottom app bar is available in ViewMultiRedditDetailActivity.
5 files changed, 311 insertions, 23 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index b394de78..395d1da5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -3,11 +3,14 @@ package ml.docilealligator.infinityforreddit.activities; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.ColorStateList; +import android.graphics.PorterDuff; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; +import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -15,6 +18,8 @@ import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; +import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.Toast; import androidx.annotation.NonNull; @@ -25,12 +30,14 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.textfield.TextInputEditText; import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; import java.util.concurrent.Executor; @@ -45,6 +52,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; @@ -58,7 +66,9 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.RandomBottomShe import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent; +import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.multireddit.DeleteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -78,7 +88,7 @@ import retrofit2.Retrofit; public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface, PostTypeBottomSheetFragment.PostTypeSelectionCallback, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, - RandomBottomSheetFragment.RandomOptionSelectionCallback { + RandomBottomSheetFragment.RandomOptionSelectionCallback, RecyclerViewContentScrollingInterface { public static final String EXTRA_MULTIREDDIT_DATA = "EMD"; public static final String EXTRA_MULTIREDDIT_PATH = "EMP"; @@ -93,6 +103,18 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_view_multi_reddit_detail_activity) Toolbar toolbar; + @BindView(R.id.bottom_app_bar_bottom_app_bar) + BottomAppBar bottomNavigationView; + @BindView(R.id.linear_layout_bottom_app_bar) + LinearLayout linearLayoutBottomAppBar; + @BindView(R.id.option_1_bottom_app_bar) + ImageView option1BottomAppBar; + @BindView(R.id.option_2_bottom_app_bar) + ImageView option2BottomAppBar; + @BindView(R.id.option_3_bottom_app_bar) + ImageView option3BottomAppBar; + @BindView(R.id.option_4_bottom_app_bar) + ImageView option4BottomAppBar; @BindView(R.id.fab_view_multi_reddit_detail_activity) FloatingActionButton fab; @Inject @@ -122,6 +144,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Named("nsfw_and_spoiler") SharedPreferences mNsfwAndSpoilerSharedPreferences; @Inject + @Named("bottom_app_bar") + SharedPreferences mBottomAppBarSharedPreference; + @Inject CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; @@ -129,10 +154,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT private String mAccountName; private String multiPath; private Fragment mFragment; - private SortTypeBottomSheetFragment sortTypeBottomSheetFragment; - private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; - private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private int fabOption; + private boolean showBottomAppBar; + private boolean lockBottomAppBar; private Call<String> subredditAutocompleteCall; @Override @@ -143,6 +167,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT ButterKnife.bind(this); + EventBus.getDefault().register(this); + applyCustomTheme(); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { @@ -171,6 +197,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); params.bottomMargin += navBarHeight; fab.setLayoutParams(params); + bottomNavigationView.setPadding(0, 0, 0, navBarHeight); } } } @@ -196,6 +223,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); + showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false); + lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); if (savedInstanceState != null) { mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); @@ -204,14 +233,59 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT initializeFragment(); } - sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle bottomSheetBundle = new Bundle(); - bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); + if (showBottomAppBar) { + int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); + int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + + bottomNavigationView.setVisibility(View.VISIBLE); + + if (optionCount == 2) { + linearLayoutBottomAppBar.setWeightSum(3); + option1BottomAppBar.setVisibility(View.GONE); + option3BottomAppBar.setVisibility(View.GONE); - sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); + option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); + option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); - postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); + }); + + option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); + }); + } else { + int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); + + option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); + option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); + option3BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option3)); + option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option4)); + + option1BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); + }); + + option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); + }); + + option3BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option3); + }); + + option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option4); + }); + } + } else { + CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + lp.setAnchorId(View.NO_ID); + lp.gravity = Gravity.END | Gravity.BOTTOM; + fab.setLayoutParams(lp); + } fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { @@ -265,12 +339,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT break; } case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + showSortTypeBottomSheetFragment(); break; } case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { - PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); - postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + showPostLayoutBottomSheetFragment(); break; } case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: { @@ -324,6 +397,175 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit(); } + private void bottomAppBarOptionAction(int option) { + switch (option) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME: { + EventBus.getDefault().post(new GoBackToMainPageEvent()); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS: { + Intent intent = new Intent(this, SubscribedThingListingActivity.class); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX: { + Intent intent = new Intent(this, InboxActivity.class); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE: { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS: { + Intent intent = new Intent(this, SubscribedThingListingActivity.class); + intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH: { + if (mFragment instanceof PostFragment) { + ((PostFragment) mFragment).refresh(); + } + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE: { + showSortTypeBottomSheetFragment(); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT: { + showPostLayoutBottomSheetFragment(); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH: { + Intent intent = new Intent(this, SearchActivity.class); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT: + goToSubreddit(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_USER: + goToUser(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_RANDOM: + random(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HIDE_READ_POSTS: + if (mFragment instanceof PostFragment) { + ((PostFragment) mFragment).hideReadPosts(); + } + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_FILTER_POSTS: + if (mFragment instanceof PostFragment) { + ((PostFragment) mFragment).filterPosts(); + } + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_UPVOTED: { + Intent intent = new Intent(this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_DOWNVOTED: { + Intent intent = new Intent(this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HIDDEN: { + Intent intent = new Intent(this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SAVED: { + Intent intent = new Intent(this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GILDED: { + Intent intent = new Intent(this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_TOP: { + if (mFragment instanceof PostFragment) { + ((PostFragment) mFragment).goBackToTop(); + } + break; + } + default: + PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); + postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); + break; + } + } + + private int getBottomAppBarOptionDrawableResource(int option) { + switch (option) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME: + return R.drawable.ic_home_black_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS: + return R.drawable.ic_subscritptions_bottom_app_bar_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX: + return R.drawable.ic_inbox_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS: + return R.drawable.ic_multi_reddit_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBMIT_POSTS: + return R.drawable.ic_add_day_night_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH: + return R.drawable.ic_refresh_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE: + return R.drawable.ic_sort_toolbar_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT: + return R.drawable.ic_post_layout_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH: + return R.drawable.ic_search_black_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT: + return R.drawable.ic_subreddit_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_USER: + return R.drawable.ic_user_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_RANDOM: + return R.drawable.ic_random_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HIDE_READ_POSTS: + return R.drawable.ic_hide_read_posts_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_FILTER_POSTS: + return R.drawable.ic_filter_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_UPVOTED: + return R.drawable.ic_arrow_upward_black_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_DOWNVOTED: + return R.drawable.ic_arrow_downward_black_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HIDDEN: + return R.drawable.ic_outline_lock_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SAVED: + return R.drawable.ic_outline_bookmarks_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GILDED: + return R.drawable.ic_star_border_24dp; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_TOP: + return R.drawable.ic_keyboard_double_arrow_up_24; + default: + return R.drawable.ic_account_circle_24dp; + } + } + + private void showSortTypeBottomSheetFragment() { + SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); + Bundle bottomSheetBundle = new Bundle(); + bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); + sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + } + + private void showPostLayoutBottomSheetFragment() { + PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + } + private void goToSubreddit() { View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false); TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text); @@ -492,7 +734,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT finish(); return true; } else if (itemId == R.id.action_sort_view_multi_reddit_detail_activity) { - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + showSortTypeBottomSheetFragment(); return true; } else if (itemId == R.id.action_search_view_multi_reddit_detail_activity) { Intent intent = new Intent(this, SearchActivity.class); @@ -504,7 +746,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } return true; } else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) { - postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + showPostLayoutBottomSheetFragment(); return true; } else if (itemId == R.id.action_edit_view_multi_reddit_detail_activity) { Intent editIntent = new Intent(this, EditMultiRedditActivity.class); @@ -556,6 +798,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } @Override + protected void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + } + + @Override public void sortTypeSelected(SortType sortType) { ((PostFragment) mFragment).changeSortType(sortType); displaySortType(); @@ -563,6 +811,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void sortTypeSelected(String sortType) { + SortTimeBottomSheetFragment sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType); sortTimeBottomSheetFragment.setArguments(bundle); @@ -591,6 +840,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); + bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); + int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyFABTheme(fab); } @@ -657,11 +912,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } break; case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE: - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + showSortTypeBottomSheetFragment(); break; case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT: - PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); - postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + showPostLayoutBottomSheetFragment(); break; case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH: Intent intent = new Intent(this, SearchActivity.class); @@ -700,4 +954,36 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT intent.putExtra(FetchRandomSubredditOrPostActivity.EXTRA_RANDOM_OPTION, option); startActivity(intent); } + + @Override + public void contentScrollUp() { + if (showBottomAppBar && !lockBottomAppBar) { + bottomNavigationView.performShow(); + } + if (!(showBottomAppBar && lockBottomAppBar)) { + fab.show(); + } + } + + @Override + public void contentScrollDown() { + if (!(showBottomAppBar && lockBottomAppBar)) { + fab.hide(); + } + if (showBottomAppBar && !lockBottomAppBar) { + bottomNavigationView.performHide(); + } + } + + @Subscribe + public void goBackToMainPageEvent(GoBackToMainPageEvent event) { + finish(); + } + + @Subscribe + public void onAccountSwitchEvent(SwitchAccountEvent event) { + if (!getClass().getName().equals(event.excludeActivityClassName)) { + finish(); + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 48f43088..977bf742 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -887,8 +887,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; }); - - fab.setVisibility(View.VISIBLE); } private void bottomAppBarOptionAction(int option) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index cf973379..f6efaf04 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -20,7 +20,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.paging.PagedListAdapter; diff --git a/app/src/main/res/layout/activity_view_multi_reddit_detail.xml b/app/src/main/res/layout/activity_view_multi_reddit_detail.xml index 460dcd04..21521bb0 100644 --- a/app/src/main/res/layout/activity_view_multi_reddit_detail.xml +++ b/app/src/main/res/layout/activity_view_multi_reddit_detail.xml @@ -39,11 +39,17 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + <include + layout="@layout/bottom_app_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" /> + <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab_view_multi_reddit_detail_activity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" - android:layout_gravity="bottom|end" /> + app:layout_anchor="@id/bottom_app_bar_bottom_app_bar" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml index 203f53ff..680a4af5 100644 --- a/app/src/main/res/layout/activity_view_user_detail.xml +++ b/app/src/main/res/layout/activity_view_user_detail.xml @@ -151,7 +151,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" - android:visibility="gone" app:layout_anchor="@id/bottom_app_bar_bottom_app_bar" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file |