[Android] TV: Update browser folders description display

Geoffrey Métais git at videolan.org
Thu Feb 7 15:21:43 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb  7 13:45:11 2019 +0100| [a03a4bf40765248df06fc68568d53f364a234cf3] | committer: Geoffrey Métais

TV: Update browser folders description display

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

 .../gui/tv/browser/DirectoryBrowserFragment.java   | 25 ++++++++++++++++------
 .../vlc/gui/tv/browser/NetworkBrowserFragment.java | 20 +++++++++++++++++
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/DirectoryBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/DirectoryBrowserFragment.java
index 693062752..afd251aab 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/DirectoryBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/DirectoryBrowserFragment.java
@@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.ExternalMonitor;
+import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.viewmodels.browser.BrowserModel;
 import org.videolan.vlc.viewmodels.browser.BrowserModelKt;
 
@@ -40,6 +41,9 @@ import java.util.List;
 import java.util.Map;
 
 import androidx.annotation.Nullable;
+import androidx.leanback.widget.ArrayObjectAdapter;
+import androidx.leanback.widget.ListRow;
+import androidx.leanback.widget.ObjectAdapter;
 import androidx.leanback.widget.Presenter;
 import androidx.leanback.widget.Row;
 import androidx.leanback.widget.RowPresenter;
@@ -75,12 +79,21 @@ public class DirectoryBrowserFragment extends MediaSortedFragment<BrowserModel>
                 }
             }
         });
-         viewModel.getDescriptionUpdate().observe(this, new Observer<Pair<Integer, String>>() {
-             @Override
-             public void onChanged(Pair<Integer, String> pair) {
-                 if (pair != null) getAdapter().notifyItemRangeChanged(0, getAdapter().size());
-             }
-         });
+        viewModel.getDescriptionUpdate().observe(this, new Observer<Pair<Integer, String>>() {
+            @Override
+            public void onChanged(Pair<Integer, String> pair) {
+                final int position = pair.component1();
+                final ArrayObjectAdapter adapter = (ArrayObjectAdapter) getAdapter();
+                int index = -1;
+                for (int i = 0; i < adapter.size(); ++i) {
+                    final ObjectAdapter objectAdapter = ((ListRow) adapter.get(i)).getAdapter();
+                    if (position > index + objectAdapter.size()) index += objectAdapter.size();
+                    else for (int j = 0; j < objectAdapter.size(); ++j) {
+                        if (++index == position) objectAdapter.notifyItemRangeChanged(j, 1, Constants.UPDATE_DESCRIPTION);
+                    }
+                }
+            }
+        });
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
index 5c306a2bf..c0cd0f323 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
@@ -37,18 +37,23 @@ import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.ExternalMonitor;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
+import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.viewmodels.browser.NetworkModel;
 
 import java.util.List;
 import java.util.Map;
 
 import androidx.annotation.Nullable;
+import androidx.leanback.widget.ArrayObjectAdapter;
+import androidx.leanback.widget.ListRow;
+import androidx.leanback.widget.ObjectAdapter;
 import androidx.leanback.widget.Presenter;
 import androidx.leanback.widget.Row;
 import androidx.leanback.widget.RowPresenter;
 import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModelProviders;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+import kotlin.Pair;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public class NetworkBrowserFragment extends MediaSortedFragment<NetworkModel> {
@@ -72,6 +77,21 @@ public class NetworkBrowserFragment extends MediaSortedFragment<NetworkModel> {
                 refresh(connected);
             }
         });
+        viewModel.getDescriptionUpdate().observe(this, new Observer<Pair<Integer, String>>() {
+            @Override
+            public void onChanged(Pair<Integer, String> pair) {
+                final int position = pair.component1();
+                final ArrayObjectAdapter adapter = (ArrayObjectAdapter) getAdapter();
+                int index = -1;
+                for (int i = 0; i < adapter.size(); ++i) {
+                    final ObjectAdapter objectAdapter = ((ListRow) adapter.get(i)).getAdapter();
+                    if (position > index + objectAdapter.size()) index += objectAdapter.size();
+                    else for (int j = 0; j < objectAdapter.size(); ++j) {
+                        if (++index == position) objectAdapter.notifyItemRangeChanged(j, 1, Constants.UPDATE_DESCRIPTION);
+                    }
+                }
+            }
+        });
     }
 
     public void refresh(boolean connected) {



More information about the Android mailing list