From 7a0fa6273f3d8995ff29221d8d3e6285827c9fbd Mon Sep 17 00:00:00 2001 From: F0x1d Date: Mon, 2 Oct 2023 22:49:41 +0300 Subject: [PATCH] [refactor]: removed useless wrappers for settings fragments --- .../settings/SettingsCrashesFragment.kt | 11 +- .../fragment/settings/SettingsMenuFragment.kt | 48 ++--- .../settings/SettingsNotificationsFragment.kt | 52 +++-- .../settings/SettingsServiceFragment.kt | 132 ++++++------ .../fragment/settings/SettingsUIFragment.kt | 192 +++++++++--------- .../settings/base/BasePreferenceFragment.kt | 16 ++ .../base/BaseSettingsWrapperFragment.kt | 45 ---- app/src/main/res/layout/fragment_settings.xml | 4 +- app/src/main/res/values/styles.xml | 6 +- app/src/main/res/values/themes.xml | 3 +- 10 files changed, 227 insertions(+), 282 deletions(-) delete mode 100644 app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BaseSettingsWrapperFragment.kt diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsCrashesFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsCrashesFragment.kt index 642785c4..d688ac63 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsCrashesFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsCrashesFragment.kt @@ -3,20 +3,15 @@ package com.f0x1d.logfox.ui.fragment.settings import android.os.Bundle import com.f0x1d.logfox.R import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment -import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class SettingsCrashesFragment: BaseSettingsWrapperFragment() { +class SettingsCrashesFragment: BasePreferenceFragment() { - override val wrappedFragment get() = SettingsCrashesWrappedFragment() override val title = R.string.crashes override val showBackArrow = true - @AndroidEntryPoint - class SettingsCrashesWrappedFragment: BasePreferenceFragment() { - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.settings_crashes) - } + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.settings_crashes) } } \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsMenuFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsMenuFragment.kt index a68460eb..7ae7a90e 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsMenuFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsMenuFragment.kt @@ -6,38 +6,30 @@ import androidx.preference.Preference import com.f0x1d.logfox.BuildConfig import com.f0x1d.logfox.R import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment -import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class SettingsMenuFragment: BaseSettingsWrapperFragment() { +class SettingsMenuFragment: BasePreferenceFragment() { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.settings_menu) - override val wrappedFragment get() = SettingsMenuWrappedFragment() - - @AndroidEntryPoint - class SettingsMenuWrappedFragment: BasePreferenceFragment() { - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.settings_menu) - - findPreference("pref_settings_ui")?.setOnPreferenceClickListener { - findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsUIFragment()) - return@setOnPreferenceClickListener true - } - findPreference("pref_settings_service")?.setOnPreferenceClickListener { - findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsServiceFragment()) - return@setOnPreferenceClickListener true - } - findPreference("pref_settings_crashes")?.setOnPreferenceClickListener { - findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsCrashesFragment()) - return@setOnPreferenceClickListener true - } - findPreference("pref_settings_notifications")?.setOnPreferenceClickListener { - findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsNotificationsFragment()) - return@setOnPreferenceClickListener true - } - - findPreference("pref_settings_app_version")?.title = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" + findPreference("pref_settings_ui")?.setOnPreferenceClickListener { + findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsUIFragment()) + return@setOnPreferenceClickListener true } + findPreference("pref_settings_service")?.setOnPreferenceClickListener { + findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsServiceFragment()) + return@setOnPreferenceClickListener true + } + findPreference("pref_settings_crashes")?.setOnPreferenceClickListener { + findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsCrashesFragment()) + return@setOnPreferenceClickListener true + } + findPreference("pref_settings_notifications")?.setOnPreferenceClickListener { + findNavController().navigate(SettingsMenuFragmentDirections.actionSettingsMenuFragmentToSettingsNotificationsFragment()) + return@setOnPreferenceClickListener true + } + + findPreference("pref_settings_app_version")?.title = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" } } \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsNotificationsFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsNotificationsFragment.kt index b9561531..91c21a3a 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsNotificationsFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsNotificationsFragment.kt @@ -11,54 +11,48 @@ import com.f0x1d.logfox.LogFoxApp import com.f0x1d.logfox.R import com.f0x1d.logfox.extensions.hasNotificationsPermission import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment -import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment import com.f0x1d.logfox.utils.preferences.AppPreferences import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint -class SettingsNotificationsFragment: BaseSettingsWrapperFragment() { +class SettingsNotificationsFragment: BasePreferenceFragment() { - override val wrappedFragment get() = SettingsNotificationWrappedFragment() override val title = R.string.notifications override val showBackArrow = true - @AndroidEntryPoint - class SettingsNotificationWrappedFragment: BasePreferenceFragment() { + @Inject + lateinit var appPreferences: AppPreferences - @Inject - lateinit var appPreferences: AppPreferences + @SuppressLint("InlinedApi") + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.settings_notifications) - @SuppressLint("InlinedApi") - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.settings_notifications) + findPreference("pref_notifications_permission")?.setOnPreferenceClickListener { + startActivity(Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) + }) + return@setOnPreferenceClickListener true + } + + findPreference("pref_logging_notification")?.apply { + isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - findPreference("pref_notifications_permission")?.setOnPreferenceClickListener { - startActivity(Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { + setOnPreferenceClickListener { + startActivity(Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) + putExtra(Settings.EXTRA_CHANNEL_ID, LogFoxApp.LOGGING_STATUS_CHANNEL_ID) }) return@setOnPreferenceClickListener true } - - findPreference("pref_logging_notification")?.apply { - isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - - setOnPreferenceClickListener { - startActivity(Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) - putExtra(Settings.EXTRA_CHANNEL_ID, LogFoxApp.LOGGING_STATUS_CHANNEL_ID) - }) - return@setOnPreferenceClickListener true - } - } } + } - override fun onStart() { - super.onStart() + override fun onStart() { + super.onStart() - findPreference("pref_notifications_permission")?.isVisible = !requireContext().hasNotificationsPermission() - } + findPreference("pref_notifications_permission")?.isVisible = !requireContext().hasNotificationsPermission() } } \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsServiceFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsServiceFragment.kt index 5c98b108..8812740d 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsServiceFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsServiceFragment.kt @@ -11,7 +11,6 @@ import com.f0x1d.logfox.extensions.setupAsListPreference import com.f0x1d.logfox.extensions.toast import com.f0x1d.logfox.repository.logging.LoggingRepository import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment -import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment import com.f0x1d.logfox.utils.fillWithStrings import com.f0x1d.logfox.utils.preferences.AppPreferences import com.f0x1d.logfox.utils.terminal.DefaultTerminal @@ -22,88 +21,83 @@ import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint -class SettingsServiceFragment: BaseSettingsWrapperFragment() { +class SettingsServiceFragment: BasePreferenceFragment() { - override val wrappedFragment get() = SettingsServiceWrappedFragment() override val title = R.string.service override val showBackArrow = true - @AndroidEntryPoint - class SettingsServiceWrappedFragment: BasePreferenceFragment() { - - @Inject - lateinit var loggingRepository: LoggingRepository - - @Inject - lateinit var appPreferences: AppPreferences - - @Inject - lateinit var terminals: Array - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.settings_service) - - findPreference("pref_selected_terminal_index")?.apply { - val filledTerminalSettings = terminals.map { it.title }.toIntArray().fillWithStrings(requireContext()) - - setupAsListPreference( - { - setIcon(R.drawable.ic_dialog_terminal) - }, - filledTerminalSettings, - { appPreferences.selectedTerminalIndex } - ) { - if (appPreferences.selectedTerminalIndex == it) { - loggingRepository.restartLogging() - return@setupAsListPreference - } - - lifecycleScope.launch { - val selectedTerminal = terminals[it] - if (selectedTerminal.isSupported()) { - appPreferences.selectedTerminalIndex = it - askAboutNewTerminalRestart() - } else - requireContext().toast(R.string.terminal_unavailable) - } - } + @Inject + lateinit var loggingRepository: LoggingRepository - observeAndUpdateSummaryForList(appPreferences, this@SettingsServiceWrappedFragment, 0, filledTerminalSettings) - } + @Inject + lateinit var appPreferences: AppPreferences + + @Inject + lateinit var terminals: Array + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.settings_service) - findPreference("pref_start_on_boot")?.apply { - setOnPreferenceChangeListener { preference, newValue -> - val badTerminal = appPreferences.selectedTerminalIndex == DefaultTerminal.INDEX + findPreference("pref_selected_terminal_index")?.apply { + val filledTerminalSettings = terminals.map { it.title }.toIntArray().fillWithStrings(requireContext()) - if (isAtLeastAndroid13 && newValue as Boolean && badTerminal) { - showAndroid13WarningDialog() - } - return@setOnPreferenceChangeListener true + setupAsListPreference( + { + setIcon(R.drawable.ic_dialog_terminal) + }, + filledTerminalSettings, + { appPreferences.selectedTerminalIndex } + ) { + if (appPreferences.selectedTerminalIndex == it) { + loggingRepository.restartLogging() + return@setupAsListPreference + } + + lifecycleScope.launch { + val selectedTerminal = terminals[it] + if (selectedTerminal.isSupported()) { + appPreferences.selectedTerminalIndex = it + askAboutNewTerminalRestart() + } else + requireContext().toast(R.string.terminal_unavailable) } } + + observeAndUpdateSummaryForList(appPreferences, this@SettingsServiceFragment, 0, filledTerminalSettings) } - private fun askAboutNewTerminalRestart() { - MaterialAlertDialogBuilder(requireContext()) - .setIcon(R.drawable.ic_dialog_terminal) - .setTitle(R.string.new_terminal_selected) - .setMessage(R.string.new_terminal_selected_question) - .setPositiveButton(R.string.yes) { dialog, _ -> - loggingRepository.restartLogging() + findPreference("pref_start_on_boot")?.apply { + setOnPreferenceChangeListener { preference, newValue -> + val badTerminal = appPreferences.selectedTerminalIndex == DefaultTerminal.INDEX + + if (isAtLeastAndroid13 && newValue as Boolean && badTerminal) { + showAndroid13WarningDialog() } - .setNeutralButton(R.string.no, null) - .show() + return@setOnPreferenceChangeListener true + } } + } - private fun showAndroid13WarningDialog() { - MaterialAlertDialogBuilder(requireContext()) - .setIcon(R.drawable.ic_dialog_warning) - .setTitle(R.string.warning) - .setMessage(R.string.android13_start_on_boot_warning) - .setCancelable(false) - .setPositiveButton(android.R.string.ok, null) - .show() - } + private fun askAboutNewTerminalRestart() { + MaterialAlertDialogBuilder(requireContext()) + .setIcon(R.drawable.ic_dialog_terminal) + .setTitle(R.string.new_terminal_selected) + .setMessage(R.string.new_terminal_selected_question) + .setPositiveButton(R.string.yes) { dialog, _ -> + loggingRepository.restartLogging() + } + .setNeutralButton(R.string.no, null) + .show() + } + + private fun showAndroid13WarningDialog() { + MaterialAlertDialogBuilder(requireContext()) + .setIcon(R.drawable.ic_dialog_warning) + .setTitle(R.string.warning) + .setMessage(R.string.android13_start_on_boot_warning) + .setCancelable(false) + .setPositiveButton(android.R.string.ok, null) + .show() } } diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsUIFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsUIFragment.kt index c50fb021..d3aad5ff 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsUIFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/SettingsUIFragment.kt @@ -11,7 +11,6 @@ import com.f0x1d.logfox.extensions.observeAndUpdateSummaryForList import com.f0x1d.logfox.extensions.setupAsEditTextPreference import com.f0x1d.logfox.extensions.setupAsListPreference import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment -import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment import com.f0x1d.logfox.utils.fillWithStrings import com.f0x1d.logfox.utils.preferences.AppPreferences import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -19,120 +18,115 @@ import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint -class SettingsUIFragment: BaseSettingsWrapperFragment() { +class SettingsUIFragment: BasePreferenceFragment() { - override val wrappedFragment get() = SettingsUIWrappedFragment() override val title = R.string.ui override val showBackArrow = true - @AndroidEntryPoint - class SettingsUIWrappedFragment: BasePreferenceFragment() { + @Inject + lateinit var appPreferences: AppPreferences - @Inject - lateinit var appPreferences: AppPreferences + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.settings_ui) - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.settings_ui) + findPreference("pref_night_theme")?.apply { + val filledThemeSettings = intArrayOf(R.string.follow_system, R.string.light, R.string.dark).fillWithStrings(requireContext()) - findPreference("pref_night_theme")?.apply { - val filledThemeSettings = intArrayOf(R.string.follow_system, R.string.light, R.string.dark).fillWithStrings(requireContext()) - - setupAsListPreference( - { - setIcon(R.drawable.ic_dialog_theme) - }, - filledThemeSettings, - { appPreferences.nightTheme } - ) { - appPreferences.nightTheme = it - requireActivity().applyTheme(it, true) - } - - observeAndUpdateSummaryForList(appPreferences, this@SettingsUIWrappedFragment, 0, filledThemeSettings) + setupAsListPreference( + { + setIcon(R.drawable.ic_dialog_theme) + }, + filledThemeSettings, + { appPreferences.nightTheme } + ) { + appPreferences.nightTheme = it + requireActivity().applyTheme(it, true) } - findPreference("pref_logs_format")?.setOnPreferenceClickListener { - MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.logs_format) - .setIcon(R.drawable.ic_dialog_list) - .setMultiChoiceItems( - intArrayOf( - R.string.date, - R.string.time, - R.string.uid, - R.string.pid, - R.string.tid, - R.string.package_name, - R.string.tag, - R.string.content - ).fillWithStrings(requireContext()), - appPreferences.showLogValues.asArray - ) { dialog, which, checked -> - when (which) { - 0 -> appPreferences.showLogDate = checked - 1 -> appPreferences.showLogTime = checked - 2 -> appPreferences.showLogUid = checked - 3 -> appPreferences.showLogPid = checked - 4 -> appPreferences.showLogTid = checked - 5 -> appPreferences.showLogPackage = checked - 6 -> appPreferences.showLogTag = checked - 7 -> appPreferences.showLogContent = checked - } - } - .setPositiveButton(R.string.close, null) - .show() - return@setOnPreferenceClickListener true - } + observeAndUpdateSummaryForList(appPreferences, this@SettingsUIFragment, 0, filledThemeSettings) + } - findPreference("pref_logs_update_interval")?.apply { - setupAsEditTextPreference({ - it.textLayout.setHint(R.string.in_ms) - it.text.inputType = InputType.TYPE_CLASS_NUMBER - }, { - setIcon(R.drawable.ic_dialog_timer) - }, { - appPreferences.logsUpdateInterval.toString() - }, { - requireContext().catchingNotNumber { - appPreferences.logsUpdateInterval = it?.toLong() ?: AppPreferences.LOGS_UPDATE_INTERVAL_DEFAULT + findPreference("pref_logs_format")?.setOnPreferenceClickListener { + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.logs_format) + .setIcon(R.drawable.ic_dialog_list) + .setMultiChoiceItems( + intArrayOf( + R.string.date, + R.string.time, + R.string.uid, + R.string.pid, + R.string.tid, + R.string.package_name, + R.string.tag, + R.string.content + ).fillWithStrings(requireContext()), + appPreferences.showLogValues.asArray + ) { dialog, which, checked -> + when (which) { + 0 -> appPreferences.showLogDate = checked + 1 -> appPreferences.showLogTime = checked + 2 -> appPreferences.showLogUid = checked + 3 -> appPreferences.showLogPid = checked + 4 -> appPreferences.showLogTid = checked + 5 -> appPreferences.showLogPackage = checked + 6 -> appPreferences.showLogTag = checked + 7 -> appPreferences.showLogContent = checked } - }) + } + .setPositiveButton(R.string.close, null) + .show() + return@setOnPreferenceClickListener true + } - observeAndUpdateSummary(appPreferences, this@SettingsUIWrappedFragment, AppPreferences.LOGS_UPDATE_INTERVAL_DEFAULT) - } + findPreference("pref_logs_update_interval")?.apply { + setupAsEditTextPreference({ + it.textLayout.setHint(R.string.in_ms) + it.text.inputType = InputType.TYPE_CLASS_NUMBER + }, { + setIcon(R.drawable.ic_dialog_timer) + }, { + appPreferences.logsUpdateInterval.toString() + }, { + requireContext().catchingNotNumber { + appPreferences.logsUpdateInterval = it?.toLong() ?: AppPreferences.LOGS_UPDATE_INTERVAL_DEFAULT + } + }) - findPreference("pref_logs_text_size")?.apply { - setupAsEditTextPreference({ - it.text.inputType = InputType.TYPE_CLASS_NUMBER - }, { - setIcon(R.drawable.ic_dialog_text_fields) - }, { - appPreferences.logsTextSize.toString() - }, { - requireContext().catchingNotNumber { - appPreferences.logsTextSize = it?.toInt() ?: AppPreferences.LOGS_TEXT_SIZE_DEFAULT - } - }) + observeAndUpdateSummary(appPreferences, this@SettingsUIFragment, AppPreferences.LOGS_UPDATE_INTERVAL_DEFAULT) + } - observeAndUpdateSummary(appPreferences, this@SettingsUIWrappedFragment, AppPreferences.LOGS_TEXT_SIZE_DEFAULT) - } + findPreference("pref_logs_text_size")?.apply { + setupAsEditTextPreference({ + it.text.inputType = InputType.TYPE_CLASS_NUMBER + }, { + setIcon(R.drawable.ic_dialog_text_fields) + }, { + appPreferences.logsTextSize.toString() + }, { + requireContext().catchingNotNumber { + appPreferences.logsTextSize = it?.toInt() ?: AppPreferences.LOGS_TEXT_SIZE_DEFAULT + } + }) - findPreference("pref_logs_display_limit")?.apply { - setupAsEditTextPreference({ - it.textLayout.setHint(R.string.lines) - it.text.inputType = InputType.TYPE_CLASS_NUMBER - }, { - setIcon(R.drawable.ic_dialog_eye) - }, { - appPreferences.logsDisplayLimit.toString() - }, { - requireContext().catchingNotNumber { - appPreferences.logsDisplayLimit = it?.toInt() ?: AppPreferences.LOGS_DISPLAY_LIMIT_DEFAULT - } - }) + observeAndUpdateSummary(appPreferences, this@SettingsUIFragment, AppPreferences.LOGS_TEXT_SIZE_DEFAULT) + } - observeAndUpdateSummary(appPreferences, this@SettingsUIWrappedFragment, AppPreferences.LOGS_DISPLAY_LIMIT_DEFAULT) - } + findPreference("pref_logs_display_limit")?.apply { + setupAsEditTextPreference({ + it.textLayout.setHint(R.string.lines) + it.text.inputType = InputType.TYPE_CLASS_NUMBER + }, { + setIcon(R.drawable.ic_dialog_eye) + }, { + appPreferences.logsDisplayLimit.toString() + }, { + requireContext().catchingNotNumber { + appPreferences.logsDisplayLimit = it?.toInt() ?: AppPreferences.LOGS_DISPLAY_LIMIT_DEFAULT + } + }) + + observeAndUpdateSummary(appPreferences, this@SettingsUIFragment, AppPreferences.LOGS_DISPLAY_LIMIT_DEFAULT) } } } \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BasePreferenceFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BasePreferenceFragment.kt index db9a493b..af1c3691 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BasePreferenceFragment.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BasePreferenceFragment.kt @@ -2,14 +2,30 @@ package com.f0x1d.logfox.ui.fragment.settings.base import android.os.Bundle import android.view.View +import androidx.navigation.fragment.findNavController import androidx.preference.PreferenceFragmentCompat +import com.f0x1d.logfox.R import com.f0x1d.logfox.extensions.isHorizontalOrientation +import com.google.android.material.appbar.MaterialToolbar import dev.chrisbanes.insetter.applyInsetter abstract class BasePreferenceFragment: PreferenceFragmentCompat() { + + open val title = R.string.settings + open val showBackArrow = false + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + view.findViewById(R.id.toolbar).apply { + setTitle(this@BasePreferenceFragment.title) + + if (showBackArrow) { + setNavigationIcon(R.drawable.ic_arrow_back) + setNavigationOnClickListener { findNavController().popBackStack() } + } + } + listView.apply { clipToPadding = false diff --git a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BaseSettingsWrapperFragment.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BaseSettingsWrapperFragment.kt deleted file mode 100644 index 460a418e..00000000 --- a/app/src/main/java/com/f0x1d/logfox/ui/fragment/settings/base/BaseSettingsWrapperFragment.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.f0x1d.logfox.ui.fragment.settings.base - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController -import com.f0x1d.logfox.R -import com.f0x1d.logfox.databinding.FragmentSettingsBinding -import com.f0x1d.logfox.ui.fragment.base.BaseFragment - -abstract class BaseSettingsWrapperFragment: BaseFragment() { - - abstract val wrappedFragment: Fragment - open val title = R.string.settings - open val showBackArrow = false - - override fun inflateBinding(inflater: LayoutInflater, container: ViewGroup?) = FragmentSettingsBinding.inflate(inflater, container, false) - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.toolbar.setTitle(title) - if (showBackArrow) { - binding.toolbar.setNavigationIcon(R.drawable.ic_arrow_back) - binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() } - } - - if (savedInstanceState == null) { - val tag = "wrapped_by_${javaClass.name}" - val fragment = childFragmentManager.findFragmentByTag(tag) - - childFragmentManager - .beginTransaction() - .apply { - if (fragment == null) - add(R.id.container, wrappedFragment, tag) - else - show(fragment) - } - .commit() - } - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 15aa20e2..a6028ba0 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -20,8 +20,8 @@ app:navigationIconTint="?colorOnSurface"/> - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bf66f8b9..a6239703 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,6 +1,6 @@ - + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 17420e3e..76e97964 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -8,8 +8,9 @@ true - @style/ThemeOverlay.LogFoxMaterialAlertDialog + @style/LogFoxMaterialAlertDialog @style/LogFoxBottomSheetDialogStyle + @style/LogFoxPreferenceTheme @font/google_sans @font/google_sans