Skip to content

Commit cd85839

Browse files
committed
Replace deprecated lifecycle launchWhen*
1 parent 763c88b commit cd85839

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

app/src/main/java/xyz/ivaniskandar/shouko/activity/GAKeyOverriderKeyguardActivity.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import androidx.activity.ComponentActivity
66
import androidx.activity.compose.setContent
77
import androidx.core.content.getSystemService
88
import androidx.core.view.WindowCompat
9+
import androidx.lifecycle.Lifecycle
910
import androidx.lifecycle.lifecycleScope
11+
import androidx.lifecycle.repeatOnLifecycle
1012
import kotlinx.coroutines.delay
1113
import kotlinx.coroutines.flow.first
1214
import kotlinx.coroutines.launch
@@ -60,9 +62,11 @@ class GAKeyOverriderKeyguardActivity : ComponentActivity() {
6062
}
6163

6264
init {
63-
lifecycleScope.launchWhenCreated {
64-
delay(700)
65-
dismissKeyguard()
65+
lifecycleScope.launch {
66+
repeatOnLifecycle(Lifecycle.State.CREATED) {
67+
delay(700)
68+
dismissKeyguard()
69+
}
6670
}
6771
}
6872
}

app/src/main/java/xyz/ivaniskandar/shouko/feature/FlipToShush.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import android.os.VibrationEffect
1818
import android.os.Vibrator
1919
import androidx.core.content.getSystemService
2020
import androidx.lifecycle.DefaultLifecycleObserver
21+
import androidx.lifecycle.Lifecycle
2122
import androidx.lifecycle.LifecycleOwner
2223
import androidx.lifecycle.lifecycleScope
24+
import androidx.lifecycle.repeatOnLifecycle
2325
import kotlinx.coroutines.CancellationException
2426
import kotlinx.coroutines.Dispatchers
2527
import kotlinx.coroutines.Job
@@ -305,15 +307,17 @@ class FlipToShush(
305307
}
306308

307309
init {
308-
lifecycleOwner.lifecycleScope.launchWhenStarted {
309-
ShoukoApplication.prefs.flipToShushEnabledFlow.collect {
310-
val shouldEnable = it && notificationManager.isNotificationPolicyAccessGranted
311-
updateFlipToShush(shouldEnable)
312-
updateScreenReceiverState(shouldEnable && !isFullTimeListening)
313-
if (!shouldEnable) {
314-
switchDndState(false)
310+
lifecycleOwner.lifecycleScope.launch {
311+
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
312+
ShoukoApplication.prefs.flipToShushEnabledFlow.collect {
313+
val shouldEnable = it && notificationManager.isNotificationPolicyAccessGranted
314+
updateFlipToShush(shouldEnable)
315+
updateScreenReceiverState(shouldEnable && !isFullTimeListening)
316+
if (!shouldEnable) {
317+
switchDndState(false)
318+
}
319+
logcat { "Flip2Shush enabled=$it" }
315320
}
316-
logcat { "Flip2Shush enabled=$it" }
317321
}
318322
}
319323
lifecycleOwner.lifecycle.addObserver(this)

app/src/main/java/xyz/ivaniskandar/shouko/feature/GAKeyOverrider.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
3838
import androidx.lifecycle.Lifecycle
3939
import androidx.lifecycle.LifecycleOwner
4040
import androidx.lifecycle.lifecycleScope
41+
import androidx.lifecycle.repeatOnLifecycle
4142
import com.kieronquinn.monetcompat.core.MonetCompat
4243
import com.topjohnwu.superuser.CallbackList
4344
import com.topjohnwu.superuser.Shell
@@ -315,13 +316,15 @@ class GAKeyOverrider(
315316
}
316317

317318
init {
318-
lifecycleOwner.lifecycleScope.launchWhenStarted {
319-
ShoukoApplication.prefs.assistButtonFlow.collect {
320-
customAction = it.action
321-
hideAssistantCue = it.hideAssistantCue
322-
updateGAKeyDisabler(!it.enabled)
323-
updateOpaOverrider(isReady)
324-
logcat { "GAKeyOverrider enabled=${it.action != null} hideCue=${it.hideAssistantCue}" }
319+
lifecycleOwner.lifecycleScope.launch {
320+
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
321+
ShoukoApplication.prefs.assistButtonFlow.collect {
322+
customAction = it.action
323+
hideAssistantCue = it.hideAssistantCue
324+
updateGAKeyDisabler(!it.enabled)
325+
updateOpaOverrider(isReady)
326+
logcat { "GAKeyOverrider enabled=${it.action != null} hideCue=${it.hideAssistantCue}" }
327+
}
325328
}
326329
}
327330
lifecycleOwner.lifecycle.addObserver(this)

app/src/main/java/xyz/ivaniskandar/shouko/feature/LockscreenShortcutHelper.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import android.content.IntentFilter
88
import android.provider.Settings
99
import androidx.core.content.getSystemService
1010
import androidx.lifecycle.DefaultLifecycleObserver
11+
import androidx.lifecycle.Lifecycle
1112
import androidx.lifecycle.LifecycleOwner
1213
import androidx.lifecycle.lifecycleScope
14+
import androidx.lifecycle.repeatOnLifecycle
1315
import kotlinx.coroutines.delay
1416
import kotlinx.coroutines.flow.combine
1517
import kotlinx.coroutines.flow.first
@@ -102,11 +104,13 @@ class LockscreenShortcutHelper(
102104

103105
init {
104106
lifecycleOwner.lifecycle.addObserver(this)
105-
lifecycleOwner.lifecycleScope.launchWhenStarted {
106-
val prefs = ShoukoApplication.prefs
107-
prefs.lockscreenLeftAction
108-
.combine(prefs.lockscreenRightAction) { a, b -> a != null || b != null }
109-
.collect { updateReceiverState(it) }
107+
lifecycleOwner.lifecycleScope.launch {
108+
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
109+
val prefs = ShoukoApplication.prefs
110+
prefs.lockscreenLeftAction
111+
.combine(prefs.lockscreenRightAction) { a, b -> a != null || b != null }
112+
.collect { updateReceiverState(it) }
113+
}
110114
}
111115
}
112116

app/src/main/java/xyz/ivaniskandar/shouko/feature/PocketNoTouchy.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import android.os.Handler
1414
import android.os.Looper
1515
import androidx.core.content.getSystemService
1616
import androidx.lifecycle.DefaultLifecycleObserver
17+
import androidx.lifecycle.Lifecycle
1718
import androidx.lifecycle.LifecycleOwner
1819
import androidx.lifecycle.lifecycleScope
20+
import androidx.lifecycle.repeatOnLifecycle
1921
import kotlinx.coroutines.flow.MutableSharedFlow
2022
import kotlinx.coroutines.launch
2123
import logcat.logcat
@@ -169,10 +171,12 @@ class PocketNoTouchy(
169171
}
170172

171173
init {
172-
lifecycleOwner.lifecycleScope.launchWhenStarted {
173-
ShoukoApplication.prefs.preventPocketTouchEnabledFlow.collect {
174-
updatePocketNoTouchy(it)
175-
logcat { "PocketNoTouchy enabled=$it" }
174+
lifecycleOwner.lifecycleScope.launch {
175+
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
176+
ShoukoApplication.prefs.preventPocketTouchEnabledFlow.collect {
177+
updatePocketNoTouchy(it)
178+
logcat { "PocketNoTouchy enabled=$it" }
179+
}
176180
}
177181
}
178182
lifecycleOwner.lifecycle.addObserver(this)

0 commit comments

Comments
 (0)