From 36248ff046a962edd32d55def68c20ce762f4122 Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 5 Oct 2020 17:45:05 +0200 Subject: [PATCH] Also delete stream state when deleting stream history --- .../newpipe/local/history/HistoryRecordManager.java | 12 +++++++----- .../local/history/StatisticsPlaylistFragment.java | 8 ++++---- .../newpipe/settings/HistorySettingsFragment.java | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java index 01d909c3c..6af57bc94 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java @@ -20,9 +20,9 @@ package org.schabi.newpipe.local.history; import android.content.Context; import android.content.SharedPreferences; -import androidx.preference.PreferenceManager; import androidx.annotation.NonNull; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; @@ -101,9 +101,11 @@ public class HistoryRecordManager { })).subscribeOn(Schedulers.io()); } - public Single deleteStreamHistory(final long streamId) { - return Single.fromCallable(() -> streamHistoryTable.deleteStreamHistory(streamId)) - .subscribeOn(Schedulers.io()); + public Completable deleteStreamHistoryAndState(final long streamId) { + return Completable.fromAction(() -> { + streamStateTable.deleteState(streamId); + streamHistoryTable.deleteStreamHistory(streamId); + }).subscribeOn(Schedulers.io()); } public Single deleteWholeStreamHistory() { @@ -111,7 +113,7 @@ public class HistoryRecordManager { .subscribeOn(Schedulers.io()); } - public Single deleteCompelteStreamStateHistory() { + public Single deleteCompleteStreamStateHistory() { return Single.fromCallable(streamStateTable::deleteAll) .subscribeOn(Schedulers.io()); } diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 887e5d124..7167c5cfa 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -420,14 +420,14 @@ public class StatisticsPlaylistFragment } private void deleteEntry(final int index) { - final LocalItem infoItem = itemListAdapter.getItemsList() - .get(index); + final LocalItem infoItem = itemListAdapter.getItemsList().get(index); if (infoItem instanceof StreamStatisticsEntry) { final StreamStatisticsEntry entry = (StreamStatisticsEntry) infoItem; - final Disposable onDelete = recordManager.deleteStreamHistory(entry.getStreamId()) + final Disposable onDelete = recordManager + .deleteStreamHistoryAndState(entry.getStreamId()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( - howManyDeleted -> { + () -> { if (getView() != null) { Snackbar.make(getView(), R.string.one_item_deleted, Snackbar.LENGTH_SHORT).show(); diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index d9b404204..893e7c740 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -55,7 +55,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) .setPositiveButton(R.string.delete, ((dialog, which) -> { final Disposable onDeletePlaybackStates - = recordManager.deleteCompelteStreamStateHistory() + = recordManager.deleteCompleteStreamStateHistory() .observeOn(AndroidSchedulers.mainThread()) .subscribe( howManyDeleted -> Toast.makeText(getActivity(), @@ -113,7 +113,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { .setPositiveButton(R.string.delete, ((dialog, which) -> { final Disposable onDeletePlaybackStates - = recordManager.deleteCompelteStreamStateHistory() + = recordManager.deleteCompleteStreamStateHistory() .observeOn(AndroidSchedulers.mainThread()) .subscribe( howManyDeleted -> Toast.makeText(getActivity(),