fix fab being hidden when scrolling to top

closes sk22#528
This commit is contained in:
sk 2023-06-03 21:54:57 +02:00
parent 6684311ec5
commit 056bfaacfe
7 changed files with 11 additions and 13 deletions

View File

@ -16,7 +16,6 @@ import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowInsets; import android.view.WindowInsets;
import android.view.animation.TranslateAnimation; import android.view.animation.TranslateAnimation;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -95,7 +94,6 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
@Override @Override
public void onCreate(Bundle savedInstanceState){ public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
UiUtils.loadMaxWidth(getContext());
if(GlobalUserPreferences.disableMarquee){ if(GlobalUserPreferences.disableMarquee){
setTitleMarqueeEnabled(false); setTitleMarqueeEnabled(false);
setSubtitleMarqueeEnabled(false); setSubtitleMarqueeEnabled(false);
@ -319,7 +317,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
currentPhotoViewer.offsetView(-dx, -dy); currentPhotoViewer.offsetView(-dx, -dy);
View fab = getFab(); View fab = getFab();
if (fab!=null && GlobalUserPreferences.autoHideFab) { if (fab!=null && GlobalUserPreferences.autoHideFab && dy != UiUtils.SCROLL_TO_TOP_DELTA) {
if (dy > 0 && fab.getVisibility() == View.VISIBLE) { if (dy > 0 && fab.getVisibility() == View.VISIBLE) {
hideFab(); hideFab();
} else if (dy < 0 && fab.getVisibility() != View.VISIBLE) { } else if (dy < 0 && fab.getVisibility() != View.VISIBLE) {

View File

@ -3,7 +3,8 @@ package org.joinmastodon.android.fragments;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import me.grishka.appkit.utils.V;
import org.joinmastodon.android.ui.utils.UiUtils;
public interface ScrollableToTop{ public interface ScrollableToTop{
void scrollToTop(); void scrollToTop();
@ -21,7 +22,7 @@ public interface ScrollableToTop{
@Override @Override
public boolean onPreDraw(){ public boolean onPreDraw(){
list.getViewTreeObserver().removeOnPreDrawListener(this); list.getViewTreeObserver().removeOnPreDrawListener(this);
list.scrollBy(0, V.dp(300)); list.scrollBy(0, UiUtils.SCROLL_TO_TOP_DELTA);
list.smoothScrollToPosition(0); list.smoothScrollToPosition(0);
return true; return true;
} }

View File

@ -65,7 +65,6 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
spoilerEmojiHelper.setText(parsedSpoilerText); spoilerEmojiHelper.setText(parsedSpoilerText);
} }
session = AccountSessionManager.getInstance().getAccount(parentFragment.getAccountID()); session = AccountSessionManager.getInstance().getAccount(parentFragment.getAccountID());
UiUtils.loadMaxWidth(parentFragment.getContext());
} }
public void setTranslationShown(boolean translationShown) { public void setTranslationShown(boolean translationShown) {

View File

@ -17,6 +17,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -141,15 +142,11 @@ public class UiUtils {
private static Handler mainHandler = new Handler(Looper.getMainLooper()); private static Handler mainHandler = new Handler(Looper.getMainLooper());
private static final DateTimeFormatter DATE_FORMATTER_SHORT_WITH_YEAR = DateTimeFormatter.ofPattern("d MMM uuuu"), DATE_FORMATTER_SHORT = DateTimeFormatter.ofPattern("d MMM"); private static final DateTimeFormatter DATE_FORMATTER_SHORT_WITH_YEAR = DateTimeFormatter.ofPattern("d MMM uuuu"), DATE_FORMATTER_SHORT = DateTimeFormatter.ofPattern("d MMM");
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT); public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
public static int MAX_WIDTH; public static int MAX_WIDTH, SCROLL_TO_TOP_DELTA;
private UiUtils() { private UiUtils() {
} }
public static void loadMaxWidth(Context ctx) {
if (MAX_WIDTH == 0) MAX_WIDTH = (int) ctx.getResources().getDimension(R.dimen.layout_max_width);
}
public static void launchWebBrowser(Context context, String url) { public static void launchWebBrowser(Context context, String url) {
try { try {
if (GlobalUserPreferences.useCustomTabs) { if (GlobalUserPreferences.useCustomTabs) {
@ -898,6 +895,10 @@ public class UiUtils {
ColorPalette palette = ColorPalette.palettes.get(GlobalUserPreferences.color); ColorPalette palette = ColorPalette.palettes.get(GlobalUserPreferences.color);
if (palette != null) palette.apply(context); if (palette != null) palette.apply(context);
Resources res = context.getResources();
MAX_WIDTH = (int) res.getDimension(R.dimen.layout_max_width);
SCROLL_TO_TOP_DELTA = (int) res.getDimension(R.dimen.scroll_to_top_delta);
} }
public static boolean isDarkTheme() { public static boolean isDarkTheme() {

View File

@ -23,7 +23,6 @@ public class ComposeMediaLayout extends ViewGroup{
public ComposeMediaLayout(Context context, AttributeSet attrs, int defStyle){ public ComposeMediaLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
UiUtils.loadMaxWidth(context);
} }
@Override @Override

View File

@ -27,7 +27,6 @@ public class MediaGridLayout extends ViewGroup{
public MediaGridLayout(Context context, AttributeSet attrs, int defStyle){ public MediaGridLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
UiUtils.loadMaxWidth(context);
} }
@Override @Override

View File

@ -3,4 +3,5 @@
<dimen name="text_max_height">220dp</dimen> <dimen name="text_max_height">220dp</dimen>
<dimen name="text_collapsed_height">145dp</dimen> <dimen name="text_collapsed_height">145dp</dimen>
<dimen name="layout_max_width">450dp</dimen> <dimen name="layout_max_width">450dp</dimen>
<dimen name="scroll_to_top_delta">300dp</dimen>
</resources> </resources>