mirror of
https://github.com/mastodon/mastodon-android.git
synced 2024-12-23 07:26:46 +01:00
Allow "new posts" button to be swiped away
This commit is contained in:
parent
eda1526830
commit
ee1a0cc666
@ -4,6 +4,7 @@ import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -34,7 +35,6 @@ import android.widget.Toolbar;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.joinmastodon.android.BuildConfig;
|
||||
import org.joinmastodon.android.E;
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||
@ -61,6 +61,7 @@ import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
|
||||
import org.joinmastodon.android.ui.viewcontrollers.HomeTimelineMenuController;
|
||||
import org.joinmastodon.android.ui.viewcontrollers.ToolbarDropdownMenuController;
|
||||
import org.joinmastodon.android.ui.views.FixedAspectRatioImageView;
|
||||
import org.joinmastodon.android.ui.views.NewPostsButtonContainer;
|
||||
import org.joinmastodon.android.updater.GithubSelfUpdater;
|
||||
import org.parceler.Parcels;
|
||||
|
||||
@ -89,7 +90,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
|
||||
private FixedAspectRatioImageView listsDropdownArrow;
|
||||
private TextView listsDropdownText;
|
||||
private Button newPostsBtn;
|
||||
private View newPostsBtnWrap;
|
||||
private NewPostsButtonContainer newPostsBtnWrap;
|
||||
private boolean newPostsBtnShown;
|
||||
private AnimatorSet currentNewPostsAnim;
|
||||
private ToolbarDropdownMenuController dropdownController;
|
||||
@ -249,6 +250,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState){
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
@ -267,6 +269,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
|
||||
newPostsBtnWrap.setAlpha(0f);
|
||||
newPostsBtnWrap.setTranslationY(V.dp(-56));
|
||||
}
|
||||
newPostsBtnWrap.setOnHideButtonListener(this::hideNewPostsButton);
|
||||
updateToolbarLogo();
|
||||
list.addOnScrollListener(new RecyclerView.OnScrollListener(){
|
||||
@Override
|
||||
@ -602,6 +605,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation){
|
||||
newPostsBtnWrap.setVisibility(View.GONE);
|
||||
newPostsBtn.setTranslationY(0);
|
||||
currentNewPostsAnim=null;
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,84 @@
|
||||
package org.joinmastodon.android.ui.views;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
||||
|
||||
public class NewPostsButtonContainer extends FrameLayout{
|
||||
private GestureDetector gestureDetector;
|
||||
private Runnable onHideButtonListener;
|
||||
private float touchslop;
|
||||
|
||||
public NewPostsButtonContainer(Context context){
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public NewPostsButtonContainer(Context context, AttributeSet attrs){
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public NewPostsButtonContainer(Context context, AttributeSet attrs, int defStyle){
|
||||
super(context, attrs, defStyle);
|
||||
gestureDetector=new GestureDetector(context, new GestureDetector.SimpleOnGestureListener(){
|
||||
private float totalYOffset;
|
||||
|
||||
@Override
|
||||
public boolean onDown(@NonNull MotionEvent e){
|
||||
totalYOffset=0;
|
||||
getChildAt(0).animate().cancel();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(@Nullable MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY){
|
||||
totalYOffset+=distanceY;
|
||||
getChildAt(0).setTranslationY(-Math.max(0, totalYOffset));
|
||||
return totalYOffset>0;
|
||||
}
|
||||
});
|
||||
gestureDetector.setIsLongpressEnabled(false);
|
||||
touchslop=ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev){
|
||||
if(gestureDetector.onTouchEvent(ev))
|
||||
return true;
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev){
|
||||
boolean r=gestureDetector.onTouchEvent(ev);
|
||||
if(ev.getAction()==MotionEvent.ACTION_UP){
|
||||
if(!r){
|
||||
if(getChildAt(0).getTranslationY()<-touchslop){
|
||||
onHideButtonListener.run();
|
||||
}else{
|
||||
animateBack();
|
||||
}
|
||||
}
|
||||
}else if(ev.getAction()==MotionEvent.ACTION_CANCEL){
|
||||
animateBack();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private void animateBack(){
|
||||
getChildAt(0).animate().translationY(0).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
|
||||
}
|
||||
|
||||
public void setOnHideButtonListener(Runnable onHideButtonListener){
|
||||
this.onHideButtonListener=onHideButtonListener;
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
android:contentDescription="@string/new_post"
|
||||
android:src="@drawable/ic_edit_24px"/>
|
||||
|
||||
<FrameLayout
|
||||
<org.joinmastodon.android.ui.views.NewPostsButtonContainer
|
||||
android:id="@+id/new_posts_btn_wrap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -56,7 +56,7 @@
|
||||
android:elevation="@dimen/m3_sys_elevation_level4"
|
||||
android:stateListAnimator="@animator/squish"
|
||||
android:text="@string/see_new_posts"/>
|
||||
</FrameLayout>
|
||||
</org.joinmastodon.android.ui.views.NewPostsButtonContainer>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/donation_banner"
|
||||
|
Loading…
Reference in New Issue
Block a user