Commit 155c18b1 authored by Christophe Deschamps's avatar Christophe Deschamps
Browse files

Recalulate row index upon deletion

parent 6ea5a67e
......@@ -28,7 +28,7 @@ import org.linhome.ui.widgets.LSpinnerListener
class DeviceEditorActionViewModel(
val owningViewModel: DeviceEditorViewModel,
val binding: ViewDataBinding,
val displayIndex: Int
val displayIndex: MutableLiveData<Int> = MutableLiveData(0)
) : ViewModel() {
var type: MutableLiveData<Int> = MutableLiveData<Int>(0)
var code: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> =
......
......@@ -27,6 +27,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.navArgs
import kotlinx.android.synthetic.main.app_bar_main.*
......@@ -88,6 +89,12 @@ class DeviceEditorFragment : GenericFragment() {
)
}
model.refreshActions.observe(viewLifecycleOwner, Observer { refresh ->
for ((index, actionViewModel) in model.actionsViewModels.withIndex()) {
actionViewModel.displayIndex.value = index+1
}
})
return binding.root
}
......
......@@ -154,7 +154,7 @@ class DeviceEditorViewModel : ViewModelWithTools() {
}
fun addAction(action: Action?, binding: ViewDataBinding) {
val actionViewModel = DeviceEditorActionViewModel(this, binding, actionsViewModels.size + 1)
val actionViewModel = DeviceEditorActionViewModel(this, binding, MutableLiveData(actionsViewModels.size + 1))
binding.setVariable(BR.actionmodel, actionViewModel)
binding.setVariable(BR.validators, ValidatorFactory.Companion)
action?.also {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment