Browse Source

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

housekeeping/remove-warnings
Antoine POPINEAU 5 years ago
parent
commit
2d5e73dcd4
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 48
      app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt
  2. 12
      app/src/main/res/layout/activity_login.xml
  3. 2
      app/src/main/res/values/colors.xml
  4. 6
      app/src/main/res/values/styles.xml

48
app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt

@ -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(
{ data -> result.fold(
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply { { data ->
setString("hostname", hostname) PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply {
setString("username", username) setString("hostname", hostname)
setString("password", password) setString("username", username)
setString("access_token", data.token) setString("password", password)
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
} }
)
} }
} }
} }

12
app/src/main/res/layout/activity_login.xml

@ -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>

2
app/src/main/res/values/colors.xml

@ -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>

6
app/src/main/res/values/styles.xml

@ -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>

Loading…
Cancel
Save