From 42bec475f7aedd834aa66044f0069e6b29e75135 Mon Sep 17 00:00:00 2001 From: Javad Jafari Date: Thu, 11 Jan 2024 20:32:38 +0330 Subject: [PATCH] #128 setup custom activity on crash --- app/build.gradle.kts | 1 + app/src/main/AndroidManifest.xml | 5 + .../BackgroundableApplication.kt | 12 + .../backgroundable/main/CrashActivity.kt | 84 +++ .../backgroundable/main/MainActivity.kt | 45 +- app/src/main/res/drawable/ic_crash_image.xml | 693 ++++++++++++++++++ app/src/main/res/values-fa/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + gradle/libs.versions.toml | 2 + 9 files changed, 823 insertions(+), 21 deletions(-) create mode 100644 app/src/main/kotlin/ir/thatsmejavad/backgroundable/main/CrashActivity.kt create mode 100644 app/src/main/res/drawable/ic_crash_image.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5de4e72..420ef06 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -265,6 +265,7 @@ dependencies { debugImplementation(libs.composeUiManifest) implementation(libs.appMetrica) + implementation(libs.caoc) } kover { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f0ce1df..1868f6f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,11 @@ android:theme="@style/Theme.App.Starting" android:usesCleartextTraffic="true" tools:targetApi="tiramisu"> + isSystemInDarkTheme() Theme.LightTheme -> false } - DisposableEffect(isDark) { - enableEdgeToEdge( - statusBarStyle = if (isDark) { - SystemBarStyle.dark(Color.Transparent.toArgb()) - } else { - SystemBarStyle.light( - scrim = Color.Transparent.toArgb(), - darkScrim = Color.Black.copy(alpha = 0.3f).toArgb() - ) - }, - navigationBarStyle = if (isDark) { - SystemBarStyle.dark(Color.Transparent.toArgb()) - } else { - SystemBarStyle.light( - Color.Transparent.toArgb(), - Color.Black.copy(alpha = 0.3f).toArgb() - ) - } - ) - onDispose {} + LaunchedEffect(isDark) { + setSystemBarsColor(isDark) } BackgroundableApp() } @@ -242,3 +224,24 @@ private fun BackgroundableNavigationBar( } } } + +internal fun AppCompatActivity.setSystemBarsColor(isDark: Boolean) { + enableEdgeToEdge( + statusBarStyle = if (isDark) { + SystemBarStyle.dark(Color.Transparent.toArgb()) + } else { + SystemBarStyle.light( + scrim = Color.Transparent.toArgb(), + darkScrim = Color.Black.copy(alpha = 0.3f).toArgb() + ) + }, + navigationBarStyle = if (isDark) { + SystemBarStyle.dark(Color.Transparent.toArgb()) + } else { + SystemBarStyle.light( + Color.Transparent.toArgb(), + Color.Black.copy(alpha = 0.3f).toArgb() + ) + } + ) +} diff --git a/app/src/main/res/drawable/ic_crash_image.xml b/app/src/main/res/drawable/ic_crash_image.xml new file mode 100644 index 0000000..daa2433 --- /dev/null +++ b/app/src/main/res/drawable/ic_crash_image.xml @@ -0,0 +1,693 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index 5a3671b..e9ab7e8 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -49,4 +49,5 @@ برنامه نویس اندروید محمد قاسمی طراح رابط کاربری + بابت ناراحتی پیش آمده پوزش می‌خواهیم، اما برنامه با یک خطای حیاتی مواجه شده است و باید بسته شود. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 81fbff9..4cb8b03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,4 +58,5 @@ Android Developer Mohammad Ghasemi UI/UX Designer + We apologize for the inconvenience, but backgroundable has encountered a critical error and must close. \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 893e2b6..39dd40a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,7 @@ agp = "8.1.2" androidxJunit = "1.1.5" appMetrica = "5.3.0" appcompat = "1.6.1" +caoc = "2.4.0" chucker = "4.0.0" coilCompose = "2.5.0" composeAnimation = "1.5.4" @@ -47,6 +48,7 @@ activityCompose = { module = "androidx.activity:activity-compose", version.ref = androidxJunit = { module = "androidx.test.ext:junit", version.ref = "androidxJunit" } appMetrica = { module = "com.yandex.android:mobmetricalib", version.ref = "appMetrica" } appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +caoc = { group = "cat.ereza", name = "customactivityoncrash", version.ref = "caoc" } chucker = { module = "com.github.chuckerteam.chucker:library", version.ref = "chucker" } chuckerNoOp = { module = "com.github.chuckerteam.chucker:library-no-op", version.ref = "chucker" } coilCompose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }