Remove NFC tag sample YAML for 'scanned by this device' on 2022.12+ (#3114)

This commit is contained in:
Joris Pelgröm 2022-11-29 04:14:30 +01:00 committed by GitHub
parent 11e8d5a8e8
commit 4ec5fbf1f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View file

@ -30,6 +30,8 @@ class NfcViewModel @Inject constructor(
var isNfcEnabled by mutableStateOf(false)
private set
var usesAndroidDeviceId by mutableStateOf(false)
private set
var nfcTagIdentifier by mutableStateOf<String?>(null)
private set
var nfcIdentifierIsEditable by mutableStateOf(true)
@ -42,6 +44,12 @@ class NfcViewModel @Inject constructor(
private val _nfcResultSnackbar = MutableSharedFlow<Int>()
var nfcResultSnackbar = _nfcResultSnackbar.asSharedFlow()
init {
viewModelScope.launch {
usesAndroidDeviceId = !integrationUseCase.isHomeAssistantVersionAtLeast(2022, 12, 0)
}
}
fun setDestination(destination: String?) {
nfcEventShouldWrite = nfcTagIdentifier != null && destination == NfcSetupActivity.NAV_WRITE
}

View file

@ -32,6 +32,7 @@ import io.homeassistant.companion.android.common.R as commonR
@Composable
fun NfcEditView(
identifier: String?,
showDeviceSample: Boolean,
onDuplicateClicked: () -> Unit,
onFireEventClicked: () -> Unit
) {
@ -79,15 +80,17 @@ fun NfcEditView(
item {
NfcTriggerExample(
modifier = Modifier.padding(bottom = 8.dp),
description = stringResource(commonR.string.nfc_trigger_any),
description = if (showDeviceSample) stringResource(commonR.string.nfc_trigger_any) else "",
example = tagTriggerExample
)
}
item {
NfcTriggerExample(
description = stringResource(commonR.string.nfc_trigger_device),
example = deviceTriggerExample
)
if (showDeviceSample) {
item {
NfcTriggerExample(
description = stringResource(commonR.string.nfc_trigger_device),
example = deviceTriggerExample
)
}
}
}
}

View file

@ -2,6 +2,7 @@ package io.homeassistant.companion.android.nfc.views
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Scaffold
@ -93,11 +94,11 @@ fun LoadNfcView(
contentColor = colorResource(commonR.color.colorOnBackground)
)
}
) {
) { contentPadding ->
NavHost(
navController = navController,
startDestination = startDestination,
modifier = Modifier
modifier = Modifier.padding(contentPadding)
) {
composable(NfcSetupActivity.NAV_WELCOME) {
NfcWelcomeView(
@ -121,6 +122,7 @@ fun LoadNfcView(
composable(NfcSetupActivity.NAV_EDIT) {
NfcEditView(
identifier = viewModel.nfcTagIdentifier,
showDeviceSample = viewModel.usesAndroidDeviceId,
onDuplicateClicked = { viewModel.duplicateNfcTag() },
onFireEventClicked = { viewModel.fireNfcTagEvent() }
)