Show the FAB in anonymous mode.

This commit is contained in:
Alex Ning 2020-12-24 23:07:18 +08:00
parent f376de69e1
commit 3938d9734f
6 changed files with 395 additions and 351 deletions

View File

@ -68,9 +68,9 @@ import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.FetchMyInfo;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface;
import ml.docilealligator.infinityforreddit.PullNotificationWorker;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@ -201,11 +201,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter;
private AppBarLayout.LayoutParams params;
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
private FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment;
private NavigationDrawerRecyclerViewAdapter adapter;
private boolean mNullAccessToken = false;
private String mAccessToken;
@ -226,6 +221,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private boolean mDisableSwipingBetweenTabs;
private boolean mShowFavoriteSubscribedSubreddits;
private boolean mShowSubscribedSubreddits;
private int fabOption;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -278,12 +274,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
@ -513,8 +503,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
if (mAccessToken == null) {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
bottomAppBar.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
} else {
if (showBottomAppBar) {
int optionCount = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4);
@ -569,8 +562,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
}
int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
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_24dp);
@ -594,13 +589,23 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fab.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);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.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);
break;
default:
if (mAccessToken == null) {
fab.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);
}
break;
}
fab.setOnClickListener(view -> {
@ -616,6 +621,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
break;
}
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break;
}
@ -644,16 +650,20 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
break;
}
});
fab.setOnLongClickListener(view -> {
FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment= new FABMoreOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null);
fabMoreOptionsBottomSheetFragment.setArguments(bundle);
fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
return true;
});
fab.setVisibility(View.VISIBLE);
}
adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences,
mNsfwAndSpoilerSharedPreferences, mCustomThemeWrapper, mAccountName,
@ -829,8 +839,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (showBottomAppBar) {
bottomAppBar.performShow();
}
fab.show();
}
fab.show();
sectionsPagerAdapter.displaySortTypeInToolbar();
}
});
@ -971,6 +981,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else {
bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false);
}
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
sortTypeBottomSheetFragment.setArguments(bundle);
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
}
@ -1011,6 +1022,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
return true;
case R.id.action_change_post_layout_main_activity:
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
@ -1074,6 +1086,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public void sortTypeSelected(String sortType) {
SortTimeBottomSheetFragment sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
sortTimeBottomSheetFragment.setArguments(bundle);
@ -1109,27 +1122,23 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public void contentScrollUp() {
if (mAccessToken != null) {
if (showBottomAppBar && !mLockBottomAppBar) {
if (mAccessToken != null && showBottomAppBar && !mLockBottomAppBar) {
bottomAppBar.performShow();
}
if (!(showBottomAppBar && mLockBottomAppBar)) {
if (!(mAccessToken != null && showBottomAppBar && mLockBottomAppBar)) {
fab.show();
}
}
}
@Override
public void contentScrollDown() {
if (mAccessToken != null) {
if (!(showBottomAppBar && mLockBottomAppBar)) {
if (!(mAccessToken != null && showBottomAppBar && mLockBottomAppBar)) {
fab.hide();
}
if (showBottomAppBar && !mLockBottomAppBar) {
if (mAccessToken != null && showBottomAppBar && !mLockBottomAppBar) {
bottomAppBar.performHide();
}
}
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
@ -1190,6 +1199,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
public void fabOptionSelected(int option) {
switch (option) {
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
@ -1201,6 +1211,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
changeSortType();
break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT:
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:

View File

@ -118,6 +118,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter;
private SlidrInterface mSlidrInterface;
private int fabOption;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -241,6 +242,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
fab.show();
sectionsPagerAdapter.displaySortTypeInToolbar();
if (position == 0) {
unlockSwipeRightToGoBack();
@ -264,7 +266,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}).attach();
fixViewPager2Sensitivity(viewPager2);
int 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) {
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH:
fab.setImageResource(R.drawable.ic_refresh_24dp);
@ -290,6 +292,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
fab.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);
}
@ -300,6 +303,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
default:
if (mAccessToken == null) {
fab.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);
}

View File

@ -222,6 +222,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int collapsedTabIndicatorColor;
private int unsubscribedColor;
private int subscribedColor;
private int fabOption;
private SlidrInterface mSlidrInterface;
private MaterialAlertDialogBuilder nsfwWarningBuilder;
@ -687,8 +688,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
bottomNavigationView.setVisibility(View.GONE);
}
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_24dp);
@ -712,13 +719,23 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
fab.setImageResource(R.drawable.ic_random_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_hide_read_posts_24dp);
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
fab.setImageResource(R.drawable.ic_filter_24dp);
break;
default:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_add_day_night_24dp);
}
break;
}
fab.setOnClickListener(view -> {
@ -768,15 +785,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
});
fab.setOnLongClickListener(view -> {
Bundle bundle = new Bundle();
bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null);
fabMoreOptionsBottomSheetFragment.setArguments(bundle);
fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
return true;
});
fab.setVisibility(View.VISIBLE);
} else {
bottomNavigationView.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
}
subscribeSubredditChip.setOnClickListener(view -> {
if (mAccessToken == null) {
@ -857,8 +872,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
if (showBottomAppBar) {
bottomNavigationView.performShow();
}
fab.show();
}
fab.show();
sectionsPagerAdapter.displaySortTypeInToolbar();
}

View File

@ -217,6 +217,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private int collapsedTabIndicatorColor;
private int unsubscribedColor;
private int subscribedColor;
private int fabOption;
private boolean showToast = false;
private boolean showBottomAppBar;
private boolean lockBottomAppBar;
@ -633,8 +634,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (showBottomAppBar) {
bottomNavigationView.performShow();
}
fab.show();
}
fab.show();
sectionsPagerAdapter.displaySortTypeInToolbar();
}
@ -710,8 +711,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
bottomNavigationView.setVisibility(View.GONE);
}
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_24dp);
@ -735,13 +742,23 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
fab.setImageResource(R.drawable.ic_random_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_hide_read_posts_24dp);
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
fab.setImageResource(R.drawable.ic_filter_24dp);
break;
default:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_add_day_night_24dp);
}
break;
}
fab.setOnClickListener(view -> {
@ -792,15 +809,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
});
fab.setOnLongClickListener(view -> {
FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null);
fabMoreOptionsBottomSheetFragment.setArguments(bundle);
fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
return true;
});
fab.setVisibility(View.VISIBLE);
} else {
bottomNavigationView.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
}
}
private void bottomAppBarOptionAction(int option) {

View File

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

View File

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