diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-25 08:35:27 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-25 08:35:27 +0000 |
commit | f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad (patch) | |
tree | 0a45bc0c51d1932da22e07bc6dab28d2216cf9d8 /app | |
parent | 1b983c1ff84fc9b8d27830d6801ad63e99d603fa (diff) | |
download | infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar.gz infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar.bz2 infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar.lz infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar.xz infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.tar.zst infinity-for-reddit-f33d4dbc61ef2f7967f9bf3ee80b2644eaf54aad.zip |
Customizing the bottom app bar in MainActivity is available (Changing option count is not available right now.
Diffstat (limited to '')
5 files changed, 173 insertions, 55 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 4387387b..858437ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -143,18 +143,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb RecyclerView navDrawerRecyclerView; @BindView(R.id.tab_layout_main_activity) TabLayout tabLayout; - @BindView(R.id.bottom_navigation_main_activity) - BottomAppBar bottomNavigationView; + @BindView(R.id.bottom_app_bar_main_activity) + BottomAppBar bottomAppBar; @BindView(R.id.linear_layout_bottom_app_bar_main_activity) LinearLayout linearLayoutBottomAppBar; - @BindView(R.id.subscriptions_bottom_app_bar_main_activity) - ImageView subscriptionsBottomAppBar; - @BindView(R.id.multi_reddit_bottom_app_bar_main_activity) - ImageView multiRedditBottomAppBar; - @BindView(R.id.message_bottom_app_bar_main_activity) - ImageView messageBottomAppBar; - @BindView(R.id.profile_bottom_app_bar_main_activity) - ImageView profileBottomAppBar; + @BindView(R.id.option_1_bottom_app_bar_main_activity) + ImageView option1BottomAppBar; + @BindView(R.id.option_2_bottom_app_bar_main_activity) + ImageView option2BottomAppBar; + @BindView(R.id.option_3_bottom_app_bar_main_activity) + ImageView option3BottomAppBar; + @BindView(R.id.option_4_bottom_app_bar_main_activity) + ImageView option4BottomAppBar; @BindView(R.id.fab_main_activity) FloatingActionButton fab; SubscribedSubredditViewModel subscribedSubredditViewModel; @@ -180,6 +180,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Named("nsfw_and_spoiler") SharedPreferences mNsfwAndSpoilerSharedPreferences; @Inject + @Named("bottom_app_bar") + SharedPreferences bottomAppBarSharedPreference; + @Inject CustomThemeWrapper mCustomThemeWrapper; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; @@ -329,14 +332,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb drawer.setBackgroundColor(backgroundColor); drawer.setStatusBarBackgroundColor(mCustomThemeWrapper.getColorPrimaryDark()); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - subscriptionsBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - multiRedditBottomAppBar.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); + 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); navigationView.setBackgroundColor(backgroundColor); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyTabLayoutTheme(tabLayout); - bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); + bottomAppBar.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); applyFABTheme(fab); } @@ -443,37 +446,83 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }).execute(); } + private void bottomAppBarOptionAction(int option) { + switch (option) { + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS: { + Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + startActivity(intent); + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS: { + Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); + startActivity(intent); + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX: { + Intent intent = new Intent(this, InboxActivity.class); + startActivity(intent); + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE: { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); + startActivity(intent); + break; + } + } + } + + private int getBottomAppBarOptionDrawableResource(int option) { + switch (option) { + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS: + return R.drawable.ic_subscritptions_bottom_app_bar_24dp; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS: + return R.drawable.ic_multi_reddit_24dp; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX: + return R.drawable.ic_inbox_24dp; + default: + return R.drawable.ic_account_circle_24dp; + } + } + private void bindView() { if (isDestroyed()) { return; } if (mAccessToken == null) { - bottomNavigationView.setVisibility(View.GONE); + bottomAppBar.setVisibility(View.GONE); fab.setVisibility(View.GONE); } else { if (showBottomAppBar) { - bottomNavigationView.setVisibility(View.VISIBLE); - subscriptionsBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); - startActivity(intent); + int optionCount = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + int option2 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS); + int option3 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE); + + bottomAppBar.setVisibility(View.VISIBLE); + + option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1)); + option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2)); + option3BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option3)); + option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option4)); + + option1BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option1); }); - multiRedditBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); - intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); - startActivity(intent); + option2BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option2); }); - messageBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, InboxActivity.class); - startActivity(intent); + option3BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option3); }); - profileBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); - startActivity(intent); + option4BottomAppBar.setOnClickListener(view -> { + bottomAppBarOptionAction(option4); }); } else { CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); @@ -482,7 +531,50 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fab.setLayoutParams(lp); } - fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag())); + int fabOption = bottomAppBarSharedPreference.getInt(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_black_24dp); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: + fab.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_black_24dp); + break; + case SharedPreferencesUtils.MAIN_ACTIVITY_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.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { + changeSortType(); + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + break; + } + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH: { + Intent intent = new Intent(this, SearchActivity.class); + startActivity(intent); + break; + } + default: + postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); + break; + } + }); fab.setVisibility(View.VISIBLE); } @@ -658,7 +750,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void onPageSelected(int position) { if (mAccessToken != null) { if (showBottomAppBar) { - bottomNavigationView.performShow(); + bottomAppBar.performShow(); } fab.show(); } @@ -796,6 +888,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb return true; } + private void changeSortType() { + int currentPostType = sectionsPagerAdapter.getCurrentPostType(); + Bundle bundle = new Bundle(); + if (currentPostType != PostDataSource.TYPE_FRONT_PAGE) { + bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); + } else { + bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); + } + sortTypeBottomSheetFragment.setArguments(bundle); + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + } + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { @@ -804,15 +908,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb startActivity(intent); return true; case R.id.action_sort_main_activity: - int currentPostType = sectionsPagerAdapter.getCurrentPostType(); - Bundle bundle = new Bundle(); - if (currentPostType != PostDataSource.TYPE_FRONT_PAGE) { - bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - } else { - bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); - } - sortTypeBottomSheetFragment.setArguments(bundle); - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + changeSortType(); return true; case R.id.action_refresh_main_activity: if (mMenu != null) { @@ -939,7 +1035,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void postScrollUp() { if (mAccessToken != null) { if (showBottomAppBar && !mLockBottomAppBar) { - bottomNavigationView.performShow(); + bottomAppBar.performShow(); } if (!(showBottomAppBar && mLockBottomAppBar)) { fab.show(); @@ -953,7 +1049,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fab.hide(); } if (showBottomAppBar && !mLockBottomAppBar) { - bottomNavigationView.performHide(); + bottomAppBar.performHide(); } } } 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 f6527a30..0776ae6a 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,15 @@ 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; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE = 3; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS = 0; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH = 1; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE = 2; + 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 String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; public static final String NSFW_BASE = "_nsfw"; diff --git a/app/src/main/res/drawable/ic_post_layout_black_24dp.xml b/app/src/main/res/drawable/ic_post_layout_black_24dp.xml new file mode 100644 index 00000000..bca9e973 --- /dev/null +++ b/app/src/main/res/drawable/ic_post_layout_black_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M3,5v14h19L22,5L3,5zM5,7h15v4L5,11L5,7zM5,17v-4h4v4L5,17zM11,17v-4h9v4h-9z" + android:fillColor="#000000"/> +</vector> diff --git a/app/src/main/res/drawable/ic_refresh_black_24dp.xml b/app/src/main/res/drawable/ic_refresh_black_24dp.xml new file mode 100644 index 00000000..528662cf --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh_black_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" + android:fillColor="#000000"/> +</vector> diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 5272b575..3f0b5c20 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -64,7 +64,7 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <com.google.android.material.bottomappbar.BottomAppBar - android:id="@+id/bottom_navigation_main_activity" + android:id="@+id/bottom_app_bar_main_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" @@ -78,25 +78,23 @@ android:weightSum="5"> <ImageView - android:id="@+id/subscriptions_bottom_app_bar_main_activity" + android:id="@+id/option_1_bottom_app_bar_main_activity" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:paddingTop="8dp" android:paddingBottom="8dp" - android:src="@drawable/ic_subscritptions_bottom_app_bar_24dp" android:background="?attr/selectableItemBackgroundBorderless" /> <ImageView - android:id="@+id/multi_reddit_bottom_app_bar_main_activity" + android:id="@+id/option_2_bottom_app_bar_main_activity" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:paddingTop="8dp" android:paddingBottom="8dp" - android:src="@drawable/ic_multi_reddit_24dp" android:background="?attr/selectableItemBackgroundBorderless" /> <TextView @@ -106,18 +104,17 @@ android:background="@android:color/transparent"/> <ImageView - android:id="@+id/message_bottom_app_bar_main_activity" + android:id="@+id/option_3_bottom_app_bar_main_activity" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:paddingTop="8dp" android:paddingBottom="8dp" - android:src="@drawable/ic_inbox_24dp" android:background="?attr/selectableItemBackgroundBorderless" /> <ImageView - android:id="@+id/profile_bottom_app_bar_main_activity" + android:id="@+id/option_4_bottom_app_bar_main_activity" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" @@ -125,7 +122,6 @@ android:paddingTop="8dp" android:paddingBottom="8dp" android:gravity="center" - android:src="@drawable/ic_account_circle_24dp" android:background="?attr/selectableItemBackgroundBorderless" /> </LinearLayout> @@ -137,8 +133,7 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" android:visibility="gone" - app:srcCompat="@drawable/ic_add_day_night_24dp" app:tint="@android:color/white" - app:layout_anchor="@id/bottom_navigation_main_activity" /> + app:layout_anchor="@id/bottom_app_bar_main_activity" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> |