[Android] [PATCH] Queue audio lists updates

Jean-Baptiste Kempf jb at videolan.org
Fri Dec 26 16:07:42 CET 2014


Cool :)

On 26 Dec, Geoffrey Métais wrote :
> Queue Artists/Albums/Songs/Genres lists refresh, and execute the currently diplayed list refresh in first
> This should speed up AudioBrowser display
> ---
>  .../vlc/gui/audio/AudioBrowserFragment.java        | 90 ++++++++++++++++------
>  1 file changed, 65 insertions(+), 25 deletions(-)
> 
> diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> index 42948df..c77b254 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> @@ -68,6 +68,8 @@ import org.videolan.vlc.widget.HeaderScrollView;
>  import java.util.ArrayList;
>  import java.util.Collections;
>  import java.util.List;
> +import java.util.concurrent.ExecutorService;
> +import java.util.concurrent.Executors;
>  
>  public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, IBrowser {
>      public final static String TAG = "VLC/AudioBrowserFragment";
> @@ -80,9 +82,10 @@ public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout
>      private AudioServiceController mAudioController;
>      private MediaLibrary mMediaLibrary;
>  
> -    private AudioBrowserListAdapter mSongsAdapter;
> +    List<Media> mAudioList;
>      private AudioBrowserListAdapter mArtistsAdapter;
>      private AudioBrowserListAdapter mAlbumsAdapter;
> +    private AudioBrowserListAdapter mSongsAdapter;
>      private AudioBrowserListAdapter mGenresAdapter;
>  
>      private View mEmptyView;
> @@ -482,16 +485,23 @@ public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout
>      }
>  
>      @Override
> -    public void display() {
> +    public void display(){
> +        display(null);
> +    }
> +
> +    public void display(final AudioBrowserListAdapter adapter) {
>          mReadyToDisplay = true;
>          if (getActivity() != null)
>              getActivity().runOnUiThread(new Runnable() {
>                  @Override
>                  public void run() {
> -                    mArtistsAdapter.notifyDataSetChanged();
> -                    mSongsAdapter.notifyDataSetChanged();
> -                    mAlbumsAdapter.notifyDataSetChanged();
> -                    mGenresAdapter.notifyDataSetChanged();
> +                    if (adapter == null) {
> +                        mArtistsAdapter.notifyDataSetChanged();
> +                        mSongsAdapter.notifyDataSetChanged();
> +                        mAlbumsAdapter.notifyDataSetChanged();
> +                        mGenresAdapter.notifyDataSetChanged();
> +                    } else
> +                        adapter.notifyDataSetChanged();
>  
>                      // Refresh the fast scroll data, since SectionIndexer doesn't respect notifyDataSetChanged
>                      int[] lists = {R.id.artists_list, R.id.albums_list, R.id.songs_list, R.id.genres_list};
> @@ -536,8 +546,8 @@ public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout
>          mArtistsAdapter.clear();
>          mAlbumsAdapter.clear();
>          mGenresAdapter.clear();
> -        final List<Media> audioList = MediaLibrary.getInstance().getAudioItems();
> -        if (audioList.isEmpty()){
> +        mAudioList = MediaLibrary.getInstance().getAudioItems();
> +        if (mAudioList.isEmpty()){
>              mSwipeRefreshLayout.setRefreshing(false);
>              mEmptyView.setVisibility(View.VISIBLE);
>              focusHelper(true, R.id.artists_list);
> @@ -545,28 +555,58 @@ public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout
>              mEmptyView.setVisibility(View.GONE);
>              mHandler.sendEmptyMessageDelayed(MSG_LOADING, 300);
>  
> -            new Thread(new Runnable() {
> -                @Override
> -                public void run() {
> -
> -                    Collections.sort(audioList, MediaComparators.byArtist);
> -                    mArtistsAdapter.addAll(audioList, AudioBrowserListAdapter.TYPE_ARTISTS);
> +            ExecutorService tpe = Executors.newSingleThreadExecutor();
> +            ArrayList<Runnable> tasks = new ArrayList<Runnable>();
> +            tasks.add(updateArtists);
> +            tasks.add(updateAlbums);
> +            tasks.add(updateSongs);
> +            tasks.add(updateGenres);
> +            //process the visible list first
> +            tasks.add(0, tasks.remove(mFlingViewPosition));
> +            for (Runnable task : tasks)
> +                tpe.submit(task);
> +        }
> +    }
>  
> -                    Collections.sort(audioList, MediaComparators.byName);
> -                    mSongsAdapter.addAll(audioList, AudioBrowserListAdapter.TYPE_SONGS);
> +    Runnable updateArtists = new Runnable() {
> +        @Override
> +        public void run() {
> +            Collections.sort(mAudioList, MediaComparators.byArtist);
> +            mArtistsAdapter.addAll(mAudioList, AudioBrowserListAdapter.TYPE_ARTISTS);
> +            if (mReadyToDisplay)
> +                display(mArtistsAdapter);
> +        }
> +    };
>  
> -                    Collections.sort(audioList, MediaComparators.byAlbum);
> -                    mAlbumsAdapter.addAll(audioList, AudioBrowserListAdapter.TYPE_ALBUMS);
> +    Runnable updateAlbums = new Runnable() {
> +        @Override
> +        public void run() {
> +            Collections.sort(mAudioList, MediaComparators.byAlbum);
> +            mAlbumsAdapter.addAll(mAudioList, AudioBrowserListAdapter.TYPE_ALBUMS);
> +            if (mReadyToDisplay)
> +                display(mAlbumsAdapter);
> +        }
> +    };
>  
> -                    Collections.sort(audioList, MediaComparators.byGenre);
> -                    mGenresAdapter.addAll(audioList, AudioBrowserListAdapter.TYPE_GENRES);
> +    Runnable updateSongs = new Runnable() {
> +        @Override
> +        public void run() {
> +            Collections.sort(mAudioList, MediaComparators.byName);
> +            mSongsAdapter.addAll(mAudioList, AudioBrowserListAdapter.TYPE_SONGS);
> +            if (mReadyToDisplay)
> +                display(mSongsAdapter);
> +        }
> +    };
>  
> -                    if (mReadyToDisplay)
> -                        display();
> -                }
> -            }).start();
> +    Runnable updateGenres = new Runnable() {
> +        @Override
> +        public void run() {
> +            Collections.sort(mAudioList, MediaComparators.byGenre);
> +            mGenresAdapter.addAll(mAudioList, AudioBrowserListAdapter.TYPE_GENRES);
> +            if (mReadyToDisplay)
> +                display(mGenresAdapter);
>          }
> -    }
> +    };
>  
>      AudioBrowserListAdapter.ContextPopupMenuListener mContextPopupMenuListener
>          = new AudioBrowserListAdapter.ContextPopupMenuListener() {
> -- 
> 2.1.0
> 
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android

-- 
With my kindest regards,

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device


More information about the Android mailing list