From 5374ac766c8296ec7d6585b25fdad955d7935a05 Mon Sep 17 00:00:00 2001 From: sk Date: Sat, 7 Oct 2023 15:21:06 +0200 Subject: [PATCH] prettier visibility toggle animation maybe fix sk22#845 --- .../fragments/BaseStatusListFragment.java | 5 ++- .../displayitems/HeaderStatusDisplayItem.java | 35 ++++++++++--------- .../main/res/layout/display_item_header.xml | 2 ++ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 29881041e..f372680e0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -9,7 +9,6 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; @@ -559,12 +558,12 @@ public abstract class BaseStatusListFragment exten // to do this if the media grid is not bound, tho - so, doing it ourselves here status.sensitiveRevealed = !status.sensitiveRevealed; } - holder.rebind(); + if(holder.getItem().hasVisibilityToggle) holder.animateVisibilityToggle(false); } public void onSensitiveRevealed(MediaGridStatusDisplayItem.Holder holder) { HeaderStatusDisplayItem.Holder header = findHolderOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class); - if(header != null) header.rebind(); + if(header != null && header.getItem().hasVisibilityToggle) header.animateVisibilityToggle(true); } protected void toggleSpoiler(Status status, String itemID){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index c1c5dc01c..ac7ee8e1b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -66,6 +66,7 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.imageloader.ImageLoaderViewHolder; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; +import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; public class HeaderStatusDisplayItem extends StatusDisplayItem{ @@ -76,7 +77,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ private CustomEmojiHelper emojiHelper=new CustomEmojiHelper(); private SpannableStringBuilder parsedName; public final Status status; - private boolean hasVisibilityToggle; + public boolean hasVisibilityToggle; boolean needBottomPadding; private CharSequence extraText; private Notification notification; @@ -331,23 +332,13 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ botIcon.setColorFilter(username.getCurrentTextColor()); deleteNotification.setVisibility(GlobalUserPreferences.enableDeleteNotifications && item.notification!=null && !item.inset ? View.VISIBLE : View.GONE); + visibility.setVisibility(item.hasVisibilityToggle ? View.VISIBLE : View.GONE); if (item.hasVisibilityToggle){ - boolean hidden = !item.status.sensitiveRevealed || (item.status.hasSpoiler() && !item.status.spoilerRevealed); - - // doing this because V.setVisibilityAnimated ignores changes between INVISIBLE and GONE - int newVis=hidden ? View.INVISIBLE : View.VISIBLE; - if(newVis==View.INVISIBLE && visibility.getVisibility()==View.GONE) - visibility.setVisibility(newVis); - else - V.setVisibilityAnimated(visibility, newVis); - - visibility.setEnabled(!hidden); - visibility.setContentDescription(item.parentFragment.getString(item.status.sensitiveRevealed ? R.string.spoiler_hide : R.string.spoiler_show)); - if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ - visibility.setTooltipText(visibility.getContentDescription()); - } - } else { - visibility.setVisibility(View.GONE); + boolean visible = item.status.sensitiveRevealed && (!item.status.hasSpoiler() || item.status.spoilerRevealed); + visibility.setAlpha(visible ? 1 : 0f); + visibility.setScaleY(visible ? 1 : 0.8f); + visibility.setScaleX(visible ? 1 : 0.8f); + visibility.setEnabled(visible); } itemView.setPadding(itemView.getPaddingLeft(), itemView.getPaddingTop(), itemView.getPaddingRight(), item.needBottomPadding ? V.dp(16) : 0); if(TextUtils.isEmpty(item.extraText)){ @@ -412,6 +403,16 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ item.inset ? V.dp(10) : V.dp(4), itemView.getPaddingBottom()); } + public void animateVisibilityToggle(boolean visible){ + visibility.animate() + .alpha(visible ? 1 : 0) + .scaleX(visible ? 1 : 0.8f) + .scaleY(visible ? 1 : 0.8f) + .setInterpolator(CubicBezierInterpolator.DEFAULT) + .start(); + visibility.setEnabled(visible); + } + @Override public void setImage(int index, Drawable drawable){ if(index>0){ diff --git a/mastodon/src/main/res/layout/display_item_header.xml b/mastodon/src/main/res/layout/display_item_header.xml index f3d18d939..8aa859ec8 100644 --- a/mastodon/src/main/res/layout/display_item_header.xml +++ b/mastodon/src/main/res/layout/display_item_header.xml @@ -43,6 +43,8 @@ android:layout_height="48dp" android:background="?android:actionBarItemBackground" android:scaleType="center" + android:contentDescription="@string/spoiler_hide" + android:tooltipText="@string/spoiler_hide" android:src="@drawable/ic_fluent_eye_24_regular" android:tint="?colorM3OnSurfaceVariant" android:visibility="gone" />