G2A Many GEOs
SHARE
TWEET

model

a guest Apr 8th, 2020 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.todo
  2.  
  3. import android.app.Application
  4. import android.util.Log
  5. import androidx.lifecycle.AndroidViewModel
  6. import androidx.lifecycle.LiveData
  7. import androidx.lifecycle.MutableLiveData
  8. import androidx.lifecycle.ViewModel
  9.  
  10. class Model(application:Application) : AndroidViewModel(application) {
  11.     private val _dataTodo = MutableLiveData<ArrayList<TodoData>>()
  12.             val data : LiveData<ArrayList<TodoData>>
  13.             get()=_dataTodo
  14.  
  15.     init{
  16.         _dataTodo.value = arrayListOf(
  17.             TodoData(1,"Mencuci",false)
  18.         )
  19.     }
  20.  
  21.     fun newTodo(newData:String){
  22.         val viewModelVal = _dataTodo.value!!
  23.         var new_id = 0
  24.  
  25.         if (viewModelVal.size == 0){
  26.             new_id = 0
  27.             Log.d("model","null")
  28.         }else{
  29.             new_id = viewModelVal[viewModelVal.lastIndex].id+1
  30.             Log.d("model","available")
  31.         }
  32.         _dataTodo.value!!.add(TodoData(new_id,newData,false))
  33.         _dataTodo.setValue(_dataTodo.value)
  34.     }
  35.  
  36.     fun deleteTodo(position:Int){
  37.         if(_dataTodo.value?.size?.compareTo(0) == 1){
  38.             _dataTodo.value!!.removeAt(position)
  39.             _dataTodo.setValue(_dataTodo.value)
  40.         }
  41.     }
  42.  
  43.     fun updateTodo(position: Int,task:String){
  44.         _dataTodo.value!![position].task = task
  45.         _dataTodo.setValue(_dataTodo.value)
  46.     }
  47. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top