diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-06-18 14:54:26 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-06-18 14:54:26 +0000 |
commit | 42a935981dd4b6fe33b4a16d58418f273d45fce2 (patch) | |
tree | d95e13f5f4c8337396f986ef32b5e09cfef46702 /app/src | |
parent | e0da948d1f77e36e722c41d278f99b73fbadebac (diff) | |
download | infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar.gz infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar.bz2 infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar.lz infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar.xz infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.tar.zst infinity-for-reddit-42a935981dd4b6fe33b4a16d58418f273d45fce2.zip |
Use Navigation Rail in MainActivity in landscape mode.
Diffstat (limited to '')
7 files changed, 439 insertions, 67 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index ce1e5f78..941aea0a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -7,7 +7,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.ColorStateList; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -23,8 +22,6 @@ 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; @@ -51,9 +48,7 @@ import androidx.work.WorkManager; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.MaterialToolbar; -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.navigation.NavigationView; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; @@ -98,6 +93,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomS import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.customviews.NavigationWrapper; import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent; import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent; import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; @@ -164,7 +160,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb RecyclerView navDrawerRecyclerView; @BindView(R.id.tab_layout_main_activity) TabLayout tabLayout; - @BindView(R.id.bottom_app_bar_bottom_app_bar) + /*@BindView(R.id.bottom_app_bar_bottom_app_bar) BottomAppBar bottomAppBar; @BindView(R.id.linear_layout_bottom_app_bar) LinearLayout linearLayoutBottomAppBar; @@ -175,9 +171,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @BindView(R.id.option_3_bottom_app_bar) ImageView option3BottomAppBar; @BindView(R.id.option_4_bottom_app_bar) - ImageView option4BottomAppBar; - @BindView(R.id.fab_main_activity) - FloatingActionButton fab; + ImageView option4BottomAppBar;*/ + /*@BindView(R.id.fab_main_activity) + FloatingActionButton fab;*/ MultiRedditViewModel multiRedditViewModel; SubscribedSubredditViewModel subscribedSubredditViewModel; AccountViewModel accountViewModel; @@ -242,6 +238,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb private int fabOption; private int inboxCount; + private NavigationWrapper navigationWrapper; + @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); @@ -256,6 +254,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb ButterKnife.bind(this); + showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false); + + navigationWrapper = new NavigationWrapper(findViewById(R.id.bottom_app_bar_bottom_app_bar), findViewById(R.id.linear_layout_bottom_app_bar), + findViewById(R.id.option_1_bottom_app_bar), findViewById(R.id.option_2_bottom_app_bar), + findViewById(R.id.option_3_bottom_app_bar), findViewById(R.id.option_4_bottom_app_bar), + findViewById(R.id.fab_main_activity), + findViewById(R.id.navigation_rail), showBottomAppBar); + EventBus.getDefault().register(this); applyCustomTheme(); @@ -279,11 +285,15 @@ 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, - linearLayoutBottomAppBar.getPaddingTop(), 0, navBarHeight); + if (navigationWrapper.navigationRailView == null) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) navigationWrapper.floatingActionButton.getLayoutParams(); + params.bottomMargin += navBarHeight; + navigationWrapper.floatingActionButton.setLayoutParams(params); + } + if (navigationWrapper.linearLayoutBottomAppBar != null) { + navigationWrapper.linearLayoutBottomAppBar.setPadding(0, + navigationWrapper.linearLayoutBottomAppBar.getPaddingTop(), 0, navBarHeight); + } navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight); } } else { @@ -308,7 +318,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); toggle.syncState(); - showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false); mBackButtonAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION, "0")); mLockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); mDisableSwipingBetweenTabs = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false); @@ -348,15 +357,16 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb int backgroundColor = mCustomThemeWrapper.getBackgroundColor(); drawer.setBackgroundColor(backgroundColor); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + navigationWrapper.applyCustomTheme(bottomAppBarIconColor, mCustomThemeWrapper.getBottomAppBarBackgroundColor()); + /*option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); option2BottomAppBar.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); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);*/ navigationView.setBackgroundColor(backgroundColor); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyTabLayoutTheme(tabLayout); - bottomAppBar.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); - applyFABTheme(fab); + //bottomAppBar.setBackgroundTint(ColorStateList.valueOf()); + applyFABTheme(navigationWrapper.floatingActionButton); } private void initializeNotificationAndBindView() { @@ -577,100 +587,140 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS); - bottomAppBar.setVisibility(View.VISIBLE); + //bottomAppBar.setVisibility(View.VISIBLE); if (optionCount == 2) { - linearLayoutBottomAppBar.setWeightSum(3); + navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); + + /*linearLayoutBottomAppBar.setWeightSum(3); option1BottomAppBar.setVisibility(View.GONE); option3BottomAppBar.setVisibility(View.GONE); option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); - option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); + option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));*/ - option2BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option1); - }); + if (navigationWrapper.navigationRailView == null) { + navigationWrapper.option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); + }); - option4BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option2); - }); + navigationWrapper.option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); + }); + } else { + navigationWrapper.navigationRailView.setOnItemSelectedListener(item -> { + int itemId = item.getItemId(); + if (itemId == R.id.navigation_rail_option_1) { + bottomAppBarOptionAction(option1); + return true; + } else if (itemId == R.id.navigation_rail_option_2) { + bottomAppBarOptionAction(option2); + return true; + } + return false; + }); + } } else { int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX); int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE); - option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); - option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); - option3BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option3)); - option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option4)); + navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), + getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), + getBottomAppBarOptionDrawableResource(option4)); - option1BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option1); - }); + /*navigationWrapper.option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); + navigationWrapper.option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); + navigationWrapper.option3BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option3)); + navigationWrapper.option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option4));*/ - option2BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option2); - }); + if (navigationWrapper.navigationRailView == null) { + navigationWrapper.option1BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); + }); - option3BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option3); - }); + navigationWrapper.option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); + }); - option4BottomAppBar.setOnClickListener(view -> { - bottomAppBarOptionAction(option4); - }); + navigationWrapper.option3BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option3); + }); + + navigationWrapper.option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option4); + }); + } else { + navigationWrapper.navigationRailView.setOnItemSelectedListener(item -> { + int itemId = item.getItemId(); + if (itemId == R.id.navigation_rail_option_1) { + bottomAppBarOptionAction(option1); + return true; + } else if (itemId == R.id.navigation_rail_option_2) { + bottomAppBarOptionAction(option2); + return true; + } else if (itemId == R.id.navigation_rail_option_3) { + bottomAppBarOptionAction(option3); + return true; + } else if (itemId == R.id.navigation_rail_option_4) { + bottomAppBarOptionAction(option4); + return true; + } + return false; + }); + } } } else { - CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) navigationWrapper.floatingActionButton.getLayoutParams(); lp.setAnchorId(View.NO_ID); lp.gravity = Gravity.END | Gravity.BOTTOM; - fab.setLayoutParams(lp); + navigationWrapper.floatingActionButton.setLayoutParams(lp); } fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH: - fab.setImageResource(R.drawable.ic_refresh_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_refresh_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: - fab.setImageResource(R.drawable.ic_sort_toolbar_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_sort_toolbar_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: - fab.setImageResource(R.drawable.ic_post_layout_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_post_layout_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH: - fab.setImageResource(R.drawable.ic_search_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_search_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: - fab.setImageResource(R.drawable.ic_subreddit_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_subreddit_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER: - fab.setImageResource(R.drawable.ic_user_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_user_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM: - fab.setImageResource(R.drawable.ic_random_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: if (mAccessToken == null) { - fab.setImageResource(R.drawable.ic_filter_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { - fab.setImageResource(R.drawable.ic_hide_read_posts_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_hide_read_posts_24dp); } break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS: - fab.setImageResource(R.drawable.ic_filter_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); break; default: if (mAccessToken == null) { - fab.setImageResource(R.drawable.ic_filter_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { - fab.setImageResource(R.drawable.ic_add_day_night_24dp); + navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_add_day_night_24dp); } break; } - fab.setOnClickListener(view -> { + navigationWrapper.floatingActionButton.setOnClickListener(view -> { switch (fabOption) { case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH: { if (sectionsPagerAdapter != null) { @@ -717,7 +767,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb break; } }); - fab.setOnLongClickListener(view -> { + navigationWrapper.floatingActionButton.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment= new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); @@ -725,7 +775,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; }); - fab.setVisibility(View.VISIBLE); + navigationWrapper.floatingActionButton.setVisibility(View.VISIBLE); adapter = new NavigationDrawerRecyclerViewMergedAdapter(this, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mNavigationDrawerSharedPreferences, mSecuritySharedPreferences, @@ -893,10 +943,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void onPageSelected(int position) { if (mAccessToken != null) { if (showBottomAppBar) { - bottomAppBar.performShow(); + navigationWrapper.showNavigation(); } } - fab.show(); + //fab.show(); + navigationWrapper.showFab(); sectionsPagerAdapter.displaySortTypeInToolbar(); } }); @@ -1179,20 +1230,24 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public void contentScrollUp() { if (showBottomAppBar && !mLockBottomAppBar) { - bottomAppBar.performShow(); + //bottomAppBar.performShow(); + navigationWrapper.showNavigation(); } if (!(showBottomAppBar && mLockBottomAppBar)) { - fab.show(); + //fab.show(); + navigationWrapper.showFab(); } } @Override public void contentScrollDown() { if (!(showBottomAppBar && mLockBottomAppBar)) { - fab.hide(); + //fab.hide(); + navigationWrapper.hideFab(); } if (showBottomAppBar && !mLockBottomAppBar) { - bottomAppBar.performHide(); + //bottomAppBar.performHide(); + navigationWrapper.hideNavigation(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/NavigationWrapper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/NavigationWrapper.java new file mode 100644 index 00000000..466cab02 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/NavigationWrapper.java @@ -0,0 +1,142 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.res.ColorStateList; +import android.graphics.drawable.Drawable; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; + +import androidx.appcompat.view.menu.MenuItemImpl; +import androidx.core.graphics.drawable.DrawableCompat; + +import com.google.android.material.bottomappbar.BottomAppBar; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.navigationrail.NavigationRailView; + +import ml.docilealligator.infinityforreddit.R; + +public class NavigationWrapper { + public BottomAppBar bottomAppBar; + public LinearLayout linearLayoutBottomAppBar; + public ImageView option1BottomAppBar; + public ImageView option2BottomAppBar; + public ImageView option3BottomAppBar; + public ImageView option4BottomAppBar; + + public NavigationRailView navigationRailView; + public FloatingActionButton floatingActionButton; + + public NavigationWrapper(BottomAppBar bottomAppBar, LinearLayout linearLayoutBottomAppBar, + ImageView option1BottomAppBar, ImageView option2BottomAppBar, + ImageView option3BottomAppBar, ImageView option4BottomAppBar, + FloatingActionButton floatingActionButton, NavigationRailView navigationRailView, + boolean showBottomAppBar) { + this.bottomAppBar = bottomAppBar; + this.linearLayoutBottomAppBar = linearLayoutBottomAppBar; + this.option1BottomAppBar = option1BottomAppBar; + this.option2BottomAppBar = option2BottomAppBar; + this.option3BottomAppBar = option3BottomAppBar; + this.option4BottomAppBar = option4BottomAppBar; + this.navigationRailView = navigationRailView; + if (navigationRailView != null) { + if (showBottomAppBar) { + this.floatingActionButton = (FloatingActionButton) navigationRailView.getHeaderView(); + } else { + navigationRailView.setVisibility(View.GONE); + this.floatingActionButton = floatingActionButton; + } + } else { + this.floatingActionButton = floatingActionButton; + } + } + + public void applyCustomTheme(int bottomAppBarIconColor, int bottomAppBarBackgroundColor) { + if (navigationRailView == null) { + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.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); + bottomAppBar.setBackgroundTint(ColorStateList.valueOf(bottomAppBarBackgroundColor)); + } else { + navigationRailView.setBackgroundColor(bottomAppBarBackgroundColor); + applyMenuItemTheme(navigationRailView.getMenu(), bottomAppBarIconColor); + } + } + + private void applyMenuItemTheme(Menu menu, int bottomAppBarIconColor) { + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + if (((MenuItemImpl) item).requestsActionButton()) { + Drawable drawable = item.getIcon(); + if (drawable != null) { + DrawableCompat.setTint(drawable, bottomAppBarIconColor); + item.setIcon(drawable); + } + } + } + } + + public void bindOptionDrawableResource(int... imageResources) { + if (navigationRailView == null) { + bottomAppBar.setVisibility(View.VISIBLE); + } else { + navigationRailView.setVisibility(View.VISIBLE); + } + + if (imageResources.length == 2) { + if (navigationRailView == null) { + linearLayoutBottomAppBar.setWeightSum(3); + option1BottomAppBar.setVisibility(View.GONE); + option3BottomAppBar.setVisibility(View.GONE); + + option2BottomAppBar.setImageResource(imageResources[0]); + option4BottomAppBar.setImageResource(imageResources[1]); + } else { + Menu menu = navigationRailView.getMenu(); + menu.findItem(R.id.navigation_rail_option_1).setIcon(imageResources[0]); + menu.findItem(R.id.navigation_rail_option_2).setIcon(imageResources[1]); + menu.findItem(R.id.navigation_rail_option_3).setVisible(false); + menu.findItem(R.id.navigation_rail_option_4).setVisible(false); + } + } else { + if (navigationRailView == null) { + option1BottomAppBar.setImageResource(imageResources[0]); + option2BottomAppBar.setImageResource(imageResources[1]); + option3BottomAppBar.setImageResource(imageResources[2]); + option4BottomAppBar.setImageResource(imageResources[3]); + } else { + Menu menu = navigationRailView.getMenu(); + menu.findItem(R.id.navigation_rail_option_1).setIcon(imageResources[0]); + menu.findItem(R.id.navigation_rail_option_2).setIcon(imageResources[1]); + menu.findItem(R.id.navigation_rail_option_3).setIcon(imageResources[2]); + menu.findItem(R.id.navigation_rail_option_4).setIcon(imageResources[3]); + } + } + } + + public void showNavigation() { + if (bottomAppBar != null) { + bottomAppBar.performShow(); + } + } + + public void hideNavigation() { + if (bottomAppBar != null) { + bottomAppBar.performHide(); + } + } + + public void showFab() { + if (navigationRailView == null) { + floatingActionButton.show(); + } + } + + public void hideFab() { + if (navigationRailView == null) { + floatingActionButton.hide(); + } + } +} diff --git a/app/src/main/res/layout-land/app_bar_main.xml b/app/src/main/res/layout-land/app_bar_main.xml new file mode 100644 index 00000000..8ec561b0 --- /dev/null +++ b/app/src/main/res/layout-land/app_bar_main.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/coordinator_layout_main_activity" + tools:application="ml.docilealligator.infinityforreddit.activities.MainActivity"> + + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <com.google.android.material.appbar.CollapsingToolbarLayout + android:id="@+id/collapsing_toolbar_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar"> + + <com.google.android.material.appbar.MaterialToolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?attr/actionBarSize" + app:layout_collapseMode="pin" + app:layout_scrollFlags="scroll|enterAlways" + app:popupTheme="@style/AppTheme.PopupOverlay" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> + + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + app:layout_scrollFlags="scroll|enterAlways" + app:tabGravity="fill" + app:tabIndicatorHeight="3dp" + app:tabRippleColor="?attr/colorControlHighlight" + app:tabUnboundedRipple="false" /> + + </com.google.android.material.appbar.AppBarLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" > + + <com.google.android.material.navigationrail.NavigationRailView + android:id="@+id/navigation_rail" + android:layout_width="80dp" + android:layout_height="match_parent" + app:headerLayout="@layout/floating_action_button" + app:menu="@menu/navigation_rail_menu" + app:labelVisibilityMode="unlabeled" + app:itemActiveIndicatorStyle="@style/App.Custom.Indicator" /> + + <androidx.viewpager2.widget.ViewPager2 + android:id="@+id/view_pager_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + </LinearLayout> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab_main_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/fab_margin" + android:visibility="gone" /> + +</androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/app/src/main/res/layout-sw600dp/app_bar_main.xml b/app/src/main/res/layout-sw600dp/app_bar_main.xml new file mode 100644 index 00000000..8ec561b0 --- /dev/null +++ b/app/src/main/res/layout-sw600dp/app_bar_main.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/coordinator_layout_main_activity" + tools:application="ml.docilealligator.infinityforreddit.activities.MainActivity"> + + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <com.google.android.material.appbar.CollapsingToolbarLayout + android:id="@+id/collapsing_toolbar_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar"> + + <com.google.android.material.appbar.MaterialToolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?attr/actionBarSize" + app:layout_collapseMode="pin" + app:layout_scrollFlags="scroll|enterAlways" + app:popupTheme="@style/AppTheme.PopupOverlay" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> + + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + app:layout_scrollFlags="scroll|enterAlways" + app:tabGravity="fill" + app:tabIndicatorHeight="3dp" + app:tabRippleColor="?attr/colorControlHighlight" + app:tabUnboundedRipple="false" /> + + </com.google.android.material.appbar.AppBarLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" > + + <com.google.android.material.navigationrail.NavigationRailView + android:id="@+id/navigation_rail" + android:layout_width="80dp" + android:layout_height="match_parent" + app:headerLayout="@layout/floating_action_button" + app:menu="@menu/navigation_rail_menu" + app:labelVisibilityMode="unlabeled" + app:itemActiveIndicatorStyle="@style/App.Custom.Indicator" /> + + <androidx.viewpager2.widget.ViewPager2 + android:id="@+id/view_pager_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + </LinearLayout> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab_main_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/fab_margin" + android:visibility="gone" /> + +</androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/app/src/main/res/layout/floating_action_button.xml b/app/src/main/res/layout/floating_action_button.xml new file mode 100644 index 00000000..21cec65e --- /dev/null +++ b/app/src/main/res/layout/floating_action_button.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.google.android.material.floatingactionbutton.FloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" />
\ No newline at end of file diff --git a/app/src/main/res/menu/navigation_rail_menu.xml b/app/src/main/res/menu/navigation_rail_menu.xml new file mode 100644 index 00000000..34d58bc1 --- /dev/null +++ b/app/src/main/res/menu/navigation_rail_menu.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:id="@+id/navigation_rail_option_1" + android:enabled="true"/> + <item + android:id="@+id/navigation_rail_option_2" + android:enabled="true"/> + <item + android:id="@+id/navigation_rail_option_3" + android:enabled="true"/> + <item + android:id="@+id/navigation_rail_option_4" + android:enabled="true"/> +</menu>
\ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 460201e0..2694fc6f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -140,6 +140,10 @@ <item name="colorOnSurface">@color/colorPrimary</item> <item name="colorPrimary">@color/primaryTextColor</item> </style> + + <style name="App.Custom.Indicator" parent="Widget.Material3.BottomNavigationView.ActiveIndicator"> + <item name="android:color">#00000000</item> + </style> <style name="FontStyle" /> |