From 7c8624bd53176bbe2b77d9e03ab11377e9587dd5 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 6 Oct 2023 16:55:02 +0200 Subject: [PATCH] fix alpha animations closes sk22#839 --- .../displayitems/FooterStatusDisplayItem.java | 22 ++++++++-------- .../ui/displayitems/GapStatusDisplayItem.java | 2 +- .../displayitems/TextStatusDisplayItem.java | 16 ++++++------ .../android/ui/utils/UiUtils.java | 26 +++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index 378728911d..7c323825f0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -63,7 +63,7 @@ public static class Holder extends StatusDisplayItem.Holder { longClickPerformed = touchingView != null && touchingView.performLongClick(); if (longClickPerformed && touchingView != null) { - touchingView.startAnimation(opacityIn); + UiUtils.opacityIn(touchingView); touchingView.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start(); } }; @@ -160,7 +160,7 @@ private boolean onButtonTouch(View v, MotionEvent event){ if (!longClickPerformed) v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start(); if (disabled) return true; if (action == MotionEvent.ACTION_UP && !longClickPerformed) v.performClick(); - else if (!longClickPerformed) v.startAnimation(opacityIn); + else if (!longClickPerformed) UiUtils.opacityIn(v); } else if (action == MotionEvent.ACTION_DOWN) { longClickPerformed = false; touchingView = v; @@ -168,13 +168,13 @@ private boolean onButtonTouch(View v, MotionEvent event){ v.animate().scaleX(0.85f).scaleY(0.85f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(75).start(); if (disabled) return true; v.postDelayed(longClickRunnable, ViewConfiguration.getLongPressTimeout()); - v.startAnimation(opacityOut); + UiUtils.opacityOut(v); } return true; } private void onReplyClick(View v){ - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); Bundle args=new Bundle(); args.putString("account", item.accountID); args.putParcelable("replyTo", Parcels.wrap(item.status)); @@ -198,7 +198,7 @@ private boolean onReplyLongClick(View v) { private void onBoostClick(View v){ if (GlobalUserPreferences.confirmBoost) { - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); onBoostLongClick(v); return; } @@ -207,7 +207,7 @@ private void onBoostClick(View v){ } private void boostConsumer(View v, Status r) { - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); bindText(boosts, r.reblogsCount); } @@ -218,7 +218,7 @@ private boolean onBoostLongClick(View v){ AccountSession session = AccountSessionManager.getInstance().getAccount(item.accountID); Consumer doReblog = (visibility) -> { - v.startAnimation(opacityOut); + UiUtils.opacityOut(v); session.getStatusInteractionController() .setReblogged(item.status, !item.status.reblogged, visibility, r->boostConsumer(v, r)); dialog.dismiss(); @@ -271,7 +271,7 @@ private boolean onBoostLongClick(View v){ menu.findViewById(R.id.quote).setOnClickListener(c->{ dialog.dismiss(); - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); Bundle args=new Bundle(); args.putString("account", item.accountID); AccountSession accountSession=AccountSessionManager.getInstance().getAccount(item.accountID); @@ -296,7 +296,7 @@ private boolean onBoostLongClick(View v){ private void onFavoriteClick(View v){ favorite.setSelected(!item.status.favourited); AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setFavorited(item.status, !item.status.favourited, r->{ - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); bindText(favorites, r.favouritesCount); }); } @@ -318,7 +318,7 @@ private boolean onFavoriteLongClick(View v) { private void onBookmarkClick(View v){ bookmark.setSelected(!item.status.bookmarked); AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked, r->{ - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); }); } @@ -337,7 +337,7 @@ private boolean onBookmarkLongClick(View v) { } private void onShareClick(View v){ - v.startAnimation(opacityIn); + UiUtils.opacityIn(v); Intent intent=new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, item.status.url); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GapStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GapStatusDisplayItem.java index 1009bb1481..9615b2b331 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GapStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GapStatusDisplayItem.java @@ -72,7 +72,7 @@ public void onBind(GapStatusDisplayItem item){ private void onViewClick(View v){ if(item.loading) return; boolean isTop=v==top; - (isTop ? textTop : textBottom).startAnimation(UiUtils.opacityOut); + UiUtils.opacityOut(isTop ? textTop : textBottom); V.setVisibilityAnimated((isTop ? progressTop : progressBottom), View.VISIBLE); item.parentFragment.onGapClick(this, isTop); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java index 4801c85022..b70b0f4ae4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java @@ -1,7 +1,5 @@ package org.joinmastodon.android.ui.displayitems; -import static org.joinmastodon.android.ui.utils.UiUtils.opacityIn; - import android.app.Activity; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; @@ -30,6 +28,7 @@ import me.grishka.appkit.imageloader.ImageLoaderViewHolder; import me.grishka.appkit.imageloader.MovieDrawable; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; +import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; public class TextStatusDisplayItem extends StatusDisplayItem{ @@ -201,6 +200,7 @@ public void updateTranslation(boolean updateText){ translationProgress=findViewById(R.id.translation_progress); translationButton.setOnClickListener(v->item.parentFragment.togglePostTranslation(item.status, item.parentID)); } + if(translationButton!=null) translationButton.animate().cancel(); if(item.status.translationState==Status.TranslationState.HIDDEN){ if(updateText) text.setText(item.text); if(translationFooter==null) return; @@ -212,8 +212,8 @@ public void updateTranslation(boolean updateText){ String displayLang=Locale.forLanguageTag(lang != null ? lang : AccountSessionManager.get(item.parentFragment.getAccountID()).preferences.postingDefaultLanguage).getDisplayLanguage(); translationButton.setText(item.parentFragment.getString(R.string.translate_post, !displayLang.isBlank() ? displayLang : lang)); - translationButton.setEnabled(true); - translationButton.setAlpha(1); + translationButton.setClickable(true); + translationButton.animate().alpha(1).setDuration(100).start(); translationInfo.setVisibility(View.GONE); UiUtils.beginLayoutTransition((ViewGroup) translationButtonWrap); }else{ @@ -221,8 +221,8 @@ public void updateTranslation(boolean updateText){ if(item.status.translationState==Status.TranslationState.SHOWN){ translationProgress.setVisibility(View.GONE); translationButton.setText(R.string.translation_show_original); - translationButton.setEnabled(true); - translationButton.setAlpha(1); + translationButton.setClickable(true); + translationButton.animate().alpha(1).setDuration(200).start(); translationInfo.setVisibility(View.VISIBLE); translationButton.setVisibility(View.VISIBLE); String displayLang=Locale.forLanguageTag(item.status.translation.detectedSourceLanguage).getDisplayLanguage(); @@ -236,8 +236,8 @@ public void updateTranslation(boolean updateText){ } }else{ // LOADING translationProgress.setVisibility(View.VISIBLE); - translationButton.setEnabled(false); - translationButton.startAnimation(opacityIn); + translationButton.setClickable(false); + translationButton.animate().alpha(UiUtils.ALPHA_PRESSED).setStartDelay(50).setDuration(300).setInterpolator(CubicBezierInterpolator.DEFAULT).start(); translationInfo.setVisibility(View.INVISIBLE); UiUtils.beginLayoutTransition((ViewGroup) translationButton.getParent()); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 678f1d470a..a77b30ca43 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -54,9 +54,8 @@ import android.view.SubMenu; import android.view.View; import android.view.ViewGroup; +import android.view.ViewPropertyAnimator; import android.view.WindowInsets; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; import android.webkit.MimeTypeMap; import android.widget.Button; import android.widget.ImageView; @@ -178,17 +177,6 @@ public class UiUtils { public static int MAX_WIDTH, SCROLL_TO_TOP_DELTA; public static final float ALPHA_PRESSED=0.55f; - public static final Animation opacityOut, opacityIn; - - static { - opacityOut = new AlphaAnimation(1, ALPHA_PRESSED); - opacityOut.setDuration(300); - opacityOut.setInterpolator(CubicBezierInterpolator.DEFAULT); - opacityOut.setFillAfter(true); - opacityIn = new AlphaAnimation(ALPHA_PRESSED, 1); - opacityIn.setDuration(400); - opacityIn.setInterpolator(CubicBezierInterpolator.DEFAULT); - } private UiUtils() { } @@ -1748,4 +1736,16 @@ public static Optional extractPronouns(Context context, @Nullable Accoun .filter(Objects::nonNull) .findFirst(); } + + public static void opacityIn(View v){ + v.animate().alpha(1).setDuration(400).setInterpolator(CubicBezierInterpolator.DEFAULT).start(); + } + + public static void opacityOut(View v){ + opacityOut(v, ALPHA_PRESSED).start(); + } + + public static ViewPropertyAnimator opacityOut(View v, float alpha){ + return v.animate().alpha(alpha).setDuration(300).setInterpolator(CubicBezierInterpolator.DEFAULT); + } }