Use AccountViewModel to store account modifications before they are saved
This commit is contained in:
@ -101,4 +101,5 @@ dependencies {
|
|||||||
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||||
implementation(libs.androidx.compose.material.icons.core)
|
implementation(libs.androidx.compose.material.icons.core)
|
||||||
implementation(libs.androidx.compose.material.icons.extended)
|
implementation(libs.androidx.compose.material.icons.extended)
|
||||||
|
implementation(libs.androidx.compose.foundation.layout)
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
63
app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt
Normal file
63
app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package com.tutpro.baresip
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
class AccountViewModel: ViewModel() {
|
||||||
|
|
||||||
|
val nickName = MutableStateFlow("")
|
||||||
|
val displayName = MutableStateFlow("")
|
||||||
|
val authUser = MutableStateFlow("")
|
||||||
|
val authPass = MutableStateFlow("")
|
||||||
|
val outbound1 = MutableStateFlow("")
|
||||||
|
val outbound2 = MutableStateFlow("")
|
||||||
|
val register = MutableStateFlow(false)
|
||||||
|
val regInt = MutableStateFlow("")
|
||||||
|
val mediaEnc = MutableStateFlow("")
|
||||||
|
val mediaNat = MutableStateFlow("")
|
||||||
|
val stunServer = MutableStateFlow("")
|
||||||
|
val stunUser = MutableStateFlow("")
|
||||||
|
val stunPass = MutableStateFlow("")
|
||||||
|
val rtcpMux = MutableStateFlow(false)
|
||||||
|
val rel100 = MutableStateFlow(false)
|
||||||
|
val dtmfMode = MutableStateFlow(0)
|
||||||
|
val answerMode = MutableStateFlow(0)
|
||||||
|
val autoRedirect = MutableStateFlow(false)
|
||||||
|
val vmUri = MutableStateFlow("")
|
||||||
|
val countryCode = MutableStateFlow("")
|
||||||
|
val telProvider = MutableStateFlow("")
|
||||||
|
val defaultAccount = MutableStateFlow(false)
|
||||||
|
val numericKeypad = MutableStateFlow(false)
|
||||||
|
|
||||||
|
private var isLoaded = false
|
||||||
|
|
||||||
|
fun loadAccount(acc: Account) {
|
||||||
|
if (isLoaded) return else isLoaded = true
|
||||||
|
nickName.value = acc.nickName
|
||||||
|
displayName.value = acc.displayName
|
||||||
|
authUser.value = acc.authUser
|
||||||
|
authPass.value = if (BaresipService.aorPasswords[acc.aor] == null && acc.authPass != NO_AUTH_PASS)
|
||||||
|
acc.authPass
|
||||||
|
else
|
||||||
|
""
|
||||||
|
outbound1.value = if (acc.outbound.isNotEmpty()) acc.outbound[0] else ""
|
||||||
|
outbound2.value = if (acc.outbound.size > 1) acc.outbound[1] else ""
|
||||||
|
register.value = acc.regint > 0
|
||||||
|
regInt.value = acc.configuredRegInt.toString()
|
||||||
|
mediaEnc.value = acc.mediaEnc
|
||||||
|
mediaNat.value = acc.mediaNat
|
||||||
|
stunServer.value = acc.stunServer
|
||||||
|
stunUser.value = acc.stunUser
|
||||||
|
stunPass.value = acc.stunPass
|
||||||
|
rtcpMux.value = acc.rtcpMux
|
||||||
|
rel100.value = acc.rel100Mode == Api.REL100_ENABLED
|
||||||
|
dtmfMode.value = acc.dtmfMode
|
||||||
|
answerMode.value = acc.answerMode
|
||||||
|
autoRedirect.value = acc.autoRedirect
|
||||||
|
vmUri.value = acc.vmUri
|
||||||
|
countryCode.value = acc.countryCode
|
||||||
|
telProvider.value = acc.telProvider
|
||||||
|
numericKeypad.value = acc.numericKeypad
|
||||||
|
defaultAccount.value = UserAgent.findAorIndex(acc.aor)!! == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ runtimeLivedata = "1.9.3"
|
|||||||
composeMaterial3 = "1.4.0"
|
composeMaterial3 = "1.4.0"
|
||||||
navigationRuntimeAndroid = "2.9.5"
|
navigationRuntimeAndroid = "2.9.5"
|
||||||
composeMaterialIcons = "1.7.8"
|
composeMaterialIcons = "1.7.8"
|
||||||
|
foundationLayout = "1.9.3"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
|
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
|
||||||
@ -49,6 +50,7 @@ androidx-compose-material3 = { group = "androidx.compose.material3", name = "mat
|
|||||||
androidx-navigation-runtime-android = { group = "androidx.navigation", name = "navigation-runtime-android", version.ref = "navigationRuntimeAndroid" }
|
androidx-navigation-runtime-android = { group = "androidx.navigation", name = "navigation-runtime-android", version.ref = "navigationRuntimeAndroid" }
|
||||||
androidx-compose-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core", version.ref = "composeMaterialIcons" }
|
androidx-compose-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core", version.ref = "composeMaterialIcons" }
|
||||||
androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "composeMaterialIcons" }
|
androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "composeMaterialIcons" }
|
||||||
|
androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout", version.ref = "foundationLayout" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
|
|||||||
Reference in New Issue
Block a user