From f39ccb622305034c7602165738c92b9e4a0cd08a Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sun, 18 Feb 2024 13:38:46 +0200 Subject: [PATCH] Stats settings --- .../org/koitharu/kotatsu/core/prefs/AppSettings.kt | 1 + .../kotatsu/settings/ServicesSettingsFragment.kt | 13 ++++++++++--- .../kotatsu/settings/StatsSettingsFragment.kt | 14 ++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_services.xml | 6 ++++++ app/src/main/res/xml/pref_stats.xml | 11 +++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/settings/StatsSettingsFragment.kt create mode 100644 app/src/main/res/xml/pref_stats.xml diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index df5095b9e..49ce3cde9 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -609,6 +609,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { const val KEY_READING_TIME = "reading_time" const val KEY_PAGES_SAVE_DIR = "pages_dir" const val KEY_PAGES_SAVE_ASK = "pages_dir_ask" + const val KEY_STATS = "stats" const val KEY_STATS_ENABLED = "stats_on" const val KEY_APP_UPDATE = "app_update" const val KEY_APP_TRANSLATION = "about_app_translation" diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt index 2eccb5ce2..717938193 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt @@ -1,7 +1,6 @@ package org.koitharu.kotatsu.settings import android.accounts.AccountManager -import android.content.ActivityNotFoundException import android.content.Intent import android.content.SharedPreferences import android.net.Uri @@ -17,6 +16,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.ui.BasePreferenceFragment import org.koitharu.kotatsu.core.util.ext.getDisplayMessage +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope import org.koitharu.kotatsu.scrobbling.anilist.data.AniListRepository import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerRepository @@ -27,7 +27,6 @@ import org.koitharu.kotatsu.scrobbling.mal.data.MALRepository import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriRepository import org.koitharu.kotatsu.sync.domain.SyncController import org.koitharu.kotatsu.sync.ui.SyncSettingsIntent -import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import javax.inject.Inject @AndroidEntryPoint @@ -51,11 +50,12 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_services) - bindSuggestionsSummary() } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + bindSuggestionsSummary() + bindStatsSummary() settings.subscribe(this) } @@ -76,6 +76,7 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services), override fun onSharedPreferenceChanged(prefs: SharedPreferences?, key: String?) { when (key) { AppSettings.KEY_SUGGESTIONS -> bindSuggestionsSummary() + AppSettings.KEY_STATS_ENABLED -> bindStatsSummary() } } @@ -194,4 +195,10 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services), if (settings.isSuggestionsEnabled) R.string.enabled else R.string.disabled, ) } + + private fun bindStatsSummary() { + findPreference(AppSettings.KEY_STATS)?.setSummary( + if (settings.isStatsEnabled) R.string.enabled else R.string.disabled, + ) + } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/StatsSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/StatsSettingsFragment.kt new file mode 100644 index 000000000..3f176636d --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/StatsSettingsFragment.kt @@ -0,0 +1,14 @@ +package org.koitharu.kotatsu.settings + +import android.os.Bundle +import dagger.hilt.android.AndroidEntryPoint +import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.ui.BasePreferenceFragment + +@AndroidEntryPoint +class StatsSettingsFragment : BasePreferenceFragment(R.string.reading_stats) { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_stats) + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 639bfbc4e..2ce8fe194 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -598,4 +598,6 @@ Ask for the destination dir every time Default page save directory Remove from history + Enable statistics + Reading statistics diff --git a/app/src/main/res/xml/pref_services.xml b/app/src/main/res/xml/pref_services.xml index 2cd394f50..9d72d8582 100644 --- a/app/src/main/res/xml/pref_services.xml +++ b/app/src/main/res/xml/pref_services.xml @@ -28,6 +28,12 @@ android:summary="@string/related_manga_summary" android:title="@string/related_manga" /> + + + + + + +