git add viewmodel

This commit is contained in:
adm 2024-10-23 18:18:35 +03:00
parent ab9d5ce37b
commit fbe57b265f
11 changed files with 114 additions and 37 deletions

View File

@ -4,7 +4,7 @@
<selectionStates>
<SelectionState runConfigName="app">
<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">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\adm\.android\avd\Medium_Phone_API_35.avd" />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/primary500"/>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/primary600"/>
<corners android:radius="14dp"/>
</shape>

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

View File

@ -9,7 +9,7 @@
<androidx.fragment.app.FragmentContainerView
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_height="match_parent"/>
android:layout_height="match_parent"/>z
</FrameLayout>

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.fragments.SignUpScreen">
tools:context=".ui.fragments.signup.SignUpScreen">
<ImageView
android:src="@drawable/wave"
android:layout_width="wrap_content"
@ -57,7 +57,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/TarmsAndPolicyRadioButton"
android:id="@+id/TarmsAndPolicyCheckBox"
android:background="@color/gray50"
android:layout_marginEnd="14dp"
android:minHeight="24dp"
@ -73,11 +73,13 @@
</LinearLayout>
<Button
android:id="@+id/CreateAccountButton"
android:layout_marginTop="36dp"
android:text="@string/create_account"
android:textColor="@color/white"
android:enabled="false"
android:textAppearance="@style/Large400"
android:background="@drawable/button_rounded_background"
android:background="@drawable/create_button_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="60dp"/>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary600">#2A4ECA</color>
<color name="darkPrimary600">#FF2A4ECA</color>
<color name="primary500">#3461FD</color>
<color name="gray700">#61677D</color>
<color name="gray800">#3B4054</color>