Skip to content

Commit

Permalink
Fixed CurrentActivityManger
Browse files Browse the repository at this point in the history
  • Loading branch information
arok committed Jun 25, 2024
1 parent 0ca52d6 commit 5b63d3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add this line to your dependencies in app-level build.gradle file:

```
dependencies {
implementation 'com.appswithlove.updraft:updraft-sdk:1.0.18'
implementation 'com.appswithlove.updraft:updraft-sdk:1.0.19'
}
```

Expand Down
2 changes: 1 addition & 1 deletion updraft-sdk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx4096m

GROUP=com.appswithlove.updraft
POM_ARTIFACT_ID=updraft-sdk
VERSION_NAME=1.0.18
VERSION_NAME=1.0.19

POM_NAME=updraft-sdk-android
POM_DESCRIPTION=Plugin for connecting with GetUpdraft platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CurrentActivityManger private constructor() : Application.ActivityLifecycl
}

private var currentActivity: Activity? = null
private var currentLifecycle: LifecycleState? = null

private val listeners: MutableSet<CurrentActivityListener> = mutableSetOf()

Expand All @@ -28,35 +27,30 @@ class CurrentActivityManger private constructor() : Application.ActivityLifecycl
listeners.remove(listener)
}

override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
currentActivity = activity
}
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}

override fun onActivityStarted(activity: Activity) {}
override fun onActivityResumed(activity: Activity) {
currentLifecycle = LifecycleState.Resumed
currentActivity = activity
dispatchCurrentActivityState()
}

override fun onActivityPaused(activity: Activity) {
currentLifecycle = LifecycleState.Paused
currentActivity = null
dispatchCurrentActivityState()
}

override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
override fun onActivityDestroyed(activity: Activity) {
currentActivity = null
currentLifecycle = null
}
override fun onActivityDestroyed(activity: Activity) {}

private fun dispatchCurrentActivityState() {
val activity = currentActivity
if (activity != null) {
listeners.forEach { listener ->
if (currentLifecycle == LifecycleState.Resumed) {
if (currentActivity != null) {
listener.onActivityResumed(activity)
} else if (currentLifecycle == LifecycleState.Paused) {
} else {
listener.onActivityPaused(activity)
}
}
Expand All @@ -67,9 +61,4 @@ class CurrentActivityManger private constructor() : Application.ActivityLifecycl
fun onActivityResumed(activity: Activity)
fun onActivityPaused(activity: Activity)
}

private enum class LifecycleState {
Resumed,
Paused
}
}

0 comments on commit 5b63d3d

Please sign in to comment.