Option to disable states indicators
This commit is contained in:
parent
41fb6f5464
commit
c7cd9e86ac
7 changed files with 93 additions and 36 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue