mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Remove UiViewModel snackbar logic (#3598)
This commit is contained in:
parent
4a5f69458c
commit
89bc9528c5
3 changed files with 29 additions and 51 deletions
|
|
@ -19,9 +19,6 @@ package com.geeksville.mesh.model
|
|||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
|
@ -42,7 +39,6 @@ import kotlinx.coroutines.flow.map
|
|||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.shareIn
|
||||
import kotlinx.coroutines.launch
|
||||
import org.meshtastic.core.analytics.platform.PlatformAnalytics
|
||||
import org.meshtastic.core.data.repository.FirmwareReleaseRepository
|
||||
import org.meshtastic.core.data.repository.MeshLogRepository
|
||||
|
|
@ -177,26 +173,6 @@ constructor(
|
|||
val myNodeInfo: StateFlow<MyNodeEntity?>
|
||||
get() = nodeDB.myNodeInfo
|
||||
|
||||
val snackBarHostState = SnackbarHostState()
|
||||
|
||||
fun showSnackBar(text: Int) = showSnackBar(app.getString(text))
|
||||
|
||||
fun showSnackBar(
|
||||
text: String,
|
||||
actionLabel: String? = null,
|
||||
withDismissAction: Boolean = false,
|
||||
duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite,
|
||||
onActionPerformed: (() -> Unit) = {},
|
||||
onDismissed: (() -> Unit) = {},
|
||||
) = viewModelScope.launch {
|
||||
snackBarHostState.showSnackbar(text, actionLabel, withDismissAction, duration).run {
|
||||
when (this) {
|
||||
SnackbarResult.ActionPerformed -> onActionPerformed()
|
||||
SnackbarResult.Dismissed -> onDismissed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
serviceRepository.errorMessage
|
||||
.filterNotNull()
|
||||
|
|
@ -217,11 +193,11 @@ constructor(
|
|||
val sharedContactRequested: StateFlow<AdminProtos.SharedContact?>
|
||||
get() = _sharedContactRequested.asStateFlow()
|
||||
|
||||
fun setSharedContactRequested(url: Uri) {
|
||||
fun setSharedContactRequested(url: Uri, onFailure: () -> Unit) {
|
||||
runCatching { _sharedContactRequested.value = url.toSharedContact() }
|
||||
.onFailure { ex ->
|
||||
Timber.e(ex, "Shared contact error")
|
||||
showSnackBar(R.string.contact_invalid)
|
||||
onFailure()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -238,11 +214,12 @@ constructor(
|
|||
val requestChannelSet: StateFlow<AppOnlyProtos.ChannelSet?>
|
||||
get() = _requestChannelSet
|
||||
|
||||
fun requestChannelUrl(url: Uri) = runCatching { _requestChannelSet.value = url.toChannelSet() }
|
||||
.onFailure { ex ->
|
||||
Timber.e(ex, "Channel url error")
|
||||
showSnackBar(R.string.channel_invalid)
|
||||
}
|
||||
fun requestChannelUrl(url: Uri, onFailure: () -> Unit) =
|
||||
runCatching { _requestChannelSet.value = url.toChannelSet() }
|
||||
.onFailure { ex ->
|
||||
Timber.e(ex, "Channel url error")
|
||||
onFailure()
|
||||
}
|
||||
|
||||
val latestStableFirmwareRelease = firmwareReleaseRepository.stableRelease.mapNotNull { it?.asDeviceVersion() }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue