diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-25 11:05:17 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-25 11:05:17 +0000 |
commit | 878328c01c309c3cd9b79eb832c6070df4ef2afd (patch) | |
tree | c7b5237bccfe7189c20172efc09d28d0be6e1ba9 /app/src/main/java | |
parent | 8764852f6e2c0b7896df9613200086af56f180ab (diff) | |
download | infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar.gz infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar.bz2 infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar.lz infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar.xz infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.tar.zst infinity-for-reddit-878328c01c309c3cd9b79eb832c6070df4ef2afd.zip |
Customizing bottom app bar and fab in ViewSubredditDetailActivity is available.
Diffstat (limited to 'app/src/main/java')
3 files changed, 167 insertions, 39 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 4103ee15..66689f59 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -250,8 +250,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb int navBarHeight = getNavBarHeight(); if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin += navBarHeight; + fab.setLayoutParams(params); linearLayoutBottomAppBar.setPadding(0, - (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight); + linearLayoutBottomAppBar.getPaddingTop(), 0, navBarHeight); navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight); } } @@ -449,12 +452,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb private void bottomAppBarOptionAction(int option) { switch (option) { case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS: { - Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + Intent intent = new Intent(this, SubscribedThingListingActivity.class); startActivity(intent); break; } case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS: { - Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + Intent intent = new Intent(this, SubscribedThingListingActivity.class); intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); startActivity(intent); break; 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 8089a65b..79c881fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -141,14 +141,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp BottomAppBar bottomNavigationView; @BindView(R.id.linear_layout_bottom_app_bar_view_subreddit_detail_activity) LinearLayout linearLayoutBottomAppBar; - @BindView(R.id.subscriptions_bottom_app_bar_view_subreddit_detail_activity) - ImageView subscriptionsBottomAppBar; - @BindView(R.id.go_back_to_main_page_bottom_app_bar_view_subreddit_detail_activity) - ImageView goBackToMainPageBottomAppBar; - @BindView(R.id.message_bottom_app_bar_view_subreddit_detail_activity) - ImageView messageBottomAppBar; - @BindView(R.id.profile_bottom_app_bar_view_subreddit_detail_activity) - ImageView profileBottomAppBar; + @BindView(R.id.option_1_bottom_app_bar_view_subreddit_detail_activity) + ImageView option1BottomAppBar; + @BindView(R.id.option_2_bottom_app_bar_view_subreddit_detail_activity) + ImageView option2BottomAppBar; + @BindView(R.id.option_3_bottom_app_bar_view_subreddit_detail_activity) + ImageView option3BottomAppBar; + @BindView(R.id.option_4_bottom_app_bar_view_subreddit_detail_activity) + ImageView option4BottomAppBar; @BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab; @Inject @@ -169,6 +169,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Named("post_layout") SharedPreferences mPostLayoutSharedPreferences; @Inject + @Named("bottom_app_bar") + SharedPreferences bottomAppBarSharedPreference; + @Inject CustomThemeWrapper mCustomThemeWrapper; public SubredditViewModel mSubredditViewModel; private FragmentManager fragmentManager; @@ -238,10 +241,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp int navBarHeight = getNavBarHeight(); if (navBarHeight > 0) { CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); - params.bottomMargin = navBarHeight; + params.bottomMargin += navBarHeight; fab.setLayoutParams(params); - linearLayoutBottomAppBar.setPadding(0, - (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight); showToast = true; } @@ -458,10 +459,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp descriptionTextView.setTextColor(primaryTextColor); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - subscriptionsBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - goBackToMainPageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - messageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - profileBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); unsubscribedColor = mCustomThemeWrapper.getUnsubscribed(); @@ -523,6 +524,52 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } } + 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; + } + } + } + + 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; + default: + return R.drawable.ic_account_circle_24dp; + } + } + private void bindView() { if (mAccessToken != null) { if (mMessageFullname != null) { @@ -540,31 +587,52 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } if (showBottomAppBar) { + int optionCount = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); + int option2 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + bottomNavigationView.setVisibility(View.VISIBLE); - subscriptionsBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(ViewSubredditDetailActivity.this, SubscribedThingListingActivity.class); - startActivity(intent); - }); - subscriptionsBottomAppBar.setOnLongClickListener(view -> { - Intent intent = new Intent(ViewSubredditDetailActivity.this, SubscribedThingListingActivity.class); - intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); - startActivity(intent); - return true; - }); + if (optionCount == 2) { + linearLayoutBottomAppBar.setWeightSum(3); + option1BottomAppBar.setVisibility(View.GONE); + option3BottomAppBar.setVisibility(View.GONE); - goBackToMainPageBottomAppBar.setOnClickListener(view -> EventBus.getDefault().post(new GoBackToMainPageEvent())); + option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); + option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); - messageBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, InboxActivity.class); - startActivity(intent); - }); + option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); + }); - profileBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); - startActivity(intent); - }); + option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); + }); + } else { + int option3 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, 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); @@ -572,7 +640,52 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp fab.setLayoutParams(lp); } - fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag())); + int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + switch (fabOption) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: + fab.setImageResource(R.drawable.ic_refresh_black_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: + fab.setImageResource(R.drawable.ic_sort_toolbar_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: + fab.setImageResource(R.drawable.ic_post_layout_black_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: + fab.setImageResource(R.drawable.ic_search_black_24dp); + break; + default: + fab.setImageResource(R.drawable.ic_add_day_night_24dp); + break; + } + fab.setOnClickListener(view -> { + switch (fabOption) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: { + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName); + startActivity(intent); + break; + } + default: + postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); + break; + } + }); + fab.setVisibility(View.VISIBLE); } else { bottomNavigationView.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 0776ae6a..2c48bc67 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -164,6 +164,7 @@ public class SharedPreferencesUtils { public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3 = "other_activities_bottom_app_bar_option_3"; public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4 = "other_activities_bottom_app_bar_option_4"; public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB = "other_activities_bottom_app_bar_fab"; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 0; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS = 1; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX = 2; @@ -174,6 +175,17 @@ public class SharedPreferencesUtils { public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT = 3; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH = 4; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME = 0; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 1; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX = 2; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE = 3; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS = 4; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS = 0; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH = 1; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE = 2; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT = 3; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH = 4; + public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; public static final String NSFW_BASE = "_nsfw"; public static final String BLUR_NSFW_BASE = "_blur_nsfw"; |