add editfragment
This commit is contained in:
parent
14b0959bc2
commit
d65ccf5ff3
@ -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<MutableList<User>>()
|
||||||
|
val users: LiveData<MutableList<User>> = _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!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user