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 5d01cc367..26fcc1a4c 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 @@ -617,7 +617,6 @@ 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 3d714db4f..c92f69fa1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ServicesSettingsFragment.kt @@ -29,6 +29,8 @@ import org.koitharu.kotatsu.sync.domain.SyncController import org.koitharu.kotatsu.sync.ui.SyncSettingsIntent import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.kitsu.ui.KitsuAuthActivity +import org.koitharu.kotatsu.settings.utils.SplitSwitchPreference +import org.koitharu.kotatsu.stats.ui.StatsActivity import javax.inject.Inject @AndroidEntryPoint @@ -52,6 +54,12 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_services) + findPreference(AppSettings.KEY_STATS_ENABLED)?.let { + it.onContainerClickListener = Preference.OnPreferenceClickListener { + it.context.startActivity(Intent(it.context, StatsActivity::class.java)) + true + } + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -199,7 +207,7 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services), } private fun bindStatsSummary() { - findPreference(AppSettings.KEY_STATS)?.setSummary( + findPreference(AppSettings.KEY_STATS_ENABLED)?.setSummary( if (settings.isStatsEnabled) R.string.enabled else R.string.disabled, ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/SplitSwitchPreference.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/SplitSwitchPreference.kt new file mode 100644 index 000000000..46bdd6795 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/SplitSwitchPreference.kt @@ -0,0 +1,32 @@ +package org.koitharu.kotatsu.settings.utils + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import androidx.preference.PreferenceViewHolder +import androidx.preference.SwitchPreferenceCompat +import org.koitharu.kotatsu.R + +class SplitSwitchPreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = androidx.preference.R.attr.switchPreferenceCompatStyle, + defStyleRes: Int = 0 +) : SwitchPreferenceCompat(context, attrs, defStyleAttr, defStyleRes) { + + init { + layoutResource = R.layout.preference_split_switch + } + + var onContainerClickListener: OnPreferenceClickListener? = null + + private val containerClickListener = View.OnClickListener { v -> + onContainerClickListener?.onPreferenceClick(this) + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + holder.findViewById(R.id.press_container)?.setOnClickListener(containerClickListener) + } + +} diff --git a/app/src/main/res/layout/preference_split_switch.xml b/app/src/main/res/layout/preference_split_switch.xml new file mode 100644 index 000000000..62b7ab728 --- /dev/null +++ b/app/src/main/res/layout/preference_split_switch.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/pref_services.xml b/app/src/main/res/xml/pref_services.xml index c1d8b8bf6..50ad3d7ee 100644 --- a/app/src/main/res/xml/pref_services.xml +++ b/app/src/main/res/xml/pref_services.xml @@ -28,7 +28,7 @@ android:summary="@string/related_manga_summary" android:title="@string/related_manga" /> -