Option to clear updates feed
This commit is contained in:
@@ -22,4 +22,7 @@ interface TrackLogsDao {
|
||||
|
||||
@Query("DELETE FROM track_logs WHERE manga_id NOT IN (SELECT manga_id FROM tracks)")
|
||||
suspend fun cleanup()
|
||||
|
||||
@Query("SELECT COUNT(*) FROM track_logs")
|
||||
suspend fun count(): Int
|
||||
}
|
||||
@@ -44,6 +44,10 @@ class TrackingRepository : KoinComponent {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun count() = db.trackLogsDao.count()
|
||||
|
||||
suspend fun clearLogs() = db.trackLogsDao.clear()
|
||||
|
||||
suspend fun cleanup() {
|
||||
db.withTransaction {
|
||||
db.tracksDao.cleanup()
|
||||
|
||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.local.Cache
|
||||
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.ui.search.MangaSuggestionsProvider
|
||||
import org.koitharu.kotatsu.utils.CacheUtils
|
||||
@@ -17,6 +18,10 @@ import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
|
||||
class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cache) {
|
||||
|
||||
private val trackerRepo by lazy {
|
||||
TrackingRepository()
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_history)
|
||||
findPreference<Preference>(R.string.key_pages_cache_clear)?.let { pref ->
|
||||
@@ -39,6 +44,12 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
||||
val items = MangaSuggestionsProvider.getItemsCount(p.context)
|
||||
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
|
||||
}
|
||||
findPreference<Preference>(R.string.key_updates_feed_clear)?.let { p ->
|
||||
lifecycleScope.launchWhenResumed {
|
||||
val items = trackerRepo.count()
|
||||
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
||||
@@ -62,6 +73,19 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
||||
).show()
|
||||
true
|
||||
}
|
||||
getString(R.string.key_updates_feed_clear) -> {
|
||||
lifecycleScope.launch {
|
||||
trackerRepo.clearLogs()
|
||||
preference.summary = preference.context.resources
|
||||
.getQuantityString(R.plurals.items, 0, 0)
|
||||
Snackbar.make(
|
||||
view ?: return@launch,
|
||||
R.string.updates_feed_cleared,
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,4 +140,6 @@
|
||||
<string name="new_version_s">Новая версия: %s</string>
|
||||
<string name="size_s">Размер: %s</string>
|
||||
<string name="waiting_for_network">Ожидание подключения…</string>
|
||||
<string name="clear_updates_feed">Очистить ленту обновлений</string>
|
||||
<string name="updates_feed_cleared">Лента обновлений очищена</string>
|
||||
</resources>
|
||||
@@ -9,6 +9,7 @@
|
||||
<string name="key_pages_cache_clear">pages_cache_clear</string>
|
||||
<string name="key_thumbs_cache_clear">thumbs_cache_clear</string>
|
||||
<string name="key_search_history_clear">search_history_clear</string>
|
||||
<string name="key_updates_feed_clear">updates_feed_clear</string>
|
||||
<string name="key_grid_size">grid_size</string>
|
||||
<string name="key_remote_sources">remote_sources</string>
|
||||
<string name="key_local_storage">local_storage</string>
|
||||
|
||||
@@ -141,4 +141,6 @@
|
||||
<string name="new_version_s">New version: %s</string>
|
||||
<string name="size_s">Size: %s</string>
|
||||
<string name="waiting_for_network">Waiting for network…</string>
|
||||
<string name="clear_updates_feed">Clear updates feed</string>
|
||||
<string name="updates_feed_cleared">Updates feed cleared</string>
|
||||
</resources>
|
||||
@@ -9,6 +9,12 @@
|
||||
android:title="@string/clear_search_history"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<Preference
|
||||
android:key="@string/key_updates_feed_clear"
|
||||
android:persistent="false"
|
||||
android:title="@string/clear_updates_feed"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
app:iconSpaceReserved="false"
|
||||
android:title="@string/cache">
|
||||
|
||||
Reference in New Issue
Block a user