Added tunnel settings
This commit is contained in:
parent
bf024abdb9
commit
d79c8f09e6
3 changed files with 180 additions and 2 deletions
|
@ -19,6 +19,116 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.main.settings.viewmodels
|
package org.linphone.activities.main.settings.viewmodels
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import org.linphone.R
|
||||||
|
import org.linphone.activities.main.settings.SettingListenerStub
|
||||||
|
import org.linphone.core.Factory
|
||||||
|
import org.linphone.core.Tunnel
|
||||||
|
import org.linphone.core.TunnelConfig
|
||||||
|
|
||||||
class TunnelSettingsViewModel : GenericSettingsViewModel() {
|
class TunnelSettingsViewModel : GenericSettingsViewModel() {
|
||||||
// TODO
|
val hostnameUrlListener = object : SettingListenerStub() {
|
||||||
|
override fun onTextValueChanged(newValue: String) {
|
||||||
|
val config = getTunnelConfig()
|
||||||
|
config.host = newValue
|
||||||
|
updateTunnelConfig(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val hostnameUrl = MutableLiveData<String>()
|
||||||
|
|
||||||
|
val portListener = object : SettingListenerStub() {
|
||||||
|
override fun onTextValueChanged(newValue: String) {
|
||||||
|
if (newValue.isNotEmpty()) {
|
||||||
|
val config = getTunnelConfig()
|
||||||
|
config.port = newValue.toInt()
|
||||||
|
updateTunnelConfig(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val port = MutableLiveData<Int>()
|
||||||
|
|
||||||
|
val useDualModeListener = object : SettingListenerStub() {
|
||||||
|
override fun onBoolValueChanged(newValue: Boolean) {
|
||||||
|
val tunnel = core.tunnel
|
||||||
|
tunnel.enableDualMode(newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val useDualMode = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
|
val hostnameUrl2Listener = object : SettingListenerStub() {
|
||||||
|
override fun onTextValueChanged(newValue: String) {
|
||||||
|
val config = getTunnelConfig()
|
||||||
|
config.host2 = newValue
|
||||||
|
updateTunnelConfig(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val hostnameUrl2 = MutableLiveData<String>()
|
||||||
|
|
||||||
|
val port2Listener = object : SettingListenerStub() {
|
||||||
|
override fun onTextValueChanged(newValue: String) {
|
||||||
|
if (newValue.isNotEmpty()) {
|
||||||
|
val config = getTunnelConfig()
|
||||||
|
config.port2 = newValue.toInt()
|
||||||
|
updateTunnelConfig(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val port2 = MutableLiveData<Int>()
|
||||||
|
|
||||||
|
val modeListener = object : SettingListenerStub() {
|
||||||
|
override fun onListValueChanged(position: Int) {
|
||||||
|
core.tunnel.mode = when (position) {
|
||||||
|
0 -> Tunnel.Mode.Disable
|
||||||
|
1 -> Tunnel.Mode.Enable
|
||||||
|
else -> Tunnel.Mode.Auto
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val modeIndex = MutableLiveData<Int>()
|
||||||
|
val modeLabels = MutableLiveData<ArrayList<String>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
val tunnel = core.tunnel
|
||||||
|
val config = getTunnelConfig()
|
||||||
|
|
||||||
|
hostnameUrl.value = config.host
|
||||||
|
port.value = config.port
|
||||||
|
useDualMode.value = tunnel.dualModeEnabled()
|
||||||
|
hostnameUrl2.value = config.host2
|
||||||
|
port2.value = config.port2
|
||||||
|
|
||||||
|
initModeList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTunnelConfig(): TunnelConfig {
|
||||||
|
val tunnel = core.tunnel
|
||||||
|
val configs = tunnel.servers
|
||||||
|
return if (configs.isNotEmpty()) {
|
||||||
|
configs[0]
|
||||||
|
} else {
|
||||||
|
Factory.instance().createTunnelConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateTunnelConfig(config: TunnelConfig) {
|
||||||
|
val tunnel = core.tunnel
|
||||||
|
tunnel.cleanServers()
|
||||||
|
if (config.host?.isNotEmpty() == true) {
|
||||||
|
tunnel.addServer(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initModeList() {
|
||||||
|
val labels = arrayListOf<String>()
|
||||||
|
labels.add(prefs.getString(R.string.tunnel_settings_disabled_mode))
|
||||||
|
labels.add(prefs.getString(R.string.tunnel_settings_always_mode))
|
||||||
|
labels.add(prefs.getString(R.string.tunnel_settings_auto_mode))
|
||||||
|
modeLabels.value = labels
|
||||||
|
|
||||||
|
modeIndex.value = when (core.tunnel.mode) {
|
||||||
|
Tunnel.Mode.Disable -> 0
|
||||||
|
Tunnel.Mode.Enable -> 1
|
||||||
|
else -> 2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:linphone="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
<import type="android.view.View"/>
|
<import type="android.view.View"/>
|
||||||
|
<import type="android.text.InputType"/>
|
||||||
<variable
|
<variable
|
||||||
name="backClickListener"
|
name="backClickListener"
|
||||||
type="android.view.View.OnClickListener"/>
|
type="android.view.View.OnClickListener"/>
|
||||||
|
@ -63,6 +65,57 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_text"
|
||||||
|
linphone:title="@{@string/tunnel_settings_hostname_url_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_hostname_url_summary}"
|
||||||
|
linphone:listener="@{viewModel.hostnameUrlListener}"
|
||||||
|
linphone:defaultValue="@{viewModel.hostnameUrl}"
|
||||||
|
linphone:inputType="@{InputType.TYPE_TEXT_VARIATION_URI}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_text"
|
||||||
|
linphone:title="@{@string/tunnel_settings_port_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_port_summary}"
|
||||||
|
linphone:listener="@{viewModel.portListener}"
|
||||||
|
linphone:defaultValue="@{viewModel.port.toString()}"
|
||||||
|
linphone:inputType="@{InputType.TYPE_CLASS_NUMBER}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_switch"
|
||||||
|
linphone:title="@{@string/tunnel_settings_dual_mode_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_dual_mode_summary}"
|
||||||
|
linphone:listener="@{viewModel.useDualModeListener}"
|
||||||
|
linphone:checked="@={viewModel.useDualMode}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_text"
|
||||||
|
linphone:title="@{@string/tunnel_settings_dual_hostname_url_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_dual_hostname_url_summary}"
|
||||||
|
linphone:listener="@{viewModel.hostnameUrl2Listener}"
|
||||||
|
linphone:defaultValue="@{viewModel.hostnameUrl2}"
|
||||||
|
linphone:inputType="@{InputType.TYPE_TEXT_VARIATION_URI}"
|
||||||
|
linphone:enabled="@{viewModel.useDualMode}"
|
||||||
|
android:visibility="@{viewModel.useDualMode ? View.VISIBLE : View.GONE}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_text"
|
||||||
|
linphone:title="@{@string/tunnel_settings_dual_port_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_dual_port_summary}"
|
||||||
|
linphone:listener="@{viewModel.port2Listener}"
|
||||||
|
linphone:defaultValue="@{viewModel.port2.toString()}"
|
||||||
|
linphone:inputType="@{InputType.TYPE_CLASS_NUMBER}"
|
||||||
|
linphone:enabled="@{viewModel.useDualMode}"
|
||||||
|
android:visibility="@{viewModel.useDualMode ? View.VISIBLE : View.GONE}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_list"
|
||||||
|
linphone:title="@{@string/tunnel_settings_mode_title}"
|
||||||
|
linphone:subtitle="@{@string/tunnel_settings_mode_summary}"
|
||||||
|
linphone:listener="@{viewModel.modeListener}"
|
||||||
|
linphone:selectedIndex="@{viewModel.modeIndex}"
|
||||||
|
linphone:labels="@{viewModel.modeLabels}"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -429,6 +429,21 @@
|
||||||
<string name="advanced_settings_go_to_android_app_settings">Android app settings</string>
|
<string name="advanced_settings_go_to_android_app_settings">Android app settings</string>
|
||||||
|
|
||||||
<!-- Tunnel settings -->
|
<!-- Tunnel settings -->
|
||||||
|
<string name="tunnel_settings_hostname_url_title">Hostname</string>
|
||||||
|
<string name="tunnel_settings_hostname_url_summary"></string>
|
||||||
|
<string name="tunnel_settings_port_title">Port</string>
|
||||||
|
<string name="tunnel_settings_port_summary"></string>
|
||||||
|
<string name="tunnel_settings_dual_mode_title">Dual mode enabled</string>
|
||||||
|
<string name="tunnel_settings_dual_mode_summary">Will use one server for upload and another one for download</string>
|
||||||
|
<string name="tunnel_settings_dual_hostname_url_title">Second server hostname</string>
|
||||||
|
<string name="tunnel_settings_dual_hostname_url_summary">Required in dual mode</string>
|
||||||
|
<string name="tunnel_settings_dual_port_title">Second server port</string>
|
||||||
|
<string name="tunnel_settings_dual_port_summary">Required in dual mode</string>
|
||||||
|
<string name="tunnel_settings_mode_title">Mode</string>
|
||||||
|
<string name="tunnel_settings_mode_summary"></string>
|
||||||
|
<string name="tunnel_settings_disabled_mode">Disabled</string>
|
||||||
|
<string name="tunnel_settings_always_mode">Always</string>
|
||||||
|
<string name="tunnel_settings_auto_mode">Auto</string>
|
||||||
|
|
||||||
<!-- Account settings -->
|
<!-- Account settings -->
|
||||||
<string name="account_settings_user_name_title">Username</string>
|
<string name="account_settings_user_name_title">Username</string>
|
||||||
|
|
Loading…
Reference in a new issue