[Android] Factorize layout of audio lists

Geoffrey Métais git at videolan.org
Wed Jan 11 14:21:11 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 11 10:33:31 2017 +0100| [1377e9e25c2a1a990d9b0444b3cae6b557652d32] | committer: Geoffrey Métais

Factorize layout of audio lists

> https://code.videolan.org/videolan/vlc-android/commit/1377e9e25c2a1a990d9b0444b3cae6b557652d32
---

 vlc-android/res/layout/audio_albums_songs.xml      | 33 +---------------
 vlc-android/res/layout/audio_browser.xml           | 46 +++-------------------
 vlc-android/res/layout/audio_recyclerview.xml      |  9 +++++
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |  6 +--
 .../vlc/gui/audio/AudioBrowserFragment.java        | 15 +++----
 5 files changed, 24 insertions(+), 85 deletions(-)

diff --git a/vlc-android/res/layout/audio_albums_songs.xml b/vlc-android/res/layout/audio_albums_songs.xml
index abd8e43..6cd4277 100644
--- a/vlc-android/res/layout/audio_albums_songs.xml
+++ b/vlc-android/res/layout/audio_albums_songs.xml
@@ -17,37 +17,8 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent">
 
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/albums"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:nestedScrollingEnabled="true"
-                android:clipToPadding="false"
-                android:scrollbars="none"
-                android:paddingBottom="@dimen/listview_bottom_padding"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:nextFocusUp="@+id/ml_menu_search"
-                android:nextFocusDown="@id/albums"
-                android:nextFocusLeft="@id/albums"
-                android:nextFocusRight="@id/albums"
-                style="@style/Theme.VLC.List" />
-
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/songs"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:scrollbars="none"
-                android:nestedScrollingEnabled="true"
-                android:paddingBottom="@dimen/listview_bottom_padding"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:nextFocusUp="@+id/ml_menu_search"
-                android:nextFocusDown="@id/songs"
-                android:nextFocusLeft="@id/songs"
-                android:nextFocusRight="@id/songs"
-                style="@style/Theme.VLC.List" />
+            <include layout="@layout/audio_recyclerview" />
+            <include layout="@layout/audio_recyclerview" />
         </android.support.v4.view.ViewPager>
     </org.videolan.vlc.gui.view.SwipeRefreshLayout>
     <org.videolan.vlc.gui.view.FastScroller
diff --git a/vlc-android/res/layout/audio_browser.xml b/vlc-android/res/layout/audio_browser.xml
index 046537d..18decfe 100644
--- a/vlc-android/res/layout/audio_browser.xml
+++ b/vlc-android/res/layout/audio_browser.xml
@@ -41,47 +41,11 @@
             android:id="@+id/pager"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
-
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/artists_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:scrollbars="none" />
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/albums_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:scrollbars="none" />
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/songs_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:scrollbars="none" />
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/genres_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:scrollbars="none" />
-            <org.videolan.vlc.gui.view.ContextMenuRecyclerView
-                android:id="@+id/playlists_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:paddingLeft="20dp"
-                android:paddingRight="20dp"
-                android:scrollbars="none" />
+            <include layout="@layout/audio_recyclerview" />
+            <include layout="@layout/audio_recyclerview" />
+            <include layout="@layout/audio_recyclerview" />
+            <include layout="@layout/audio_recyclerview" />
+            <include layout="@layout/audio_recyclerview" />
         </android.support.v4.view.ViewPager>
     </org.videolan.vlc.gui.view.SwipeRefreshLayout>
     <org.videolan.vlc.gui.view.FastScroller
diff --git a/vlc-android/res/layout/audio_recyclerview.xml b/vlc-android/res/layout/audio_recyclerview.xml
new file mode 100644
index 0000000..e4dd107
--- /dev/null
+++ b/vlc-android/res/layout/audio_recyclerview.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<org.videolan.vlc.gui.view.ContextMenuRecyclerView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:clipToPadding="false"
+    android:paddingLeft="20dp"
+    android:paddingRight="20dp"
+    android:scrollbars="none" />
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 3e864fb..b580fe2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -109,8 +109,9 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
 
         View v = inflater.inflate(R.layout.audio_albums_songs, container, false);
 
-        ContextMenuRecyclerView albumsList = (ContextMenuRecyclerView) v.findViewById(R.id.albums);
-        ContextMenuRecyclerView songsList = (ContextMenuRecyclerView) v.findViewById(R.id.songs);
+        mViewPager = (ViewPager) v.findViewById(R.id.pager);
+        ContextMenuRecyclerView albumsList = (ContextMenuRecyclerView) mViewPager.getChildAt(MODE_ALBUM);
+        ContextMenuRecyclerView songsList = (ContextMenuRecyclerView) mViewPager.getChildAt(MODE_SONG);
 
         mLists = new ContextMenuRecyclerView[]{albumsList, songsList};
         String[] titles = new String[] {getString(R.string.albums), getString(R.string.songs)};
@@ -119,7 +120,6 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
 
         songsList.setAdapter(mSongsAdapter);
         albumsList.setAdapter(mAlbumsAdapter);
-        mViewPager = (ViewPager) v.findViewById(R.id.pager);
         mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1);
         mViewPager.setAdapter(new AudioPagerAdapter(mLists, titles));
 
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 4fdfbe8..c371ef7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -127,19 +127,14 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
 
         mEmptyView = (TextView) v.findViewById(R.id.no_media);
 
-        ContextMenuRecyclerView songsList = (ContextMenuRecyclerView)v.findViewById(R.id.songs_list);
-        ContextMenuRecyclerView artistList = (ContextMenuRecyclerView)v.findViewById(R.id.artists_list);
-        ContextMenuRecyclerView albumList = (ContextMenuRecyclerView)v.findViewById(R.id.albums_list);
-        ContextMenuRecyclerView genreList = (ContextMenuRecyclerView)v.findViewById(R.id.genres_list);
-        ContextMenuRecyclerView playlistsList = (ContextMenuRecyclerView)v.findViewById(R.id.playlists_list);
-
+        mViewPager = (ViewPager) v.findViewById(R.id.pager);
         mFastScroller = (FastScroller) v.findViewById(R.id.songs_fast_scroller);
-
-        mLists = new ContextMenuRecyclerView[]{artistList, albumList, songsList, genreList, playlistsList};
+        mLists = new ContextMenuRecyclerView[MODE_TOTAL];
+        for (int i = 0; i < MODE_TOTAL; i++)
+            mLists[i] = (ContextMenuRecyclerView) mViewPager.getChildAt(i);
 
         String[] titles = new String[] {getString(R.string.artists), getString(R.string.albums),
                 getString(R.string.songs), getString(R.string.genres), getString(R.string.playlists)};
-        mViewPager = (ViewPager) v.findViewById(R.id.pager);
         mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1);
         mViewPager.setAdapter(new AudioPagerAdapter(mLists, titles));
 
@@ -157,7 +152,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
         RecyclerView.RecycledViewPool rvp = new RecyclerView.RecycledViewPool();
-        for (int i = 0; i< mLists.length; ++i) {
+        for (int i = 0; i< MODE_TOTAL; ++i) {
             LinearLayoutManager llm = new LinearLayoutManager(getActivity());
             llm.setRecycleChildrenOnDetach(true);
             mLists[i].setLayoutManager(llm);



More information about the Android mailing list