collapse start chat button

This commit is contained in:
Daniel Gultsch 2024-04-08 07:45:44 +02:00
parent b30a88e7a5
commit dc0a139392
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 59 additions and 0 deletions

View file

@ -299,6 +299,7 @@ public class ConversationsOverviewFragment extends XmppFragment {
});
this.binding.list.setAdapter(this.conversationsAdapter);
this.binding.list.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));
this.binding.list.addOnScrollListener(ExtendedFabSizeChanger.of(binding.fab));
this.touchHelper = new ItemTouchHelper(this.callback);
this.touchHelper.attachToRecyclerView(this.binding.list);
return binding.getRoot();

View file

@ -0,0 +1,29 @@
package eu.siacs.conversations.ui;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
public class ExtendedFabSizeChanger extends RecyclerView.OnScrollListener {
private final ExtendedFloatingActionButton extendedFloatingActionButton;
private ExtendedFabSizeChanger(
final ExtendedFloatingActionButton extendedFloatingActionButton) {
this.extendedFloatingActionButton = extendedFloatingActionButton;
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (RecyclerViews.findFirstVisibleItemPosition(recyclerView) > 0) {
extendedFloatingActionButton.shrink();
} else {
extendedFloatingActionButton.extend();
}
}
public static RecyclerView.OnScrollListener of(final ExtendedFloatingActionButton fab) {
return new ExtendedFabSizeChanger(fab);
}
}

View file

@ -0,0 +1,29 @@
package eu.siacs.conversations.ui;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public final class RecyclerViews {
private RecyclerViews() {
throw new IllegalStateException("Do not instantiate me");
}
public static boolean scrolledToTop(final RecyclerView recyclerView) {
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager linearLayoutManager) {
return linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 0;
} else {
return false;
}
}
public static int findFirstVisibleItemPosition(final RecyclerView recyclerView) {
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager linearLayoutManager) {
return linearLayoutManager.findFirstVisibleItemPosition();
} else {
return RecyclerView.NO_POSITION;
}
}
}