Bottom app bar is available in ViewMultiRedditDetailActivity.

This commit is contained in:
Docile-Alligator 2022-04-08 16:39:30 +08:00
parent 8c8dc45f19
commit e7da8c1f69
5 changed files with 311 additions and 23 deletions

View File

@ -3,11 +3,14 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.Gravity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -15,6 +18,8 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; 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.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; 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.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -45,6 +52,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; 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.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent;
import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment;
import ml.docilealligator.infinityforreddit.multireddit.DeleteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.DeleteMultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
@ -78,7 +88,7 @@ import retrofit2.Retrofit;
public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback,
RandomBottomSheetFragment.RandomOptionSelectionCallback { RandomBottomSheetFragment.RandomOptionSelectionCallback, RecyclerViewContentScrollingInterface {
public static final String EXTRA_MULTIREDDIT_DATA = "EMD"; public static final String EXTRA_MULTIREDDIT_DATA = "EMD";
public static final String EXTRA_MULTIREDDIT_PATH = "EMP"; public static final String EXTRA_MULTIREDDIT_PATH = "EMP";
@ -93,6 +103,18 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
CollapsingToolbarLayout collapsingToolbarLayout; CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_view_multi_reddit_detail_activity) @BindView(R.id.toolbar_view_multi_reddit_detail_activity)
Toolbar toolbar; 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) @BindView(R.id.fab_view_multi_reddit_detail_activity)
FloatingActionButton fab; FloatingActionButton fab;
@Inject @Inject
@ -122,6 +144,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Named("nsfw_and_spoiler") @Named("nsfw_and_spoiler")
SharedPreferences mNsfwAndSpoilerSharedPreferences; SharedPreferences mNsfwAndSpoilerSharedPreferences;
@Inject @Inject
@Named("bottom_app_bar")
SharedPreferences mBottomAppBarSharedPreference;
@Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
@Inject @Inject
Executor mExecutor; Executor mExecutor;
@ -129,10 +154,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
private String mAccountName; private String mAccountName;
private String multiPath; private String multiPath;
private Fragment mFragment; private Fragment mFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
private int fabOption; private int fabOption;
private boolean showBottomAppBar;
private boolean lockBottomAppBar;
private Call<String> subredditAutocompleteCall; private Call<String> subredditAutocompleteCall;
@Override @Override
@ -143,6 +167,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
ButterKnife.bind(this); ButterKnife.bind(this);
EventBus.getDefault().register(this);
applyCustomTheme(); applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { 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(); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.bottomMargin += navBarHeight; params.bottomMargin += navBarHeight;
fab.setLayoutParams(params); 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); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); 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) { if (savedInstanceState != null) {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
@ -204,14 +233,59 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
initializeFragment(); initializeFragment();
} }
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); if (showBottomAppBar) {
Bundle bottomSheetBundle = new Bundle(); int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4);
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME);
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS);
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); bottomNavigationView.setVisibility(View.VISIBLE);
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); if (optionCount == 2) {
linearLayoutBottomAppBar.setWeightSum(3);
option1BottomAppBar.setVisibility(View.GONE);
option3BottomAppBar.setVisibility(View.GONE);
option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1));
option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));
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); fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
switch (fabOption) { switch (fabOption) {
@ -265,12 +339,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
break; break;
} }
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: {
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); showSortTypeBottomSheetFragment();
break; break;
} }
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); showPostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break; break;
} }
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: { 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(); 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() { private void goToSubreddit() {
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false); 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); 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(); finish();
return true; return true;
} else if (itemId == R.id.action_sort_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_sort_view_multi_reddit_detail_activity) {
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); showSortTypeBottomSheetFragment();
return true; return true;
} else if (itemId == R.id.action_search_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_search_view_multi_reddit_detail_activity) {
Intent intent = new Intent(this, SearchActivity.class); Intent intent = new Intent(this, SearchActivity.class);
@ -504,7 +746,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
} }
return true; return true;
} else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) {
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); showPostLayoutBottomSheetFragment();
return true; return true;
} else if (itemId == R.id.action_edit_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_edit_view_multi_reddit_detail_activity) {
Intent editIntent = new Intent(this, EditMultiRedditActivity.class); Intent editIntent = new Intent(this, EditMultiRedditActivity.class);
@ -555,6 +797,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment); getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
} }
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Override @Override
public void sortTypeSelected(SortType sortType) { public void sortTypeSelected(SortType sortType) {
((PostFragment) mFragment).changeSortType(sortType); ((PostFragment) mFragment).changeSortType(sortType);
@ -563,6 +811,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Override @Override
public void sortTypeSelected(String sortType) { public void sortTypeSelected(String sortType) {
SortTimeBottomSheetFragment sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType); bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
sortTimeBottomSheetFragment.setArguments(bundle); sortTimeBottomSheetFragment.setArguments(bundle);
@ -591,6 +840,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
protected void applyCustomTheme() { protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); 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); applyFABTheme(fab);
} }
@ -657,11 +912,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
} }
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); showSortTypeBottomSheetFragment();
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT:
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); showPostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:
Intent intent = new Intent(this, SearchActivity.class); 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); intent.putExtra(FetchRandomSubredditOrPostActivity.EXTRA_RANDOM_OPTION, option);
startActivity(intent); 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();
}
}
} }

View File

@ -887,8 +887,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
return true; return true;
}); });
fab.setVisibility(View.VISIBLE);
} }
private void bottomAppBarOptionAction(int option) { private void bottomAppBarOptionAction(int option) {

View File

@ -20,7 +20,6 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet; import androidx.constraintlayout.widget.ConstraintSet;
import androidx.paging.PagedListAdapter; import androidx.paging.PagedListAdapter;

View File

@ -39,11 +39,17 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 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 <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_view_multi_reddit_detail_activity" android:id="@+id/fab_view_multi_reddit_detail_activity"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" 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> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -151,7 +151,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
android:visibility="gone"
app:layout_anchor="@id/bottom_app_bar_bottom_app_bar" /> app:layout_anchor="@id/bottom_app_bar_bottom_app_bar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>