Update: Repository Textfields improved

Improve: Top app-bar theme changes
This commit is contained in:
LooKeR 2021-10-20 17:06:15 +05:30
parent 15254243da
commit 662ae07d1d
8 changed files with 73 additions and 175 deletions

View File

@ -16,7 +16,6 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -62,13 +61,9 @@ class EditRepositoryFragment() : ScreenFragment() {
private class Layout(view: View) { private class Layout(view: View) {
val address = view.findViewById<EditText>(R.id.address)!! val address = view.findViewById<EditText>(R.id.address)!!
val addressMirror = view.findViewById<View>(R.id.address_mirror)!! val addressMirror = view.findViewById<View>(R.id.address_mirror)!!
val addressError = view.findViewById<TextView>(R.id.address_error)!!
val fingerprint = view.findViewById<EditText>(R.id.fingerprint)!! val fingerprint = view.findViewById<EditText>(R.id.fingerprint)!!
val fingerprintError = view.findViewById<TextView>(R.id.fingerprint_error)!!
val username = view.findViewById<EditText>(R.id.username)!! val username = view.findViewById<EditText>(R.id.username)!!
val usernameError = view.findViewById<TextView>(R.id.username_error)!!
val password = view.findViewById<EditText>(R.id.password)!! val password = view.findViewById<EditText>(R.id.password)!!
val passwordError = view.findViewById<TextView>(R.id.password_error)!!
val overlay = view.findViewById<View>(R.id.overlay)!! val overlay = view.findViewById<View>(R.id.overlay)!!
val skip = view.findViewById<View>(R.id.skip)!! val skip = view.findViewById<View>(R.id.skip)!!
} }
@ -269,6 +264,10 @@ class EditRepositoryFragment() : ScreenFragment() {
.map { it.withoutKnownPath }.toSet() .map { it.withoutKnownPath }.toSet()
invalidateAddress() invalidateAddress()
} }
invalidateAddress()
invalidateFingerprint()
invalidateUsernamePassword()
} }
override fun onDestroyView() { override fun onDestroyView() {
@ -284,14 +283,6 @@ class EditRepositoryFragment() : ScreenFragment() {
checkDisposable = null checkDisposable = null
} }
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
invalidateAddress()
invalidateFingerprint()
invalidateUsernamePassword()
}
private var addressError = false private var addressError = false
private var fingerprintError = false private var fingerprintError = false
private var usernamePasswordError = false private var usernamePasswordError = false
@ -312,12 +303,8 @@ class EditRepositoryFragment() : ScreenFragment() {
} else { } else {
R.string.invalid_address R.string.invalid_address
} }
layout.address.setError(addressErrorResId != null)
layout.addressError.visibility = if (addressErrorResId != null) View.VISIBLE else View.GONE
if (addressErrorResId != null) {
layout.addressError.setText(addressErrorResId)
}
addressError = addressErrorResId != null addressError = addressErrorResId != null
addressErrorResId?.let { layout.address.error = getString(it) }
invalidateState() invalidateState()
} }
@ -325,11 +312,6 @@ class EditRepositoryFragment() : ScreenFragment() {
val layout = layout!! val layout = layout!!
val fingerprint = layout.fingerprint.text.toString().replace(" ", "") val fingerprint = layout.fingerprint.text.toString().replace(" ", "")
val fingerprintInvalid = fingerprint.isNotEmpty() && fingerprint.length != 64 val fingerprintInvalid = fingerprint.isNotEmpty() && fingerprint.length != 64
layout.fingerprintError.visibility = if (fingerprintInvalid) View.VISIBLE else View.GONE
if (fingerprintInvalid) {
layout.fingerprintError.setText(R.string.invalid_fingerprint_format)
}
layout.fingerprint.setError(fingerprintInvalid)
fingerprintError = fingerprintInvalid fingerprintError = fingerprintInvalid
invalidateState() invalidateState()
} }
@ -341,19 +323,6 @@ class EditRepositoryFragment() : ScreenFragment() {
val usernameInvalid = username.contains(':') val usernameInvalid = username.contains(':')
val usernameEmpty = username.isEmpty() && password.isNotEmpty() val usernameEmpty = username.isEmpty() && password.isNotEmpty()
val passwordEmpty = username.isNotEmpty() && password.isEmpty() val passwordEmpty = username.isNotEmpty() && password.isEmpty()
layout.usernameError.visibility =
if (usernameInvalid || usernameEmpty) View.VISIBLE else View.GONE
layout.passwordError.visibility = if (passwordEmpty) View.VISIBLE else View.GONE
if (usernameInvalid) {
layout.usernameError.setText(R.string.invalid_username_format)
} else if (usernameEmpty) {
layout.usernameError.setText(R.string.username_missing)
}
layout.username.setError(usernameEmpty)
if (passwordEmpty) {
layout.passwordError.setText(R.string.password_missing)
}
layout.password.setError(passwordEmpty)
usernamePasswordError = usernameInvalid || usernameEmpty || passwordEmpty usernamePasswordError = usernameInvalid || usernameEmpty || passwordEmpty
invalidateState() invalidateState()
} }
@ -417,11 +386,6 @@ class EditRepositoryFragment() : ScreenFragment() {
layout?.address?.setText(address) layout?.address?.setText(address)
} }
private fun EditText.setError(error: Boolean) {
val drawable = background.mutate()
drawable.colorFilter = if (error) errorColorFilter else null
}
private fun onSaveRepositoryClick(check: Boolean) { private fun onSaveRepositoryClick(check: Boolean) {
if (checkDisposable == null) { if (checkDisposable == null) {
val layout = layout!! val layout = layout!!
@ -475,7 +439,7 @@ class EditRepositoryFragment() : ScreenFragment() {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { result, throwable -> .subscribe { result, throwable ->
checkDisposable = null checkDisposable = null
throwable?.printStackTrace() throwable.printStackTrace()
val resultAddress = val resultAddress =
result?.let { if (it.isEmpty()) null else it } ?: address result?.let { if (it.isEmpty()) null else it } ?: address
val allow = resultAddress == address || run { val allow = resultAddress == address || run {

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.7" android:color="?android:attr/textColorSecondary" android:state_selected="false" />
<item android:color="?android:attr/textColorPrimary" android:state_selected="true" />
</selector>

View File

@ -15,36 +15,25 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingStart="12dp" android:paddingHorizontal="12dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingEnd="12dp"
android:paddingBottom="12dp"> android:paddingBottom="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="-12dp"
android:text="@string/address"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<EditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/address"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="https://" android:hint="@string/address"
android:inputType="textUri" android:paddingVertical="12dp">
android:paddingTop="16dp"
android:paddingBottom="16dp" <com.google.android.material.textfield.TextInputEditText
android:textSize="16sp" android:id="@+id/address"
tools:ignore="Autofill,HardcodedText" /> android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/address_mirror" android:id="@+id/address_mirror"
@ -61,120 +50,41 @@
</FrameLayout> </FrameLayout>
<TextView <com.google.android.material.textfield.TextInputLayout
android:id="@+id/address_error"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:hint="@string/fingerprint"
android:layout_marginTop="-2dp" android:paddingVertical="12dp">
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
android:visibility="gone" />
<TextView <com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="-12dp"
android:text="@string/fingerprint"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
<EditText
android:id="@+id/fingerprint" android:id="@+id/fingerprint"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent" />
android:fontFamily="monospace" </com.google.android.material.textfield.TextInputLayout>
android:gravity="top"
android:inputType="textNoSuggestions|textMultiLine"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="16sp"
tools:ignore="Autofill,LabelFor" />
<TextView <com.google.android.material.textfield.TextInputLayout
android:id="@+id/fingerprint_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="-2dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="-12dp"
android:text="@string/username"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/username" android:hint="@string/username"
android:inputType="textNoSuggestions" android:paddingVertical="12dp">
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="16sp"
tools:ignore="Autofill,LabelFor" />
<TextView <com.google.android.material.textfield.TextInputEditText
android:id="@+id/username_error" android:id="@+id/username"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent" />
android:layout_marginStart="4dp" </com.google.android.material.textfield.TextInputLayout>
android:layout_marginTop="-2dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
android:visibility="gone" />
<TextView <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="-12dp"
android:text="@string/password"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/password" android:hint="@string/password"
android:inputType="textPassword" android:paddingVertical="12dp">
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="16sp"
tools:ignore="Autofill,LabelFor" />
<TextView <com.google.android.material.textfield.TextInputEditText
android:id="@+id/password_error" android:id="@+id/password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent" />
android:layout_marginStart="4dp" </com.google.android.material.textfield.TextInputLayout>
android:layout_marginTop="-2dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout> </LinearLayout>

View File

@ -10,15 +10,15 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/colorBackground" android:background="?android:attr/colorBackground"
android:elevation="0dp" android:elevation="0dp"
android:paddingHorizontal="10dp" android:orientation="vertical"
android:orientation="vertical"> android:paddingHorizontal="10dp">
<com.looker.droidify.widget.Toolbar <com.looker.droidify.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="?attr/colorPrimarySurface" android:background="@drawable/background_border"
android:background="@drawable/background_border" /> android:backgroundTint="?attr/colorPrimarySurface" />
<FrameLayout <FrameLayout
android:id="@+id/toolbar_extra" android:id="@+id/toolbar_extra"

View File

@ -7,9 +7,9 @@
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:orientation="horizontal" android:orientation="horizontal"
app:cardBackgroundColor="?android:attr/colorBackground" app:cardBackgroundColor="?android:attr/colorBackground"
app:cardCornerRadius="@dimen/shape_medium_corner"
app:cardElevation="0dp" app:cardElevation="0dp"
app:strokeColor="@null" app:strokeColor="@null"
app:cardCornerRadius="@dimen/shape_medium_corner"
app:strokeWidth="0dp"> app:strokeWidth="0dp">
<LinearLayout <LinearLayout

View File

@ -3,16 +3,15 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="?attr/colorPrimarySurface"
android:background="@drawable/background_border" android:background="@drawable/background_border"
android:backgroundTint="?attr/colorPrimarySurface"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tabs" android:id="@+id/tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/bg_item_rounded_ripple" android:background="@drawable/bg_item_rounded_ripple" />
android:orientation="horizontal" />
<FrameLayout <FrameLayout
android:id="@+id/section_layout" android:id="@+id/section_layout"

View File

@ -4,6 +4,7 @@
<color name="green100">#A3EBB7</color> <color name="green100">#A3EBB7</color>
<color name="green200">#6EC898</color> <color name="green200">#6EC898</color>
<color name="green300">#51DF93</color> <color name="green300">#51DF93</color>
<color name="green900">#1B5E20</color>
<color name="red200">#EF9A9A</color> <color name="red200">#EF9A9A</color>
<color name="red300">#EF8A8A</color> <color name="red300">#EF8A8A</color>

View File

@ -13,16 +13,17 @@
<item name="toolbarStyle">@style/Widget.Main.Toolbar</item> <item name="toolbarStyle">@style/Widget.Main.Toolbar</item>
<item name="android:colorBackground">@color/white</item> <item name="android:colorBackground">@color/white</item>
<item name="colorOnBackground">@color/grey_dark</item> <item name="colorOnBackground">@color/grey_dark</item>
<item name="colorPrimarySurface">@color/green50</item>
<item name="android:colorAccent">@color/accent_light</item> <item name="android:colorAccent">@color/accent_light</item>
<item name="colorError">@color/error_light</item> <item name="colorError">@color/error_light</item>
<item name="android:textColorPrimary">@color/green200</item>
<item name="android:textColor">@color/black</item> <item name="android:textColor">@color/black</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:fastScrollThumbDrawable">@drawable/scrollbar_thumb</item> <item name="android:fastScrollThumbDrawable">@drawable/scrollbar_thumb</item>
<item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item> <item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item> <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="switchStyle">@style/Theme.Switch</item> <item name="switchStyle">@style/Theme.Switch</item>
<item name="materialAlertDialogTheme">@style/Theme.Alert</item> <item name="materialAlertDialogTheme">@style/Theme.Alert</item>
<item name="tabStyle">@style/Theme.Tab</item>
<item name="textInputStyle">@style/Theme.EditText</item>
<item name="android:statusBarColor">@color/white</item> <item name="android:statusBarColor">@color/white</item>
<item name="android:navigationBarColor">@android:color/transparent</item> <item name="android:navigationBarColor">@android:color/transparent</item>
</style> </style>
@ -35,7 +36,6 @@
<item name="toolbarStyle">@style/Widget.Main.Toolbar</item> <item name="toolbarStyle">@style/Widget.Main.Toolbar</item>
<item name="android:colorBackground">@color/black</item> <item name="android:colorBackground">@color/black</item>
<item name="colorOnBackground">@color/green200</item> <item name="colorOnBackground">@color/green200</item>
<item name="colorPrimarySurface">@color/grey_dark</item>
<item name="android:colorAccent">@color/accent_dark</item> <item name="android:colorAccent">@color/accent_dark</item>
<item name="colorError">@color/error_dark</item> <item name="colorError">@color/error_dark</item>
<item name="android:textColorPrimary">@color/green200</item> <item name="android:textColorPrimary">@color/green200</item>
@ -44,6 +44,8 @@
<item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item> <item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item>
<item name="switchStyle">@style/Theme.Switch</item> <item name="switchStyle">@style/Theme.Switch</item>
<item name="materialAlertDialogTheme">@style/Theme.Alert</item> <item name="materialAlertDialogTheme">@style/Theme.Alert</item>
<item name="tabStyle">@style/Theme.Tab</item>
<item name="textInputStyle">@style/Theme.EditText</item>
<item name="android:statusBarColor">@color/black</item> <item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@android:color/transparent</item> <item name="android:navigationBarColor">@android:color/transparent</item>
</style> </style>
@ -64,6 +66,8 @@
<item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item> <item name="android:fastScrollTrackDrawable">@drawable/scrollbar_track</item>
<item name="switchStyle">@style/Theme.Switch</item> <item name="switchStyle">@style/Theme.Switch</item>
<item name="materialAlertDialogTheme">@style/Theme.Alert</item> <item name="materialAlertDialogTheme">@style/Theme.Alert</item>
<item name="tabStyle">@style/Theme.Tab</item>
<item name="textInputStyle">@style/Theme.EditText</item>
<item name="android:statusBarColor">@color/pitch_black</item> <item name="android:statusBarColor">@color/pitch_black</item>
<item name="android:navigationBarColor">@android:color/transparent</item> <item name="android:navigationBarColor">@android:color/transparent</item>
</style> </style>
@ -77,12 +81,26 @@
</item> </item>
</style> </style>
<style name="Theme.Tab" parent="Widget.Material3.TabLayout">
<item name="tabTextColor">@color/tab_text_color</item>
<item name="tabIndicatorColor">?android:attr/textColorPrimary</item>
</style>
<style name="Theme.Alert" parent="ThemeOverlay.Material3.MaterialAlertDialog.Centered"> <style name="Theme.Alert" parent="ThemeOverlay.Material3.MaterialAlertDialog.Centered">
<item name="colorPrimary">?attr/colorOnSurface</item> <item name="colorPrimary">?attr/colorOnSurface</item>
<item name="android:dialogCornerRadius" tools:targetApi="p">@dimen/shape_large_corner</item>
<item name="android:backgroundTint">?attr/colorSurface</item> <item name="android:backgroundTint">?attr/colorSurface</item>
<item name="colorOnSurfaceVariant">?attr/colorOnSurface</item> <item name="colorOnSurfaceVariant">?attr/colorOnSurface</item>
</style> </style>
<style name="Theme.EditText" parent="Widget.Material3.TextInputLayout.FilledBox">
<item name="boxBackgroundColor">?attr/colorSurface</item>
<item name="boxStrokeColor">?attr/colorPrimary</item>
<item name="boxStrokeWidth">2dp</item>
<item name="hintTextColor">?attr/colorPrimary</item>
<item name="android:textColorHint">?attr/colorPrimary</item>
</style>
<style name="Theme.Progress" parent="Widget.Material3.LinearProgressIndicator"> <style name="Theme.Progress" parent="Widget.Material3.LinearProgressIndicator">
<item name="trackColor">?attr/colorSurface</item> <item name="trackColor">?attr/colorSurface</item>
<item name="trackThickness">8dp</item> <item name="trackThickness">8dp</item>