feat(Scrollable): add isScrolledToTop

Checks if the list is already scrolled to the top. Can be used to change the interaction depending on it.
This commit is contained in:
FineFindus
2023-03-18 15:43:14 +01:00
parent 02af385853
commit 287e75e54a
13 changed files with 66 additions and 0 deletions

View File

@@ -631,6 +631,11 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
protected int getListWidthForMediaLayout(){
return list.getWidth();
}

View File

@@ -237,6 +237,11 @@ public class EditTimelinesFragment extends BaseRecyclerFragment<TimelineDefiniti
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
@Override
public void onDestroy() {
super.onDestroy();

View File

@@ -149,6 +149,11 @@ public class FollowRequestsListFragment extends BaseRecyclerFragment<FollowReque
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
private class AccountsAdapter extends UsableRecyclerView.Adapter<AccountViewHolder> implements ImageLoaderRecyclerAdapter{
public AccountsAdapter(){

View File

@@ -76,6 +76,11 @@ public class FollowedHashtagsFragment extends BaseRecyclerFragment<Hashtag> impl
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
private class HashtagsAdapter extends RecyclerView.Adapter<HashtagViewHolder>{
@NonNull
@Override

View File

@@ -480,6 +480,11 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
((ScrollableToTop) fragments[pager.getCurrentItem()]).scrollToTop();
}
@Override
public boolean isScrolledToTop() {
return ((ScrollableToTop) fragments[pager.getCurrentItem()]).isScrolledToTop();
}
public void hideNewPostsButton(){
if(!newPostsBtnShown)
return;

View File

@@ -200,6 +200,11 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
private class ListsAdapter extends RecyclerView.Adapter<ListViewHolder>{
@NonNull
@Override

View File

@@ -205,6 +205,11 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc
getFragmentForPage(pager.getCurrentItem()).scrollToTop();
}
@Override
public boolean isScrolledToTop() {
return getFragmentForPage(pager.getCurrentItem()).isScrolledToTop();
}
public void loadData(){
refreshFollowRequestsBadge();
if(allNotificationsFragment!=null && !allNotificationsFragment.loaded && !allNotificationsFragment.dataLoading)

View File

@@ -1229,6 +1229,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
scrollView.smoothScrollTo(0, 0);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
private void onFollowersOrFollowingClick(View v){
Bundle args=new Bundle();
args.putString("account", accountID);

View File

@@ -6,6 +6,8 @@ import androidx.recyclerview.widget.RecyclerView;
import me.grishka.appkit.utils.V;
public interface ScrollableToTop{
boolean isScrolledToTop();
void scrollToTop();
/**

View File

@@ -146,6 +146,11 @@ public class DiscoverAccountsFragment extends BaseRecyclerFragment<DiscoverAccou
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
@Override
public boolean isOnTop() {
return isRecyclerViewOnTop(list);

View File

@@ -302,6 +302,15 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
}
}
@Override
public boolean isScrolledToTop() {
if(!searchActive){
return ((ScrollableToTop)getFragmentForPage(pager.getCurrentItem())).isScrolledToTop();
}else{
return searchFragment.isScrolledToTop();
}
}
public void loadData(){
if(hashtagsFragment!=null && !hashtagsFragment.loaded && !hashtagsFragment.dataLoading)
hashtagsFragment.loadData();

View File

@@ -89,6 +89,11 @@ public class DiscoverNewsFragment extends BaseRecyclerFragment<Card> implements
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
@Override
public boolean isOnTop() {
return isRecyclerViewOnTop(list);

View File

@@ -74,6 +74,11 @@ public class TrendingHashtagsFragment extends BaseRecyclerFragment<Hashtag> impl
smoothScrollRecyclerViewToTop(list);
}
@Override
public boolean isScrolledToTop() {
return list.getChildAt(0).getTop() == 0;
}
@Override
public boolean isOnTop() {
return isRecyclerViewOnTop(list);