git add viewmodel
This commit is contained in:
parent
ab9d5ce37b
commit
fbe57b265f
@ -4,7 +4,7 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2024-10-21T12:15:47.573416700Z">
|
<DropdownSelection timestamp="2024-10-23T13:44:51.378268100Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\adm\.android\avd\Medium_Phone_API_35.avd" />
|
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\adm\.android\avd\Medium_Phone_API_35.avd" />
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package com.example.autorization.ui.fragments
|
|
||||||
|
|
||||||
import android.graphics.Typeface
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.text.InputType
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.CheckBox
|
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.RadioButton
|
|
||||||
import android.widget.Toast
|
|
||||||
import com.example.autorization.R
|
|
||||||
|
|
||||||
class SignUpScreen : Fragment(R.layout.fragment_sign_up_screen) {
|
|
||||||
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
val radioCheck = view.findViewById<CheckBox>(R.id.TarmsAndPolicyRadioButton)
|
|
||||||
val passwordEditText = view.findViewById<EditText>(R.id.PasswordEditText)
|
|
||||||
var passwordIsVisible = false
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.example.autorization.ui.fragments.signup
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.InputType
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.core.widget.doOnTextChanged
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import com.example.autorization.R
|
||||||
|
|
||||||
|
class SignUpScreen : Fragment(R.layout.fragment_sign_up_screen) {
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
val viewModel by viewModels<SignUpViewModel> ()
|
||||||
|
val passwordEditText = view.findViewById<EditText>(R.id.PasswordEditText)
|
||||||
|
val termsCheckBox = view.findViewById<CheckBox>(R.id.TarmsAndPolicyCheckBox)
|
||||||
|
val createButton = view.findViewById<Button>(R.id.CreateAccountButton)
|
||||||
|
var passwordIsVisible = false
|
||||||
|
|
||||||
|
passwordEditText.doOnTextChanged { text, start, before, count ->
|
||||||
|
viewModel.setLogin(text.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.signUpState.observeForever{ it ->
|
||||||
|
createButton.isEnabled = it.acceptTerms
|
||||||
|
}
|
||||||
|
|
||||||
|
termsCheckBox.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||||
|
viewModel.changeTerms(isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
passwordEditText.setOnTouchListener { v, event ->
|
||||||
|
if(event.action == MotionEvent.ACTION_UP){
|
||||||
|
if(event.rawX >= passwordEditText.right -
|
||||||
|
passwordEditText.compoundDrawables[2].bounds.width()
|
||||||
|
- passwordEditText.paddingEnd){
|
||||||
|
passwordIsVisible = !passwordIsVisible
|
||||||
|
if(passwordIsVisible){
|
||||||
|
passwordEditText.inputType = InputType.TYPE_CLASS_TEXT or
|
||||||
|
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||||
|
}else{
|
||||||
|
passwordEditText.inputType = InputType.TYPE_CLASS_TEXT or
|
||||||
|
InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.example.autorization.ui.fragments.signup
|
||||||
|
|
||||||
|
data class SignUpState(
|
||||||
|
var login:String = "",
|
||||||
|
var password: String ="",
|
||||||
|
var name: String = "",
|
||||||
|
var acceptTerms: Boolean = false,
|
||||||
|
var buttonEnable: Boolean = acceptTerms
|
||||||
|
)
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.example.autorization.ui.fragments.signup
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import java.util.stream.Stream
|
||||||
|
import kotlin.math.log
|
||||||
|
|
||||||
|
class SignUpViewModel:ViewModel() {
|
||||||
|
private var _signUpState: MutableLiveData<SignUpState> = MutableLiveData(SignUpState())
|
||||||
|
val signUpState : LiveData<SignUpState> = _signUpState
|
||||||
|
|
||||||
|
|
||||||
|
fun setLogin(login:String) {
|
||||||
|
_signUpState.postValue(_signUpState.value?.copy(login = login))
|
||||||
|
}
|
||||||
|
fun changeTerms(isAccept:Boolean) {
|
||||||
|
_signUpState.postValue(_signUpState.value?.copy(acceptTerms = isAccept))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/gray700"/>
|
||||||
|
<corners android:radius="14dp"/>
|
||||||
|
</shape>
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
|
<shape android:shape="rectangle"
|
||||||
<solid android:color="@color/primary500"/>
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/primary600"/>
|
||||||
<corners android:radius="14dp"/>
|
<corners android:radius="14dp"/>
|
||||||
</shape>
|
</shape>
|
7
app/src/main/res/drawable/create_button_color.xml
Normal file
7
app/src/main/res/drawable/create_button_color.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@drawable/button_dark_rounded_background"
|
||||||
|
android:state_enabled="false"/>
|
||||||
|
<item android:drawable="@drawable/button_rounded_background"
|
||||||
|
android:state_enabled="true"/>
|
||||||
|
</selector>
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<androidx.fragment.app.FragmentContainerView
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/fragment_container_view"
|
android:id="@+id/fragment_container_view"
|
||||||
android:name="com.example.autorization.ui.fragments.SignUpScreen"
|
android:name="com.example.autorization.ui.fragments.signup.SignUpScreen"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>z
|
||||||
</FrameLayout>
|
</FrameLayout>
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".ui.fragments.SignUpScreen">
|
tools:context=".ui.fragments.signup.SignUpScreen">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:src="@drawable/wave"
|
android:src="@drawable/wave"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -57,7 +57,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/TarmsAndPolicyRadioButton"
|
android:id="@+id/TarmsAndPolicyCheckBox"
|
||||||
android:background="@color/gray50"
|
android:background="@color/gray50"
|
||||||
android:layout_marginEnd="14dp"
|
android:layout_marginEnd="14dp"
|
||||||
android:minHeight="24dp"
|
android:minHeight="24dp"
|
||||||
@ -73,11 +73,13 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/CreateAccountButton"
|
||||||
android:layout_marginTop="36dp"
|
android:layout_marginTop="36dp"
|
||||||
android:text="@string/create_account"
|
android:text="@string/create_account"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
|
android:enabled="false"
|
||||||
android:textAppearance="@style/Large400"
|
android:textAppearance="@style/Large400"
|
||||||
android:background="@drawable/button_rounded_background"
|
android:background="@drawable/create_button_color"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="60dp"/>
|
android:minHeight="60dp"/>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="primary600">#2A4ECA</color>
|
<color name="primary600">#2A4ECA</color>
|
||||||
|
<color name="darkPrimary600">#FF2A4ECA</color>
|
||||||
<color name="primary500">#3461FD</color>
|
<color name="primary500">#3461FD</color>
|
||||||
<color name="gray700">#61677D</color>
|
<color name="gray700">#61677D</color>
|
||||||
<color name="gray800">#3B4054</color>
|
<color name="gray800">#3B4054</color>
|
||||||
|
Loading…
Reference in New Issue
Block a user