Commit 598301ea authored by Geoffrey Métais's avatar Geoffrey Métais

TV: Update browser folders description display

parent 03e21f0c
......@@ -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
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment