Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
fix alpha animations
Browse files Browse the repository at this point in the history
closes #839
  • Loading branch information
sk22 committed Oct 6, 2023
1 parent 331548b commit 7c8624b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class Holder extends StatusDisplayItem.Holder<FooterStatusDisplayI
private final Runnable longClickRunnable = () -> {
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();
}
};
Expand Down Expand Up @@ -160,21 +160,21 @@ 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;
v.setPivotX(V.sp(28));
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));
Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -218,7 +218,7 @@ private boolean onBoostLongClick(View v){
AccountSession session = AccountSessionManager.getInstance().getAccount(item.accountID);

Consumer<StatusPrivacy> doReblog = (visibility) -> {
v.startAnimation(opacityOut);
UiUtils.opacityOut(v);
session.getStatusInteractionController()
.setReblogged(item.status, !item.status.reblogged, visibility, r->boostConsumer(v, r));
dialog.dismiss();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
}
Expand All @@ -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);
});
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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;
Expand All @@ -212,17 +212,17 @@ 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{
translationFooter.setVisibility(View.VISIBLE);
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();
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
}
Expand Down Expand Up @@ -1748,4 +1736,16 @@ public static Optional<String> 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);
}
}

0 comments on commit 7c8624b

Please sign in to comment.