From d65ccf5ff381dd762602732fd131485170be7cd4 Mon Sep 17 00:00:00 2001 From: adm Date: Thu, 7 Nov 2024 18:36:37 +0300 Subject: [PATCH] add editfragment --- .../ui/fragments/users/UserViewModel.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/src/main/java/com/example/autorization/ui/fragments/users/UserViewModel.kt 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