mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-09 22:08:44 +00:00
center login btn, set login btn selectors
This commit is contained in:
parent
de270a9171
commit
3aff147a77
6 changed files with 60 additions and 4 deletions
|
|
@ -0,0 +1,34 @@
|
|||
package com.habitrpg.common.habitica.extensions
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
|
||||
class OnChangeTextWatcher(private var function: (CharSequence?, Int, Int, Int) -> Unit) : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable?) { /* no-on */ }
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { /* no-on */ }
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
function(s, start, before, count)
|
||||
}
|
||||
}
|
||||
|
||||
class BeforeChangeTextWatcher(private var function: (CharSequence?, Int, Int, Int) -> Unit) : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable?) { /* no-on */ }
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
function(s, start, count, after)
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { /* no-on */ }
|
||||
}
|
||||
|
||||
class AfterChangeTextWatcher(private var function: (Editable?) -> Unit) : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
function(s)
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { /* no-on */ }
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { /* no-on */ }
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import androidx.core.view.isVisible
|
|||
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.ActivityLoginBinding
|
||||
import com.habitrpg.common.habitica.extensions.OnChangeTextWatcher
|
||||
import com.habitrpg.wearos.habitica.ui.viewmodels.LoginViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
|
|
@ -81,6 +82,12 @@ class LoginActivity: BaseActivity<ActivityLoginBinding, LoginViewModel>() {
|
|||
binding.registerButton.setOnClickListener { openRegisterOnPhone() }
|
||||
|
||||
binding.passwordEditText.transformationMethod = PasswordTransformationMethod()
|
||||
binding.usernameEditText.addTextChangedListener(OnChangeTextWatcher { _, _, _, _ ->
|
||||
setLoginButtonIsEnabled()
|
||||
})
|
||||
binding.passwordEditText.addTextChangedListener(OnChangeTextWatcher { _, _, _, _ ->
|
||||
setLoginButtonIsEnabled()
|
||||
})
|
||||
|
||||
currentState = State.INITIAL
|
||||
}
|
||||
|
|
@ -116,6 +123,10 @@ class LoginActivity: BaseActivity<ActivityLoginBinding, LoginViewModel>() {
|
|||
alert.show()
|
||||
}
|
||||
|
||||
private fun setLoginButtonIsEnabled() {
|
||||
binding.loginButton.isEnabled = binding.usernameEditText.text.isNotEmpty() && binding.passwordEditText.text.isNotEmpty()
|
||||
}
|
||||
|
||||
private val pickAccountResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
|
||||
viewModel.handleGoogleLoginResult(this, task, recoverFromPlayServicesErrorResult)
|
||||
|
|
|
|||
5
wearos/src/main/res/drawable/button_state_color.xml
Normal file
5
wearos/src/main/res/drawable/button_state_color.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="true" android:color="@color/watch_purple_100" />
|
||||
<item android:state_enabled="false" android:color="@color/gray_5" />
|
||||
</selector>
|
||||
5
wearos/src/main/res/drawable/button_text_state_color.xml
Normal file
5
wearos/src/main/res/drawable/button_text_state_color.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="true" android:color="@color/black" />
|
||||
<item android:state_enabled="false" android:color="@color/gray_200" />
|
||||
</selector>
|
||||
|
|
@ -78,7 +78,6 @@
|
|||
android:id="@+id/username_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp"
|
||||
android:textColorHint="@color/gray_200"
|
||||
android:inputType="textEmailAddress"
|
||||
android:hint="@string/email_username"
|
||||
android:paddingHorizontal="16dp"
|
||||
|
|
@ -90,7 +89,6 @@
|
|||
<EditText
|
||||
android:id="@+id/password_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:textColorHint="@color/gray_200"
|
||||
android:layout_height="52dp"
|
||||
android:hint="@string/password"
|
||||
android:background="@drawable/row_background_outline"
|
||||
|
|
@ -104,6 +102,9 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sign_in"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:enabled="false"
|
||||
android:textAlignment="center"
|
||||
style="@style/ChipButton.Purple"/>
|
||||
</LinearLayout>
|
||||
</com.habitrpg.wearos.habitica.ui.views.HabiticaScrollView>
|
||||
|
|
@ -39,8 +39,8 @@
|
|||
</style>
|
||||
|
||||
<style name="ChipButton.Purple" parent="ChipButton">
|
||||
<item name="android:backgroundTint">@color/watch_purple_100</item>
|
||||
<item name="android:textColor">@color/black</item>
|
||||
<item name="android:backgroundTint">@drawable/button_state_color</item>
|
||||
<item name="android:textColor">@drawable/button_text_state_color</item>
|
||||
</style>
|
||||
|
||||
<style name="ChipButton.Red" parent="ChipButton">
|
||||
|
|
|
|||
Loading…
Reference in a new issue