Handle fablayout expand backpress on its callback
This commit is contained in:
1 parent
6912e578ca
commit
e49f5c95f4
4 files changed
+49
-72
No files matched your search
@@ -367,6 +367,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
mFastScroller.setHandlerDrawable(handlerDrawable);
|
||||
mFastScroller.setOnDragHandlerListener(this);
|
||||
|
||||
mFabLayout.addOnExpandListener(new FabLayoutListener());
|
||||
mFabLayout.setExpanded(false, false);
|
||||
mFabLayout.setHidePrimaryFab(true);
|
||||
mFabLayout.setAutoCancel(false);
|
||||
@@ -555,15 +556,6 @@ public class DownloadsScene extends ToolbarScene
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartDragHandler() {
|
||||
// Lock right drawer
|
||||
@@ -1190,6 +1182,14 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
}
|
||||
|
||||
private class FabLayoutListener implements FabLayout.OnExpandListener {
|
||||
@Override
|
||||
public void onExpand(boolean expanded) {
|
||||
if (!expanded && mRecyclerView != null && mRecyclerView.isInCustomChoice())
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadChoiceListener implements EasyRecyclerView.CustomChoiceListener {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -95,7 +94,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
private static final long ANIMATE_TIME = 300L;
|
||||
|
||||
private static final String KEY_URL_BUILDER = "url_builder";
|
||||
private static final String KEY_SEARCH_MODE = "search_mode";
|
||||
private static final String KEY_HAS_FIRST_REFRESH = "has_first_refresh";
|
||||
private static final String KEY_FAV_COUNT_ARRAY = "fav_count_array";
|
||||
// For modify action
|
||||
@@ -148,7 +146,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
private int mFavLocalCount = 0;
|
||||
private int mFavCountSum = 0;
|
||||
private boolean mHasFirstRefresh;
|
||||
private boolean mSearchMode;
|
||||
// Avoid unnecessary search bar update
|
||||
private String mOldFavCat;
|
||||
// Avoid unnecessary search bar update
|
||||
@@ -187,7 +184,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
private void onInit() {
|
||||
mUrlBuilder = new FavListUrlBuilder();
|
||||
mUrlBuilder.setFavCat(Settings.getRecentFavCat());
|
||||
mSearchMode = false;
|
||||
}
|
||||
|
||||
private void onRestore(Bundle savedInstanceState) {
|
||||
@@ -195,7 +191,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
if (mUrlBuilder == null) {
|
||||
mUrlBuilder = new FavListUrlBuilder();
|
||||
}
|
||||
mSearchMode = savedInstanceState.getBoolean(KEY_SEARCH_MODE);
|
||||
mHasFirstRefresh = savedInstanceState.getBoolean(KEY_HAS_FIRST_REFRESH);
|
||||
mFavCountArray = savedInstanceState.getIntArray(KEY_FAV_COUNT_ARRAY);
|
||||
}
|
||||
@@ -212,7 +207,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
}
|
||||
outState.putBoolean(KEY_HAS_FIRST_REFRESH, hasFirstRefresh);
|
||||
outState.putParcelable(KEY_URL_BUILDER, mUrlBuilder);
|
||||
outState.putBoolean(KEY_SEARCH_MODE, mSearchMode);
|
||||
outState.putIntArray(KEY_FAV_COUNT_ARRAY, mFavCountArray);
|
||||
}
|
||||
|
||||
@@ -243,6 +237,7 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
mRecyclerView = mContentLayout.getRecyclerView();
|
||||
FastScroller fastScroller = mContentLayout.getFastScroller();
|
||||
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
|
||||
mFabLayout.addOnExpandListener(new FabLayoutListener());
|
||||
((ViewGroup) mFabLayout.getParent()).removeView(mFabLayout);
|
||||
AssertUtils.assertNotNull(container);
|
||||
container.addView(mFabLayout);
|
||||
@@ -282,15 +277,9 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
mFabLayout.setAutoCancel(true);
|
||||
mFabLayout.setHidePrimaryFab(false);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
mFabLayout.setOnExpandListener(this);
|
||||
mFabLayout.addOnExpandListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
// Restore search mode
|
||||
if (mSearchMode) {
|
||||
mSearchMode = false;
|
||||
enterSearchMode();
|
||||
}
|
||||
|
||||
// Only refresh for the first time
|
||||
if (!mHasFirstRefresh) {
|
||||
mHasFirstRefresh = true;
|
||||
@@ -418,19 +407,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
mDrawerAdapter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
} else if (mFabLayout != null && mFabLayout.isExpanded()) {
|
||||
mFabLayout.toggle();
|
||||
} else if (mSearchMode) {
|
||||
exitSearchMode();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartDragHandler() {
|
||||
// Lock right drawer
|
||||
@@ -466,8 +442,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
return true;
|
||||
}
|
||||
|
||||
exitSearchMode();
|
||||
|
||||
mUrlBuilder.setKeyword(null);
|
||||
mUrlBuilder.setFavCat(newFavCat);
|
||||
updateSearchBar();
|
||||
@@ -496,7 +470,7 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
|
||||
public boolean onItemLongClick(int position) {
|
||||
// Can not into
|
||||
if (mRecyclerView != null && !mSearchMode) {
|
||||
if (mRecyclerView != null) {
|
||||
if (!mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.intoCustomChoiceMode();
|
||||
}
|
||||
@@ -515,8 +489,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
return;
|
||||
}
|
||||
|
||||
exitSearchMode();
|
||||
|
||||
mUrlBuilder.setKeyword(query);
|
||||
updateSearchBar();
|
||||
mHelper.refresh();
|
||||
@@ -699,22 +671,6 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
}
|
||||
}
|
||||
|
||||
private void enterSearchMode() {
|
||||
if (mSearchMode) {
|
||||
return;
|
||||
}
|
||||
mSearchMode = true;
|
||||
showSearchBar();
|
||||
}
|
||||
|
||||
private void exitSearchMode() {
|
||||
if (!mSearchMode) {
|
||||
return;
|
||||
}
|
||||
mSearchMode = false;
|
||||
showSearchBar();
|
||||
}
|
||||
|
||||
private void onGetFavoritesSuccess(FavoritesParser.Result result, int taskId) {
|
||||
if (mHelper != null && mHelper.isCurrentTask(taskId)) {
|
||||
|
||||
@@ -1049,6 +1005,14 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
}
|
||||
}
|
||||
|
||||
private class FabLayoutListener implements FabLayout.OnExpandListener {
|
||||
@Override
|
||||
public void onExpand(boolean expanded) {
|
||||
if (!expanded && mRecyclerView != null && mRecyclerView.isInCustomChoice())
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
}
|
||||
}
|
||||
|
||||
private class FavoritesHelper extends GalleryInfoContentHelper {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -586,7 +585,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
mFabLayout.setExpanded(false);
|
||||
mFabLayout.setHidePrimaryFab(false);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
mFabLayout.setOnExpandListener(this);
|
||||
mFabLayout.addOnExpandListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
int colorID = ResourcesKt.resolveColor(getTheme(), com.google.android.material.R.attr.colorOnSurface);
|
||||
@@ -780,19 +779,11 @@ public final class GalleryListScene extends SearchBarScene
|
||||
}
|
||||
|
||||
public boolean isBackpressCanPreviewLauncherStatus() {
|
||||
if (null != mFabLayout && mFabLayout.isExpanded()) {
|
||||
return false;
|
||||
}
|
||||
return mState == STATE_NORMAL && getStackIndex() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (null != mFabLayout && mFabLayout.isExpanded()) {
|
||||
mFabLayout.setExpanded(false);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mState) {
|
||||
case STATE_NORMAL:
|
||||
if (getStackIndex() == 0)
|
||||
|
||||
@@ -23,9 +23,10 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.Interpolator
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.scene.StageActivity
|
||||
import com.hippo.yorozuya.AnimationUtils
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener
|
||||
|
||||
@@ -40,9 +41,31 @@ class FabLayout @JvmOverloads constructor(
|
||||
private var mAutoCancel = true
|
||||
private var mHidePrimaryFab = false
|
||||
private var mMainFabCenterY = -1f
|
||||
private var mOnExpandListener: OnExpandListener? = null
|
||||
private var mOnExpandListeners = arrayListOf<OnExpandListener>()
|
||||
private var mOnClickFabListener: OnClickFabListener? = null
|
||||
|
||||
private val mOnBackPressedCallback = object : OnBackPressedCallback(false), OnExpandListener {
|
||||
override fun handleOnBackPressed() {
|
||||
isExpanded = false
|
||||
}
|
||||
|
||||
override fun onExpand(expanded: Boolean) {
|
||||
isEnabled = expanded
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
(context as ComponentActivity).onBackPressedDispatcher.addCallback(mOnBackPressedCallback)
|
||||
mOnExpandListeners.add(mOnBackPressedCallback)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
mOnBackPressedCallback.remove()
|
||||
mOnExpandListeners.remove(mOnBackPressedCallback)
|
||||
}
|
||||
|
||||
init {
|
||||
isSoundEffectsEnabled = false
|
||||
clipToPadding = false
|
||||
@@ -166,8 +189,8 @@ class FabLayout @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnExpandListener(listener: OnExpandListener?) {
|
||||
mOnExpandListener = listener
|
||||
fun addOnExpandListener(listener: OnExpandListener) {
|
||||
mOnExpandListeners.add(listener)
|
||||
}
|
||||
|
||||
fun setOnClickFabListener(listener: OnClickFabListener?) {
|
||||
@@ -261,9 +284,8 @@ class FabLayout @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
mOnExpandListener?.onExpand(expanded)
|
||||
mOnExpandListeners.forEach { it.onExpand(expanded) }
|
||||
}
|
||||
(context as StageActivity).updateBackPressCallBackStatus()
|
||||
}
|
||||
|
||||
private fun setPrimaryFabAnimation(child: View, expanded: Boolean, delay: Boolean) {
|
||||
|
||||
Reference in new issue
Block a user