Skip to content

Commit 01fcfde

Browse files
committed
Switched StateFlow for a Channel for scan event notification
1 parent ac3baa6 commit 01fcfde

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId = "com.hoker.intra_example"
1414
minSdk = 28
1515
targetSdk = 35
16-
versionCode = 129
17-
versionName = "1.2.9"
16+
versionCode = 130
17+
versionName = "1.3.0"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
vectorDrawables {

intra/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ afterEvaluate {
6161
from(components["release"])
6262
groupId = "com.github.CarbideCowboy"
6363
artifactId = "Intra"
64-
version = "1.2.9"
64+
version = "1.3.0"
6565
}
6666
}
6767
}

intra/src/main/java/com/hoker/intra/domain/NfcAdapterController.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import android.nfc.NfcAdapter
55
import android.nfc.Tag
66
import android.os.Bundle
77
import android.util.Log
8-
import kotlinx.coroutines.flow.MutableStateFlow
9-
import kotlinx.coroutines.flow.asStateFlow
8+
import kotlinx.coroutines.channels.Channel
9+
import kotlinx.coroutines.flow.receiveAsFlow
1010
import javax.inject.Inject
1111

1212
open class NfcAdapterController @Inject constructor(
1313
private val nfcAdapter: NfcAdapter?
1414
) {
1515
private var onTagDiscoveredListener: ((Tag?) -> Unit)? = null
1616
private val listenerMap = LinkedHashMap<String, Pair<String, (Tag?) -> Unit>>()
17-
private val _connectionState: MutableStateFlow<Boolean> = MutableStateFlow(false)
18-
val connectionState = _connectionState.asStateFlow()
17+
private val _onScanChannel = Channel<Unit>(Channel.BUFFERED)
18+
val scanEvent = _onScanChannel.receiveAsFlow()
1919

2020
fun enableNfc(activity: NfcActivity) {
2121
nfcAdapter?.let { adapter ->
@@ -26,12 +26,8 @@ open class NfcAdapterController @Inject constructor(
2626
adapter.enableReaderMode(
2727
activity,
2828
{ tag ->
29-
_connectionState.value = true
30-
try {
31-
onTagDiscoveredListener?.invoke(tag)
32-
} finally {
33-
_connectionState.value = false
34-
}
29+
_onScanChannel.trySend(Unit)
30+
onTagDiscoveredListener?.invoke(tag)
3531
},
3632
flags,
3733
options

0 commit comments

Comments
 (0)