rename lifecycle hooks

This commit is contained in:
qimiko committed 2022-11-16 10:35:32 -07:00
1 parent 810ad7c315
commit 544bd19fe7
3 files changed
+6 -6

No files matched your search

@@ -22,8 +22,8 @@ import androidx.compose.ui.unit.sp
import com.geode.launcher.ui.theme.GeodeLauncherTheme import com.geode.launcher.ui.theme.GeodeLauncherTheme
import com.geode.launcher.ui.theme.Typography import com.geode.launcher.ui.theme.Typography
import com.geode.launcher.utils.LaunchUtils import com.geode.launcher.utils.LaunchUtils
import com.geode.launcher.utils.countdownTimerWatcher import com.geode.launcher.utils.useCountdownTimer
import com.geode.launcher.utils.preferenceWatcher import com.geode.launcher.utils.usePreference
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@@ -61,7 +61,7 @@ fun onSettings(context: Context) {
fun MainScreen(gdInstalled: Boolean = true) { fun MainScreen(gdInstalled: Boolean = true) {
val context = LocalContext.current val context = LocalContext.current
val shouldAutomaticallyLaunch = preferenceWatcher( val shouldAutomaticallyLaunch = usePreference(
preferenceFileKey = R.string.preference_file_key, preferenceFileKey = R.string.preference_file_key,
preferenceId = R.string.preference_load_automatically preferenceId = R.string.preference_load_automatically
) )
@@ -83,7 +83,7 @@ fun MainScreen(gdInstalled: Boolean = true) {
) )
if (gdInstalled) { if (gdInstalled) {
if (shouldAutomaticallyLaunch.value) { if (shouldAutomaticallyLaunch.value) {
val countdownTimer = countdownTimerWatcher( val countdownTimer = useCountdownTimer(
time = 3000, time = 3000,
onCountdownFinish = { onCountdownFinish = {
// just in case this changed async // just in case this changed async
@@ -10,7 +10,7 @@ import androidx.lifecycle.LifecycleOwner
const val MS_TO_SEC = 1000 const val MS_TO_SEC = 1000
@Composable @Composable
fun countdownTimerWatcher(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, time: Int, onCountdownFinish: () -> Unit): MutableState<Int> { fun useCountdownTimer(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, time: Int, onCountdownFinish: () -> Unit): MutableState<Int> {
val timeData = remember { val timeData = remember {
mutableStateOf(time / MS_TO_SEC % MS_TO_SEC) mutableStateOf(time / MS_TO_SEC % MS_TO_SEC)
} }
@@ -12,7 +12,7 @@ import androidx.lifecycle.LifecycleOwner
@Composable @Composable
fun preferenceWatcher(@StringRes preferenceFileKey: Int, @StringRes preferenceId: Int, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): MutableState<Boolean> { fun usePreference(@StringRes preferenceFileKey: Int, @StringRes preferenceId: Int, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): MutableState<Boolean> {
val context = LocalContext.current val context = LocalContext.current
val preferences = context.getSharedPreferences( val preferences = context.getSharedPreferences(
context.getString(preferenceFileKey), Context.MODE_PRIVATE context.getString(preferenceFileKey), Context.MODE_PRIVATE