Scroll fragments to top from the tab bar
This commit is contained in:
parent
f4e71cf130
commit
d25b7e67b8
|
@ -56,7 +56,7 @@ import me.grishka.appkit.utils.BindableViewHolder;
|
|||
import me.grishka.appkit.utils.V;
|
||||
import me.grishka.appkit.views.UsableRecyclerView;
|
||||
|
||||
public abstract class BaseStatusListFragment<T extends DisplayItemsParent> extends BaseRecyclerFragment<T> implements PhotoViewerHost{
|
||||
public abstract class BaseStatusListFragment<T extends DisplayItemsParent> extends BaseRecyclerFragment<T> implements PhotoViewerHost, ScrollableToTop{
|
||||
protected ArrayList<StatusDisplayItem> displayItems=new ArrayList<>();
|
||||
protected DisplayItemsAdapter adapter;
|
||||
protected String accountID;
|
||||
|
@ -377,22 +377,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||
Toolbar toolbar=getToolbar();
|
||||
if(toolbar==null)
|
||||
return;
|
||||
toolbar.setOnClickListener(v->{
|
||||
if(list.getChildCount()>0 && list.getChildAdapterPosition(list.getChildAt(0))>10){
|
||||
list.scrollToPosition(0);
|
||||
list.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){
|
||||
@Override
|
||||
public boolean onPreDraw(){
|
||||
list.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
list.scrollBy(0, V.dp(300));
|
||||
list.smoothScrollToPosition(0);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}else{
|
||||
list.smoothScrollToPosition(0);
|
||||
}
|
||||
});
|
||||
toolbar.setOnClickListener(v->scrollToTop());
|
||||
}
|
||||
|
||||
protected int getMainAdapterOffset(){
|
||||
|
@ -552,6 +537,24 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||
return holders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollToTop(){
|
||||
if(list.getChildCount()>0 && list.getChildAdapterPosition(list.getChildAt(0))>10){
|
||||
list.scrollToPosition(0);
|
||||
list.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){
|
||||
@Override
|
||||
public boolean onPreDraw(){
|
||||
list.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
list.scrollBy(0, V.dp(300));
|
||||
list.smoothScrollToPosition(0);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}else{
|
||||
list.smoothScrollToPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter<BindableViewHolder<StatusDisplayItem>> implements ImageLoaderRecyclerAdapter{
|
||||
|
||||
public DisplayItemsAdapter(){
|
||||
|
|
|
@ -158,6 +158,11 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
|||
|
||||
private void onTabSelected(@IdRes int tab){
|
||||
Fragment newFragment=fragmentForTab(tab);
|
||||
if(tab==currentTab){
|
||||
if(newFragment instanceof ScrollableToTop)
|
||||
((ScrollableToTop) newFragment).scrollToTop();
|
||||
return;
|
||||
}
|
||||
getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit();
|
||||
if(newFragment instanceof LoaderFragment){
|
||||
LoaderFragment lf=(LoaderFragment) newFragment;
|
||||
|
|
|
@ -83,7 +83,7 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
|
|||
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
||||
import me.grishka.appkit.utils.V;
|
||||
|
||||
public class ProfileFragment extends LoaderFragment implements OnBackPressedListener{
|
||||
public class ProfileFragment extends LoaderFragment implements OnBackPressedListener, ScrollableToTop{
|
||||
private static final int AVATAR_RESULT=722;
|
||||
private static final int COVER_RESULT=343;
|
||||
|
||||
|
@ -430,10 +430,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
toolbarTitleView.setTranslationY(titleTransY);
|
||||
toolbarSubtitleView.setTranslationY(titleTransY);
|
||||
}
|
||||
getToolbar().setOnClickListener(v->{
|
||||
getScrollableRecyclerView().scrollToPosition(0);
|
||||
scrollView.smoothScrollTo(0, 0);
|
||||
});
|
||||
getToolbar().setOnClickListener(v->scrollToTop());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -798,6 +795,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollToTop(){
|
||||
getScrollableRecyclerView().scrollToPosition(0);
|
||||
scrollView.smoothScrollTo(0, 0);
|
||||
}
|
||||
|
||||
private class ProfilePagerAdapter extends RecyclerView.Adapter<SimpleViewHolder>{
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package org.joinmastodon.android.fragments;
|
||||
|
||||
/*package*/ interface ScrollableToTop{
|
||||
void scrollToTop();
|
||||
}
|
|
@ -1,25 +1,27 @@
|
|||
package org.joinmastodon.android.model;
|
||||
|
||||
import org.joinmastodon.android.api.AllFieldsAreRequired;
|
||||
import org.joinmastodon.android.api.ObjectValidationException;
|
||||
import org.joinmastodon.android.api.RequiredField;
|
||||
import org.parceler.Parcel;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@AllFieldsAreRequired
|
||||
@Parcel
|
||||
public class Poll extends BaseModel{
|
||||
@RequiredField
|
||||
public String id;
|
||||
public Instant expiresAt;
|
||||
public boolean expired;
|
||||
public boolean multiple;
|
||||
public int votersCount;
|
||||
public boolean voted;
|
||||
@RequiredField
|
||||
public List<Integer> ownVotes;
|
||||
@RequiredField
|
||||
public List<Option> options;
|
||||
@RequiredField
|
||||
public List<Emoji> emojis;
|
||||
|
||||
public transient ArrayList<Option> selectedOptions;
|
||||
|
|
|
@ -123,7 +123,7 @@ public class PhotoLayoutHelper{
|
|||
};
|
||||
}
|
||||
}else if(cnt==4){
|
||||
if(/*(ratios.get(0) > 1.2 * maxRatio || avgRatio > 1.5 * maxRatio) &&*/ orients.equals("wwww")){ // 2nd, 3rd and 4th photos are on the next line
|
||||
if(/*(ratios.get(0) > 1.2 * maxRatio || avgRatio > 1.5 * maxRatio) &&*/ orients.equals("wwww") || true /* temporary fix */){ // 2nd, 3rd and 4th photos are on the next line
|
||||
float hCover=Math.min(maxW/ratios.get(0), (maxH-marginH)*0.66f);
|
||||
float h=(maxW-2*marginW)/(ratios.get(1)+ratios.get(2)+ratios.get(3));
|
||||
float w0=h*ratios.get(1);
|
||||
|
|
|
@ -43,12 +43,12 @@ public class TabBar extends LinearLayout{
|
|||
}
|
||||
|
||||
private void onChildClick(View v){
|
||||
listener.accept(selectedTabID);
|
||||
if(v.getId()==selectedTabID)
|
||||
return;
|
||||
findViewById(selectedTabID).setSelected(false);
|
||||
v.setSelected(true);
|
||||
selectedTabID=v.getId();
|
||||
listener.accept(selectedTabID);
|
||||
}
|
||||
|
||||
public void setListener(IntConsumer listener){
|
||||
|
|
Loading…
Reference in New Issue