Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 2def8d46 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

IllustrationPreference: Hide illustration when we fail to play anim

AOSP skips a lot of lottie animations ;(

Change-Id: Ia600a3ce4dcc59c68a151eff26d253db665d8cd7
parent 2ff41915
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class IllustrationPreference extends Preference {
        illustrationFrame.setLayoutParams(lp);

        illustrationView.setCacheComposition(mCacheComposition);
        handleImageWithAnimation(illustrationView);
        handleImageWithAnimation(illustrationFrame, illustrationView);
        handleImageFrameMaxHeight(backgroundView, illustrationView);

        if (mIsAutoScale) {
@@ -302,7 +302,8 @@ public class IllustrationPreference extends Preference {
        }
    }

    private void handleImageWithAnimation(LottieAnimationView illustrationView) {
    private void handleImageWithAnimation(FrameLayout illustrationFrame,
            LottieAnimationView illustrationView) {
        if (mImageDrawable != null) {
            resetAnimations(illustrationView);
            illustrationView.setImageDrawable(mImageDrawable);
@@ -321,7 +322,7 @@ public class IllustrationPreference extends Preference {
            } else {
                // The lottie image from the raw folder also returns null because the ImageView
                // couldn't handle it now.
                startLottieAnimationWith(illustrationView, mImageUri);
                startLottieAnimationWith(illustrationFrame, illustrationView, mImageUri);
            }
        }

@@ -334,7 +335,7 @@ public class IllustrationPreference extends Preference {
            } else {
                // The lottie image from the raw folder also returns null because the ImageView
                // couldn't handle it now.
                startLottieAnimationWith(illustrationView, mImageResId);
                startLottieAnimationWith(illustrationFrame, illustrationView, mImageResId);
            }
        }
    }
@@ -372,21 +373,27 @@ public class IllustrationPreference extends Preference {
        ((Animatable) drawable).start();
    }

    private static void startLottieAnimationWith(LottieAnimationView illustrationView,
            Uri imageUri) {
    private static void startLottieAnimationWith(FrameLayout illustrationFrame,
            LottieAnimationView illustrationView, Uri imageUri) {
        final InputStream inputStream =
                getInputStreamFromUri(illustrationView.getContext(), imageUri);
        illustrationView.setFailureListener(
                result -> Log.w(TAG, "Invalid illustration image uri: " + imageUri, result));
        illustrationFrame.setVisibility(View.VISIBLE);
        illustrationView.setFailureListener(result -> {
            Log.w(TAG, "Invalid illustration image uri: " + imageUri, result);
            illustrationFrame.setVisibility(View.GONE);
        });
        illustrationView.setAnimation(inputStream, /* cacheKey= */ null);
        illustrationView.setRepeatCount(LottieDrawable.INFINITE);
        illustrationView.playAnimation();
    }

    private static void startLottieAnimationWith(LottieAnimationView illustrationView,
            @RawRes int rawRes) {
        illustrationView.setFailureListener(
                result -> Log.w(TAG, "Invalid illustration resource id: " + rawRes, result));
    private static void startLottieAnimationWith(FrameLayout illustrationFrame,
            LottieAnimationView illustrationView, @RawRes int rawRes) {
        illustrationFrame.setVisibility(View.VISIBLE);
        illustrationView.setFailureListener(result -> {
            Log.w(TAG, "Invalid illustration resource id: " + rawRes, result);
            illustrationFrame.setVisibility(View.GONE);
        });
        illustrationView.setAnimation(rawRes);
        illustrationView.setRepeatCount(LottieDrawable.INFINITE);
        illustrationView.playAnimation();