- 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:
Grady Clark 2020-03-08 07:42:52 -05:00 committed by Stypox
parent 954399b255
commit 8cab790030
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 31 additions and 109 deletions

View File

@ -2,7 +2,6 @@ package org.schabi.newpipe.local.playlist;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
@ -56,6 +55,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
import static org.schabi.newpipe.util.AnimationUtils.animateView;
@ -79,7 +79,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
private View headerPlayAllButton;
private View headerPopupButton;
private View headerBackgroundButton;
private ItemTouchHelper itemTouchHelper;
private LocalPlaylistManager playlistManager;
@ -87,6 +87,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
private PublishSubject<Long> debouncedSaveSignal;
private CompositeDisposable disposables;
private Disposable removeWatchedWorker;
/* Has the playlist been fully loaded from db */
private AtomicBoolean isLoadingComplete;
@ -151,7 +152,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
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);
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
@ -299,6 +300,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
disposables.dispose();
}
if(removeWatchedWorker != null) removeWatchedWorker.dispose();
removeWatchedWorker = null;
debouncedSaveSignal = null;
playlistManager = null;
disposables = null;
@ -352,9 +356,21 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_removeWatched:
//Solution, Scorched Earth, Copy non duplicates, clear playlist, then copy back over
//Other options didn't work as intended, or crashed. Like deleteItem(playlist_item) crashes when called in this function.
new RemoveWatchedStreams().execute();
RemoveWatchedStreams remover = new RemoveWatchedStreams();
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;
default:
return super.onOptionsItemSelected(item);
@ -716,27 +732,24 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
return new SinglePlayQueue(streamInfoItems, index);
}
private class RemoveWatchedStreams extends AsyncTask<String, Long, Long> {
private class RemoveWatchedStreams{
List<PlaylistStreamEntry> localItems = new ArrayList<>();
Long RemovedItemCount = 0l;
boolean thumbnailVideoRemoved = false;
@Override
// Do this in the main thread
protected void onPreExecute() {
super.onPreExecute();
showLoading();
localItems.clear();
}
@Override
protected Long doInBackground(String... urls) {
// Do not do this in the main thread
protected Long doInBackground(List<PlaylistStreamEntry> playlist) {
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
Iterator<StreamHistoryEntry> it_history;
StreamHistoryEntry history_item;
Flowable<List<PlaylistStreamEntry>> playlist = playlistManager.getPlaylistStreams(playlistId);
Iterator<PlaylistStreamEntry> it_playlist = playlist.blockingFirst().iterator();
Iterator<PlaylistStreamEntry> it_playlist = playlist.iterator();
PlaylistStreamEntry playlist_item = null;
boolean isNonDuplicate;
@ -769,8 +782,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
return this.RemovedItemCount;
}
@Override
protected void onPostExecute(Long result) {
// Do this in the main thread
protected void onPostExecute() {
itemListAdapter.clearStreamItemList();
itemListAdapter.addItems(localItems);
localItems.clear();

View File

@ -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>

View File

@ -50,7 +50,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/playlist_stream_count">
<include layout="@layout/local_playlist_control" />
<include layout="@layout/playlist_control" />
</LinearLayout>
</RelativeLayout>

View File

@ -593,6 +593,7 @@
<string name="choose_instance_prompt">Choose an instance</string>
<string name="app_language_title">App language</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>
<!-- Time duration plurals -->
<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_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="remove_watched">Remove Watched</string>
</resources>