show compose button when switching tab

closes sk22#506
This commit is contained in:
sk
2023-05-25 20:26:59 +02:00
parent ec556511e6
commit b1e0dc5843
5 changed files with 54 additions and 26 deletions

View File

@@ -68,7 +68,7 @@ import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.V; import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.UsableRecyclerView; import me.grishka.appkit.views.UsableRecyclerView;
public abstract class BaseStatusListFragment<T extends DisplayItemsParent> extends RecyclerFragment<T> implements PhotoViewerHost, ScrollableToTop{ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> extends RecyclerFragment<T> implements PhotoViewerHost, ScrollableToTop, HasFab{
protected ArrayList<StatusDisplayItem> displayItems=new ArrayList<>(); protected ArrayList<StatusDisplayItem> displayItems=new ArrayList<>();
protected DisplayItemsAdapter adapter; protected DisplayItemsAdapter adapter;
protected String accountID; protected String accountID;
@@ -268,15 +268,16 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
}); });
} }
@Override
public @Nullable View getFab() { public @Nullable View getFab() {
if (getParentFragment() instanceof HasFab l) return l.getFab(); if (getParentFragment() instanceof HasFab l) return l.getFab();
else return fab; else return fab;
} }
public void animateFab(boolean show) { @Override
public void showFab() {
View fab = getFab(); View fab = getFab();
if (fab == null) return; if (fab == null || fab.getVisibility() == View.VISIBLE) return;
if (show && fab.getVisibility() != View.VISIBLE) {
fab.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE);
TranslateAnimation animate = new TranslateAnimation( TranslateAnimation animate = new TranslateAnimation(
0, 0,
@@ -285,7 +286,12 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
0); 0);
animate.setDuration(300); animate.setDuration(300);
fab.startAnimation(animate); fab.startAnimation(animate);
} else if (!show && fab.getVisibility() == View.VISIBLE) { }
@Override
public void hideFab() {
View fab = getFab();
if (fab == null || fab.getVisibility() != View.VISIBLE) return;
TranslateAnimation animate = new TranslateAnimation( TranslateAnimation animate = new TranslateAnimation(
0, 0,
0, 0,
@@ -296,7 +302,6 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
fab.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE);
scrollDiff = 0; scrollDiff = 0;
} }
}
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState){ public void onViewCreated(View view, Bundle savedInstanceState){
@@ -312,10 +317,10 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
View fab = getFab(); View fab = getFab();
if (fab!=null && GlobalUserPreferences.autoHideFab) { if (fab!=null && GlobalUserPreferences.autoHideFab) {
if (dy > 0 && fab.getVisibility() == View.VISIBLE) { if (dy > 0 && fab.getVisibility() == View.VISIBLE) {
animateFab(false); hideFab();
} else if (dy < 0 && fab.getVisibility() != View.VISIBLE) { } else if (dy < 0 && fab.getVisibility() != View.VISIBLE) {
if (list.getChildAt(0).getTop() == 0 || scrollDiff > 400) { if (list.getChildAt(0).getTop() == 0 || scrollDiff > 400) {
animateFab(true); showFab();
scrollDiff = 0; scrollDiff = 0;
} else { } else {
scrollDiff += Math.abs(dy); scrollDiff += Math.abs(dy);

View File

@@ -4,4 +4,6 @@ import android.view.View;
public interface HasFab { public interface HasFab {
View getFab(); View getFab();
void showFab();
void hideFab();
} }

View File

@@ -228,6 +228,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
} }
getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit(); getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit();
maybeTriggerLoading(newFragment); maybeTriggerLoading(newFragment);
if (newFragment instanceof HasFab fabulous) fabulous.showFab();
currentTab=tab; currentTab=tab;
((FragmentStackActivity)getActivity()).invalidateSystemBarColors(this); ((FragmentStackActivity)getActivity()).invalidateSystemBarColors(this);
} }

View File

@@ -448,10 +448,20 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
updateSwitcherIcon(i); updateSwitcherIcon(i);
} }
@Override
public void showFab() {
if (fragments[pager.getCurrentItem()] instanceof BaseStatusListFragment<?> l) l.showFab();
}
@Override
public void hideFab() {
if (fragments[pager.getCurrentItem()] instanceof BaseStatusListFragment<?> l) l.hideFab();
}
private void updateSwitcherIcon(int i) { private void updateSwitcherIcon(int i) {
timelineIcon.setImageResource(timelines[i].getIcon().iconRes); timelineIcon.setImageResource(timelines[i].getIcon().iconRes);
timelineTitle.setText(timelines[i].getTitle(getContext())); timelineTitle.setText(timelines[i].getTitle(getContext()));
if (fragments[i] instanceof BaseStatusListFragment<?> l) l.animateFab(true); showFab();
} }
@Override @Override

View File

@@ -758,6 +758,16 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
return fab; return fab;
} }
@Override
public void showFab() {
if (getFragmentForPage(pager.getCurrentItem()) instanceof HasFab fabulous) fabulous.showFab();
}
@Override
public void hideFab() {
if (getFragmentForPage(pager.getCurrentItem()) instanceof HasFab fabulous) fabulous.hideFab();
}
private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){ private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){
int topBarsH=getToolbar().getHeight()+statusBarHeight; int topBarsH=getToolbar().getHeight()+statusBarHeight;
if(scrollY>avatarBorder.getTop()-topBarsH){ if(scrollY>avatarBorder.getTop()-topBarsH){