Add option to clear history

This commit is contained in:
Jays2Kings 2022-04-24 17:08:10 -04:00
parent fb81c0eb95
commit 789692c906
4 changed files with 36 additions and 0 deletions

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.recents package eu.kanade.tachiyomi.ui.recents
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.History
@ -21,6 +22,8 @@ import eu.kanade.tachiyomi.util.chapter.ChapterSort
import eu.kanade.tachiyomi.util.system.executeOnIO import eu.kanade.tachiyomi.util.system.executeOnIO
import eu.kanade.tachiyomi.util.system.launchIO import eu.kanade.tachiyomi.util.system.launchIO
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.system.withUIContext
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
@ -501,6 +504,16 @@ class RecentsPresenter(
} }
} }
fun deleteAllHistory() {
presenterScope.launchIO {
db.deleteHistory().executeAsBlocking()
withUIContext {
controller?.activity?.toast(R.string.clear_history_completed)
getRecents()
}
}
}
companion object { companion object {
private var lastRecents: List<RecentMangaItem>? = null private var lastRecents: List<RecentMangaItem>? = null

View file

@ -2,8 +2,10 @@ package eu.kanade.tachiyomi.ui.recents.options
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.RecentsHistoryViewBinding import eu.kanade.tachiyomi.databinding.RecentsHistoryViewBinding
import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.bindToPreference
import eu.kanade.tachiyomi.util.system.materialAlertDialog
import eu.kanade.tachiyomi.widget.BaseRecentsDisplayView import eu.kanade.tachiyomi.widget.BaseRecentsDisplayView
class RecentsHistoryView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class RecentsHistoryView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@ -12,5 +14,15 @@ class RecentsHistoryView @JvmOverloads constructor(context: Context, attrs: Attr
override fun inflateBinding() = RecentsHistoryViewBinding.bind(this) override fun inflateBinding() = RecentsHistoryViewBinding.bind(this)
override fun initGeneralPreferences() { override fun initGeneralPreferences() {
binding.groupChapters.bindToPreference(preferences.groupChaptersHistory()) binding.groupChapters.bindToPreference(preferences.groupChaptersHistory())
binding.clearHistory.setOnClickListener {
val activity = controller?.activity ?: return@setOnClickListener
activity.materialAlertDialog()
.setMessage(R.string.clear_history_confirmation)
.setPositiveButton(R.string.clear) { _, _ ->
controller?.presenter?.deleteAllHistory()
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}
} }
} }

View file

@ -20,5 +20,13 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/group_chapters_together" android:text="@string/group_chapters_together"
android:textColor="?attr/colorOnBackground" /> android:textColor="?attr/colorOnBackground" />
<com.google.android.material.button.MaterialButton
android:id="@+id/clear_history"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/clear_history" />
</LinearLayout> </LinearLayout>
</eu.kanade.tachiyomi.ui.recents.options.RecentsHistoryView> </eu.kanade.tachiyomi.ui.recents.options.RecentsHistoryView>

View file

@ -271,6 +271,9 @@
<string name="only_unread">Only unread</string> <string name="only_unread">Only unread</string>
<string name="only_downloaded">Only downloaded</string> <string name="only_downloaded">Only downloaded</string>
<string name="unread_or_downloaded">Unread or downloaded</string> <string name="unread_or_downloaded">Unread or downloaded</string>
<string name="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>
<!-- Recents Settings --> <!-- Recents Settings -->
<string name="show_reset_history_button">Show reset history button</string> <string name="show_reset_history_button">Show reset history button</string>