From c7cd9e86ac41b08ca742bb583dfb197275e406de Mon Sep 17 00:00:00 2001 From: Vasiliy Date: Sat, 27 Apr 2019 19:04:13 +0300 Subject: [PATCH] Option to disable states indicators --- .../newpipe/info_list/InfoListAdapter.java | 82 ++++++++++++------- .../newpipe/local/LocalItemListAdapter.java | 32 ++++++-- app/src/main/res/values-ru/strings.xml | 2 + app/src/main/res/values-uk/strings.xml | 2 + app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/history_settings.xml | 8 ++ 7 files changed, 93 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 8a30c998a..e74a6f2ba 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -1,12 +1,16 @@ package org.schabi.newpipe.info_list; import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.view.ViewGroup; +import org.schabi.newpipe.R; import org.schabi.newpipe.database.stream.model.StreamStateEntity; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; @@ -128,13 +132,19 @@ public class InfoListAdapter extends RecyclerView.Adapter data) { - stateLoaders.add( - historyRecordManager.loadStreamStateBatch(data) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(streamStateEntities -> { - addInfoItemList(data, streamStateEntities); - }) - ); + if (isPlaybackStatesVisible()) { + stateLoaders.add( + historyRecordManager.loadStreamStateBatch(data) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(streamStateEntities -> { + addInfoItemList(data, streamStateEntities); + }) + ); + } else { + final ArrayList states = new ArrayList<>(data.size()); + for (int i = data.size(); i > 0; i--) states.add(null); + addInfoItemList(data, states); + } } private void addInfoItemList(List data, List statesEntities) { @@ -163,13 +173,17 @@ public class InfoListAdapter extends RecyclerView.Adapter { - addInfoItem(data, streamStateEntity[0]); - }) - ); + if (isPlaybackStatesVisible()) { + stateLoaders.add( + historyRecordManager.loadStreamState(data) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(streamStateEntity -> { + addInfoItem(data, streamStateEntity[0]); + }) + ); + } else { + addInfoItem(data, null); + } } private void addInfoItem(InfoItem data, StreamStateEntity state) { @@ -200,23 +214,25 @@ public class InfoListAdapter extends RecyclerView.Adapter { - if (streamStateEntities.size() == states.size()) { - for (int i = 0; i < states.size(); i++) { - final StreamStateEntity newState = streamStateEntities.get(i); - if (!Objects.equals(states.get(i), newState)) { - states.set(i, newState); - notifyItemChanged(header == null ? i : i + 1); + if (isPlaybackStatesVisible()) { + stateLoaders.add( + historyRecordManager.loadStreamStateBatch(infoItemList) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe((streamStateEntities) -> { + if (streamStateEntities.size() == states.size()) { + for (int i = 0; i < states.size(); i++) { + final StreamStateEntity newState = streamStateEntities.get(i); + if (!Objects.equals(states.get(i), newState)) { + states.set(i, newState); + notifyItemChanged(header == null ? i : i + 1); + } } + } else { + //oops, something is wrong } - } else { - //oops, something is wrong - } - }) - ); + }) + ); + } } public void clearStreamItemList() { @@ -363,4 +379,12 @@ public class InfoListAdapter extends RecyclerView.Adapter data) { - stateLoaders.add( - historyRecordManager.loadLocalStreamStateBatch(data) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(streamStateEntities -> - addItems(data, streamStateEntities)) - ); + if (isPlaybackStatesVisible()) { + stateLoaders.add( + historyRecordManager.loadLocalStreamStateBatch(data) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(streamStateEntities -> + addItems(data, streamStateEntities)) + ); + } else { + final ArrayList states = new ArrayList<>(data.size()); + for (int i = data.size(); i > 0; i--) states.add(null); + addItems(data, states); + } } private void addItems(List data, List streamStates) { @@ -138,7 +148,7 @@ public class LocalItemListAdapter extends RecyclerView.AdapterИстория просмотров Продолжать воспроизведение Восстанавливать с последней позиции + Позиции в списках + Отображать индикаторы позиций просмотра в списках Очистить данные Запоминать воспроизведённые потоки Возобновить при фокусе diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 41e6f22ba..0ab0ba78d 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -156,6 +156,8 @@ Історія переглядiв Продовживати перегляд Відновлювати останню позицію + Позиції у списках + Відображати індикатори позицій переглядів у списках Очистити дані Вести облік перегляду відеозаписів Відновити відтворення diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index b70305d56..dd9c30080 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -151,6 +151,7 @@ enable_watch_history main_page_content enable_playback_resume + enable_playback_state_lists import_data export_data diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f2ef075c..d92dbeb09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -98,6 +98,8 @@ Watch history Resume playback Restore last playback position + Positions in lists + Show playback position indicators in lists Clear data Keep track of watched videos Resume on focus gain diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml index 305b1c360..cae2d56c0 100644 --- a/app/src/main/res/xml/history_settings.xml +++ b/app/src/main/res/xml/history_settings.xml @@ -19,6 +19,14 @@ android:title="@string/enable_playback_resume_title" app:iconSpaceReserved="false" /> + +