mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 17:40:33 +00:00
- Will now use ReactiveX instead of AsyncTask, when removing watched videos.
- Removed redundant file 'local_playlist_control' - Fixed grammer issue
This commit is contained in:
parent
954399b255
commit
8cab790030
@ -2,7 +2,6 @@ package org.schabi.newpipe.local.playlist;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -56,6 +55,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
|||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.disposables.Disposables;
|
import io.reactivex.disposables.Disposables;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.reactivex.subjects.PublishSubject;
|
import io.reactivex.subjects.PublishSubject;
|
||||||
|
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||||
@ -87,6 +87,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
|
|
||||||
private PublishSubject<Long> debouncedSaveSignal;
|
private PublishSubject<Long> debouncedSaveSignal;
|
||||||
private CompositeDisposable disposables;
|
private CompositeDisposable disposables;
|
||||||
|
private Disposable removeWatchedWorker;
|
||||||
|
|
||||||
/* Has the playlist been fully loaded from db */
|
/* Has the playlist been fully loaded from db */
|
||||||
private AtomicBoolean isLoadingComplete;
|
private AtomicBoolean isLoadingComplete;
|
||||||
@ -151,7 +152,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
|
|
||||||
headerStreamCount = headerRootLayout.findViewById(R.id.playlist_stream_count);
|
headerStreamCount = headerRootLayout.findViewById(R.id.playlist_stream_count);
|
||||||
|
|
||||||
playlistControl = headerRootLayout.findViewById(R.id.local_playlist_control);
|
playlistControl = headerRootLayout.findViewById(R.id.playlist_control);
|
||||||
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button);
|
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button);
|
||||||
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
|
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
|
||||||
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
|
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
|
||||||
@ -299,6 +300,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
disposables.dispose();
|
disposables.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(removeWatchedWorker != null) removeWatchedWorker.dispose();
|
||||||
|
removeWatchedWorker = null;
|
||||||
|
|
||||||
debouncedSaveSignal = null;
|
debouncedSaveSignal = null;
|
||||||
playlistManager = null;
|
playlistManager = null;
|
||||||
disposables = null;
|
disposables = null;
|
||||||
@ -352,9 +356,21 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_item_removeWatched:
|
case R.id.menu_item_removeWatched:
|
||||||
//Solution, Scorched Earth, Copy non duplicates, clear playlist, then copy back over
|
RemoveWatchedStreams remover = new RemoveWatchedStreams();
|
||||||
//Other options didn't work as intended, or crashed. Like deleteItem(playlist_item) crashes when called in this function.
|
|
||||||
new RemoveWatchedStreams().execute();
|
remover.onPreExecute();
|
||||||
|
removeWatchedWorker = Flowable.just(playlistManager.getPlaylistStreams(playlistId).blockingFirst())
|
||||||
|
.subscribeOn(Schedulers.newThread())
|
||||||
|
.filter((@NonNull List<PlaylistStreamEntry> playlist) -> {
|
||||||
|
remover.doInBackground(playlist);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
).observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(playlist -> {
|
||||||
|
remover.onPostExecute();
|
||||||
|
}, (@io.reactivex.annotations.NonNull Throwable throwable) -> {
|
||||||
|
onError(throwable);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -716,27 +732,24 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
return new SinglePlayQueue(streamInfoItems, index);
|
return new SinglePlayQueue(streamInfoItems, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RemoveWatchedStreams extends AsyncTask<String, Long, Long> {
|
private class RemoveWatchedStreams{
|
||||||
List<PlaylistStreamEntry> localItems = new ArrayList<>();
|
List<PlaylistStreamEntry> localItems = new ArrayList<>();
|
||||||
Long RemovedItemCount = 0l;
|
Long RemovedItemCount = 0l;
|
||||||
boolean thumbnailVideoRemoved = false;
|
boolean thumbnailVideoRemoved = false;
|
||||||
|
|
||||||
@Override
|
// Do this in the main thread
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
|
||||||
showLoading();
|
showLoading();
|
||||||
localItems.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Do not do this in the main thread
|
||||||
protected Long doInBackground(String... urls) {
|
protected Long doInBackground(List<PlaylistStreamEntry> playlist) {
|
||||||
|
|
||||||
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
|
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
|
||||||
Iterator<StreamHistoryEntry> it_history;
|
Iterator<StreamHistoryEntry> it_history;
|
||||||
StreamHistoryEntry history_item;
|
StreamHistoryEntry history_item;
|
||||||
|
|
||||||
Flowable<List<PlaylistStreamEntry>> playlist = playlistManager.getPlaylistStreams(playlistId);
|
Iterator<PlaylistStreamEntry> it_playlist = playlist.iterator();
|
||||||
Iterator<PlaylistStreamEntry> it_playlist = playlist.blockingFirst().iterator();
|
|
||||||
PlaylistStreamEntry playlist_item = null;
|
PlaylistStreamEntry playlist_item = null;
|
||||||
|
|
||||||
boolean isNonDuplicate;
|
boolean isNonDuplicate;
|
||||||
@ -769,8 +782,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
return this.RemovedItemCount;
|
return this.RemovedItemCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Do this in the main thread
|
||||||
protected void onPostExecute(Long result) {
|
protected void onPostExecute() {
|
||||||
itemListAdapter.clearStreamItemList();
|
itemListAdapter.clearStreamItemList();
|
||||||
itemListAdapter.addItems(localItems);
|
itemListAdapter.addItems(localItems);
|
||||||
localItems.clear();
|
localItems.clear();
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/local_playlist_control"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:visibility="invisible"
|
|
||||||
tools:visibility="visible">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/playlist_ctrl_play_bg_button"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/playlist_ctrl_height"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:background="?attr/selectableItemBackground">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:text="@string/controls_background_title"
|
|
||||||
android:textSize="@dimen/channel_rss_title_size"
|
|
||||||
android:textColor="?attr/colorAccent"
|
|
||||||
android:drawablePadding="4dp"
|
|
||||||
android:drawableLeft="?attr/audio"
|
|
||||||
android:drawableStart="?attr/audio"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<View android:id="@+id/anchorLeft"
|
|
||||||
android:layout_width="1dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clickable="false"
|
|
||||||
android:layout_marginBottom="@dimen/playlist_ctrl_seperator_margin"
|
|
||||||
android:layout_marginTop="@dimen/playlist_ctrl_seperator_margin"
|
|
||||||
android:background="?attr/colorAccent"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:id="@+id/playlist_ctrl_play_all_button">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:text="@string/play_all"
|
|
||||||
android:textSize="@dimen/channel_rss_title_size"
|
|
||||||
android:textColor="?attr/colorAccent"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<View android:id="@+id/anchorRight"
|
|
||||||
android:layout_width="1dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clickable="false"
|
|
||||||
android:layout_marginBottom="@dimen/playlist_ctrl_seperator_margin"
|
|
||||||
android:layout_marginTop="@dimen/playlist_ctrl_seperator_margin"
|
|
||||||
android:background="?attr/colorAccent"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:id="@+id/playlist_ctrl_play_popup_button">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:text="@string/controls_popup_title"
|
|
||||||
android:textSize="@dimen/channel_rss_title_size"
|
|
||||||
android:textColor="?attr/colorAccent"
|
|
||||||
android:drawablePadding="4dp"
|
|
||||||
android:drawableLeft="?attr/popup"
|
|
||||||
android:drawableStart="?attr/popup"/>
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
@ -50,7 +50,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/playlist_stream_count">
|
android:layout_below="@id/playlist_stream_count">
|
||||||
|
|
||||||
<include layout="@layout/local_playlist_control" />
|
<include layout="@layout/playlist_control" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -593,6 +593,7 @@
|
|||||||
<string name="choose_instance_prompt">Choose an instance</string>
|
<string name="choose_instance_prompt">Choose an instance</string>
|
||||||
<string name="app_language_title">App language</string>
|
<string name="app_language_title">App language</string>
|
||||||
<string name="systems_language">System default</string>
|
<string name="systems_language">System default</string>
|
||||||
|
<string name="remove_watched">Remove watched</string>
|
||||||
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
|
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
|
||||||
<!-- Time duration plurals -->
|
<!-- Time duration plurals -->
|
||||||
<plurals name="seconds">
|
<plurals name="seconds">
|
||||||
@ -637,6 +638,4 @@
|
|||||||
<string name="feed_use_dedicated_fetch_method_enable_button">Enable fast mode</string>
|
<string name="feed_use_dedicated_fetch_method_enable_button">Enable fast mode</string>
|
||||||
<string name="feed_use_dedicated_fetch_method_disable_button">Disable fast mode</string>
|
<string name="feed_use_dedicated_fetch_method_disable_button">Disable fast mode</string>
|
||||||
<string name="feed_use_dedicated_fetch_method_help_text">Do you think feed loading is too slow? If so, try enabling fast loading (you can change it in settings or by pressing the button below).\n\nNewPipe offers two feed loading strategies:\n• Fetching the whole subscription channel, which is slow but complete.\n• Using a dedicated service endpoint, which is fast but usually not complete.\n\nThe difference between the two is that the fast one usually lacks some information, like the item\'s duration or type (can\'t distinguish between live videos and normal ones) and it may return less items.\n\nYouTube is an example of a service that offers this fast method with its RSS feed.\n\nSo the choice boils down to what you prefer: speed or precise information.</string>
|
<string name="feed_use_dedicated_fetch_method_help_text">Do you think feed loading is too slow? If so, try enabling fast loading (you can change it in settings or by pressing the button below).\n\nNewPipe offers two feed loading strategies:\n• Fetching the whole subscription channel, which is slow but complete.\n• Using a dedicated service endpoint, which is fast but usually not complete.\n\nThe difference between the two is that the fast one usually lacks some information, like the item\'s duration or type (can\'t distinguish between live videos and normal ones) and it may return less items.\n\nYouTube is an example of a service that offers this fast method with its RSS feed.\n\nSo the choice boils down to what you prefer: speed or precise information.</string>
|
||||||
|
|
||||||
<string name="remove_watched">Remove Watched</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user