Skip to content

Commit

Permalink
chore: fix receiver null error
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Sep 30, 2023
1 parent 5f4078d commit 7f0d7f1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/li/songe/gkd/util/Store.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import li.songe.gkd.app
import java.util.WeakHashMap


private val onReceives = mutableListOf<(
context: Context?,
intent: Intent?,
) -> Unit>()
private val onReceives by lazy {
mutableListOf<(
context: Context?,
intent: Intent?,
) -> Unit>()
}

private val receiver by lazy {
object : BroadcastReceiver() {
Expand All @@ -39,8 +41,8 @@ private inline fun <reified T : Parcelable> createStorageFlow(
key: String,
crossinline init: () -> T,
): StateFlow<T> {
val stateFlow = MutableStateFlow(kv.decodeParcelable(key, T::class.java) ?: init())
receiver
val stateFlow = MutableStateFlow(kv.decodeParcelable(key, T::class.java) ?: init())
onReceives.add { _, intent ->
val extras = intent?.extras ?: return@add
val type = extras.getString("type") ?: return@add
Expand Down

0 comments on commit 7f0d7f1

Please sign in to comment.