mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	add delete while history
add delete whole history
This commit is contained in:
		| @@ -239,7 +239,8 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC | |||||||
|         if (rootView == null && getView() != null) rootView = getView(); |         if (rootView == null && getView() != null) rootView = getView(); | ||||||
|         if (rootView == null) return; |         if (rootView == null) return; | ||||||
|  |  | ||||||
|         ErrorActivity.reportError(getContext(), exception, MainActivity.class, rootView, ErrorActivity.ErrorInfo.make(userAction, serviceName, request, errorId)); |         ErrorActivity.reportError(getContext(), exception, MainActivity.class, rootView, | ||||||
|  |                 ErrorActivity.ErrorInfo.make(userAction, serviceName, request, errorId)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|   | |||||||
| @@ -544,7 +544,7 @@ public class SearchFragment | |||||||
|                                     howManyDeleted -> suggestionPublisher |                                     howManyDeleted -> suggestionPublisher | ||||||
|                                             .onNext(searchEditText.getText().toString()), |                                             .onNext(searchEditText.getText().toString()), | ||||||
|                                     throwable -> showSnackBarError(throwable, |                                     throwable -> showSnackBarError(throwable, | ||||||
|                                             UserAction.SOMETHING_ELSE, "none", |                                             UserAction.DELETE_FROM_HISTORY, "none", | ||||||
|                                             "Deleting item failed", R.string.general_error) |                                             "Deleting item failed", R.string.general_error) | ||||||
|                             ); |                             ); | ||||||
|                     disposables.add(onDelete); |                     disposables.add(onDelete); | ||||||
|   | |||||||
| @@ -45,6 +45,7 @@ import java.util.List; | |||||||
|  |  | ||||||
| import io.reactivex.Flowable; | import io.reactivex.Flowable; | ||||||
| import io.reactivex.Maybe; | import io.reactivex.Maybe; | ||||||
|  | import io.reactivex.Scheduler; | ||||||
| import io.reactivex.Single; | import io.reactivex.Single; | ||||||
| import io.reactivex.schedulers.Schedulers; | import io.reactivex.schedulers.Schedulers; | ||||||
|  |  | ||||||
| @@ -98,6 +99,11 @@ public class HistoryRecordManager { | |||||||
|                 .subscribeOn(Schedulers.io()); |                 .subscribeOn(Schedulers.io()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public Single<Integer> deleteWholeStreamHistory() { | ||||||
|  |         return Single.fromCallable(() -> streamHistoryTable.deleteAll()) | ||||||
|  |                 .subscribeOn(Schedulers.io()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public Flowable<List<StreamHistoryEntry>> getStreamHistory() { |     public Flowable<List<StreamHistoryEntry>> getStreamHistory() { | ||||||
|         return streamHistoryTable.getHistory().subscribeOn(Schedulers.io()); |         return streamHistoryTable.getHistory().subscribeOn(Schedulers.io()); | ||||||
|     } |     } | ||||||
| @@ -132,20 +138,6 @@ public class HistoryRecordManager { | |||||||
|     // Search History |     // Search History | ||||||
|     /////////////////////////////////////////////////////// |     /////////////////////////////////////////////////////// | ||||||
|  |  | ||||||
|     public Single<List<Long>> insertSearches(final Collection<SearchHistoryEntry> entries) { |  | ||||||
|         return Single.fromCallable(() -> searchHistoryTable.insertAll(entries)) |  | ||||||
|                 .subscribeOn(Schedulers.io()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Single<Integer> deleteSearches(final Collection<SearchHistoryEntry> entries) { |  | ||||||
|         return Single.fromCallable(() -> searchHistoryTable.delete(entries)) |  | ||||||
|                 .subscribeOn(Schedulers.io()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Flowable<List<SearchHistoryEntry>> getSearchHistory() { |  | ||||||
|         return searchHistoryTable.getAll(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Maybe<Long> onSearched(final int serviceId, final String search) { |     public Maybe<Long> onSearched(final int serviceId, final String search) { | ||||||
|         if (!isSearchHistoryEnabled()) return Maybe.empty(); |         if (!isSearchHistoryEnabled()) return Maybe.empty(); | ||||||
|  |  | ||||||
| @@ -168,6 +160,11 @@ public class HistoryRecordManager { | |||||||
|                 .subscribeOn(Schedulers.io()); |                 .subscribeOn(Schedulers.io()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public Single<Integer> deleteWholeSearchHistory() { | ||||||
|  |         return Single.fromCallable(() -> searchHistoryTable.deleteAll()) | ||||||
|  |                 .subscribeOn(Schedulers.io()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public Flowable<List<SearchHistoryEntry>> getRelatedSearches(final String query, |     public Flowable<List<SearchHistoryEntry>> getRelatedSearches(final String query, | ||||||
|                                                                  final int similarQueryLimit, |                                                                  final int similarQueryLimit, | ||||||
|                                                                  final int uniqueQueryLimit) { |                                                                  final int uniqueQueryLimit) { | ||||||
|   | |||||||
| @@ -338,7 +338,7 @@ public class StatisticsPlaylistFragment | |||||||
|                             howManyDelted -> Snackbar.make(getView(), R.string.one_item_deleted, |                             howManyDelted -> Snackbar.make(getView(), R.string.one_item_deleted, | ||||||
|                                     Snackbar.LENGTH_SHORT).show(), |                                     Snackbar.LENGTH_SHORT).show(), | ||||||
|                             throwable -> showSnackBarError(throwable, |                             throwable -> showSnackBarError(throwable, | ||||||
|                                     UserAction.SOMETHING_ELSE, "none", |                                     UserAction.DELETE_FROM_HISTORY, "none", | ||||||
|                                     "Deleting item failed", R.string.general_error)); |                                     "Deleting item failed", R.string.general_error)); | ||||||
|  |  | ||||||
|             disposables.add(onDelte); |             disposables.add(onDelte); | ||||||
|   | |||||||
| @@ -14,7 +14,8 @@ public enum UserAction { | |||||||
|     REQUESTED_STREAM("requested stream"), |     REQUESTED_STREAM("requested stream"), | ||||||
|     REQUESTED_CHANNEL("requested channel"), |     REQUESTED_CHANNEL("requested channel"), | ||||||
|     REQUESTED_PLAYLIST("requested playlist"), |     REQUESTED_PLAYLIST("requested playlist"), | ||||||
|     REQUESTED_KIOSK("requested kiosk"); |     REQUESTED_KIOSK("requested kiosk"), | ||||||
|  |     DELETE_FROM_HISTORY("delete from history"); | ||||||
|  |  | ||||||
|  |  | ||||||
|     private final String message; |     private final String message; | ||||||
|   | |||||||
| @@ -1,20 +1,44 @@ | |||||||
| package org.schabi.newpipe.settings; | package org.schabi.newpipe.settings; | ||||||
|  |  | ||||||
|  | import android.content.DialogInterface; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||||
|  | import android.support.design.widget.Snackbar; | ||||||
|  | import android.support.v7.app.AlertDialog; | ||||||
| import android.support.v7.preference.Preference; | import android.support.v7.preference.Preference; | ||||||
|  | import android.util.Log; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
|  |  | ||||||
|  | import org.schabi.newpipe.MainActivity; | ||||||
| import org.schabi.newpipe.R; | import org.schabi.newpipe.R; | ||||||
|  | import org.schabi.newpipe.local.history.HistoryRecordManager; | ||||||
|  | import org.schabi.newpipe.report.ErrorActivity; | ||||||
|  | import org.schabi.newpipe.report.UserAction; | ||||||
| import org.schabi.newpipe.util.InfoCache; | import org.schabi.newpipe.util.InfoCache; | ||||||
|  |  | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Collection; | ||||||
|  |  | ||||||
|  | import io.reactivex.android.schedulers.AndroidSchedulers; | ||||||
|  | import io.reactivex.disposables.CompositeDisposable; | ||||||
|  | import io.reactivex.disposables.Disposable; | ||||||
|  | import io.reactivex.disposables.Disposables; | ||||||
|  |  | ||||||
| public class HistorySettingsFragment extends BasePreferenceFragment { | public class HistorySettingsFragment extends BasePreferenceFragment { | ||||||
|     private String cacheWipeKey; |     private String cacheWipeKey; | ||||||
|  |     private String viewsHistroyClearKey; | ||||||
|  |     private String searchHistoryClearKey; | ||||||
|  |     private HistoryRecordManager recordManager; | ||||||
|  |     private CompositeDisposable disposables; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void onCreate(@Nullable Bundle savedInstanceState) { |     public void onCreate(@Nullable Bundle savedInstanceState) { | ||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
|         cacheWipeKey = getString(R.string.metadata_cache_wipe_key); |         cacheWipeKey = getString(R.string.metadata_cache_wipe_key); | ||||||
|  |         viewsHistroyClearKey = getString(R.string.clear_views_history_key); | ||||||
|  |         searchHistoryClearKey = getString(R.string.clear_search_history_key); | ||||||
|  |         recordManager = new HistoryRecordManager(getActivity()); | ||||||
|  |         disposables = new CompositeDisposable(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -30,6 +54,58 @@ public class HistorySettingsFragment extends BasePreferenceFragment { | |||||||
|                     Toast.LENGTH_SHORT).show(); |                     Toast.LENGTH_SHORT).show(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (preference.getKey().equals(viewsHistroyClearKey)) { | ||||||
|  |             new AlertDialog.Builder(getActivity()) | ||||||
|  |                     .setTitle(R.string.delete_view_history_alert) | ||||||
|  |                     .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) | ||||||
|  |                     .setPositiveButton(R.string.delete, ((dialog, which) -> { | ||||||
|  |                         final Disposable onDelte = recordManager.deleteWholeStreamHistory() | ||||||
|  |                                 .observeOn(AndroidSchedulers.mainThread()) | ||||||
|  |                                 .subscribe( | ||||||
|  |                                         howManyDelted -> Toast.makeText(getActivity(), | ||||||
|  |                                                 R.string.view_history_deleted, | ||||||
|  |                                                 Toast.LENGTH_SHORT).show(), | ||||||
|  |                                         throwable -> ErrorActivity.reportError(getContext(), | ||||||
|  |                                                 throwable, | ||||||
|  |                                                 SettingsActivity.class, null, | ||||||
|  |                                                 ErrorActivity.ErrorInfo.make( | ||||||
|  |                                                         UserAction.DELETE_FROM_HISTORY, | ||||||
|  |                                                         "none", | ||||||
|  |                                                         "Delete view history", | ||||||
|  |                                                         R.string.general_error))); | ||||||
|  |  | ||||||
|  |                         disposables.add(onDelte); | ||||||
|  |                     })) | ||||||
|  |                     .create() | ||||||
|  |                     .show(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (preference.getKey().equals(searchHistoryClearKey)) { | ||||||
|  |             new AlertDialog.Builder(getActivity()) | ||||||
|  |                     .setTitle(R.string.delete_search_history_alert) | ||||||
|  |                     .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) | ||||||
|  |                     .setPositiveButton(R.string.delete, ((dialog, which) -> { | ||||||
|  |                         final Disposable onDelte = recordManager.deleteWholeSearchHistory() | ||||||
|  |                                 .observeOn(AndroidSchedulers.mainThread()) | ||||||
|  |                                 .subscribe( | ||||||
|  |                                         howManyDelted -> Toast.makeText(getActivity(), | ||||||
|  |                                                 R.string.search_history_deleted, | ||||||
|  |                                                 Toast.LENGTH_SHORT).show(), | ||||||
|  |                                         throwable -> ErrorActivity.reportError(getContext(), | ||||||
|  |                                                 throwable, | ||||||
|  |                                                 SettingsActivity.class, null, | ||||||
|  |                                                 ErrorActivity.ErrorInfo.make( | ||||||
|  |                                                         UserAction.DELETE_FROM_HISTORY, | ||||||
|  |                                                         "none", | ||||||
|  |                                                         "Delete search history", | ||||||
|  |                                                         R.string.general_error))); | ||||||
|  |  | ||||||
|  |                         disposables.add(onDelte); | ||||||
|  |                     })) | ||||||
|  |                     .create() | ||||||
|  |                     .show(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return super.onPreferenceTreeClick(preference); |         return super.onPreferenceTreeClick(preference); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -147,6 +147,8 @@ | |||||||
|     <string name="download_thumbnail_key" translatable="false">download_thumbnail_key</string> |     <string name="download_thumbnail_key" translatable="false">download_thumbnail_key</string> | ||||||
|  |  | ||||||
|     <string name="metadata_cache_wipe_key" translatable="false">cache_wipe_key</string> |     <string name="metadata_cache_wipe_key" translatable="false">cache_wipe_key</string> | ||||||
|  |     <string name="clear_views_history_key" translatable="false">clear_play_history</string> | ||||||
|  |     <string name="clear_search_history_key" translatable="false">clear_search_history</string> | ||||||
|  |  | ||||||
|     <!-- FileName Downloads  --> |     <!-- FileName Downloads  --> | ||||||
|     <string name="settings_file_charset_key" translatable="false">file_rename</string> |     <string name="settings_file_charset_key" translatable="false">file_rename</string> | ||||||
|   | |||||||
| @@ -155,6 +155,14 @@ | |||||||
|     <string name="export_data_title">Export database</string> |     <string name="export_data_title">Export database</string> | ||||||
|     <string name="import_data_summary">Will override your current history and subscriptions</string> |     <string name="import_data_summary">Will override your current history and subscriptions</string> | ||||||
|     <string name="export_data_summary">Export history, subscriptions and playlists.</string> |     <string name="export_data_summary">Export history, subscriptions and playlists.</string> | ||||||
|  |     <string name="clear_views_history_title">Clear watch history</string> | ||||||
|  |     <string name="clear_views_history_summary">Deletes the history of played streams.</string> | ||||||
|  |     <string name="delete_view_history_alert">Delete whole watch history.</string> | ||||||
|  |     <string name="view_history_deleted">Watch history deleted.</string> | ||||||
|  |     <string name="clear_search_history_title">Clear search history</string> | ||||||
|  |     <string name="clear_search_history_summary">Deletes history of search keywords.</string> | ||||||
|  |     <string name="delete_search_history_alert">Delete whole search history.</string> | ||||||
|  |     <string name="search_history_deleted">Search history deleted.</string> | ||||||
|     <!-- error strings --> |     <!-- error strings --> | ||||||
|     <string name="general_error">Error</string> |     <string name="general_error">Error</string> | ||||||
|     <string name="network_error">Network error</string> |     <string name="network_error">Network error</string> | ||||||
|   | |||||||
| @@ -21,4 +21,14 @@ | |||||||
|         android:summary="@string/metadata_cache_wipe_summary" |         android:summary="@string/metadata_cache_wipe_summary" | ||||||
|         android:title="@string/metadata_cache_wipe_title"/> |         android:title="@string/metadata_cache_wipe_title"/> | ||||||
|  |  | ||||||
|  |     <Preference | ||||||
|  |         android:key="@string/clear_views_history_key" | ||||||
|  |         android:title="@string/clear_views_history_title" | ||||||
|  |         android:summary="@string/clear_views_history_summary"/> | ||||||
|  |  | ||||||
|  |     <Preference | ||||||
|  |         android:key="@string/clear_search_history_key" | ||||||
|  |         android:title="@string/clear_search_history_title" | ||||||
|  |         android:summary="@string/clear_search_history_summary"/> | ||||||
|  |  | ||||||
| </PreferenceScreen> | </PreferenceScreen> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger