Commit 501cdd96 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Replaced MaterialEditText in the new server dialog with TextInputLayout

parent ec4edc8c
......@@ -16,13 +16,11 @@ import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatImageView
import com.frostnerd.lifecyclemanagement.BaseActivity
import com.frostnerd.materialedittext.MaterialEditText
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.canUseFingerprintAuthentication
import com.frostnerd.smokescreen.getPreferences
import com.frostnerd.smokescreen.service.Command
import com.frostnerd.smokescreen.service.DnsVpnService
import kotlinx.android.synthetic.main.dialog_pin.*
import kotlinx.android.synthetic.main.dialog_pin.view.*
import java.math.BigInteger
import java.security.MessageDigest
......
......@@ -21,6 +21,8 @@ import com.frostnerd.materialedittext.MaterialEditText
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.getPreferences
import com.frostnerd.smokescreen.log
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.dialog_new_server.*
import kotlinx.android.synthetic.main.dialog_new_server.view.*
......@@ -75,7 +77,19 @@ class NewServerDialog(
setOnShowListener {
addUrlTextWatcher(primaryServerWrap, primaryServer, false)
addUrlTextWatcher(secondaryServerWrap, secondaryServer, true)
serverName.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
serverNameWrap.error = if (s.isNullOrBlank()) context.getString(R.string.error_invalid_servername)
else null
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
})
serverNameWrap.error = context.getString(R.string.error_invalid_servername)
getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {
if (inputsValid()) {
val name = serverName.text.toString()
......@@ -120,11 +134,15 @@ class NewServerDialog(
if (dnsOverHttps) {
if(titleOverride == null) setTitle(R.string.dialog_newserver_title_https)
view.primaryServer.setHint(R.string.dialog_newserver_primaryserver_hint)
view.secondaryServer.setHint(R.string.dialog_newserver_secondaryserver_hint)
view.secondaryServer.apply {
if(isFocused || error != null) setHint(R.string.dialog_newserver_secondaryserver_hint)
}
}else {
if(titleOverride == null) setTitle(R.string.dialog_newserver_title_tls)
view.primaryServer.setHint(R.string.dialog_newserver_primaryserver_hint_dot)
view.secondaryServer.setHint(R.string.dialog_newserver_secondaryserver_hint_dot)
view.secondaryServer.apply {
if(isFocused || error != null) setHint(R.string.dialog_newserver_secondaryserver_hint_dot)
}
}
if(titleOverride != null) setTitle(titleOverride)
}
......@@ -250,7 +268,7 @@ class NewServerDialog(
else TLSUpstreamAddress(parsedHost)
}
fun addUrlTextWatcher(materialEditText: MaterialEditText, editText: EditText, emptyAllowed: Boolean) {
fun addUrlTextWatcher(input: TextInputLayout, editText: TextInputEditText, emptyAllowed: Boolean) {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
val valid =
......@@ -258,10 +276,9 @@ class NewServerDialog(
s.toString()
))
materialEditText.indicatorState = if (valid) {
if (s.isBlank()) MaterialEditText.IndicatorState.UNDEFINED
else MaterialEditText.IndicatorState.CORRECT
} else MaterialEditText.IndicatorState.INCORRECT
input.error = if (valid) {
null
} else context.getString(R.string.error_invalid_url)
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
......@@ -273,10 +290,9 @@ class NewServerDialog(
})
}
fun inputsValid(): Boolean = serverNameWrap.indicatorState != MaterialEditText.IndicatorState.INCORRECT &&
primaryServerWrap.indicatorState != MaterialEditText.IndicatorState.INCORRECT &&
secondaryServerWrap.indicatorState != MaterialEditText.IndicatorState.INCORRECT
fun inputsValid(): Boolean = serverNameWrap.error == null &&
primaryServerWrap.error == null &&
secondaryServerWrap.error == null
override fun destroy() {}
}
\ No newline at end of file
......@@ -13,7 +13,6 @@ import android.widget.EditText
import com.frostnerd.dnstunnelproxy.DnsServerInformation
import com.frostnerd.encrypteddnstunnelproxy.HttpsDnsServerInformation
import com.frostnerd.lifecyclemanagement.BaseActivity
import com.frostnerd.materialedittext.MaterialEditText
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.activity.BackgroundVpnConfigureActivity
import com.frostnerd.smokescreen.dialog.NewServerDialog
......@@ -23,7 +22,6 @@ import com.frostnerd.smokescreen.tlsServerFromHosts
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.activity_tasker_configure.*
import kotlinx.android.synthetic.main.dialog_new_server.view.*
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
......
......@@ -9,15 +9,14 @@
android:paddingBottom="@dimen/dialog_vertical_margin"
android:layout_height="match_parent">
<LinearLayout 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: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="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
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="wrap_content">
<Spinner
android:layout_width="match_parent"
......@@ -25,98 +24,66 @@
android:layout_marginBottom="12dp"
android:layout_height="wrap_content"/>
<com.frostnerd.materialedittext.MaterialEditText
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
app:labelColorPrimary="?attr/foregroundElementColor"
app:labelColorSecondary="?attr/foregroundElementColor"
android:layout_marginTop="8dp"
app:revealDelay="0"
app:revealType="revealInstant"
app:labelText="@string/dialog_newserver_name"
app:hint="@string/dialog_newserver_name_hint"
app:allowCollapse="false"
app:minCharLength="1"
app:maxCharLength="50"
app:indicatorState="incorrect"
app:animationDuration="0"
android:id="@+id/serverNameWrap"
app:errorEnabled="true"
android:hint="@string/dialog_newserver_name"
android:textColorHint="?attr/foregroundElementColor"
android:layout_marginTop="8dp"
app:openKeyboardOnFocus="true"
android:layout_height="wrap_content">
<EditText
android:id="@+id/serverName"
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/dialog_newserver_name_hint"
android:id="@+id/serverName"
android:inputType="text"
android:imeOptions="actionNext"
android:maxLines="1"
android:text=""
android:nextFocusDown="@id/secondaryServer"
android:importantForAutofill="no"
android:textColor="?attr/foregroundElementColor">
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<requestFocus/>
</EditText>
</com.frostnerd.materialedittext.MaterialEditText>
<com.frostnerd.materialedittext.MaterialEditText
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
app:labelColorPrimary="?attr/foregroundElementColor"
app:labelColorSecondary="?attr/foregroundElementColor"
android:layout_marginTop="8dp"
app:revealDelay="0"
app:revealType="revealInstant"
app:minCharLength="1"
app:labelText="@string/dialog_newserver_primaryserver"
app:hint="@string/dialog_newserver_primaryserver_hint"
app:allowCollapse="false"
app:animationDuration="0"
app:indicatorState="incorrect"
android:id="@+id/primaryServerWrap"
app:errorEnabled="true"
android:hint="@string/dialog_newserver_primaryserver"
android:textColorHint="?attr/foregroundElementColor"
android:layout_marginTop="8dp"
app:openKeyboardOnFocus="true"
android:layout_height="wrap_content">
<EditText
android:id="@+id/primaryServer"
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/dialog_newserver_name_hint"
android:id="@+id/primaryServer"
android:inputType="text"
android:imeOptions="actionNext"
android:maxLines="1"
android:text=""
android:nextFocusDown="@id/secondaryServer"
android:importantForAutofill="no"
android:textColor="?attr/foregroundElementColor">
</EditText>
</com.frostnerd.materialedittext.MaterialEditText>
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.frostnerd.materialedittext.MaterialEditText
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
app:labelColorPrimary="?attr/foregroundElementColor"
app:labelColorSecondary="?attr/foregroundElementColor"
app:revealDelay="0"
android:layout_marginTop="8dp"
app:revealType="revealInstant"
app:labelText="@string/dialog_newserver_secondaryserver"
app:hint="@string/dialog_newserver_secondaryserver_hint"
android:id="@+id/secondaryServerWrap"
app:allowCollapse="false"
app:animationDuration="0"
app:errorEnabled="true"
android:hint="@string/dialog_newserver_secondaryserver"
android:textColorHint="?attr/foregroundElementColor"
android:layout_marginTop="8dp"
app:openKeyboardOnFocus="true"
android:layout_height="wrap_content">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:nextFocusUp="@id/primaryServer"
android:id="@+id/secondaryServer"
android:inputType="text"
android:imeOptions="actionNext"
android:maxLines="1"
android:id="@+id/secondaryServer"
android:text=""
android:importantForAutofill="no"
android:textColor="?attr/foregroundElementColor">
</EditText>
</com.frostnerd.materialedittext.MaterialEditText>
android:nextFocusDown="@id/primaryServer"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>
......@@ -21,6 +21,7 @@
<string name="error_invalid_url">Please provide a valid url.</string>
<string name="error_invalid_pin">Please provide your PIN.</string>
<string name="error_invalid_servername">Please provide a name.</string>
<string name="main_dnssurveillance_infotext">Be aware that the DNS server you are connected to is able to record which sites you are visiting. Check the respective privacy statements for more information.</string>
<string name="main_dnssurveillance_privacystatement">Privacy statement of %1s</string>
......
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