diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt index 2db2a53e5..ce36be7a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt @@ -1,18 +1,24 @@ package eu.kanade.tachiyomi.ui.recent.history +import android.app.Dialog +import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.LinearLayoutManager +import com.afollestad.materialdialogs.MaterialDialog import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupRestoreService +import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.databinding.HistoryControllerBinding +import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController @@ -25,6 +31,7 @@ import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.appcompat.queryTextChanges +import uy.kohesive.injekt.injectLazy /** * Fragment that shows recently read manga. @@ -42,6 +49,8 @@ class HistoryController : HistoryAdapter.OnItemClickListener, RemoveHistoryDialog.Listener { + private val db: DatabaseHelper by injectLazy() + /** * Adapter containing the recent manga. */ @@ -196,4 +205,32 @@ class HistoryController : onExpand = { invalidateMenuOnExpand() } ) } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_clear_history -> { + val ctrl = ClearHistoryDialogController() + ctrl.targetController = this@HistoryController + ctrl.showDialog(router) + } + } + + return super.onOptionsItemSelected(item) + } + + class ClearHistoryDialogController : DialogController() { + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + return MaterialDialog(activity!!) + .message(R.string.clear_history_confirmation) + .positiveButton(android.R.string.ok) { + (targetController as? HistoryController)?.clearHistory() + } + .negativeButton(android.R.string.cancel) + } + } + + private fun clearHistory() { + db.deleteHistory().executeAsBlocking() + activity?.toast(R.string.clear_history_completed) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index f3f496b1d..636e3faa6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -110,16 +110,6 @@ class SettingsAdvancedController : SettingsController() { ctrl.showDialog(router) } } - preference { - titleRes = R.string.pref_clear_history - summaryRes = R.string.pref_clear_history_summary - - onClick { - val ctrl = ClearHistoryDialogController() - ctrl.targetController = this@SettingsAdvancedController - ctrl.showDialog(router) - } - } } preferenceCategory { @@ -197,22 +187,6 @@ class SettingsAdvancedController : SettingsController() { } } - class ClearHistoryDialogController : DialogController() { - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog(activity!!) - .message(R.string.clear_history_confirmation) - .positiveButton(android.R.string.ok) { - (targetController as? SettingsAdvancedController)?.clearHistory() - } - .negativeButton(android.R.string.cancel) - } - } - - private fun clearHistory() { - db.deleteHistory().executeAsBlocking() - activity?.toast(R.string.clear_history_completed) - } - private fun clearDatabase() { db.deleteMangasNotInLibrary().executeAsBlocking() db.deleteHistoryNoLastRead().executeAsBlocking() diff --git a/app/src/main/res/menu/history.xml b/app/src/main/res/menu/history.xml index b84ac7836..3c5d65bae 100644 --- a/app/src/main/res/menu/history.xml +++ b/app/src/main/res/menu/history.xml @@ -1,5 +1,7 @@ - + + - \ No newline at end of file + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 948f6ccb5..3ea845fd0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -431,10 +431,6 @@ Helps with background library updates and backups Battery optimization is already disabled Couldn\'t open device settings - History deleted - Are you sure? All history will be lost. - Clear history - Delete reading history for all manga Website @@ -650,6 +646,9 @@ Ch. %1$s - %2$s + Clear history + History deleted + Are you sure? All history will be lost. Source migration guide