diff --git a/app/src/main/java/com/example/autorization/ui/fragments/users/UserViewModel.kt b/app/src/main/java/com/example/autorization/ui/fragments/users/UserViewModel.kt new file mode 100644 index 0000000..6a9ad70 --- /dev/null +++ b/app/src/main/java/com/example/autorization/ui/fragments/users/UserViewModel.kt @@ -0,0 +1,35 @@ +package com.example.autorization.ui.fragments.users + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.example.autorization.ui.fragments.signup.User + +class +UserViewModel: ViewModel() { + + private val _users = MutableLiveData>() + val users: LiveData> = _users + + init { + val list = mutableListOf( + User(email = "test@mail.ruu", name = "Bob", password = "321"), + User(email = "test@mail.ru", name = "Alex", password = "123"), + ) + _users.postValue(list) + } + + fun addUser(user:User){ + + _users.value?.add(0, user) + + } + + fun removeUserByPosition(index:Int){ + val list = _users.value?.toMutableList() + if (list != null){ + list.removeAt(index) + _users.postValue(list!!) + } + } +} \ No newline at end of file