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

Commit 21bdabf4 authored by linus_lee's avatar linus_lee
Browse files

Eleven: Fix some bugs around the blur drawable not loading

I found three main bugs after some painful investigation

1) The stored key was different from the task key causing the check to always
return false, meaning the blurtask was always cancelled.  If we tried to load
the same album music 3 times in a row, the blur image will always re-kick off
even though they are the same image

2) Images don't load while scrolling for perf reasons, and for the lists,
the adapters are notified on scroll stop, but the blur image/album art pager/
bottom album art aren't

3) This was the winner - so if we load an image followed by two default images
on the 2nd default image we create the transition drawable but don't set it into
the blur image because it is a duplicate.  Inside the transition drawable it takes
the drawable and sets the listener to the transition drawable, so even if though we
don't set it into the imageview, the 1st transition drawable now isn't hooked up properly
and if this happens while the application isn't in the foreground then you can come back
and the transition drawable wouldn't have fired off

https://cyanogen.atlassian.net/browse/MUSIC-173
https://cyanogen.atlassian.net/browse/MUSIC-138

Change-Id: I9f99273bfcfe328179849f2131d4b1b2c98ca088
parent f6096a26
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ import android.view.ViewGroup;

import com.cyngn.eleven.MusicPlaybackService;
import com.cyngn.eleven.R;
import com.cyngn.eleven.cache.ICacheListener;
import com.cyngn.eleven.cache.ImageCache;
import com.cyngn.eleven.model.AlbumArtistDetails;
import com.cyngn.eleven.utils.ApolloUtils;
import com.cyngn.eleven.utils.MusicUtils;
@@ -144,7 +146,7 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
     * The fragments to be displayed inside this adapter.  This wraps the album art
     * and handles loading the album art for a given audio id
     */
    public static class AlbumArtFragment extends Fragment {
    public static class AlbumArtFragment extends Fragment implements ICacheListener {
        private static final String ID = "com.cyngn.eleven.adapters.AlbumArtPagerAdapter.AlbumArtFragment.ID";

        private View mRootView;
@@ -165,6 +167,7 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
            super.onCreate(savedInstanceState);

            mAudioId = getArguments().getLong(ID, NO_TRACK_ID);
            ImageCache.getInstance(getActivity()).addCacheListener(this);
        }

        @Override
@@ -173,6 +176,13 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
            return mRootView;
        }

        @Override
        public void onDestroy() {
            super.onDestroy();

            ImageCache.getInstance(getActivity()).removeCacheListener(this);
        }

        @Override
        public void onDestroyView() {
            super.onDestroyView();
@@ -230,6 +240,11 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
                    mImageView
            );
        }

        @Override
        public void onCacheUnpaused() {
            loadImageAsync();
        }
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -149,8 +149,8 @@ public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBit
                        resultContainer.mPaletteColor);

                // set the transition drawable
                blurScrimImage.setTransitionDrawable(false,
                        resultContainer.mImageViewBitmapDrawable, paletteTransition);
                blurScrimImage.setTransitionDrawable(resultContainer.mImageViewBitmapDrawable,
                        paletteTransition);
            }
        }
    }
+8 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 Cyanogen, Inc.
 */
package com.cyngn.eleven.cache;

public interface ICacheListener {
    void onCacheUnpaused();
}
+18 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;

/**
 * This class holds the memory and disk bitmap caches.
@@ -91,6 +92,11 @@ public final class ImageCache {
     */
    private DiskLruCache mDiskCache;

    /**
     * listeners to the cache state
     */
    private HashSet<ICacheListener> mListeners = new HashSet<ICacheListener>();

    private static ImageCache sInstance;

    /**
@@ -619,6 +625,10 @@ public final class ImageCache {
                mPauseDiskAccess = pause;
                if (!pause) {
                    mPauseLock.notify();

                    for (ICacheListener listener : mListeners) {
                        listener.onCacheUnpaused();
                    }
                }
            }
        }
@@ -645,6 +655,14 @@ public final class ImageCache {
        return mPauseDiskAccess;
    }

    public void addCacheListener(ICacheListener listener) {
        mListeners.add(listener);
    }

    public void removeCacheListener(ICacheListener listener) {
        mListeners.remove(listener);
    }

    /**
     * Get a usable cache directory (external if available, internal otherwise)
     *
+12 −0
Original line number Diff line number Diff line
@@ -152,6 +152,18 @@ public class ImageFetcher extends ImageWorker {
        sKeys.clear();
    }

    public void addCacheListener(ICacheListener listener) {
        if (mImageCache != null) {
            mImageCache.addCacheListener(listener);
        }
    }

    public void removeCacheListener(ICacheListener listener) {
        if (mImageCache != null) {
            mImageCache.removeCacheListener(listener);
        }
    }

    /**
     * @param key The key used to find the image to remove
     */
Loading