mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:39:18 +01:00
Move clear history from advanced settings to history screen menu (closes #4613)
This commit is contained in:
parent
fddd8ce305
commit
b6b78994d8
@ -1,18 +1,24 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recent.history
|
package eu.kanade.tachiyomi.ui.recent.history
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreService
|
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.History
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.databinding.HistoryControllerBinding
|
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.NoToolbarElevationController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
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.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import reactivecircus.flowbinding.appcompat.queryTextChanges
|
import reactivecircus.flowbinding.appcompat.queryTextChanges
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that shows recently read manga.
|
* Fragment that shows recently read manga.
|
||||||
@ -42,6 +49,8 @@ class HistoryController :
|
|||||||
HistoryAdapter.OnItemClickListener,
|
HistoryAdapter.OnItemClickListener,
|
||||||
RemoveHistoryDialog.Listener {
|
RemoveHistoryDialog.Listener {
|
||||||
|
|
||||||
|
private val db: DatabaseHelper by injectLazy()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter containing the recent manga.
|
* Adapter containing the recent manga.
|
||||||
*/
|
*/
|
||||||
@ -196,4 +205,32 @@ class HistoryController :
|
|||||||
onExpand = { invalidateMenuOnExpand() }
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,16 +110,6 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
ctrl.showDialog(router)
|
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 {
|
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() {
|
private fun clearDatabase() {
|
||||||
db.deleteMangasNotInLibrary().executeAsBlocking()
|
db.deleteMangasNotInLibrary().executeAsBlocking()
|
||||||
db.deleteHistoryNoLastRead().executeAsBlocking()
|
db.deleteHistoryNoLastRead().executeAsBlocking()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_search"
|
android:id="@+id/action_search"
|
||||||
android:icon="@drawable/ic_search_24dp"
|
android:icon="@drawable/ic_search_24dp"
|
||||||
@ -8,4 +10,9 @@
|
|||||||
app:iconTint="?attr/colorOnPrimary"
|
app:iconTint="?attr/colorOnPrimary"
|
||||||
app:showAsAction="ifRoom|collapseActionView" />
|
app:showAsAction="ifRoom|collapseActionView" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_clear_history"
|
||||||
|
android:title="@string/pref_clear_history"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -431,10 +431,6 @@
|
|||||||
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>
|
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>
|
||||||
<string name="battery_optimization_disabled">Battery optimization is already disabled</string>
|
<string name="battery_optimization_disabled">Battery optimization is already disabled</string>
|
||||||
<string name="battery_optimization_setting_activity_not_found">Couldn\'t open device settings</string>
|
<string name="battery_optimization_setting_activity_not_found">Couldn\'t open device settings</string>
|
||||||
<string name="clear_history_completed">History deleted</string>
|
|
||||||
<string name="clear_history_confirmation">Are you sure? All history will be lost.</string>
|
|
||||||
<string name="pref_clear_history">Clear history</string>
|
|
||||||
<string name="pref_clear_history_summary">Delete reading history for all manga</string>
|
|
||||||
|
|
||||||
<!-- About section -->
|
<!-- About section -->
|
||||||
<string name="website">Website</string>
|
<string name="website">Website</string>
|
||||||
@ -650,6 +646,9 @@
|
|||||||
|
|
||||||
<!-- History fragment -->
|
<!-- History fragment -->
|
||||||
<string name="recent_manga_time">Ch. %1$s - %2$s</string>
|
<string name="recent_manga_time">Ch. %1$s - %2$s</string>
|
||||||
|
<string name="pref_clear_history">Clear history</string>
|
||||||
|
<string name="clear_history_completed">History deleted</string>
|
||||||
|
<string name="clear_history_confirmation">Are you sure? All history will be lost.</string>
|
||||||
|
|
||||||
<!-- Source migration screen -->
|
<!-- Source migration screen -->
|
||||||
<string name="migration_help_guide">Source migration guide</string>
|
<string name="migration_help_guide">Source migration guide</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user