mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-25 20:42:34 +01: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;
|
||||
|
||||
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<RecyclerView.ViewHolde
|
||||
}
|
||||
|
||||
public void addInfoItemList(final List<InfoItem> 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<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) {
|
||||
@ -163,13 +173,17 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
|
||||
public void addInfoItem(InfoItem data) {
|
||||
stateLoaders.add(
|
||||
historyRecordManager.loadStreamState(data)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(streamStateEntity -> {
|
||||
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<RecyclerView.ViewHolde
|
||||
if (infoItemList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
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<RecyclerView.ViewHolde
|
||||
public void dispose() {
|
||||
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;
|
||||
|
||||
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.LocalItem;
|
||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
||||
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) {
|
||||
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<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) {
|
||||
@ -138,7 +148,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
|
||||
public void updateStates() {
|
||||
if (localItems.isEmpty()) return;
|
||||
if (localItems.isEmpty() || !isPlaybackStatesVisible()) return;
|
||||
stateLoaders.add(
|
||||
historyRecordManager.loadLocalStreamStateBatch(localItems)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -325,4 +335,12 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
public void dispose() {
|
||||
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_playback_resume_title">Продолжать воспроизведение</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="enable_watch_history_summary">Запоминать воспроизведённые потоки</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_playback_resume_title">Продовживати перегляд</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="enable_watch_history_summary">Вести облік перегляду відеозаписів</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="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_state_lists_key" translatable="false">enable_playback_state_lists</string>
|
||||
|
||||
<string name="import_data">import_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_playback_resume_title">Resume playback</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="enable_watch_history_summary">Keep track of watched videos</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"
|
||||
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
|
||||
android:defaultValue="true"
|
||||
android:key="@string/enable_search_history_key"
|
||||
|
Loading…
Reference in New Issue
Block a user