Skip to content

Commit

Permalink
#459 feat (action shortcuts) show snackbar to fix action
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Sep 8, 2020
1 parent a07d719 commit 51a595d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class CreateActionShortcutViewModel : ViewModel() {
chooseActionBehavior.value = Event(behavior)
}

fun rebuildActionModels() {
actionList.value = actionList.value
}

class Factory : ViewModelProvider.Factory {

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ import androidx.lifecycle.map
import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import com.google.gson.Gson
import io.github.sds100.keymapper.Constants
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.action
import io.github.sds100.keymapper.data.model.Action
import io.github.sds100.keymapper.data.model.ActionBehavior
import io.github.sds100.keymapper.data.viewmodel.CreateActionShortcutViewModel
import io.github.sds100.keymapper.databinding.FragmentCreateActionShortcutBinding
import io.github.sds100.keymapper.service.MyAccessibilityService
import io.github.sds100.keymapper.ui.activity.LaunchActionShortcutActivity
import io.github.sds100.keymapper.util.*
import io.github.sds100.keymapper.util.result.RecoverableFailure
import io.github.sds100.keymapper.util.result.getFullMessage
import io.github.sds100.keymapper.util.result.valueOrNull
import kotlinx.coroutines.launch
import splitties.alertdialog.appcompat.alertDialog
import splitties.alertdialog.appcompat.cancelButton
import splitties.alertdialog.appcompat.messageResource
import splitties.alertdialog.appcompat.positiveButton
import splitties.snackbar.action
import splitties.snackbar.longSnack
import java.util.*

/**
Expand Down Expand Up @@ -110,6 +115,24 @@ class CreateActionShortcutFragment : Fragment() {
findNavController().navigate(direction)
})

mViewModel.showFixPrompt.observe(viewLifecycleOwner, EventObserver {
coordinatorLayout.longSnack(it.getFullMessage(requireContext())) {

//only add an action to fix the error if the error can be recovered from
if (it is RecoverableFailure) {
action(R.string.snackbar_fix) {
lifecycleScope.launch {
it.recover(requireActivity()) {
mViewModel.rebuildActionModels()
}
}
}
}

show()
}
})

subscribeActionList()

appBar.setOnMenuItemClickListener { menuItem ->
Expand Down

0 comments on commit 51a595d

Please sign in to comment.