mirror of
				https://github.com/SimpleMobileTools/Simple-Flashlight.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	Migrate SettingsActivity to compose
This commit is contained in:
		| @@ -43,6 +43,11 @@ android { | |||||||
|     buildFeatures { |     buildFeatures { | ||||||
|         viewBinding = true |         viewBinding = true | ||||||
|         buildConfig = true |         buildConfig = true | ||||||
|  |         compose = true | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     composeOptions { | ||||||
|  |         kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     buildTypes { |     buildTypes { | ||||||
| @@ -80,6 +85,13 @@ android { | |||||||
|  |  | ||||||
|     tasks.withType<KotlinCompile> { |     tasks.withType<KotlinCompile> { | ||||||
|         kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get() |         kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get() | ||||||
|  |         kotlinOptions.freeCompilerArgs = listOf( | ||||||
|  |             "-opt-in=kotlin.RequiresOptIn", | ||||||
|  |             "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api", | ||||||
|  |             "-opt-in=androidx.compose.material.ExperimentalMaterialApi", | ||||||
|  |             "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi", | ||||||
|  |             "-Xcontext-receivers" | ||||||
|  |         ) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     namespace = libs.versions.app.version.appId.get() |     namespace = libs.versions.app.version.appId.get() | ||||||
| @@ -95,4 +107,7 @@ dependencies { | |||||||
|  |  | ||||||
|     implementation(libs.androidx.constraintlayout) |     implementation(libs.androidx.constraintlayout) | ||||||
|     implementation(libs.eventbus) |     implementation(libs.eventbus) | ||||||
|  |     implementation(libs.bundles.lifecycle) | ||||||
|  |     implementation(libs.bundles.compose) | ||||||
|  |     debugImplementation(libs.bundles.compose.preview) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,145 +2,64 @@ package com.simplemobiletools.flashlight.activities | |||||||
|  |  | ||||||
| import android.content.Intent | import android.content.Intent | ||||||
| import android.os.Bundle | import android.os.Bundle | ||||||
| import com.simplemobiletools.commons.extensions.* | import androidx.activity.compose.setContent | ||||||
|  | import androidx.compose.runtime.getValue | ||||||
|  | import androidx.compose.runtime.remember | ||||||
|  | import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||||||
|  | import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple | ||||||
|  | import com.simplemobiletools.commons.compose.theme.AppThemeSurface | ||||||
| import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS | import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS | ||||||
| import com.simplemobiletools.commons.helpers.NavigationIcon |  | ||||||
| import com.simplemobiletools.commons.helpers.isTiramisuPlus |  | ||||||
| import com.simplemobiletools.flashlight.databinding.ActivitySettingsBinding |  | ||||||
| import com.simplemobiletools.flashlight.extensions.config | import com.simplemobiletools.flashlight.extensions.config | ||||||
|  | import com.simplemobiletools.flashlight.screens.SettingsScreen | ||||||
| import java.util.Locale | import java.util.Locale | ||||||
| import kotlin.system.exitProcess |  | ||||||
|  |  | ||||||
| class SettingsActivity : SimpleActivity() { | class SettingsActivity : SimpleActivity() { | ||||||
|     private val binding by viewBinding(ActivitySettingsBinding::inflate) |     private val preferences by lazy { config } | ||||||
|  |  | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         isMaterialActivity = true |  | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
|         setContentView(binding.root) |         enableEdgeToEdgeSimple() | ||||||
|  |         setContent { | ||||||
|  |             AppThemeSurface { | ||||||
|  |                 val displayLanguage = remember { Locale.getDefault().displayLanguage } | ||||||
|  |                 val turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn) | ||||||
|  |                 val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode) | ||||||
|  |                 val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay) | ||||||
|  |                 val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos) | ||||||
|  |                 val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope) | ||||||
|  |  | ||||||
|         binding.apply { |                 SettingsScreen( | ||||||
|             updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false) |                     displayLanguage = displayLanguage, | ||||||
|             setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar) |                     onSetupLanguagePress = ::launchChangeAppLanguageIntent, | ||||||
|         } |                     customizeColors = ::startCustomizationActivity, | ||||||
|     } |                     turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow, | ||||||
|  |                     forcePortraitModeChecked = forcePortraitModeFlow, | ||||||
|     override fun onResume() { |                     showBrightDisplayButtonChecked = showBrightDisplayButtonFlow, | ||||||
|         super.onResume() |                     showSosButtonChecked = showSosButtonFlow, | ||||||
|         setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow) |                     showStroboscopeButtonChecked = showStroboscopeButtonFlow, | ||||||
|  |                     customizeWidgetColors = { | ||||||
|         setupPurchaseThankYou() |  | ||||||
|         setupCustomizeColors() |  | ||||||
|         setupCustomizeWidgetColors() |  | ||||||
|         setupUseEnglish() |  | ||||||
|         setupLanguage() |  | ||||||
|         setupTurnFlashlightOn() |  | ||||||
|         setupBrightDisplay() |  | ||||||
|         setupStroboscope() |  | ||||||
|         setupSOS() |  | ||||||
|         setupForcePortrait() |  | ||||||
|         updateTextColors(binding.settingsHolder) |  | ||||||
|  |  | ||||||
|         arrayOf(binding.settingsColorCustomizationSectionLabel, binding.settingsGeneralSettingsLabel).forEach { |  | ||||||
|             it.setTextColor(getProperPrimaryColor()) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupPurchaseThankYou() { |  | ||||||
|         binding.settingsPurchaseThankYouHolder.apply { |  | ||||||
|             beGoneIf(isOrWasThankYouInstalled()) |  | ||||||
|             setOnClickListener { |  | ||||||
|                 launchPurchaseThankYouIntent() |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupCustomizeColors() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsColorCustomizationLabel.text = getCustomizeColorsString() |  | ||||||
|             settingsColorCustomizationHolder.setOnClickListener { |  | ||||||
|                 handleCustomizeColorsClick() |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupCustomizeWidgetColors() { |  | ||||||
|         binding.settingsWidgetColorCustomizationHolder.setOnClickListener { |  | ||||||
|                         Intent(this, WidgetTorchConfigureActivity::class.java).apply { |                         Intent(this, WidgetTorchConfigureActivity::class.java).apply { | ||||||
|                             putExtra(IS_CUSTOMIZING_COLORS, true) |                             putExtra(IS_CUSTOMIZING_COLORS, true) | ||||||
|                             startActivity(this) |                             startActivity(this) | ||||||
|                         } |                         } | ||||||
|         } |                     }, | ||||||
|     } |                     onTurnFlashlightOnStartupPress = { | ||||||
|  |                         preferences.turnFlashlightOn = it | ||||||
|     private fun setupUseEnglish() { |                     }, | ||||||
|         binding.apply { |                     onForcePortraitModePress = { | ||||||
|             settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) |                         preferences.forcePortraitMode = it | ||||||
|             settingsUseEnglish.isChecked = config.useEnglish |                     }, | ||||||
|             settingsUseEnglishHolder.setOnClickListener { |                     onShowBrightDisplayButtonPress = { | ||||||
|                 settingsUseEnglish.toggle() |                         preferences.brightDisplay = it | ||||||
|                 config.useEnglish = settingsUseEnglish.isChecked |                     }, | ||||||
|                 exitProcess(0) |                     onShowSosButtonPress = { | ||||||
|             } |                         preferences.sos = it | ||||||
|         } |                     }, | ||||||
|     } |                     onShowStroboscopeButtonPress = { | ||||||
|  |                         preferences.stroboscope = it | ||||||
|     private fun setupLanguage() { |                     }, | ||||||
|         binding.apply { |                     goBack = ::finish | ||||||
|             settingsLanguage.text = Locale.getDefault().displayLanguage |                 ) | ||||||
|             settingsLanguageHolder.beVisibleIf(isTiramisuPlus()) |  | ||||||
|             settingsLanguageHolder.setOnClickListener { |  | ||||||
|                 launchChangeAppLanguageIntent() |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupTurnFlashlightOn() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsTurnFlashlightOn.isChecked = config.turnFlashlightOn |  | ||||||
|             settingsTurnFlashlightOnHolder.setOnClickListener { |  | ||||||
|                 settingsTurnFlashlightOn.toggle() |  | ||||||
|                 config.turnFlashlightOn = settingsTurnFlashlightOn.isChecked |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupBrightDisplay() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsBrightDisplay.isChecked = config.brightDisplay |  | ||||||
|             settingsBrightDisplayHolder.setOnClickListener { |  | ||||||
|                 settingsBrightDisplay.toggle() |  | ||||||
|                 config.brightDisplay = settingsBrightDisplay.isChecked |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupStroboscope() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsStroboscope.isChecked = config.stroboscope |  | ||||||
|             settingsStroboscopeHolder.setOnClickListener { |  | ||||||
|                 settingsStroboscope.toggle() |  | ||||||
|                 config.stroboscope = settingsStroboscope.isChecked |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupSOS() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsSos.isChecked = config.sos |  | ||||||
|             settingsSosHolder.setOnClickListener { |  | ||||||
|                 settingsSos.toggle() |  | ||||||
|                 config.sos = settingsSos.isChecked |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun setupForcePortrait() { |  | ||||||
|         binding.apply { |  | ||||||
|             settingsForcePortrait.isChecked = config.forcePortraitMode |  | ||||||
|             settingsForcePortraitHolder.setOnClickListener { |  | ||||||
|                 settingsForcePortrait.toggle() |  | ||||||
|                 config.forcePortraitMode = settingsForcePortrait.isChecked |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,7 +2,11 @@ package com.simplemobiletools.flashlight.helpers | |||||||
|  |  | ||||||
| import android.content.Context | import android.content.Context | ||||||
| import android.graphics.Color | import android.graphics.Color | ||||||
|  | import com.simplemobiletools.commons.extensions.sharedPreferencesCallback | ||||||
| import com.simplemobiletools.commons.helpers.BaseConfig | import com.simplemobiletools.commons.helpers.BaseConfig | ||||||
|  | import kotlinx.coroutines.flow.Flow | ||||||
|  | import kotlinx.coroutines.flow.filterNotNull | ||||||
|  | import kotlin.reflect.KProperty0 | ||||||
|  |  | ||||||
| class Config(context: Context) : BaseConfig(context) { | class Config(context: Context) : BaseConfig(context) { | ||||||
|     companion object { |     companion object { | ||||||
| @@ -13,18 +17,26 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|         get() = prefs.getBoolean(BRIGHT_DISPLAY, true) |         get() = prefs.getBoolean(BRIGHT_DISPLAY, true) | ||||||
|         set(brightDisplay) = prefs.edit().putBoolean(BRIGHT_DISPLAY, brightDisplay).apply() |         set(brightDisplay) = prefs.edit().putBoolean(BRIGHT_DISPLAY, brightDisplay).apply() | ||||||
|  |  | ||||||
|  |     val brightDisplayFlow = ::brightDisplay.asFlow() | ||||||
|  |  | ||||||
|     var stroboscope: Boolean |     var stroboscope: Boolean | ||||||
|         get() = prefs.getBoolean(STROBOSCOPE, true) |         get() = prefs.getBoolean(STROBOSCOPE, true) | ||||||
|         set(stroboscope) = prefs.edit().putBoolean(STROBOSCOPE, stroboscope).apply() |         set(stroboscope) = prefs.edit().putBoolean(STROBOSCOPE, stroboscope).apply() | ||||||
|  |  | ||||||
|  |     val stroboscopeFlow = ::stroboscope.asFlow() | ||||||
|  |  | ||||||
|     var sos: Boolean |     var sos: Boolean | ||||||
|         get() = prefs.getBoolean(SOS, true) |         get() = prefs.getBoolean(SOS, true) | ||||||
|         set(sos) = prefs.edit().putBoolean(SOS, sos).apply() |         set(sos) = prefs.edit().putBoolean(SOS, sos).apply() | ||||||
|  |  | ||||||
|  |     val sosFlow = ::sos.asFlow() | ||||||
|  |  | ||||||
|     var turnFlashlightOn: Boolean |     var turnFlashlightOn: Boolean | ||||||
|         get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false) |         get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false) | ||||||
|         set(turnFlashlightOn) = prefs.edit().putBoolean(TURN_FLASHLIGHT_ON, turnFlashlightOn).apply() |         set(turnFlashlightOn) = prefs.edit().putBoolean(TURN_FLASHLIGHT_ON, turnFlashlightOn).apply() | ||||||
|  |  | ||||||
|  |     val turnFlashlightOnFlow = ::turnFlashlightOn.asFlow() | ||||||
|  |  | ||||||
|     var stroboscopeProgress: Int |     var stroboscopeProgress: Int | ||||||
|         get() = prefs.getInt(STROBOSCOPE_PROGRESS, 1000) |         get() = prefs.getInt(STROBOSCOPE_PROGRESS, 1000) | ||||||
|         set(stroboscopeProgress) = prefs.edit().putInt(STROBOSCOPE_PROGRESS, stroboscopeProgress).apply() |         set(stroboscopeProgress) = prefs.edit().putInt(STROBOSCOPE_PROGRESS, stroboscopeProgress).apply() | ||||||
| @@ -41,6 +53,8 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|         get() = prefs.getBoolean(FORCE_PORTRAIT_MODE, true) |         get() = prefs.getBoolean(FORCE_PORTRAIT_MODE, true) | ||||||
|         set(forcePortraitMode) = prefs.edit().putBoolean(FORCE_PORTRAIT_MODE, forcePortraitMode).apply() |         set(forcePortraitMode) = prefs.edit().putBoolean(FORCE_PORTRAIT_MODE, forcePortraitMode).apply() | ||||||
|  |  | ||||||
|  |     val forcePortraitModeFlow = ::forcePortraitMode.asFlow() | ||||||
|  |  | ||||||
|     var brightnessLevel: Int |     var brightnessLevel: Int | ||||||
|         get() = prefs.getInt(BRIGHTNESS_LEVEL, DEFAULT_BRIGHTNESS_LEVEL) |         get() = prefs.getInt(BRIGHTNESS_LEVEL, DEFAULT_BRIGHTNESS_LEVEL) | ||||||
|         set(brightnessLevel) = prefs.edit().putInt(BRIGHTNESS_LEVEL, brightnessLevel).apply() |         set(brightnessLevel) = prefs.edit().putInt(BRIGHTNESS_LEVEL, brightnessLevel).apply() | ||||||
| @@ -52,4 +66,6 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|     var sleepInTS: Long |     var sleepInTS: Long | ||||||
|         get() = prefs.getLong(SLEEP_IN_TS, 0) |         get() = prefs.getLong(SLEEP_IN_TS, 0) | ||||||
|         set(sleepInTS) = prefs.edit().putLong(SLEEP_IN_TS, sleepInTS).apply() |         set(sleepInTS) = prefs.edit().putLong(SLEEP_IN_TS, sleepInTS).apply() | ||||||
|  |  | ||||||
|  |     private fun <T> KProperty0<T>.asFlow(): Flow<T> = prefs.run { sharedPreferencesCallback { this@asFlow.get() } }.filterNotNull() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -0,0 +1,114 @@ | |||||||
|  | package com.simplemobiletools.flashlight.screens | ||||||
|  |  | ||||||
|  | import androidx.compose.material3.HorizontalDivider | ||||||
|  | import androidx.compose.material3.MaterialTheme | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.ui.res.stringResource | ||||||
|  | import com.simplemobiletools.commons.compose.extensions.MyDevices | ||||||
|  | import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent | ||||||
|  | import com.simplemobiletools.commons.compose.settings.SettingsGroup | ||||||
|  | import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponent | ||||||
|  | import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent | ||||||
|  | import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold | ||||||
|  | import com.simplemobiletools.commons.compose.theme.AppThemeSurface | ||||||
|  | import com.simplemobiletools.commons.compose.theme.divider_grey | ||||||
|  | import com.simplemobiletools.commons.helpers.isTiramisuPlus | ||||||
|  | import com.simplemobiletools.flashlight.R | ||||||
|  |  | ||||||
|  | @Composable | ||||||
|  | internal fun SettingsScreen( | ||||||
|  |     displayLanguage: String, | ||||||
|  |     turnFlashlightOnStartupChecked: Boolean, | ||||||
|  |     forcePortraitModeChecked: Boolean, | ||||||
|  |     showBrightDisplayButtonChecked: Boolean, | ||||||
|  |     showSosButtonChecked: Boolean, | ||||||
|  |     showStroboscopeButtonChecked: Boolean, | ||||||
|  |     onSetupLanguagePress: () -> Unit, | ||||||
|  |     customizeColors: () -> Unit, | ||||||
|  |     customizeWidgetColors: () -> Unit, | ||||||
|  |     onTurnFlashlightOnStartupPress: (Boolean) -> Unit, | ||||||
|  |     onForcePortraitModePress: (Boolean) -> Unit, | ||||||
|  |     onShowBrightDisplayButtonPress: (Boolean) -> Unit, | ||||||
|  |     onShowSosButtonPress: (Boolean) -> Unit, | ||||||
|  |     onShowStroboscopeButtonPress: (Boolean) -> Unit, | ||||||
|  |     goBack: () -> Unit, | ||||||
|  | ) { | ||||||
|  |     SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { | ||||||
|  |         SettingsGroup(title = { | ||||||
|  |             SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization)) | ||||||
|  |         }) { | ||||||
|  |             SettingsPreferenceComponent( | ||||||
|  |                 preferenceTitle = stringResource(id = R.string.customize_colors), | ||||||
|  |                 doOnPreferenceClick = customizeColors, | ||||||
|  |             ) | ||||||
|  |             SettingsPreferenceComponent( | ||||||
|  |                 preferenceTitle = stringResource(id = R.string.customize_widget_colors), | ||||||
|  |                 doOnPreferenceClick = customizeWidgetColors | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |         HorizontalDivider(color = divider_grey) | ||||||
|  |         SettingsGroup(title = { | ||||||
|  |             SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings)) | ||||||
|  |         }) { | ||||||
|  |  | ||||||
|  |             if (isTiramisuPlus()) { | ||||||
|  |                 SettingsPreferenceComponent( | ||||||
|  |                     preferenceTitle = stringResource(id = R.string.language), | ||||||
|  |                     preferenceSummary = displayLanguage, | ||||||
|  |                     doOnPreferenceClick = onSetupLanguagePress, | ||||||
|  |                     preferenceSummaryColor = MaterialTheme.colorScheme.onSurface, | ||||||
|  |                 ) | ||||||
|  |             } | ||||||
|  |             SettingsCheckBoxComponent( | ||||||
|  |                 title = stringResource(id = R.string.turn_flashlight_on), | ||||||
|  |                 initialValue = turnFlashlightOnStartupChecked, | ||||||
|  |                 onChange = onTurnFlashlightOnStartupPress | ||||||
|  |             ) | ||||||
|  |             SettingsCheckBoxComponent( | ||||||
|  |                 title = stringResource(id = R.string.force_portrait_mode), | ||||||
|  |                 initialValue = forcePortraitModeChecked, | ||||||
|  |                 onChange = onForcePortraitModePress | ||||||
|  |             ) | ||||||
|  |             SettingsCheckBoxComponent( | ||||||
|  |                 title = stringResource(id = R.string.show_bright_display), | ||||||
|  |                 initialValue = showBrightDisplayButtonChecked, | ||||||
|  |                 onChange = onShowBrightDisplayButtonPress | ||||||
|  |             ) | ||||||
|  |             SettingsCheckBoxComponent( | ||||||
|  |                 title = stringResource(id = R.string.show_sos), | ||||||
|  |                 initialValue = showSosButtonChecked, | ||||||
|  |                 onChange = onShowSosButtonPress | ||||||
|  |             ) | ||||||
|  |             SettingsCheckBoxComponent( | ||||||
|  |                 title = stringResource(id = R.string.show_stroboscope), | ||||||
|  |                 initialValue = showStroboscopeButtonChecked, | ||||||
|  |                 onChange = onShowStroboscopeButtonPress | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @Composable | ||||||
|  | @MyDevices | ||||||
|  | private fun SettingsScreenPreview() { | ||||||
|  |     AppThemeSurface { | ||||||
|  |         SettingsScreen( | ||||||
|  |             displayLanguage = "English", | ||||||
|  |             turnFlashlightOnStartupChecked = false, | ||||||
|  |             forcePortraitModeChecked = true, | ||||||
|  |             showBrightDisplayButtonChecked = true, | ||||||
|  |             showSosButtonChecked = true, | ||||||
|  |             showStroboscopeButtonChecked = true, | ||||||
|  |             onSetupLanguagePress = {}, | ||||||
|  |             customizeColors = {}, | ||||||
|  |             customizeWidgetColors = {}, | ||||||
|  |             onTurnFlashlightOnStartupPress = {}, | ||||||
|  |             onForcePortraitModePress = {}, | ||||||
|  |             onShowBrightDisplayButtonPress = {}, | ||||||
|  |             onShowSosButtonPress = {}, | ||||||
|  |             onShowStroboscopeButtonPress = {}, | ||||||
|  |             goBack = {}, | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -1,212 +0,0 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> |  | ||||||
| <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |  | ||||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" |  | ||||||
|     xmlns:tools="http://schemas.android.com/tools" |  | ||||||
|     android:id="@+id/settings_coordinator" |  | ||||||
|     android:layout_width="match_parent" |  | ||||||
|     android:layout_height="match_parent"> |  | ||||||
|  |  | ||||||
|     <com.google.android.material.appbar.MaterialToolbar |  | ||||||
|         android:id="@+id/settings_toolbar" |  | ||||||
|         android:layout_width="match_parent" |  | ||||||
|         android:layout_height="?attr/actionBarSize" |  | ||||||
|         android:background="@color/color_primary" |  | ||||||
|         app:title="@string/settings" |  | ||||||
|         app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" /> |  | ||||||
|  |  | ||||||
|     <androidx.core.widget.NestedScrollView |  | ||||||
|         android:id="@+id/settings_nested_scrollview" |  | ||||||
|         android:layout_width="match_parent" |  | ||||||
|         android:layout_height="match_parent" |  | ||||||
|         android:layout_marginTop="?attr/actionBarSize" |  | ||||||
|         android:fillViewport="true" |  | ||||||
|         android:scrollbars="none"> |  | ||||||
|  |  | ||||||
|         <LinearLayout |  | ||||||
|             android:id="@+id/settings_holder" |  | ||||||
|             android:layout_width="match_parent" |  | ||||||
|             android:layout_height="wrap_content" |  | ||||||
|             android:orientation="vertical"> |  | ||||||
|  |  | ||||||
|             <TextView |  | ||||||
|                 android:id="@+id/settings_color_customization_section_label" |  | ||||||
|                 style="@style/SettingsSectionLabelStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content" |  | ||||||
|                 android:text="@string/color_customization" /> |  | ||||||
|  |  | ||||||
|             <androidx.constraintlayout.widget.ConstraintLayout |  | ||||||
|                 android:id="@+id/settings_color_customization_holder" |  | ||||||
|                 style="@style/SettingsHolderTextViewOneLinerStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyTextView |  | ||||||
|                     android:id="@+id/settings_color_customization_label" |  | ||||||
|                     style="@style/SettingsTextLabelStyle" |  | ||||||
|                     android:layout_width="wrap_content" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/customize_colors" |  | ||||||
|                     app:layout_constraintStart_toStartOf="parent" |  | ||||||
|                     app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
|  |  | ||||||
|             </androidx.constraintlayout.widget.ConstraintLayout> |  | ||||||
|  |  | ||||||
|             <androidx.constraintlayout.widget.ConstraintLayout |  | ||||||
|                 android:id="@+id/settings_widget_color_customization_holder" |  | ||||||
|                 style="@style/SettingsHolderTextViewOneLinerStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyTextView |  | ||||||
|                     android:id="@+id/settings_widget_color_customization_label" |  | ||||||
|                     style="@style/SettingsTextLabelStyle" |  | ||||||
|                     android:layout_width="wrap_content" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/customize_widget_colors" |  | ||||||
|                     app:layout_constraintStart_toStartOf="parent" |  | ||||||
|                     app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
|  |  | ||||||
|             </androidx.constraintlayout.widget.ConstraintLayout> |  | ||||||
|  |  | ||||||
|             <include |  | ||||||
|                 android:id="@+id/settings_color_customization_divider" |  | ||||||
|                 layout="@layout/divider" /> |  | ||||||
|  |  | ||||||
|             <TextView |  | ||||||
|                 android:id="@+id/settings_general_settings_label" |  | ||||||
|                 style="@style/SettingsSectionLabelStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content" |  | ||||||
|                 android:text="@string/general_settings" /> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_purchase_thank_you_holder" |  | ||||||
|                 style="@style/SettingsHolderTextViewStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyTextView |  | ||||||
|                     android:id="@+id/settings_purchase_thank_you" |  | ||||||
|                     style="@style/SettingsTextLabelStyle" |  | ||||||
|                     android:layout_width="wrap_content" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/purchase_simple_thank_you" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_use_english_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_use_english" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/use_english_language" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_language_holder" |  | ||||||
|                 style="@style/SettingsHolderTextViewStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyTextView |  | ||||||
|                     android:id="@+id/settings_language_label" |  | ||||||
|                     style="@style/SettingsTextLabelStyle" |  | ||||||
|                     android:layout_width="wrap_content" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/language" /> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyTextView |  | ||||||
|                     android:id="@+id/settings_language" |  | ||||||
|                     style="@style/SettingsTextValueStyle" |  | ||||||
|                     android:layout_width="wrap_content" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:layout_below="@+id/settings_language_label" |  | ||||||
|                     tools:text="English" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_turn_flashlight_on_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_turn_flashlight_on" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/turn_flashlight_on" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_force_portrait_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_force_portrait" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/force_portrait_mode" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_bright_display_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_bright_display" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/show_bright_display" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_sos_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_sos" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/show_sos" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|  |  | ||||||
|             <RelativeLayout |  | ||||||
|                 android:id="@+id/settings_stroboscope_holder" |  | ||||||
|                 style="@style/SettingsHolderCheckboxStyle" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content"> |  | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |  | ||||||
|                     android:id="@+id/settings_stroboscope" |  | ||||||
|                     style="@style/SettingsCheckboxStyle" |  | ||||||
|                     android:layout_width="match_parent" |  | ||||||
|                     android:layout_height="wrap_content" |  | ||||||
|                     android:text="@string/show_stroboscope" /> |  | ||||||
|  |  | ||||||
|             </RelativeLayout> |  | ||||||
|         </LinearLayout> |  | ||||||
|     </androidx.core.widget.NestedScrollView> |  | ||||||
| </androidx.coordinatorlayout.widget.CoordinatorLayout> |  | ||||||
| @@ -1,12 +1,20 @@ | |||||||
| [versions] | [versions] | ||||||
| #jetbrains | #jetbrains | ||||||
| kotlin = "1.9.0" | kotlin = "1.9.10" | ||||||
| #AndroidX | #AndroidX | ||||||
| androidx-constraintlayout = "2.1.4" | androidx-constraintlayout = "2.1.4" | ||||||
|  | androidx-customView = "1.2.0-alpha02" | ||||||
|  | androidx-customViewPooling = "1.0.0" | ||||||
|  | androidx-lifecycle = "2.7.0-alpha02" | ||||||
| #EventBus | #EventBus | ||||||
| eventbusVersion = "3.3.1" | eventbusVersion = "3.3.1" | ||||||
| #Simple tools | #Simple tools | ||||||
| simple-commons = "de113ad025" | simple-commons = "f87e960171" | ||||||
|  | #Compose | ||||||
|  | composeActivity = "1.8.0-rc01" | ||||||
|  | compose = "1.6.0-alpha06" | ||||||
|  | composeCompiler = "1.5.3" | ||||||
|  | composeMaterial3 = "1.2.0-alpha08" | ||||||
| #Gradle | #Gradle | ||||||
| gradlePlugins-agp = "8.1.1" | gradlePlugins-agp = "8.1.1" | ||||||
| #build | #build | ||||||
| @@ -20,10 +28,54 @@ app-version-appId = "com.simplemobiletools.flashlight" | |||||||
| app-version-versionCode = "65" | app-version-versionCode = "65" | ||||||
| app-version-versionName = "5.10.0" | app-version-versionName = "5.10.0" | ||||||
| [libraries] | [libraries] | ||||||
| #Simple Mobile Tools | #AndroidX | ||||||
| androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" } | androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" } | ||||||
|  | androidx-customView = { module = "androidx.customview:customview", version.ref = "androidx-customView" } | ||||||
|  | androidx-customViewPooling = { module = "androidx.customview:customview-poolingcontainer", version.ref = "androidx-customViewPooling" } | ||||||
|  | #Android X lifecycle | ||||||
|  | androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" } | ||||||
|  | androidx-lifecycle-viewModel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" } | ||||||
|  | androidx-lifecycle-viewModel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } | ||||||
|  | androidx-lifecycle-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" } | ||||||
|  | #EventBus | ||||||
| eventbus = { module = "org.greenrobot:eventbus", version.ref = "eventbusVersion" } | eventbus = { module = "org.greenrobot:eventbus", version.ref = "eventbusVersion" } | ||||||
|  | #Simple Mobile Tools | ||||||
| simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" } | simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" } | ||||||
|  | #Compose | ||||||
|  | compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "composeCompiler" } | ||||||
|  | compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" } | ||||||
|  | compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "composeMaterial3" } | ||||||
|  | compose-material2 = { module = "androidx.compose.material:material", version.ref = "compose" } | ||||||
|  | compose-material-icons = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" } | ||||||
|  | compose-animation = { module = "androidx.compose.animation:animation", version.ref = "compose" } | ||||||
|  | compose-activity = { module = "androidx.activity:activity-compose", version.ref = "composeActivity" } | ||||||
|  | compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" } | ||||||
|  | compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" } | ||||||
|  | compose-uiTooling-debug = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } | ||||||
|  | compose-uiTooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } | ||||||
|  | [bundles] | ||||||
|  | compose = [ | ||||||
|  |     "compose-activity", | ||||||
|  |     "compose-animation", | ||||||
|  |     "compose-compiler", | ||||||
|  |     "compose-foundation", | ||||||
|  |     "compose-material-icons", | ||||||
|  |     "compose-material3", | ||||||
|  |     "compose-runtime", | ||||||
|  |     "compose-ui", | ||||||
|  |     "compose-uiTooling-preview", | ||||||
|  | ] | ||||||
|  | compose-preview = [ | ||||||
|  |     "androidx-customView", | ||||||
|  |     "androidx-customViewPooling", | ||||||
|  |     "compose-uiTooling-debug", | ||||||
|  | ] | ||||||
|  | lifecycle = [ | ||||||
|  |     "androidx-lifecycle-compose", | ||||||
|  |     "androidx-lifecycle-runtime", | ||||||
|  |     "androidx-lifecycle-viewModel", | ||||||
|  |     "androidx-lifecycle-viewModel-compose", | ||||||
|  | ] | ||||||
| [plugins] | [plugins] | ||||||
| android = { id = "com.android.application", version.ref = "gradlePlugins-agp" } | android = { id = "com.android.application", version.ref = "gradlePlugins-agp" } | ||||||
| kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } | kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user