Skip to content

Commit

Permalink
Option to clear updates feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Jun 29, 2020
1 parent b27bc86 commit a0aa33a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -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 {
Expand All @@ -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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions app/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/pref_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit a0aa33a

Please sign in to comment.