Prevent crashes when int or float setting field is emptied

This commit is contained in:
Sylvain Berfini 2020-08-21 13:55:36 +02:00
parent 03d8cb54f9
commit bc40aabe13
7 changed files with 47 additions and 13 deletions

View file

@ -22,6 +22,7 @@ package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.NumberFormatException
import java.util.*
import kotlin.collections.ArrayList
import org.linphone.LinphoneApplication.Companion.coreContext
@ -236,14 +237,20 @@ class AccountSettingsViewModel(val proxyConfig: ProxyConfig) : GenericSettingsVi
val avpfRrIntervalListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
proxyConfig.avpfRrInterval = newValue.toInt()
try {
proxyConfig.avpfRrInterval = newValue.toInt()
} catch (nfe: NumberFormatException) {
}
}
}
val avpfRrInterval = MutableLiveData<Int>()
val expiresListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
proxyConfig.expires = newValue.toInt()
try {
proxyConfig.expires = newValue.toInt()
} catch (nfe: NumberFormatException) {
}
}
}
val expires = MutableLiveData<Int>()

View file

@ -21,6 +21,7 @@ package org.linphone.activities.main.settings.viewmodels
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.R
import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.core.AudioDevice
@ -124,14 +125,20 @@ class AudioSettingsViewModel : GenericSettingsViewModel() {
val microphoneGainListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
core.micGainDb = newValue.toFloat()
try {
core.micGainDb = newValue.toFloat()
} catch (nfe: NumberFormatException) {
}
}
}
val microphoneGain = MutableLiveData<Float>()
val playbackGainListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
core.playbackGainDb = newValue.toFloat()
try {
core.playbackGainDb = newValue.toFloat()
} catch (nfe: NumberFormatException) {
}
}
}
val playbackGain = MutableLiveData<Float>()

View file

@ -20,6 +20,7 @@
package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.R
import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.core.MediaEncryption
@ -99,14 +100,20 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
val autoAnswerDelayListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
prefs.autoAnswerDelay = newValue.toInt()
try {
prefs.autoAnswerDelay = newValue.toInt()
} catch (nfe: NumberFormatException) {
}
}
}
val autoAnswerDelay = MutableLiveData<Int>()
val incomingTimeoutListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
core.incTimeout = newValue.toInt()
try {
core.incTimeout = newValue.toInt()
} catch (nfe: NumberFormatException) {
}
}
}
val incomingTimeout = MutableLiveData<Int>()

View file

@ -20,6 +20,7 @@
package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.R
import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.utils.Event
@ -54,10 +55,11 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
val autoDownloadMaxSizeListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
if (newValue.isNotEmpty()) {
try {
val maxSize = newValue.toInt()
core.maxSizeForAutoDownloadIncomingFiles = maxSize
updateAutoDownloadIndexFromMaxSize(maxSize)
} catch (nfe: NumberFormatException) {
}
}
}

View file

@ -20,6 +20,7 @@
package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.activities.main.settings.SettingListenerStub
class NetworkSettingsViewModel : GenericSettingsViewModel() {
@ -56,8 +57,11 @@ class NetworkSettingsViewModel : GenericSettingsViewModel() {
val sipPortListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
val port = newValue.toInt()
setSipPort(port)
try {
val port = newValue.toInt()
setSipPort(port)
} catch (nfe: NumberFormatException) {
}
}
}
val sipPort = MutableLiveData<Int>()

View file

@ -20,6 +20,7 @@
package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.R
import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.core.Factory
@ -38,10 +39,11 @@ class TunnelSettingsViewModel : GenericSettingsViewModel() {
val portListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
if (newValue.isNotEmpty()) {
try {
val config = getTunnelConfig()
config.port = newValue.toInt()
updateTunnelConfig(config)
} catch (nfe: NumberFormatException) {
}
}
}
@ -66,10 +68,11 @@ class TunnelSettingsViewModel : GenericSettingsViewModel() {
val port2Listener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
if (newValue.isNotEmpty()) {
try {
val config = getTunnelConfig()
config.port2 = newValue.toInt()
updateTunnelConfig(config)
} catch (nfe: NumberFormatException) {
}
}
}

View file

@ -21,6 +21,7 @@ package org.linphone.activities.main.settings.viewmodels
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.MutableLiveData
import java.lang.NumberFormatException
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.activities.main.settings.SettingListenerStub
@ -97,8 +98,11 @@ class VideoSettingsViewModel : GenericSettingsViewModel() {
val bandwidthLimitListener = object : SettingListenerStub() {
override fun onTextValueChanged(newValue: String) {
core.downloadBandwidth = newValue.toInt()
core.uploadBandwidth = newValue.toInt()
try {
core.downloadBandwidth = newValue.toInt()
core.uploadBandwidth = newValue.toInt()
} catch (nfe: NumberFormatException) {
}
}
}
val bandwidthLimit = MutableLiveData<Int>()