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

Replaced MaterialEditText in the configure activity with TextInputLayout

parent 6b592ce9
......@@ -64,7 +64,7 @@ class NewHostSourceDialog (context: Context,
nameTil.error = null
}
if(url.text.isNullOrBlank() || !URLUtil.isValidUrl(url.text.toString())) {
urlTil.error = context.getString(R.string.dialog_newhostsource_url_invalid)
urlTil.error = context.getString(R.string.error_invalid_url)
valid = false
} else {
urlTil.error = null
......
......@@ -20,6 +20,8 @@ import com.frostnerd.smokescreen.dialog.NewServerDialog
import com.frostnerd.smokescreen.fromServerUrls
import com.frostnerd.smokescreen.hasHttpsServer
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.*
......@@ -104,6 +106,7 @@ class ConfigureActivity : BaseActivity() {
}
}
}
setHints()
}
}
}
......@@ -155,28 +158,35 @@ class ConfigureActivity : BaseActivity() {
validationRegex = if (position == 0) NewServerDialog.SERVER_URL_REGEX else NewServerDialog.TLS_REGEX
primaryServer.text = primaryServer.text
secondaryServer.text = secondaryServer.text
if(position == 1) {
primaryServer.setHint(R.string.dialog_newserver_primaryserver_hint)
secondaryServer.setHint(R.string.dialog_newserver_secondaryserver_hint)
} else {
primaryServer.setHint(R.string.dialog_newserver_primaryserver_hint_dot)
secondaryServer.setHint(R.string.dialog_newserver_secondaryserver_hint_dot)
}
setHints()
}
}
addUrlTextWatcher(primaryServerWrap, primaryServer, false)
addUrlTextWatcher(secondaryServerWrap, secondaryServer, true)
setHints()
}
private fun addUrlTextWatcher(materialEditText: MaterialEditText, editText: EditText, emptyAllowed: Boolean) {
private fun setHints() {
val doh = serverType.selectedItemPosition == 0
println("DOH: $doh")
primaryServer.hint = if(primaryServer.hasFocus() || primaryServerWrap.error != null) {
if(doh) getString(R.string.dialog_newserver_primaryserver_hint)
else getString(R.string.dialog_newserver_primaryserver_hint_dot)
} else null
secondaryServer.hint = if(secondaryServer.hasFocus()) {
if(doh) getString(R.string.dialog_newserver_secondaryserver_hint)
else getString(R.string.dialog_newserver_secondaryserver_hint_dot)
} else null
}
private fun addUrlTextWatcher(input: TextInputLayout, editText: TextInputEditText, emptyAllowed: Boolean) {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
val valid = (emptyAllowed && s.isBlank()) || validationRegex.matches(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 getString(R.string.error_invalid_url)
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
......@@ -186,6 +196,9 @@ class ConfigureActivity : BaseActivity() {
}
})
editText.setOnFocusChangeListener { _, hasFocus ->
setHints()
}
}
override fun onBackPressed() {
......@@ -206,8 +219,8 @@ class ConfigureActivity : BaseActivity() {
if (action == "start") {
settings.putBoolean(TaskerHelper.DATA_KEY_STARTIFRUNNING, startIfRunning.isChecked)
if (!useServersFromConfig.isChecked) {
if (primaryServerWrap.indicatorState != MaterialEditText.IndicatorState.INCORRECT &&
secondaryServerWrap.indicatorState != MaterialEditText.IndicatorState.INCORRECT
if (primaryServerWrap.error == null &&
secondaryServerWrap.error == null
) {
var primary = primaryServer.text.toString()
var secondary = if (secondaryServer.text.isNullOrBlank()) null else secondaryServer.text.toString()
......
......@@ -70,63 +70,42 @@
android:visibility="gone"
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"
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:textColorHint="?android:attr/textColorSecondary"
android:hint="@string/dialog_newserver_primaryserver"
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:inputType="text"
android:id="@+id/primaryServer"
android:maxLines="1"
android:text=""
android:imeOptions="actionNext"
android:inputType="textUri"
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:textColorHint="?android:attr/textColorSecondary"
android:hint="@string/dialog_newserver_secondaryserver"
android:layout_height="wrap_content">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/secondaryServer"
android:maxLines="1"
android:imeOptions="actionNext"
android:inputType="textUri"
android:nextFocusUp="@id/primaryServer"
android:inputType="text"
android:maxLines="1"
android:id="@+id/secondaryServer"
android:text=""
android:importantForAutofill="no"
android:textColor="?attr/foregroundElementColor">
</EditText>
</com.frostnerd.materialedittext.MaterialEditText>
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
......
......@@ -124,7 +124,6 @@
<string name="dialog_newhostsource_name">Name</string>
<string name="dialog_newhostsource_url">URL</string>
<string name="dialog_newhostsource_error_name_empty">Bitte gebe einen Namen an.</string>
<string name="dialog_newhostsource_url_invalid">Bitte gebe eine valide URL an.</string>
<string name="dialog_newdnsrule_title">Neue Dns Regel</string>
<string name="dialog_newdnsrule_hint_host">Host</string>
......
......@@ -16,6 +16,8 @@
<string name="open_app">App öffnen</string>
<string name="all_close">Schließen</string>
<string name="error_invalid_url">Bitte gebe eine valide URL an.</string>
<string name="main_dnssurveillance_infotext">Bitte behalte im Hinterkopf, dass der DNS Server, mit welchem du verbunden bist, sehen kann, welche Webseiten zu besuchst. Überprüfe die Datenschutzerklärung des Servers für mehr Informationen.</string>
<string name="main_dnssurveillance_privacystatement">Datenschutzerklärung von %1s</string>
......
......@@ -125,7 +125,6 @@
<string name="dialog_newhostsource_name">Naam</string>
<string name="dialog_newhostsource_url">URL</string>
<string name="dialog_newhostsource_error_name_empty">Geef a.u.b een naam op.</string>
<string name="dialog_newhostsource_url_invalid">Geef a.u.b een geldige URL op.</string>
<string name="dialog_newdnsrule_title">Nieuwe Dns regel</string>
<string name="dialog_newdnsrule_hint_host">Host</string>
......
......@@ -13,6 +13,8 @@
<string name="open_app">Open app</string>
<string name="all_close">Sluit</string>
<string name="error_invalid_url">Geef a.u.b een geldige URL op.</string>
<string name="main_dnssurveillance_privacystatement">Privacyverklaring van %1s</string>
<string name="quicksettings_stop_text">Stop Nebulo</string>
......
......@@ -122,7 +122,6 @@
<string name="dialog_newhostsource_url">URL</string>
<string name="dialog_newhostsource_choose_file">Choose file</string>
<string name="dialog_newhostsource_error_name_empty">Please provide a name.</string>
<string name="dialog_newhostsource_url_invalid">Please provide a valid url.</string>
<string name="dialog_newdnsrule_title">New Dns rule</string>
<string name="dialog_newdnsrule_hint_host">Host</string>
......
......@@ -19,6 +19,8 @@
<string name="open_app">Open app</string>
<string name="all_close">Close</string>
<string name="error_invalid_url">Please provide a valid url.</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