diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b589d56e..b86273d9 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml
new file mode 100644
index 00000000..b268ef36
--- /dev/null
+++ b/.idea/deploymentTargetSelector.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 00000000..c8f004d7
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index e1eea1d6..c224ad56 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml
new file mode 100644
index 00000000..1ac507e0
--- /dev/null
+++ b/.idea/material_theme_project_new.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 00000000..f8051a6f
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 00000000..16660f1d
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 483b1b39..d6507908 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,24 +6,22 @@ plugins {
id 'androidx.navigation.safeargs'
id 'dev.rikka.tools.refine'
id 'com.google.android.gms.oss-licenses-plugin'
+ id 'com.google.devtools.ksp'
}
//Permission for Columbus to use
rootProject.ext.set("columbusPermission", "com.google.android.columbus.taptap.permission.CONFIGURE_COLUMBUS_GESTURE")
-def tagName = '1.6.1'
-def tagVersion = 1610
+def tagName = '1.6.2'
+def tagVersion = 1620
android {
- compileSdk 34
-
- //aidl is broken on 33...
- buildToolsVersion "32.0.0"
+ compileSdk 35
defaultConfig {
applicationId "com.kieronquinn.app.taptap"
minSdk 24
- targetSdk 33
+ targetSdk 35
versionCode tagVersion
versionName tagName
@@ -55,6 +53,7 @@ android {
jvmTarget = '17'
}
buildFeatures {
+ buildConfig true
viewBinding true
aidl true
}
@@ -67,38 +66,38 @@ android {
dependencies {
//AndroidX
- implementation 'androidx.core:core-ktx:1.10.1'
- implementation 'androidx.appcompat:appcompat:1.6.1'
+ implementation 'androidx.core:core-ktx:1.13.1'
+ implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
- implementation "androidx.work:work-runtime-ktx:2.8.1"
- implementation "androidx.core:core-ktx:1.10.1"
- implementation "androidx.vectordrawable:vectordrawable-seekable:1.0.0-beta01"
+ implementation "androidx.work:work-runtime-ktx:2.9.1"
+ implementation "androidx.core:core-ktx:1.13.1"
+ implementation "androidx.vectordrawable:vectordrawable-seekable:1.0.0"
implementation "androidx.core:core-splashscreen:1.0.1"
- implementation "androidx.fragment:fragment-ktx:1.5.7"
- implementation "androidx.activity:activity-ktx:1.7.2"
+ implementation "androidx.fragment:fragment-ktx:1.8.4"
+ implementation "androidx.activity:activity-ktx:1.9.3"
//Lifecycle
- def lifecycleVersion = '2.6.1'
+ def lifecycleVersion = '2.8.6'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
//Desugaring to allow Java Date on older Android versions
- coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'
//OSS licences screen
- implementation 'com.google.android.gms:play-services-oss-licenses:17.0.1'
+ implementation 'com.google.android.gms:play-services-oss-licenses:17.1.0'
//Room
- def room_version = "2.5.1"
+ def room_version = "2.6.1"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
- kapt "androidx.room:room-compiler:$room_version"
+ ksp "androidx.room:room-compiler:$room_version"
//MD3
- implementation 'com.google.android.material:material:1.9.0'
+ implementation 'com.google.android.material:material:1.12.0'
//MonetCompat for Monet backwards compatibility
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
@@ -107,17 +106,17 @@ dependencies {
implementation "androidx.palette:palette-ktx:1.0.0"
//Coroutines
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
//Koin
- implementation "io.insert-koin:koin-android:3.4.0"
+ implementation "io.insert-koin:koin-android:3.5.6"
//Retrofit for updates + device spec query (opt-in)
- implementation "com.squareup.retrofit2:retrofit:2.9.0"
- implementation "com.squareup.retrofit2:converter-gson:2.9.0"
+ implementation "com.squareup.retrofit2:retrofit:2.11.0"
+ implementation "com.squareup.retrofit2:converter-gson:2.11.0"
//Gson for serialization
- implementation 'com.google.code.gson:gson:2.9.1'
+ implementation 'com.google.code.gson:gson:2.11.0'
//Columbus module is separate to make it easier to work with
implementation project(path: ':columbus')
@@ -138,12 +137,12 @@ dependencies {
implementation 'com.joaomgcd:taskerpluginlibrary:0.4.2'
//Shizuku + libsu for shell/root services
- def shizuku_version = '12.1.0'
+ def shizuku_version = '13.1.5'
implementation "dev.rikka.shizuku:api:$shizuku_version"
implementation "dev.rikka.shizuku:provider:$shizuku_version"
implementation "dev.rikka.tools.refine:runtime:$refine_version"
- def libsuVersion = '5.0.3'
+ def libsuVersion = '5.2.2'
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"
implementation "com.github.topjohnwu.libsu:service:${libsuVersion}"
@@ -160,14 +159,14 @@ dependencies {
implementation "io.noties.markwon:core:4.6.2"
//Lottie for animations
- implementation 'com.airbnb.android:lottie:5.2.0'
+ implementation 'com.airbnb.android:lottie:6.4.1'
//Process Phoenix to fully restart the app when needed
- implementation 'com.jakewharton:process-phoenix:2.1.2'
+ implementation 'com.jakewharton:process-phoenix:3.0.0'
//Test
- testImplementation 'junit:junit:4.+'
- androidTestImplementation 'androidx.test.ext:junit:1.1.5'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+ testImplementation 'junit:junit:4.13.2'
+ androidTestImplementation 'androidx.test.ext:junit:1.2.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
\ No newline at end of file
diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm
new file mode 100644
index 00000000..3e51158b
Binary files /dev/null and b/app/release/baselineProfiles/0/app-release.dm differ
diff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dm
new file mode 100644
index 00000000..f0d0ba90
Binary files /dev/null and b/app/release/baselineProfiles/1/app-release.dm differ
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index 055a61aa..f0a2d8fc 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -11,10 +11,27 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
- "versionCode": 1600,
- "versionName": "1.6",
+ "versionCode": 1620,
+ "versionName": "1.6.2",
"outputFile": "app-release.apk"
}
],
- "elementType": "File"
+ "elementType": "File",
+ "baselineProfiles": [
+ {
+ "minApi": 28,
+ "maxApi": 30,
+ "baselineProfiles": [
+ "baselineProfiles/1/app-release.dm"
+ ]
+ },
+ {
+ "minApi": 31,
+ "maxApi": 2147483647,
+ "baselineProfiles": [
+ "baselineProfiles/0/app-release.dm"
+ ]
+ }
+ ],
+ "minSdkVersionForDexing": 24
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 454e11fa..f127a188 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,11 +25,14 @@
tools:ignore="ProtectedPermissions" />
+
+ android:theme="@style/Theme.TapTap.Splash"
+ tools:targetApi="tiramisu">
@@ -73,7 +76,8 @@
android:process=":crashreporting"
android:excludeFromRecents="true"/>
-
+
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/accessibility/TapTapAccessibilityRouter.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/accessibility/TapTapAccessibilityRouter.kt
index a78ffc87..f30f59f1 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/accessibility/TapTapAccessibilityRouter.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/accessibility/TapTapAccessibilityRouter.kt
@@ -2,11 +2,10 @@ package com.kieronquinn.app.taptap.components.accessibility
import android.content.Intent
import androidx.fragment.app.Fragment
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.ui.activities.MainActivity
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
-import kotlinx.coroutines.flow.collect
interface TapTapAccessibilityRouter {
@@ -40,7 +39,7 @@ interface TapTapAccessibilityRouter {
suspend fun onGestureAccessibilityStarted()
fun bringToFrontOnAccessibilityStart(fragment: Fragment) {
- fragment.viewLifecycleOwner.lifecycleScope.launchWhenCreated {
+ fragment.viewLifecycleOwner.whenCreated {
this@TapTapAccessibilityRouter.accessibilityStartBus.collect {
fragment.bringToFront()
}
@@ -48,7 +47,7 @@ interface TapTapAccessibilityRouter {
}
fun bringToFrontOnGestureAccessibilityStart(fragment: Fragment) {
- fragment.viewLifecycleOwner.lifecycleScope.launchWhenCreated {
+ fragment.viewLifecycleOwner.whenCreated {
this@TapTapAccessibilityRouter.gestureAccessibilityStartBus.collect {
fragment.bringToFront()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/TapTapAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/TapTapAction.kt
index b37e630d..f6d0d1a2 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/TapTapAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/TapTapAction.kt
@@ -12,7 +12,6 @@ import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.actions.Action
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.gates.Gate
@@ -26,6 +25,7 @@ import com.kieronquinn.app.taptap.service.accessibility.TapTapGestureAccessibili
import com.kieronquinn.app.taptap.utils.extensions.getAccessibilityIntent
import com.kieronquinn.app.taptap.utils.extensions.isServiceRunning
import com.kieronquinn.app.taptap.utils.extensions.runOnDestroy
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationChannel
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationId
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationIntentId
@@ -86,7 +86,7 @@ abstract class TapTapAction(
}
private fun handleTrigger(detectionProperties: GestureSensor.DetectionProperties, isTripleTap: Boolean) {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
onTriggered(detectionProperties, isTripleTap)
}
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/AcceptCallAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/AcceptCallAction.kt
index 0dcd9f17..dfdcd078 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/AcceptCallAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/AcceptCallAction.kt
@@ -5,19 +5,15 @@ import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.telecom.TelecomManager
-import android.telephony.PhoneStateListener
import android.telephony.TelephonyManager
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
-import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.doesHavePermissions
import com.kieronquinn.app.taptap.utils.extensions.onCallStateChanged
-import kotlinx.coroutines.flow.callbackFlow
-import kotlinx.coroutines.flow.collect
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
class AcceptCallAction(
serviceLifecycle: Lifecycle,
@@ -43,7 +39,7 @@ class AcceptCallAction(
}
init {
- lifecycleScope.launchWhenResumed {
+ lifecycle.whenResumed {
phoneStateListener.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppAction.kt
index a19f2446..74e03209 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppAction.kt
@@ -9,7 +9,11 @@ import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRo
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.isAppLaunchable
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchAppAction(
@@ -29,7 +33,7 @@ class LaunchAppAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppShortcutAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppShortcutAction.kt
index 9e120a6a..8a97145d 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppShortcutAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAppShortcutAction.kt
@@ -1,20 +1,21 @@
package com.kieronquinn.app.taptap.components.columbus.actions.custom
import android.content.Context
-import android.os.Parcelable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.google.gson.Gson
-import com.google.gson.annotations.SerializedName
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.models.columbus.AppShortcutData
import com.kieronquinn.app.taptap.repositories.service.TapTapShizukuServiceRepository
-import kotlinx.coroutines.flow.*
-import kotlinx.parcelize.Parcelize
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchAppShortcutAction(
@@ -40,7 +41,7 @@ class LaunchAppShortcutAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAssistantAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAssistantAction.kt
index 3335b2b7..df3bac9b 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAssistantAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchAssistantAction.kt
@@ -10,7 +10,11 @@ import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRo
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.isPackageAssistant
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchAssistantAction(
@@ -29,7 +33,7 @@ class LaunchAssistantAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchCameraAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchCameraAction.kt
index 3f95c489..e3f5eb54 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchCameraAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchCameraAction.kt
@@ -11,7 +11,11 @@ import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.getCameraLaunchIntent
import com.kieronquinn.app.taptap.utils.extensions.isPackageCamera
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchCameraAction(
@@ -35,7 +39,7 @@ class LaunchCameraAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchReachabilityAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchReachabilityAction.kt
index fecd45bf..88728931 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchReachabilityAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchReachabilityAction.kt
@@ -12,7 +12,12 @@ import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.ui.activities.ReachabilityActivity
import com.kieronquinn.app.taptap.utils.extensions.isActivityRunning
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchReachabilityAction(
@@ -32,7 +37,7 @@ class LaunchReachabilityAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, "")
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
currentApp.collect()
}
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchSearchAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchSearchAction.kt
index 30673e84..02dccfcb 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchSearchAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchSearchAction.kt
@@ -13,7 +13,11 @@ import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRo
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.isPackageAssistant
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchSearchAction(
@@ -33,7 +37,7 @@ class LaunchSearchAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchShortcutAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchShortcutAction.kt
index 655ccc4a..64e08af9 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchShortcutAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/LaunchShortcutAction.kt
@@ -12,7 +12,11 @@ import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRo
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.deserialize
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class LaunchShortcutAction(
@@ -44,7 +48,7 @@ class LaunchShortcutAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/NotificationsExpandAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/NotificationsExpandAction.kt
index 00d12c7a..546e6a0e 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/NotificationsExpandAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/NotificationsExpandAction.kt
@@ -4,12 +4,12 @@ import android.accessibilityservice.AccessibilityService
import android.content.Context
import android.os.Build
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.coroutineScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import org.koin.core.component.inject
class NotificationsExpandAction(
@@ -33,7 +33,7 @@ class NotificationsExpandAction(
override val tag = "NotificationExpandAction"
init {
- serviceLifecycle.coroutineScope.launchWhenCreated {
+ serviceLifecycle.whenCreated {
accessibilityRouter.accessibilityOutputBus.collect {
if(it is TapTapAccessibilityRouter.AccessibilityOutput.NotificationShadeState){
isNotificationShadeOpen = it.open
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/QuickSettingsExpandAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/QuickSettingsExpandAction.kt
index b0f5d682..cb383450 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/QuickSettingsExpandAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/QuickSettingsExpandAction.kt
@@ -4,14 +4,13 @@ import android.accessibilityservice.AccessibilityService
import android.content.Context
import android.os.Build
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.coroutineScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.delay
-import kotlinx.coroutines.flow.collect
import org.koin.core.component.inject
class QuickSettingsExpandAction(
@@ -35,7 +34,7 @@ class QuickSettingsExpandAction(
override val tag = "NotificationExpandAction"
init {
- serviceLifecycle.coroutineScope.launchWhenCreated {
+ serviceLifecycle.whenCreated {
accessibilityRouter.accessibilityOutputBus.collect {
if(it is TapTapAccessibilityRouter.AccessibilityOutput.QuickSettingsShadeState){
isQuickSettingsOpen = it.open
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/RejectCallAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/RejectCallAction.kt
index 0a6459ab..d81a73cf 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/RejectCallAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/RejectCallAction.kt
@@ -7,15 +7,13 @@ import android.os.Build
import android.telecom.TelecomManager
import android.telephony.TelephonyManager
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
-import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.doesHavePermissions
import com.kieronquinn.app.taptap.utils.extensions.onCallStateChanged
-import kotlinx.coroutines.flow.collect
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
class RejectCallAction(
serviceLifecycle: Lifecycle,
@@ -41,7 +39,7 @@ class RejectCallAction(
}
init {
- lifecycleScope.launchWhenResumed {
+ lifecycle.whenResumed {
phoneStateListener.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/SnapchatAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/SnapchatAction.kt
index 0a303d4b..4929c085 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/SnapchatAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/SnapchatAction.kt
@@ -2,7 +2,6 @@ package com.kieronquinn.app.taptap.components.columbus.actions.custom
import android.app.KeyguardManager
import android.content.ActivityNotFoundException
-import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.provider.MediaStore
@@ -15,7 +14,11 @@ import com.kieronquinn.app.taptap.components.columbus.actions.TapTapAction
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapWhenGate
import com.kieronquinn.app.taptap.utils.extensions.EXTRA_KEY_IS_FROM_COLUMBUS
import com.kieronquinn.app.taptap.utils.extensions.isAppLaunchable
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class SnapchatAction(
@@ -44,7 +47,7 @@ class SnapchatAction(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/WakeDeviceAction.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/WakeDeviceAction.kt
index b7836abc..07330177 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/WakeDeviceAction.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/actions/custom/WakeDeviceAction.kt
@@ -13,9 +13,9 @@ import com.kieronquinn.app.taptap.components.settings.TapTapSettings
import com.kieronquinn.app.taptap.ui.activities.UnlockDeviceActivity
import com.kieronquinn.app.taptap.ui.activities.WakeUpActivity
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
@@ -48,7 +48,7 @@ class WakeDeviceAction(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, !powerManager.isInteractive)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
screenState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/feedback/TapTapFeedbackEffect.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/feedback/TapTapFeedbackEffect.kt
index 5185ca47..e58b1456 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/feedback/TapTapFeedbackEffect.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/feedback/TapTapFeedbackEffect.kt
@@ -2,10 +2,10 @@ package com.kieronquinn.app.taptap.components.columbus.feedback
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.feedback.FeedbackEffect
import com.google.android.columbus.sensors.GestureSensor
import com.kieronquinn.app.taptap.utils.extensions.runOnDestroy
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import org.koin.core.component.KoinComponent
/**
@@ -29,7 +29,7 @@ abstract class TapTapFeedbackEffect(private val serviceLifecycle: Lifecycle): Fe
detectionProperties: GestureSensor.DetectionProperties?
) {
if(detectionProperties == null) return
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
when(flags){
//Progress
2 -> onProgress(detectionProperties)
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/AppVisibilityGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/AppVisibilityGate.kt
index 91c41e62..61f7bb3a 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/AppVisibilityGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/AppVisibilityGate.kt
@@ -5,7 +5,11 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class AppVisibilityGate(
@@ -20,7 +24,7 @@ class AppVisibilityGate(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
appOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/BatterySaverGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/BatterySaverGate.kt
index 64666527..6fb463b7 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/BatterySaverGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/BatterySaverGate.kt
@@ -7,6 +7,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -28,7 +29,7 @@ class BatterySaverGate(
}
init {
- lifecycleScope.launchWhenCreated {
+ whenCreated {
batterySaverEnabled.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/CameraVisibilityGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/CameraVisibilityGate.kt
index eb29bd1f..d448b004 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/CameraVisibilityGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/CameraVisibilityGate.kt
@@ -6,7 +6,11 @@ import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.isPackageCamera
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class CameraVisibilityGate(
@@ -21,7 +25,7 @@ class CameraVisibilityGate(
.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ whenCreated {
cameraOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/ChargingStateGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/ChargingStateGate.kt
index 2269dfde..75e6d336 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/ChargingStateGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/ChargingStateGate.kt
@@ -7,8 +7,8 @@ import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
import com.kieronquinn.app.taptap.utils.extensions.isPowerConnected
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -23,7 +23,7 @@ class ChargingStateGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, context.isPowerConnected())
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
batteryState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/KeyboardVisibilityGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/KeyboardVisibilityGate.kt
index 27ab0c51..0aaec0d3 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/KeyboardVisibilityGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/KeyboardVisibilityGate.kt
@@ -10,7 +10,12 @@ import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.getSettingAsFlow
import com.kieronquinn.app.taptap.utils.extensions.isKeyboardOpen
import com.kieronquinn.app.taptap.utils.extensions.secureStringConverter
-import kotlinx.coroutines.flow.*
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
import org.koin.core.component.inject
class KeyboardVisibilityGate(
@@ -34,7 +39,7 @@ class KeyboardVisibilityGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
keyboardOpen.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateGate.kt
index d9755dee..977563b4 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateGate.kt
@@ -8,8 +8,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -32,7 +32,7 @@ class LockScreenStateGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, powerManager.isInteractive && keyguardManager.isKeyguardLocked)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
screenState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateInverseGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateInverseGate.kt
index e4f281eb..d0061c8f 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateInverseGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LockScreenStateInverseGate.kt
@@ -9,8 +9,8 @@ import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.PassiveGate
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -35,7 +35,7 @@ class LockScreenStateInverseGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, powerManager.isInteractive && keyguardManager.isKeyguardLocked)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
screenState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LowBatteryGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LowBatteryGate.kt
index 947345ea..2dd26412 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LowBatteryGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/LowBatteryGate.kt
@@ -8,8 +8,9 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.registerReceiverCompat
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -28,7 +29,7 @@ class LowBatteryGate(
}
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
batteryLevel.collect {
notifyListeners()
}
@@ -36,7 +37,7 @@ class LowBatteryGate(
}
private fun getBatteryLevel(): Float {
- val batteryStatus = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
+ val batteryStatus = context.registerReceiverCompat(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
val level = batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: return 1f
val scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
if(level == -1 || scale == -1) return 1f
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateGate.kt
index 61699e3a..52828f1e 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateGate.kt
@@ -8,8 +8,8 @@ import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.PassiveGate
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -31,7 +31,7 @@ class PowerStateGate(
init {
- lifecycleScope.launchWhenResumed {
+ lifecycle.whenResumed {
screenState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateInverseGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateInverseGate.kt
index bdadea43..bfc750dc 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateInverseGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/PowerStateInverseGate.kt
@@ -7,8 +7,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -27,7 +27,7 @@ class PowerStateInverseGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, powerManager.isInteractive)
init {
- lifecycleScope.launchWhenResumed {
+ lifecycle.whenResumed {
screenState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/TelephonyActivityGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/TelephonyActivityGate.kt
index c7042390..26872a8b 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/TelephonyActivityGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/TelephonyActivityGate.kt
@@ -6,8 +6,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.onCallStateChanged
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -25,7 +25,7 @@ class TelephonyActivityGate(
}
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
isCallBlocked.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/UsbStateGate.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/UsbStateGate.kt
index 375a127d..4cdafcb4 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/UsbStateGate.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/gates/custom/UsbStateGate.kt
@@ -5,8 +5,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.columbus.gates.TapTapGate
import com.kieronquinn.app.taptap.utils.extensions.broadcastReceiverAsFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -25,7 +25,7 @@ class UsbStateGate(
}.stateIn(lifecycleScope, SharingStarted.Eagerly, false)
init {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
usbState.collect {
notifyListeners()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/sensors/TapTapCHREGestureSensor.kt b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/sensors/TapTapCHREGestureSensor.kt
index e32f87b0..b303ab25 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/sensors/TapTapCHREGestureSensor.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/components/columbus/sensors/TapTapCHREGestureSensor.kt
@@ -13,7 +13,6 @@ import android.os.RemoteException
import android.os.SystemClock
import android.util.Log
import androidx.lifecycle.LifecycleOwner
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.proto.nano.ColumbusGesture
import com.google.android.columbus.sensors.CHREGestureSensor
import com.google.android.columbus.sensors.configuration.GestureConfiguration
@@ -21,8 +20,10 @@ import com.kieronquinn.app.taptap.contexthub.IRemoteContextHubClient
import com.kieronquinn.app.taptap.repositories.service.TapTapShizukuServiceRepository
import com.kieronquinn.app.taptap.repositories.service.TapTapShizukuServiceRepository.ShizukuServiceResponse
import com.kieronquinn.app.taptap.utils.contexthub.ContextHubClientCallbackLocalToRemoteWrapper
+import com.kieronquinn.app.taptap.utils.extensions.registerReceiverCompat
import com.kieronquinn.app.taptap.utils.extensions.runOnDestroy
import com.kieronquinn.app.taptap.utils.extensions.unregisterReceiverIfRegistered
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.flow.FlowQueue
import com.kieronquinn.app.taptap.utils.logging.UiEventLogger
import com.kieronquinn.app.taptap.utils.statusbar.StatusBarStateController
@@ -127,7 +128,7 @@ class TapTapCHREGestureSensor(
onFail: (() -> Unit)?,
onSuccess: (() -> Unit)?
) {
- lifecycleOwner.lifecycleScope.launchWhenCreated {
+ lifecycleOwner.lifecycle.whenCreated {
messageBuffer.add(NanoMessage(messageType, bytes, onFail, onSuccess))
}
}
@@ -232,8 +233,8 @@ class TapTapCHREGestureSensor(
}
override fun startListening(heuristicMode: Boolean) {
- context.registerReceiver(screenStateReceiver, IntentFilter(Intent.ACTION_SCREEN_ON))
- context.registerReceiver(screenStateReceiver, IntentFilter(Intent.ACTION_SCREEN_OFF))
+ context.registerReceiverCompat(screenStateReceiver, IntentFilter(Intent.ACTION_SCREEN_ON))
+ context.registerReceiverCompat(screenStateReceiver, IntentFilter(Intent.ACTION_SCREEN_OFF))
super.startListening(heuristicMode)
}
@@ -256,7 +257,7 @@ class TapTapCHREGestureSensor(
lifecycleOwner.lifecycle.runOnDestroy {
stopListening()
}
- lifecycleOwner.lifecycleScope.launchWhenCreated {
+ lifecycleOwner.lifecycle.whenCreated {
messageBuffer.asFlow().debounce(250L).collect {
processNanoMessages(messageBuffer.asQueue())
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapAccessibilityService.kt b/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapAccessibilityService.kt
index 63c19fd4..75016014 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapAccessibilityService.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapAccessibilityService.kt
@@ -1,8 +1,8 @@
package com.kieronquinn.app.taptap.service.accessibility
import android.view.accessibility.AccessibilityEvent
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.lifecycle.LifecycleAccessibilityService
import kotlinx.coroutines.flow.filterNot
import org.koin.android.ext.android.inject
@@ -49,10 +49,10 @@ class TapTapAccessibilityService: LifecycleAccessibilityService() {
override fun onCreate() {
super.onCreate()
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
setupInputListener()
}
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
router.onAccessibilityStarted()
}
}
@@ -85,7 +85,7 @@ class TapTapAccessibilityService: LifecycleAccessibilityService() {
currentPackageName = event.packageName?.toString() ?: "android"
}
}
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
if(this@TapTapAccessibilityService.currentPackageName != currentPackageName){
this@TapTapAccessibilityService.currentPackageName = currentPackageName
router.postOutput(TapTapAccessibilityRouter.AccessibilityOutput.AppOpen(currentPackageName))
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapGestureAccessibilityService.kt b/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapGestureAccessibilityService.kt
index 38eab46a..9ce3b9e8 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapGestureAccessibilityService.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/service/accessibility/TapTapGestureAccessibilityService.kt
@@ -2,14 +2,12 @@ package com.kieronquinn.app.taptap.service.accessibility
import android.accessibilityservice.GestureDescription
import android.graphics.Path
-import android.util.Log
import android.view.accessibility.AccessibilityEvent
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.components.accessibility.TapTapAccessibilityRouter
import com.kieronquinn.app.taptap.utils.extensions.getStaticStatusBarHeight
import com.kieronquinn.app.taptap.utils.extensions.px
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.lifecycle.LifecycleAccessibilityService
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import org.koin.android.ext.android.inject
@@ -83,7 +81,7 @@ class TapTapGestureAccessibilityService : LifecycleAccessibilityService() {
override fun onCreate() {
super.onCreate()
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
setupInputListener()
}
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/service/foreground/TapTapForegroundService.kt b/app/src/main/java/com/kieronquinn/app/taptap/service/foreground/TapTapForegroundService.kt
index faf2196d..f55322d9 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/service/foreground/TapTapForegroundService.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/service/foreground/TapTapForegroundService.kt
@@ -9,7 +9,6 @@ import android.os.Build
import android.provider.Settings
import androidx.core.app.NotificationCompat
import androidx.lifecycle.LifecycleService
-import androidx.lifecycle.lifecycleScope
import com.google.android.columbus.ColumbusServiceWrapper
import com.kieronquinn.app.taptap.BuildConfig
import com.kieronquinn.app.taptap.R
@@ -27,6 +26,8 @@ import com.kieronquinn.app.taptap.repositories.service.TapTapShizukuServiceRepos
import com.kieronquinn.app.taptap.utils.extensions.canUseContextHub
import com.kieronquinn.app.taptap.utils.extensions.isNativeColumbusEnabled
import com.kieronquinn.app.taptap.utils.extensions.isServiceRunning
+import com.kieronquinn.app.taptap.utils.extensions.startForegroundCompat
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationChannel
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationId
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationIntentId
@@ -59,11 +60,7 @@ class TapTapForegroundService : LifecycleService(), KoinScopeComponent {
fun start(context: Context, isRestart: Boolean = false) {
val intent = getIntent(context, isRestart)
context.stopService(intent)
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- context.startForegroundService(intent)
- } else {
- context.startService(intent)
- }
+ context.startService(intent)
}
fun stop(context: Context) {
@@ -93,11 +90,11 @@ class TapTapForegroundService : LifecycleService(), KoinScopeComponent {
override fun onCreate() {
super.onCreate()
- startForeground(TapTapNotificationId.BACKGROUND.ordinal, createForegroundNotification())
+ startForegroundCompat(TapTapNotificationId.BACKGROUND.ordinal, createForegroundNotification())
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
listenForStartOrFail(intent?.getBooleanExtra(KEY_IS_RESTART, false) ?: false)
startService()
}
@@ -162,7 +159,7 @@ class TapTapForegroundService : LifecycleService(), KoinScopeComponent {
serviceRouter.onServiceStarted()
}
- private fun listenForStartOrFail(isRestart: Boolean) = lifecycleScope.launchWhenCreated {
+ private fun listenForStartOrFail(isRestart: Boolean) = lifecycle.whenCreated {
showStartingNotification(isRestart)
serviceEventEmitter.serviceEvent.take(1).collect {
sendUpdateBroadcast()
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/service/quicksetting/TapTapQuickSettingTile.kt b/app/src/main/java/com/kieronquinn/app/taptap/service/quicksetting/TapTapQuickSettingTile.kt
index 982b5311..570754bd 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/service/quicksetting/TapTapQuickSettingTile.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/service/quicksetting/TapTapQuickSettingTile.kt
@@ -10,8 +10,12 @@ import com.kieronquinn.app.taptap.components.service.TapTapServiceRouter
import com.kieronquinn.app.taptap.components.settings.TapTapSettings
import com.kieronquinn.app.taptap.components.settings.invert
import com.kieronquinn.app.taptap.service.foreground.TapTapForegroundService
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.lifecycle.LifecycleTileService
-import kotlinx.coroutines.flow.*
+import kotlinx.coroutines.flow.MutableSharedFlow
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.stateIn
import org.koin.android.ext.android.inject
class TapTapQuickSettingTile: LifecycleTileService() {
@@ -51,7 +55,7 @@ class TapTapQuickSettingTile: LifecycleTileService() {
}
private fun setupState(){
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
state.collect {
handleState(it ?: return@collect)
}
@@ -73,13 +77,13 @@ class TapTapQuickSettingTile: LifecycleTileService() {
triggerUpdate()
}
- private fun triggerUpdate() = lifecycleScope.launchWhenCreated {
+ private fun triggerUpdate() = lifecycle.whenCreated {
reload.emit(Unit)
}
override fun onClick() {
super.onClick()
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
settings.serviceEnabled.invert()
TapTapForegroundService.stop(applicationContext)
if(settings.serviceEnabled.get()){
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/FlashlightToggleActivity.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/FlashlightToggleActivity.kt
index 748be46e..554d11fe 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/FlashlightToggleActivity.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/FlashlightToggleActivity.kt
@@ -18,14 +18,13 @@ import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.R
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationChannel
import com.kieronquinn.app.taptap.utils.notifications.TapTapNotificationId
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.callbackFlow
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.take
/**
@@ -70,7 +69,7 @@ class FlashlightToggleActivity: AppCompatActivity() {
}
private fun toggleFlashlight(){
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
torchCallback.take(1).collect {
try {
val cameraId = cameraManager.cameraIdList[0]
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/MainActivity.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/MainActivity.kt
index 155c22b7..e361b1b7 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/MainActivity.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/activities/MainActivity.kt
@@ -6,11 +6,11 @@ import android.os.Bundle
import android.view.View
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.ui.screens.root.RootSharedViewModel
import com.kieronquinn.app.taptap.utils.extensions.EXTRA_KEY_IS_FROM_COLUMBUS
import com.kieronquinn.app.taptap.utils.extensions.delayPreDrawUntilFlow
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.app.taptap.work.TapTapUpdateCheckWorker
import com.kieronquinn.monetcompat.app.MonetCompatActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -33,7 +33,7 @@ class MainActivity: MonetCompatActivity() {
//TODO move when android.core:splashscreen supports animations
findViewById(android.R.id.content).delayPreDrawUntilFlow(rootViewModel.appReady, lifecycle)
}
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
monet.awaitMonetReady()
setContentView(R.layout.activity_main)
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BaseBottomSheetFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BaseBottomSheetFragment.kt
index 077285fe..c398f793 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BaseBottomSheetFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BaseBottomSheetFragment.kt
@@ -5,13 +5,17 @@ import android.app.Dialog
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
-import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.animation.addListener
-import androidx.core.view.*
-import androidx.lifecycle.lifecycleScope
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.marginTop
+import androidx.core.view.updateLayoutParams
+import androidx.core.view.updateMargins
+import androidx.core.view.updatePadding
import androidx.viewbinding.ViewBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
@@ -20,6 +24,7 @@ import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.components.blur.BlurProvider
import com.kieronquinn.app.taptap.utils.extensions.awaitPost
import com.kieronquinn.app.taptap.utils.extensions.isDarkMode
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import com.kieronquinn.monetcompat.core.MonetCompat
import org.koin.android.ext.android.inject
@@ -137,7 +142,7 @@ abstract class BaseBottomSheetFragment(private val inflate: (Lay
private fun applyBlur(ratio: Float){
val dialogWindow = dialog?.window ?: return
val appWindow = activity?.window ?: return
- lifecycleScope.launchWhenResumed {
+ whenResumed {
dialogWindow.decorView.awaitPost()
blurProvider.applyDialogBlur(dialogWindow, appWindow, ratio)
}
@@ -146,7 +151,7 @@ abstract class BaseBottomSheetFragment(private val inflate: (Lay
override fun onResume() {
super.onResume()
if(isBlurShowing){
- lifecycleScope.launchWhenResumed {
+ whenResumed {
view?.awaitPost()
applyBlur(1f)
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundActivity.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundActivity.kt
index 5c4fd6a0..55b22348 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundActivity.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundActivity.kt
@@ -3,8 +3,8 @@ package com.kieronquinn.app.taptap.ui.base
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
-import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
+import com.kieronquinn.app.taptap.utils.extensions.whenCreated
import com.kieronquinn.monetcompat.app.MonetCompatActivity
abstract class BoundActivity(private val inflate: (LayoutInflater, ViewGroup?, Boolean) -> T): MonetCompatActivity() {
@@ -15,7 +15,7 @@ abstract class BoundActivity(private val inflate: (LayoutInflate
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- lifecycleScope.launchWhenCreated {
+ lifecycle.whenCreated {
monet.awaitMonetReady()
_binding = inflate(layoutInflater, null, false).apply {
setContentView(root)
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundFragment.kt
index 85fda719..e49738be 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/base/BoundFragment.kt
@@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.core.view.WindowInsetsCompat
import androidx.viewbinding.ViewBinding
import com.kieronquinn.app.taptap.utils.TransitionUtils
import com.kieronquinn.monetcompat.app.MonetFragment
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/container/ContainerFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/container/ContainerFragment.kt
index d2655bd0..d9209a44 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/container/ContainerFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/container/ContainerFragment.kt
@@ -1,12 +1,13 @@
package com.kieronquinn.app.taptap.ui.screens.container
+import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.view.MenuInflater
import android.view.View
-import androidx.activity.addCallback
+import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.ColorUtils
@@ -20,10 +21,31 @@ import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.components.navigation.ContainerNavigation
import com.kieronquinn.app.taptap.components.navigation.setupWithNavigation
import com.kieronquinn.app.taptap.databinding.FragmentContainerBinding
-import com.kieronquinn.app.taptap.ui.base.*
+import com.kieronquinn.app.taptap.ui.base.BackAvailable
+import com.kieronquinn.app.taptap.ui.base.BoundFragment
+import com.kieronquinn.app.taptap.ui.base.CanShowSnackbar
+import com.kieronquinn.app.taptap.ui.base.LockCollapsed
+import com.kieronquinn.app.taptap.ui.base.ProvidesBack
+import com.kieronquinn.app.taptap.ui.base.ProvidesOverflow
+import com.kieronquinn.app.taptap.ui.base.ProvidesTitle
import com.kieronquinn.app.taptap.ui.screens.container.ContainerSharedViewModel.FabState.Hidden
import com.kieronquinn.app.taptap.ui.screens.container.ContainerSharedViewModel.FabState.Shown
-import com.kieronquinn.app.taptap.utils.extensions.*
+import com.kieronquinn.app.taptap.utils.extensions.awaitPost
+import com.kieronquinn.app.taptap.utils.extensions.collapsedState
+import com.kieronquinn.app.taptap.utils.extensions.getRememberedAppBarCollapsed
+import com.kieronquinn.app.taptap.utils.extensions.getTopFragment
+import com.kieronquinn.app.taptap.utils.extensions.isDarkMode
+import com.kieronquinn.app.taptap.utils.extensions.isLandscape
+import com.kieronquinn.app.taptap.utils.extensions.isRtl
+import com.kieronquinn.app.taptap.utils.extensions.onApplyInsets
+import com.kieronquinn.app.taptap.utils.extensions.onDestinationChanged
+import com.kieronquinn.app.taptap.utils.extensions.onItemClicked
+import com.kieronquinn.app.taptap.utils.extensions.onNavigationIconClicked
+import com.kieronquinn.app.taptap.utils.extensions.onSwipeDismissed
+import com.kieronquinn.app.taptap.utils.extensions.rememberAppBarCollapsed
+import com.kieronquinn.app.taptap.utils.extensions.setOnBackPressedCallback
+import com.kieronquinn.app.taptap.utils.extensions.setTypeface
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import com.kieronquinn.monetcompat.extensions.applyMonet
import com.kieronquinn.monetcompat.extensions.toArgb
import com.kieronquinn.monetcompat.extensions.views.setTint
@@ -37,6 +59,23 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
class ContainerFragment: BoundFragment(FragmentContainerBinding::inflate) {
+ companion object {
+ private val SYSTEM_INSETS = setOf(
+ WindowInsetsCompat.Type.systemBars(),
+ WindowInsetsCompat.Type.ime(),
+ WindowInsetsCompat.Type.statusBars(),
+ WindowInsetsCompat.Type.displayCutout()
+ ).or()
+
+ private fun Collection.or(): Int {
+ var current = 0
+ forEach {
+ current = current.or(it)
+ }
+ return current
+ }
+ }
+
private val googleSansMedium by lazy {
ResourcesCompat.getFont(requireContext(), R.font.google_sans_text_medium)
}
@@ -87,14 +126,33 @@ class ContainerFragment: BoundFragment(FragmentContain
setupSnackbar()
setupUpdateSnackbar()
setupColumbusSettingPhoenix()
+ setupInsets()
viewModel.writeSettingsVersion()
}
+ private fun setupInsets() = with(binding.root) {
+ val padding = resources.getDimensionPixelSize(R.dimen.margin_16)
+ onApplyInsets { _, insets ->
+ val inset = insets.getInsets(SYSTEM_INSETS)
+ binding.fragmentContainerContainer.updatePadding(
+ left = inset.left, right = inset.right
+ )
+ binding.toolbar.updatePadding(
+ left = inset.left, right = inset.right
+ )
+ if(isRtl()) {
+ binding.collapsingToolbar.expandedTitleMarginEnd = inset.right + padding
+ }else {
+ binding.collapsingToolbar.expandedTitleMarginStart = inset.left + padding
+ }
+ }
+ }
+
private fun setupMonet() {
binding.root.setBackgroundColor(monet.getBackgroundColor(requireContext()))
}
- private fun setupColumbusSettingPhoenix() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupColumbusSettingPhoenix() = whenResumed {
sharedViewModel.columbusSettingPhoenixBus.collect {
viewModel.phoenix()
}
@@ -120,7 +178,7 @@ class ContainerFragment: BoundFragment(FragmentContain
arrayOf(intArrayOf(android.R.attr.state_selected), intArrayOf()),
intArrayOf(indicatorColor ?: Color.TRANSPARENT, Color.TRANSPARENT)
)
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
//The onItemClicked flow can only be attached once due to its callbacks, so we share it to split the logic
val flows = onItemClicked().shareIn(lifecycleScope, SharingStarted.Eagerly)
launch {
@@ -144,7 +202,7 @@ class ContainerFragment: BoundFragment(FragmentContain
}
private fun setupToolbar() = with(binding.toolbar) {
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
onNavigationIconClicked().collect {
(navHostFragment.getTopFragment() as? ProvidesBack)?.let {
if(it.onBackPressed()) return@collect
@@ -154,30 +212,33 @@ class ContainerFragment: BoundFragment(FragmentContain
}
}
+ @SuppressLint("RestrictedApi")
private fun setupBack() {
- val callback = requireActivity().onBackPressedDispatcher.addCallback(
- this,
- shouldBackDispatcherBeEnabled()
- ) {
- (navHostFragment.getTopFragment() as? ProvidesBack)?.let {
- if(it.onBackPressed()) return@addCallback
- }
- if(!navController.popBackStack()) {
- requireActivity().finish()
+ val callback = object: OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ (navHostFragment.getTopFragment() as? ProvidesBack)?.let {
+ if(it.onBackPressed()) return
+ }
+ if(!navController.popBackStack()) {
+ requireActivity().finish()
+ }
}
}
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ navController.setOnBackPressedCallback(callback)
+ navController.enableOnBackPressed(shouldBackDispatcherBeEnabled())
+ navController.setOnBackPressedDispatcher(requireActivity().onBackPressedDispatcher)
+ whenResumed {
navController.onDestinationChanged().collect {
- callback.isEnabled = shouldBackDispatcherBeEnabled()
+ navController.enableOnBackPressed(shouldBackDispatcherBeEnabled())
}
}
}
private fun shouldBackDispatcherBeEnabled(): Boolean {
- return navHostFragment.getTopFragment() is ProvidesBack || navController.hasBackAvailable()
+ return navHostFragment.getTopFragment() is ProvidesBack
}
- private fun setupNavigation() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupNavigation() = whenResumed {
launch {
navHostFragment.setupWithNavigation(navigation)
}
@@ -191,14 +252,14 @@ class ContainerFragment: BoundFragment(FragmentContain
}
}
- private fun setupStack() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupStack() = whenResumed {
navController.onDestinationChanged().collect {
binding.root.awaitPost()
onTopFragmentChanged(navHostFragment.getTopFragment() ?: return@collect)
}
}
- private fun setupCollapsedState() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupCollapsedState() = whenResumed {
binding.appBar.collapsedState().collect {
navHostFragment.getTopFragment()?.rememberAppBarCollapsed(it)
}
@@ -213,7 +274,7 @@ class ContainerFragment: BoundFragment(FragmentContain
}else{
setupMenu(null)
}
- if(topFragment is LockCollapsed) {
+ if(topFragment is LockCollapsed || requireContext().isLandscape()) {
binding.appBar.setExpanded(false)
}else {
binding.appBar.setExpanded(!topFragment.getRememberedAppBarCollapsed())
@@ -244,7 +305,7 @@ class ContainerFragment: BoundFragment(FragmentContain
view.updatePadding(bottom = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom)
}
handleFabState(sharedViewModel.fabState.value)
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
sharedViewModel.fabState.collect {
handleFabState(it)
}
@@ -270,7 +331,7 @@ class ContainerFragment: BoundFragment(FragmentContain
}
}
- private fun setupSnackbar() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupSnackbar() = whenResumed {
sharedViewModel.snackbarBus.collect {
Snackbar.make(binding.root, it, Snackbar.LENGTH_LONG).apply {
applyMonet()
@@ -284,7 +345,7 @@ class ContainerFragment: BoundFragment(FragmentContain
private fun setupUpdateSnackbar() {
handleUpdateSnackbar(viewModel.showUpdateSnackbar.value)
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
viewModel.showUpdateSnackbar.collect {
handleUpdateSnackbar(it)
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/decision/DecisionFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/decision/DecisionFragment.kt
index ea37f657..ead2b48b 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/decision/DecisionFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/decision/DecisionFragment.kt
@@ -5,8 +5,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.ui.screens.root.RootSharedViewModel
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -24,7 +24,7 @@ class DecisionFragment: Fragment() {
return View(context)
}
- private fun setupDecision() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupDecision() = whenResumed {
decisionViewModel.decisionMade.collect {
rootSharedViewModel.postDecisionMade()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/disablecolumbus/DisableColumbusFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/disablecolumbus/DisableColumbusFragment.kt
index 7309564d..cc0cd349 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/disablecolumbus/DisableColumbusFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/disablecolumbus/DisableColumbusFragment.kt
@@ -4,12 +4,12 @@ import android.os.Bundle
import android.text.Html
import android.text.util.Linkify
import android.view.View
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.databinding.FragmentDisableColumbusBinding
import com.kieronquinn.app.taptap.ui.base.BoundFragment
import com.kieronquinn.app.taptap.utils.extensions.applyBackgroundTint
import com.kieronquinn.app.taptap.utils.extensions.onClicked
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import me.saket.bettermovementmethod.BetterLinkMovementMethod
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -31,13 +31,13 @@ class DisableColumbusFragment: BoundFragment(Fra
binding.disableColumbusCard.applyBackgroundTint(monet)
}
- private fun setupOpenSettings() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupOpenSettings() = whenResumed {
binding.disableColumbusOpenSettings.onClicked().collect {
viewModel.onOpenSettingsClicked()
}
}
- private fun setupPhoenix() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupPhoenix() = whenResumed {
viewModel.phoenixBus.collect {
viewModel.phoenix()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/reachability/ReachabilityFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/reachability/ReachabilityFragment.kt
index 1a0c3404..b77e407e 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/reachability/ReachabilityFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/reachability/ReachabilityFragment.kt
@@ -6,13 +6,12 @@ import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Toast
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.databinding.FragmentReachabilityBinding
import com.kieronquinn.app.taptap.ui.base.BoundFragment
import com.kieronquinn.app.taptap.utils.extensions.onClicked
import com.kieronquinn.app.taptap.utils.extensions.onLongClicked
-import kotlinx.coroutines.flow.collect
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import org.koin.androidx.viewmodel.ext.android.viewModel
class ReachabilityFragment: BoundFragment(FragmentReachabilityBinding::inflate) {
@@ -39,7 +38,7 @@ class ReachabilityFragment: BoundFragment(FragmentR
setupNotificationsClick()
setupQuickSettingsClick()
setupNotificationsLongClick()
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
if(!viewModel.getHasLeftHandedSet()){
Toast.makeText(requireContext(), R.string.reachability_left_handed_info, Toast.LENGTH_LONG).show()
}
@@ -52,7 +51,7 @@ class ReachabilityFragment: BoundFragment(FragmentR
binding.reachabilityQuickSettings.iconTint = accent
}
- private fun setupHandedness() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupHandedness() = whenResumed {
viewModel.isLeftHanded.collect {
if(it) {
binding.reachabilityContainer.gravity = Gravity.BOTTOM or Gravity.START
@@ -62,26 +61,26 @@ class ReachabilityFragment: BoundFragment(FragmentR
}
}
- private fun setupNotificationsClick() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupNotificationsClick() = whenResumed {
binding.reachabilityNotifications.onClicked().collect {
viewModel.onNotificationsClicked()
}
}
- private fun setupQuickSettingsClick() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupQuickSettingsClick() = whenResumed {
binding.reachabilityQuickSettings.onClicked().collect {
viewModel.onQuickSettingsClicked()
}
}
- private fun setupNotificationsLongClick() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupNotificationsLongClick() = whenResumed {
binding.reachabilityNotifications.onLongClicked().collect {
viewModel.onNotificationsLongClicked()
}
}
fun onWindowAttributesChanged(height: Int) {
- lifecycleScope.launchWhenResumed {
+ whenResumed {
if(height < minButtonHeight){
binding.reachabilityNotifications.visibility = View.GONE
binding.reachabilityQuickSettings.visibility = View.GONE
@@ -93,7 +92,7 @@ class ReachabilityFragment: BoundFragment(FragmentR
}
fun onExitMultiWindow(providedApp: String?) {
- lifecycleScope.launchWhenResumed {
+ whenResumed {
viewModel.getCurrentApp() ?: providedApp?.let {
requireContext().packageManager.getLaunchIntentForPackage(it)?.run {
startActivity(this)
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/root/RootFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/root/RootFragment.kt
index d1269201..05509445 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/root/RootFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/root/RootFragment.kt
@@ -2,13 +2,13 @@ package com.kieronquinn.app.taptap.ui.screens.root
import android.os.Bundle
import android.view.View
-import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.components.navigation.RootNavigation
import com.kieronquinn.app.taptap.components.navigation.setupWithNavigation
import com.kieronquinn.app.taptap.databinding.FragmentRootBinding
import com.kieronquinn.app.taptap.ui.base.BoundFragment
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
@@ -25,7 +25,7 @@ class RootFragment: BoundFragment(FragmentRootBinding::infl
setupNavigation()
}
- private fun setupNavigation() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupNavigation() = whenResumed {
launch {
navHostFragment.setupWithNavigation(navigation)
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericAdapter.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericAdapter.kt
index 2d02883b..d3c428f8 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericAdapter.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericAdapter.kt
@@ -8,7 +8,6 @@ import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.coroutineScope
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.kieronquinn.app.taptap.R
@@ -19,9 +18,14 @@ import com.kieronquinn.app.taptap.models.action.TapTapUIAction
import com.kieronquinn.app.taptap.ui.screens.settings.actions.SettingsActionsGenericViewModel.SettingsActionsItem
import com.kieronquinn.app.taptap.ui.screens.settings.actions.SettingsActionsGenericViewModel.SettingsActionsItem.SettingsActionsItemType
import com.kieronquinn.app.taptap.ui.views.LifecycleAwareRecyclerView
-import com.kieronquinn.app.taptap.utils.extensions.*
+import com.kieronquinn.app.taptap.utils.extensions.addRippleForeground
+import com.kieronquinn.app.taptap.utils.extensions.applyBackgroundTint
+import com.kieronquinn.app.taptap.utils.extensions.isDarkMode
+import com.kieronquinn.app.taptap.utils.extensions.onClicked
+import com.kieronquinn.app.taptap.utils.extensions.onLongClicked
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import com.kieronquinn.monetcompat.core.MonetCompat
-import java.util.*
+import java.util.Collections
class SettingsActionsGenericAdapter(
recyclerView: RecyclerView,
@@ -151,12 +155,12 @@ class SettingsActionsGenericAdapter(
ContextCompat.getDrawable(context, R.drawable.ic_action_chip_when_empty)
itemActionChipWhen.text = context.getString(R.string.item_action_when_empty)
}
- holder.lifecycle.coroutineScope.launchWhenResumed {
+ holder.lifecycle.whenResumed {
itemSettingsActionsActionHandle.onLongClicked().collect {
onHandleLongPressed(holder)
}
}
- holder.lifecycle.coroutineScope.launchWhenResumed {
+ holder.lifecycle.whenResumed {
root.onLongClicked().collect {
val isSelected = item.isSelected
clearSelection()
@@ -165,7 +169,7 @@ class SettingsActionsGenericAdapter(
notifyItemChanged(holder.adapterPosition)
}
}
- holder.lifecycle.coroutineScope.launchWhenResumed {
+ holder.lifecycle.whenResumed {
itemActionChipWhen.onClicked().collect {
onWhenGateChipClicked(item.action)
}
@@ -178,13 +182,13 @@ class SettingsActionsGenericAdapter(
itemSettingsActionsInfoContent.text = context.getText(item.contentRes)
if(item.onClick != null){
root.addRippleForeground()
- lifecycle.coroutineScope.launchWhenResumed {
+ lifecycle.whenResumed {
root.onClicked().collect {
item.onClick.invoke()
}
}
}
- lifecycle.coroutineScope.launchWhenResumed {
+ lifecycle.whenResumed {
itemSettingsActionsInfoDismiss.onClicked().collect {
item.onCloseClick.invoke()
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericFragment.kt
index ec3cf210..0662035a 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/SettingsActionsGenericFragment.kt
@@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.constraintlayout.widget.Group
import androidx.core.view.isVisible
import androidx.fragment.app.setFragmentResultListener
-import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@@ -26,8 +25,8 @@ import com.kieronquinn.app.taptap.ui.screens.settings.actions.whengates.Settings
import com.kieronquinn.app.taptap.utils.extensions.applyBottomInsets
import com.kieronquinn.app.taptap.utils.extensions.awaitState
import com.kieronquinn.app.taptap.utils.extensions.scrollToBottom
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
import com.kieronquinn.monetcompat.extensions.views.applyMonet
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.debounce
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
@@ -77,7 +76,7 @@ abstract class SettingsActionsGenericFragment(inflate
private fun setupState() {
handleState(viewModel.state.value)
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
viewModel.state.collect {
handleState(it)
}
@@ -101,7 +100,7 @@ abstract class SettingsActionsGenericFragment(inflate
}
}
- private fun setupFab() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupFab() = whenResumed {
sharedViewModel.fabClicked.collect {
when (it) {
ContainerSharedViewModel.FabState.FabAction.ADD_ACTION -> {
@@ -123,7 +122,7 @@ abstract class SettingsActionsGenericFragment(inflate
private fun setupFabState() {
handleFabState(viewModel.fabState.value)
- viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ whenResumed {
viewModel.fabState.collect {
handleFabState(it)
}
@@ -143,20 +142,20 @@ abstract class SettingsActionsGenericFragment(inflate
}
}
- private fun setupScrollToBottom() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupScrollToBottom() = whenResumed {
viewModel.scrollToBottomBus.collect {
viewModel.state.awaitState(SettingsActionsGenericViewModel.State.Loaded::class.java)
getRecyclerView().scrollToBottom()
}
}
- private fun setupReloadService() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupReloadService() = whenResumed {
viewModel.reloadServiceBus.debounce(1000L).collect {
sharedViewModel.restartService(requireContext())
}
}
- private fun setupSwitchReloadService() = viewLifecycleOwner.lifecycleScope.launchWhenResumed {
+ private fun setupSwitchReloadService() = whenResumed {
viewModel.switchChanged?.debounce(1000L)?.collect {
sharedViewModel.restartService(requireContext())
}
diff --git a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/help/SettingsActionsHelpBottomSheetFragment.kt b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/help/SettingsActionsHelpBottomSheetFragment.kt
index 08504d3b..4601fb2d 100644
--- a/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/help/SettingsActionsHelpBottomSheetFragment.kt
+++ b/app/src/main/java/com/kieronquinn/app/taptap/ui/screens/settings/actions/help/SettingsActionsHelpBottomSheetFragment.kt
@@ -4,13 +4,12 @@ import android.os.Bundle
import android.view.View
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
-import androidx.lifecycle.lifecycleScope
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.databinding.FragmentSettingsActionsHelpBinding
import com.kieronquinn.app.taptap.ui.base.BaseBottomSheetFragment
import com.kieronquinn.app.taptap.utils.extensions.onApplyInsets
import com.kieronquinn.app.taptap.utils.extensions.onClicked
-import kotlinx.coroutines.flow.collect
+import com.kieronquinn.app.taptap.utils.extensions.whenResumed
class SettingsActionsHelpBottomSheetFragment: BaseBottomSheetFragment(FragmentSettingsActionsHelpBinding::inflate) {
@@ -34,7 +33,7 @@ class SettingsActionsHelpBottomSheetFragment: BaseBottomSheetFragment(inflate: (Layo
private val onResume = MutableSharedFlow()
private val permissionResponse = MutableSharedFlow