mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 09:00:31 +00:00
Option to disable states indicators
This commit is contained in:
parent
41fb6f5464
commit
c7cd9e86ac
@ -1,12 +1,16 @@
|
|||||||
package org.schabi.newpipe.info_list;
|
package org.schabi.newpipe.info_list;
|
||||||
|
|
||||||
import android.app.Activity;
|
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.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
@ -128,13 +132,19 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addInfoItemList(final List<InfoItem> data) {
|
public void addInfoItemList(final List<InfoItem> data) {
|
||||||
stateLoaders.add(
|
if (isPlaybackStatesVisible()) {
|
||||||
historyRecordManager.loadStreamStateBatch(data)
|
stateLoaders.add(
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
historyRecordManager.loadStreamStateBatch(data)
|
||||||
.subscribe(streamStateEntities -> {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
addInfoItemList(data, streamStateEntities);
|
.subscribe(streamStateEntities -> {
|
||||||
})
|
addInfoItemList(data, streamStateEntities);
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final ArrayList<StreamStateEntity> states = new ArrayList<>(data.size());
|
||||||
|
for (int i = data.size(); i > 0; i--) states.add(null);
|
||||||
|
addInfoItemList(data, states);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addInfoItemList(List<InfoItem> data, List<StreamStateEntity> statesEntities) {
|
private void addInfoItemList(List<InfoItem> data, List<StreamStateEntity> statesEntities) {
|
||||||
@ -163,13 +173,17 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addInfoItem(InfoItem data) {
|
public void addInfoItem(InfoItem data) {
|
||||||
stateLoaders.add(
|
if (isPlaybackStatesVisible()) {
|
||||||
historyRecordManager.loadStreamState(data)
|
stateLoaders.add(
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
historyRecordManager.loadStreamState(data)
|
||||||
.subscribe(streamStateEntity -> {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
addInfoItem(data, streamStateEntity[0]);
|
.subscribe(streamStateEntity -> {
|
||||||
})
|
addInfoItem(data, streamStateEntity[0]);
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
addInfoItem(data, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addInfoItem(InfoItem data, StreamStateEntity state) {
|
private void addInfoItem(InfoItem data, StreamStateEntity state) {
|
||||||
@ -200,23 +214,25 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
if (infoItemList.isEmpty()) {
|
if (infoItemList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stateLoaders.add(
|
if (isPlaybackStatesVisible()) {
|
||||||
historyRecordManager.loadStreamStateBatch(infoItemList)
|
stateLoaders.add(
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
historyRecordManager.loadStreamStateBatch(infoItemList)
|
||||||
.subscribe((streamStateEntities) -> {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
if (streamStateEntities.size() == states.size()) {
|
.subscribe((streamStateEntities) -> {
|
||||||
for (int i = 0; i < states.size(); i++) {
|
if (streamStateEntities.size() == states.size()) {
|
||||||
final StreamStateEntity newState = streamStateEntities.get(i);
|
for (int i = 0; i < states.size(); i++) {
|
||||||
if (!Objects.equals(states.get(i), newState)) {
|
final StreamStateEntity newState = streamStateEntities.get(i);
|
||||||
states.set(i, newState);
|
if (!Objects.equals(states.get(i), newState)) {
|
||||||
notifyItemChanged(header == null ? i : i + 1);
|
states.set(i, newState);
|
||||||
|
notifyItemChanged(header == null ? i : i + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//oops, something is wrong
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
//oops, something is wrong
|
);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearStreamItemList() {
|
public void clearStreamItemList() {
|
||||||
@ -363,4 +379,12 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
stateLoaders.clear();
|
stateLoaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPlaybackStatesVisible() {
|
||||||
|
final Context context = infoItemBuilder.getContext();
|
||||||
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)
|
||||||
|
&& prefs.getBoolean(context.getString(R.string.enable_playback_resume_key), true)
|
||||||
|
&& prefs.getBoolean(context.getString(R.string.enable_playback_state_lists_key), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package org.schabi.newpipe.local;
|
package org.schabi.newpipe.local;
|
||||||
|
|
||||||
import android.app.Activity;
|
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.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
@ -99,12 +103,18 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addItems(List<? extends LocalItem> data) {
|
public void addItems(List<? extends LocalItem> data) {
|
||||||
stateLoaders.add(
|
if (isPlaybackStatesVisible()) {
|
||||||
historyRecordManager.loadLocalStreamStateBatch(data)
|
stateLoaders.add(
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
historyRecordManager.loadLocalStreamStateBatch(data)
|
||||||
.subscribe(streamStateEntities ->
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
addItems(data, streamStateEntities))
|
.subscribe(streamStateEntities ->
|
||||||
);
|
addItems(data, streamStateEntities))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final ArrayList<StreamStateEntity> states = new ArrayList<>(data.size());
|
||||||
|
for (int i = data.size(); i > 0; i--) states.add(null);
|
||||||
|
addItems(data, states);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addItems(List<? extends LocalItem> data, List<StreamStateEntity> streamStates) {
|
private void addItems(List<? extends LocalItem> data, List<StreamStateEntity> streamStates) {
|
||||||
@ -138,7 +148,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateStates() {
|
public void updateStates() {
|
||||||
if (localItems.isEmpty()) return;
|
if (localItems.isEmpty() || !isPlaybackStatesVisible()) return;
|
||||||
stateLoaders.add(
|
stateLoaders.add(
|
||||||
historyRecordManager.loadLocalStreamStateBatch(localItems)
|
historyRecordManager.loadLocalStreamStateBatch(localItems)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
@ -325,4 +335,12 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
stateLoaders.clear();
|
stateLoaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPlaybackStatesVisible() {
|
||||||
|
final Context context = localItemBuilder.getContext();
|
||||||
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)
|
||||||
|
&& prefs.getBoolean(context.getString(R.string.enable_playback_resume_key), true)
|
||||||
|
&& prefs.getBoolean(context.getString(R.string.enable_playback_state_lists_key), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,8 @@
|
|||||||
<string name="enable_watch_history_title">История просмотров</string>
|
<string name="enable_watch_history_title">История просмотров</string>
|
||||||
<string name="enable_playback_resume_title">Продолжать воспроизведение</string>
|
<string name="enable_playback_resume_title">Продолжать воспроизведение</string>
|
||||||
<string name="enable_playback_resume_summary">Восстанавливать с последней позиции</string>
|
<string name="enable_playback_resume_summary">Восстанавливать с последней позиции</string>
|
||||||
|
<string name="enable_playback_state_lists_title">Позиции в списках</string>
|
||||||
|
<string name="enable_playback_state_lists_summary">Отображать индикаторы позиций просмотра в списках</string>
|
||||||
<string name="settings_category_clear_data_title">Очистить данные</string>
|
<string name="settings_category_clear_data_title">Очистить данные</string>
|
||||||
<string name="enable_watch_history_summary">Запоминать воспроизведённые потоки</string>
|
<string name="enable_watch_history_summary">Запоминать воспроизведённые потоки</string>
|
||||||
<string name="resume_on_audio_focus_gain_title">Возобновить при фокусе</string>
|
<string name="resume_on_audio_focus_gain_title">Возобновить при фокусе</string>
|
||||||
|
@ -156,6 +156,8 @@
|
|||||||
<string name="enable_watch_history_title">Історія переглядiв</string>
|
<string name="enable_watch_history_title">Історія переглядiв</string>
|
||||||
<string name="enable_playback_resume_title">Продовживати перегляд</string>
|
<string name="enable_playback_resume_title">Продовживати перегляд</string>
|
||||||
<string name="enable_playback_resume_summary">Відновлювати останню позицію</string>
|
<string name="enable_playback_resume_summary">Відновлювати останню позицію</string>
|
||||||
|
<string name="enable_playback_state_lists_title">Позиції у списках</string>
|
||||||
|
<string name="enable_playback_state_lists_summary">Відображати індикатори позицій переглядів у списках</string>
|
||||||
<string name="settings_category_clear_data_title">Очистити дані</string>
|
<string name="settings_category_clear_data_title">Очистити дані</string>
|
||||||
<string name="enable_watch_history_summary">Вести облік перегляду відеозаписів</string>
|
<string name="enable_watch_history_summary">Вести облік перегляду відеозаписів</string>
|
||||||
<string name="resume_on_audio_focus_gain_title">Відновити відтворення</string>
|
<string name="resume_on_audio_focus_gain_title">Відновити відтворення</string>
|
||||||
|
@ -151,6 +151,7 @@
|
|||||||
<string name="enable_watch_history_key" translatable="false">enable_watch_history</string>
|
<string name="enable_watch_history_key" translatable="false">enable_watch_history</string>
|
||||||
<string name="main_page_content_key" translatable="false">main_page_content</string>
|
<string name="main_page_content_key" translatable="false">main_page_content</string>
|
||||||
<string name="enable_playback_resume_key" translatable="false">enable_playback_resume</string>
|
<string name="enable_playback_resume_key" translatable="false">enable_playback_resume</string>
|
||||||
|
<string name="enable_playback_state_lists_key" translatable="false">enable_playback_state_lists</string>
|
||||||
|
|
||||||
<string name="import_data">import_data</string>
|
<string name="import_data">import_data</string>
|
||||||
<string name="export_data">export_data</string>
|
<string name="export_data">export_data</string>
|
||||||
|
@ -98,6 +98,8 @@
|
|||||||
<string name="enable_watch_history_title">Watch history</string>
|
<string name="enable_watch_history_title">Watch history</string>
|
||||||
<string name="enable_playback_resume_title">Resume playback</string>
|
<string name="enable_playback_resume_title">Resume playback</string>
|
||||||
<string name="enable_playback_resume_summary">Restore last playback position</string>
|
<string name="enable_playback_resume_summary">Restore last playback position</string>
|
||||||
|
<string name="enable_playback_state_lists_title">Positions in lists</string>
|
||||||
|
<string name="enable_playback_state_lists_summary">Show playback position indicators in lists</string>
|
||||||
<string name="settings_category_clear_data_title">Clear data</string>
|
<string name="settings_category_clear_data_title">Clear data</string>
|
||||||
<string name="enable_watch_history_summary">Keep track of watched videos</string>
|
<string name="enable_watch_history_summary">Keep track of watched videos</string>
|
||||||
<string name="resume_on_audio_focus_gain_title">Resume on focus gain</string>
|
<string name="resume_on_audio_focus_gain_title">Resume on focus gain</string>
|
||||||
|
@ -19,6 +19,14 @@
|
|||||||
android:title="@string/enable_playback_resume_title"
|
android:title="@string/enable_playback_resume_title"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:dependency="@string/enable_playback_resume_key"
|
||||||
|
android:key="@string/enable_playback_state_lists_key"
|
||||||
|
android:summary="@string/enable_playback_state_lists_summary"
|
||||||
|
android:title="@string/enable_playback_state_lists_title"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="@string/enable_search_history_key"
|
android:key="@string/enable_search_history_key"
|
||||||
|
Loading…
Reference in New Issue
Block a user