Commit c99cac5e authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added server selection dialog to tasker activity

parent e3b4e9c0
......@@ -41,20 +41,25 @@ import kotlinx.coroutines.launch
*/
class ServerChoosalDialog(
context: AppCompatActivity,
selectedServer:DnsServerInformation<*>?,
showTls:Boolean = selectedServer?.hasTlsServer() ?: true,
onEntrySelected: (config: DnsServerInformation<*>) -> Unit
) :
BaseDialog(context, context.getPreferences().theme.dialogStyle) {
private var populationJob: Job? = null
private var currentSelectedServer: DnsServerInformation<*>
private var currentSelectedServer: DnsServerInformation<*>?
private lateinit var defaultConfig: List<DnsServerInformation<*>>
private lateinit var userConfig: List<UserServerConfiguration>
constructor(context: AppCompatActivity,
onEntrySelected: (config: DnsServerInformation<*>) -> Unit):this(context, context.getPreferences().dnsServerConfig, onEntrySelected=onEntrySelected)
init {
val view = layoutInflater.inflate(R.layout.dialog_server_configuration, null, false)
setTitle(R.string.dialog_serverconfiguration_title)
setView(view)
currentSelectedServer = context.getPreferences().dnsServerConfig
currentSelectedServer = selectedServer
setButton(
DialogInterface.BUTTON_NEUTRAL, context.getString(android.R.string.cancel)
......@@ -62,10 +67,9 @@ class ServerChoosalDialog(
setButton(
DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok)
) { _, _ ->
onEntrySelected.invoke(currentSelectedServer)
currentSelectedServer?.apply(onEntrySelected)
}
val isCurrentServerTls = currentSelectedServer.hasTlsServer()
loadServerData(isCurrentServerTls)
loadServerData(showTls)
val spinnerAdapter = ArrayAdapter<String>(
context, android.R.layout.simple_spinner_item,
......@@ -77,7 +81,7 @@ class ServerChoosalDialog(
spinnerAdapter.setDropDownViewResource(R.layout.item_tasker_action_spinner_dropdown_item)
val spinner = view.findViewById<Spinner>(R.id.spinner)
spinner.adapter = spinnerAdapter
if(isCurrentServerTls) spinner.setSelection(1)
if(showTls) spinner.setSelection(1)
view.findViewById<RadioGroup>(R.id.knownServersGroup).setOnCheckedChangeListener { group, _ ->
val button = view.findViewById(group.checkedRadioButtonId) as RadioButton
val payload = button.tag
......@@ -174,6 +178,7 @@ class ServerChoosalDialog(
}
private fun markCurrentSelectedServer() {
val currentSelectedServer = this.currentSelectedServer ?: return
for (id in 0 until knownServersGroup.childCount) {
val child = knownServersGroup.getChildAt(id) as RadioButton
val payload = child.tag
......@@ -299,7 +304,7 @@ class ServerChoosalDialog(
currentSelectedServer =
if (userConfiguration.isHttpsServer()) AbstractHttpsDNSHandle.KNOWN_DNS_SERVERS.minBy { it.key }!!.value else AbstractTLSDnsHandle.KNOWN_DNS_SERVERS.minBy { it.key }!!.value
markCurrentSelectedServer()
context.getPreferences().dnsServerConfig = currentSelectedServer
context.getPreferences().dnsServerConfig = currentSelectedServer!!
}
knownServersGroup.removeView(button)
}.show()
......@@ -348,7 +353,7 @@ class ServerChoosalDialog(
currentSelectedServer =
if (isHttps) AbstractHttpsDNSHandle.KNOWN_DNS_SERVERS.minBy { it.key }!!.value else AbstractTLSDnsHandle.KNOWN_DNS_SERVERS.minBy { it.key }!!.value
markCurrentSelectedServer()
context.getPreferences().dnsServerConfig = currentSelectedServer
context.getPreferences().dnsServerConfig = currentSelectedServer!!
}
knownServersGroup.removeView(button)
}.show()
......
......@@ -12,12 +12,10 @@ import android.widget.ArrayAdapter
import com.frostnerd.dnstunnelproxy.DnsServerInformation
import com.frostnerd.encrypteddnstunnelproxy.HttpsDnsServerInformation
import com.frostnerd.lifecyclemanagement.BaseActivity
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.activity.BackgroundVpnConfigureActivity
import com.frostnerd.smokescreen.dialog.NewServerDialog
import com.frostnerd.smokescreen.fromServerUrls
import com.frostnerd.smokescreen.hasHttpsServer
import com.frostnerd.smokescreen.tlsServerFromHosts
import com.frostnerd.smokescreen.dialog.ServerChoosalDialog
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.activity_tasker_configure.*
......@@ -157,6 +155,15 @@ class ConfigureActivity : BaseActivity() {
setHints()
}
}
selectServer.setOnClickListener {
ServerChoosalDialog(this@ConfigureActivity, null, serverType.selectedItemPosition == 1) {
val typePosition = if(it.hasTlsServer()) 1 else 0
if(serverType.selectedItemPosition != typePosition) serverType.setSelection(typePosition)
primaryServer.setText(it.servers.first().address.formatToString())
if(it.servers.size > 1) secondaryServer.setText(it.servers.last().address.formatToString())
else secondaryServer.setText("")
}.show()
}
addUrlTextWatcher(primaryServerWrap, primaryServer, false)
addUrlTextWatcher(secondaryServerWrap, secondaryServer, true)
setHints()
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/dialog_horizontal_margin"
android:paddingRight="@dimen/dialog_horizontal_margin"
android:paddingTop="@dimen/dialog_vertical_margin"
android:paddingBottom="@dimen/dialog_vertical_margin"
android:layout_height="match_parent">
android:paddingRight="@dimen/dialog_horizontal_margin"
android:paddingBottom="@dimen/dialog_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:text="@string/tasker_action"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_height="wrap_content"/>
android:text="@string/tasker_action"
android:textStyle="bold" />
<Spinner
android:layout_width="wrap_content"
android:id="@+id/actionType"
android:layout_height="wrap_content"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/startConfigWrap"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:layout_height="wrap_content">
android:orientation="vertical">
<CheckBox
android:id="@+id/startIfRunning"
android:layout_width="wrap_content"
android:text="@string/tasker_start_if_running"
android:textColor="?android:attr/textColor"
android:layout_height="wrap_content"
android:checked="true"
android:id="@+id/startIfRunning"
android:layout_height="wrap_content"/>
android:text="@string/tasker_start_if_running"
android:textColor="?android:attr/textColor" />
<CheckBox
android:id="@+id/useCustomServer"
android:layout_width="wrap_content"
android:text="@string/tasker_use_custom_server"
android:textColor="?android:attr/textColor"
android:layout_height="wrap_content"
android:checked="false"
android:id="@+id/useCustomServer"
android:layout_height="wrap_content"/>
android:text="@string/tasker_use_custom_server"
android:textColor="?android:attr/textColor" />
<Spinner
android:layout_width="match_parent"
android:id="@+id/serverType"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_height="wrap_content"/>
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/serverConfigWrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:visibility="gone"
android:layout_height="wrap_content">
android:orientation="vertical"
android:visibility="gone">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/primaryServerWrap"
app:errorEnabled="true"
android:textColorHint="?android:attr/textColorSecondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_newserver_primaryserver"
android:layout_height="wrap_content">
android:textColorHint="?android:attr/textColorSecondary"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:id="@+id/primaryServer"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textUri"
android:nextFocusDown="@id/secondaryServer"
android:layout_height="wrap_content"/>
android:maxLines="1"
android:nextFocusDown="@id/secondaryServer" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/secondaryServerWrap"
app:errorEnabled="true"
android:textColorHint="?android:attr/textColorSecondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_newserver_secondaryserver"
android:layout_height="wrap_content">
android:textColorHint="?android:attr/textColorSecondary"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:id="@+id/secondaryServer"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textUri"
android:nextFocusUp="@id/primaryServer"
android:layout_height="wrap_content"/>
android:maxLines="1"
android:nextFocusUp="@id/primaryServer" />
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/selectServer"
android:background="@drawable/main_roundbuttons"
android:contentDescription="@string/contentdescription_main_servericon"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_main_server"
android:tint="?android:attr/textColor" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment