Scroll fragments to top from the tab bar
This commit is contained in:
@@ -56,7 +56,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 BaseRecyclerFragment<T> implements PhotoViewerHost{
|
public abstract class BaseStatusListFragment<T extends DisplayItemsParent> extends BaseRecyclerFragment<T> implements PhotoViewerHost, ScrollableToTop{
|
||||||
protected ArrayList<StatusDisplayItem> displayItems=new ArrayList<>();
|
protected ArrayList<StatusDisplayItem> displayItems=new ArrayList<>();
|
||||||
protected DisplayItemsAdapter adapter;
|
protected DisplayItemsAdapter adapter;
|
||||||
protected String accountID;
|
protected String accountID;
|
||||||
@@ -377,22 +377,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||||||
Toolbar toolbar=getToolbar();
|
Toolbar toolbar=getToolbar();
|
||||||
if(toolbar==null)
|
if(toolbar==null)
|
||||||
return;
|
return;
|
||||||
toolbar.setOnClickListener(v->{
|
toolbar.setOnClickListener(v->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 int getMainAdapterOffset(){
|
protected int getMainAdapterOffset(){
|
||||||
@@ -552,6 +537,24 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||||||
return holders;
|
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{
|
protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter<BindableViewHolder<StatusDisplayItem>> implements ImageLoaderRecyclerAdapter{
|
||||||
|
|
||||||
public DisplayItemsAdapter(){
|
public DisplayItemsAdapter(){
|
||||||
|
|||||||
@@ -158,6 +158,11 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
|||||||
|
|
||||||
private void onTabSelected(@IdRes int tab){
|
private void onTabSelected(@IdRes int tab){
|
||||||
Fragment newFragment=fragmentForTab(tab);
|
Fragment newFragment=fragmentForTab(tab);
|
||||||
|
if(tab==currentTab){
|
||||||
|
if(newFragment instanceof ScrollableToTop)
|
||||||
|
((ScrollableToTop) newFragment).scrollToTop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit();
|
getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit();
|
||||||
if(newFragment instanceof LoaderFragment){
|
if(newFragment instanceof LoaderFragment){
|
||||||
LoaderFragment lf=(LoaderFragment) newFragment;
|
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.CubicBezierInterpolator;
|
||||||
import me.grishka.appkit.utils.V;
|
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 AVATAR_RESULT=722;
|
||||||
private static final int COVER_RESULT=343;
|
private static final int COVER_RESULT=343;
|
||||||
|
|
||||||
@@ -430,10 +430,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||||||
toolbarTitleView.setTranslationY(titleTransY);
|
toolbarTitleView.setTranslationY(titleTransY);
|
||||||
toolbarSubtitleView.setTranslationY(titleTransY);
|
toolbarSubtitleView.setTranslationY(titleTransY);
|
||||||
}
|
}
|
||||||
getToolbar().setOnClickListener(v->{
|
getToolbar().setOnClickListener(v->scrollToTop());
|
||||||
getScrollableRecyclerView().scrollToPosition(0);
|
|
||||||
scrollView.smoothScrollTo(0, 0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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>{
|
private class ProfilePagerAdapter extends RecyclerView.Adapter<SimpleViewHolder>{
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.joinmastodon.android.fragments;
|
||||||
|
|
||||||
|
/*package*/ interface ScrollableToTop{
|
||||||
|
void scrollToTop();
|
||||||
|
}
|
||||||
@@ -1,25 +1,27 @@
|
|||||||
package org.joinmastodon.android.model;
|
package org.joinmastodon.android.model;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.AllFieldsAreRequired;
|
|
||||||
import org.joinmastodon.android.api.ObjectValidationException;
|
import org.joinmastodon.android.api.ObjectValidationException;
|
||||||
|
import org.joinmastodon.android.api.RequiredField;
|
||||||
import org.parceler.Parcel;
|
import org.parceler.Parcel;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllFieldsAreRequired
|
|
||||||
@Parcel
|
@Parcel
|
||||||
public class Poll extends BaseModel{
|
public class Poll extends BaseModel{
|
||||||
|
@RequiredField
|
||||||
public String id;
|
public String id;
|
||||||
public Instant expiresAt;
|
public Instant expiresAt;
|
||||||
public boolean expired;
|
public boolean expired;
|
||||||
public boolean multiple;
|
public boolean multiple;
|
||||||
public int votersCount;
|
public int votersCount;
|
||||||
public boolean voted;
|
public boolean voted;
|
||||||
|
@RequiredField
|
||||||
public List<Integer> ownVotes;
|
public List<Integer> ownVotes;
|
||||||
|
@RequiredField
|
||||||
public List<Option> options;
|
public List<Option> options;
|
||||||
|
@RequiredField
|
||||||
public List<Emoji> emojis;
|
public List<Emoji> emojis;
|
||||||
|
|
||||||
public transient ArrayList<Option> selectedOptions;
|
public transient ArrayList<Option> selectedOptions;
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class PhotoLayoutHelper{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}else if(cnt==4){
|
}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 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 h=(maxW-2*marginW)/(ratios.get(1)+ratios.get(2)+ratios.get(3));
|
||||||
float w0=h*ratios.get(1);
|
float w0=h*ratios.get(1);
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ public class TabBar extends LinearLayout{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onChildClick(View v){
|
private void onChildClick(View v){
|
||||||
|
listener.accept(selectedTabID);
|
||||||
if(v.getId()==selectedTabID)
|
if(v.getId()==selectedTabID)
|
||||||
return;
|
return;
|
||||||
findViewById(selectedTabID).setSelected(false);
|
findViewById(selectedTabID).setSelected(false);
|
||||||
v.setSelected(true);
|
v.setSelected(true);
|
||||||
selectedTabID=v.getId();
|
selectedTabID=v.getId();
|
||||||
listener.accept(selectedTabID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(IntConsumer listener){
|
public void setListener(IntConsumer listener){
|
||||||
|
|||||||
Reference in New Issue
Block a user