Fix crash on illegal characters in URL. Fixed caret and error color on login form.

This commit is contained in:
Antoine POPINEAU 2019-10-23 22:05:56 +02:00
parent 0fa0b5d212
commit 2d5e73dcd4
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
4 changed files with 36 additions and 30 deletions

View File

@ -49,8 +49,6 @@ class LoginActivity : AppCompatActivity() {
else e.message else e.message
hostname_field.error = message hostname_field.error = message
return@setOnClickListener
} }
hostname_field.error = "" hostname_field.error = ""
@ -65,27 +63,37 @@ class LoginActivity : AppCompatActivity() {
} }
GlobalScope.launch(Main) { GlobalScope.launch(Main) {
val result = Fuel.post("$hostname/api/v1/token", body) try {
.awaitObjectResult(gsonDeserializerOf(FwCredentials::class.java)) val result = Fuel.post("$hostname/api/v1/token", body)
.awaitObjectResult(gsonDeserializerOf(FwCredentials::class.java))
result.fold( result.fold(
{ data -> { data ->
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply { PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply {
setString("hostname", hostname) setString("hostname", hostname)
setString("username", username) setString("username", username)
setString("password", password) setString("password", password)
setString("access_token", data.token) setString("access_token", data.token)
}
dialog.dismiss()
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
},
{ error ->
dialog.dismiss()
hostname_field.error = error.localizedMessage
} }
)
} catch (e: Exception) {
dialog.dismiss()
dialog.dismiss() val message =
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) if (e.message?.isEmpty() == true) getString(R.string.login_error_hostname)
}, else e.message
{ error ->
dialog.dismiss()
hostname_field.error = error.localizedMessage hostname_field.error = message
} }
)
} }
} }
} }

View File

@ -33,7 +33,6 @@
android:hint="@string/login_hostname" android:hint="@string/login_hostname"
android:textColorHint="@drawable/login_input" android:textColorHint="@drawable/login_input"
app:boxStrokeColor="@drawable/login_input" app:boxStrokeColor="@drawable/login_input"
app:errorTextAppearance="@style/AppTheme.ErrorStyle"
app:hintTextColor="@drawable/login_input"> app:hintTextColor="@drawable/login_input">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -42,7 +41,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textUri" android:inputType="textUri"
android:lines="1" android:lines="1"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:textCursorDrawable="@null" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -55,7 +55,6 @@
android:hint="@string/login_username" android:hint="@string/login_username"
android:textColorHint="@drawable/login_input" android:textColorHint="@drawable/login_input"
app:boxStrokeColor="@drawable/login_input" app:boxStrokeColor="@drawable/login_input"
app:errorTextAppearance="@style/AppTheme.ErrorStyle"
app:hintTextColor="@drawable/login_input"> app:hintTextColor="@drawable/login_input">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -64,7 +63,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textEmailAddress" android:inputType="textEmailAddress"
android:lines="1" android:lines="1"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:textCursorDrawable="@null" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -77,7 +77,6 @@
android:hint="@string/login_password" android:hint="@string/login_password"
android:textColorHint="@drawable/login_input" android:textColorHint="@drawable/login_input"
app:boxStrokeColor="@drawable/login_input" app:boxStrokeColor="@drawable/login_input"
app:errorTextAppearance="@style/AppTheme.ErrorStyle"
app:hintTextColor="@drawable/login_input" app:hintTextColor="@drawable/login_input"
app:passwordToggleEnabled="true"> app:passwordToggleEnabled="true">
@ -87,7 +86,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" android:inputType="textPassword"
android:lines="1" android:lines="1"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:textCursorDrawable="@null" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View File

@ -6,7 +6,7 @@
<color name="colorPrimary">#327eae</color> <color name="colorPrimary">#327eae</color>
<color name="colorPrimaryDark">#3d3e40</color> <color name="colorPrimaryDark">#3d3e40</color>
<color name="colorAccent">#d35400</color> <color name="colorAccent">#d35400</color>
<color name="colorError">#b94705</color> <color name="colorError">#fdcfbb</color>
<color name="colorSelected">#dadada</color> <color name="colorSelected">#dadada</color>
<color name="colorFavorite">#e17055</color> <color name="colorFavorite">#e17055</color>

View File

@ -11,6 +11,8 @@
<item name="materialButtonStyle">@style/AppTheme.ButtonStyle</item> <item name="materialButtonStyle">@style/AppTheme.ButtonStyle</item>
<item name="preferenceTheme">@style/AppTheme.Preference</item> <item name="preferenceTheme">@style/AppTheme.Preference</item>
<item name="colorError">@color/colorError</item>
</style> </style>
<style name="AppTheme.Fragment"> <style name="AppTheme.Fragment">
@ -76,8 +78,4 @@
<item name="android:background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>
</style> </style>
<style name="AppTheme.ErrorStyle" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/colorError</item>
</style>
</resources> </resources>