Skip to content

Commit

Permalink
Add convenience Activity accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Dec 21, 2023
1 parent e695ead commit 7cb9652
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions dachlatten-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation(libs.coroutines)
implementation(libs.lifecycle.process)
implementation(libs.annotation.jvm)
implementation(libs.androidx.activity)

testImplementation(libs.coroutines)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.sipgate.dachlatten.android.activity

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.activity.ComponentActivity

fun Context.getActivity(): Activity? =
when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ compose-compiler = "1.5.5"
kotlinx-datetime = "0.5.0"
kover = "0.7.5"
mockk = "1.13.8"
androidx-activity = "1.8.2"

[libraries]
coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
Expand All @@ -22,6 +23,7 @@ coroutinesTest = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-t
support-annotations = { module = "com.android.support:support-annotations", version.ref = "support-annotations" }
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
androidx-activity = { group = "androidx.activity", name = "activity-compose", version.ref = "androidx-activity" }

lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "androidx-lifecycle" }
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose" }
Expand Down

0 comments on commit 7cb9652

Please sign in to comment.