Skip to content

Commit

Permalink
#378 remove constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Nov 21, 2020
1 parent 6e7071a commit a02acd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ class FingerprintGestureViewModel(
}
}

fun removeAction(gestureId: String, actionId: String) = viewModelScope.launch {
mRepository.editGesture(gestureId) {
val newActionList = it.actionList.toMutableList().apply {
removeAll { action ->
action.uid == actionId
}
}

it.copy(actionList = newActionList)
}
}

fun addConstraint(gestureId: String, constraint: Constraint) = viewModelScope.launch {
mRepository.editGesture(gestureId) {
val newConstraintList = it.constraintList.toMutableList().apply {
Expand All @@ -70,19 +82,19 @@ class FingerprintGestureViewModel(
}
}

fun removeAction(gestureId: String, actionId: String) = viewModelScope.launch {
fun removeConstraint(gestureId: String, constraintId: String) = viewModelScope.launch {
mRepository.editGesture(gestureId) {
val newActionList = it.actionList.toMutableList().apply {
removeAll { action ->
Timber.d("${action.uid} $actionId")
action.uid == actionId
val newConstraintList = it.constraintList.toMutableList().apply {
removeAll { constraint ->
constraint.uniqueId == constraintId
}
}

it.copy(actionList = newActionList)
it.copy(constraintList = newConstraintList)
}
}


fun setEnabled(id: String, isEnabled: Boolean) = viewModelScope.launch {
mRepository.editGesture(id) {
it.copy(isEnabled = isEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FingerprintGestureFragment : DefaultRecyclerViewFragment() {
onBind { _, view, _ ->
(view.dataBinding as ListItemFingerprintGestureBinding).apply {
epoxyRecyclerViewActions.bindActions(it.id, it.actionModels)
epoxyRecyclerViewConstraints.bindConstraints(it.constraintModels)
epoxyRecyclerViewConstraints.bindConstraints(it.id, it.constraintModels)
}
}
}
Expand Down Expand Up @@ -140,13 +140,14 @@ class FingerprintGestureFragment : DefaultRecyclerViewFragment() {
}
}

private fun EpoxyRecyclerView.bindConstraints(models: List<ConstraintModel>) = withModels {
private fun EpoxyRecyclerView.bindConstraints(gestureId: String, models: List<ConstraintModel>) = withModels {
models.forEach {
constraint {
id(it.id)
model(it)

onRemoveClick { _ ->
mViewModel.removeConstraint(gestureId, it.id)
}

val tintType = when {
Expand Down

0 comments on commit a02acd5

Please sign in to comment.