-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Auto Connection Feature using Application.ActivityLifecycleCallbacks
- Loading branch information
Showing
12 changed files
with
123 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
thunder/src/main/java/com/jeremy/thunder/connection/AppConnectionListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.jeremy.thunder.connection | ||
|
||
import com.jeremy.thunder.state.ActivityState | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
interface AppConnectionListener { | ||
fun collectState(): StateFlow<ActivityState> | ||
} |
43 changes: 43 additions & 0 deletions
43
thunder/src/main/java/com/jeremy/thunder/connection/AppConnectionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.jeremy.thunder.connection | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.os.Bundle | ||
import com.jeremy.thunder.state.ActivityState | ||
import com.jeremy.thunder.state.GetReady | ||
import com.jeremy.thunder.state.Initialize | ||
import com.jeremy.thunder.state.ShutDown | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
class AppConnectionProvider : AppConnectionListener, Application.ActivityLifecycleCallbacks { | ||
|
||
private val _eventFlow = MutableStateFlow<ActivityState>(Initialize) | ||
|
||
override fun collectState(): StateFlow<ActivityState> { | ||
return _eventFlow.asStateFlow() | ||
} | ||
|
||
override fun onActivityCreated(p0: Activity, p1: Bundle?) { | ||
_eventFlow.tryEmit(GetReady) | ||
} | ||
|
||
override fun onActivityStarted(p0: Activity) { | ||
_eventFlow.tryEmit(GetReady) | ||
} | ||
|
||
override fun onActivityResumed(p0: Activity) { | ||
_eventFlow.tryEmit(GetReady) | ||
} | ||
|
||
override fun onActivityPaused(p0: Activity) {} | ||
|
||
override fun onActivityStopped(p0: Activity) {} | ||
|
||
override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) {} | ||
|
||
override fun onActivityDestroyed(p0: Activity) { | ||
_eventFlow.tryEmit(ShutDown) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
thunder/src/main/java/com/jeremy/thunder/state/ActivityState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.jeremy.thunder.state | ||
|
||
sealed interface ActivityState | ||
|
||
object Initialize: ActivityState | ||
|
||
object GetReady: ActivityState | ||
|
||
object ShutDown: ActivityState |