fix: limit sort interaction to handle

This commit is contained in:
Andries Smit 2022-03-28 14:29:49 +02:00
parent b2bfd47bcb
commit 47f835469d
6 changed files with 39 additions and 64 deletions

View file

@ -77,8 +77,7 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
}
)
}
fun click() {
holder.binding.root.setOnClickListener {
if (actionHelper.isNoAction) {
val manager = fragmentManager
val editQuickWizardDialog = EditQuickWizardDialog()
@ -91,23 +90,18 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
actionHelper.updateSelection(position, entry, holder.binding.cbRemove.isChecked)
}
}
// For accessibility add click lister too, unfortunately sort can not made accessible
holder.binding.root.setOnClickListener {
click()
}
holder.binding.root.setOnTouchListener { _, event ->
if (event.actionMasked == MotionEvent.ACTION_UP) {
click()
} else if (event.actionMasked == MotionEvent.ACTION_DOWN && actionHelper.isSorting) {
holder.binding.sortHandle.setOnTouchListener { _, event ->
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
onStartDrag(holder)
}
return@setOnTouchListener true
}
return@setOnTouchListener false
}
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
actionHelper.updateSelection(position, entry, value)
}
holder.binding.handleView.visibility = actionHelper.isSorting.toVisibility()
holder.binding.sortHandle.visibility = actionHelper.isSorting.toVisibility()
holder.binding.cbRemove.visibility = actionHelper.isRemoving.toVisibility()
}

View file

@ -147,10 +147,12 @@ class BGSourceFragment : DaggerFragment() {
}
holder.binding.root.setOnLongClickListener {
actionHelper.startRemove()
if (actionHelper.startRemove()) {
holder.binding.cbRemove.toggle()
actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked)
true
return@setOnLongClickListener true
}
false
}
holder.binding.root.setOnClickListener {
if (actionHelper.isRemoving) {

View file

@ -81,7 +81,7 @@
tools:ignore="RtlSymmetry" />
<ImageView
android:id="@+id/handleView"
android:id="@+id/sortHandle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"

View file

@ -26,9 +26,6 @@ import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog
import info.nightscout.androidaps.utils.dragHelpers.ItemTouchHelperAdapter
import info.nightscout.androidaps.utils.dragHelpers.OnStartDragListener
import info.nightscout.androidaps.utils.dragHelpers.SimpleItemTouchHelperCallback
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
@ -36,6 +33,9 @@ import info.nightscout.androidaps.utils.ActionHelper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.dragHelpers.ItemTouchHelperAdapter
import info.nightscout.androidaps.utils.dragHelpers.OnStartDragListener
import info.nightscout.androidaps.utils.dragHelpers.SimpleItemTouchHelperCallback
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
@ -206,22 +206,14 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
for (res in actionIcons) {
addImage(res, holder.context, holder.binding.iconLayout)
}
// enabled event
holder.binding.aapsLogo.visibility = (automation.systemAction).toVisibility()
// Enabled events
holder.binding.enabled.setOnClickListener {
automation.isEnabled = holder.binding.enabled.isChecked
rxBus.send(EventAutomationDataChanged())
}
holder.binding.aapsLogo.visibility = (automation.systemAction).toVisibility()
var longPress = false
val handler = Handler(Looper.getMainLooper())
val mLongPressed = Runnable {
longPress = true
actionHelper.startAction()
}
fun click() {
if (actionHelper.isNoAction && !longPress) {
holder.binding.rootLayout.setOnClickListener {
if (actionHelper.isNoAction) {
val dialog = EditEventDialog()
val args = Bundle()
args.putString("event", automation.toJSON())
@ -233,40 +225,21 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
actionHelper.updateSelection(position, automation, holder.binding.cbRemove.isChecked)
}
}
// Implement click listeners and touch handler for accessibility, unfortunately drag and drop for sorting can not be made accessible
holder.binding.rootLayout.setOnClickListener {
click()
}
holder.binding.rootLayout.setOnLongClickListener {
actionHelper.startAction()
true
}
holder.binding.rootLayout.setOnTouchListener { _, touchEvent ->
when (touchEvent.actionMasked) {
MotionEvent.ACTION_UP -> {
handler.removeCallbacks(mLongPressed)
click()
longPress = false
}
MotionEvent.ACTION_DOWN -> {
if (actionHelper.isSorting) {
holder.binding.sortHandle.setOnTouchListener { _, touchEvent ->
if (touchEvent.actionMasked == MotionEvent.ACTION_DOWN) {
onStartDrag(holder)
}
if (actionHelper.isNoAction && !actionHelper.inMenu) {
handler.postDelayed(mLongPressed, ViewConfiguration.getLongPressTimeout().toLong())
}
}
}
return@setOnTouchListener true
}
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
return@setOnTouchListener false
}
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
actionHelper.updateSelection(position, automation, value)
}
holder.binding.iconSort.visibility = actionHelper.isSorting.toVisibility()
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
holder.binding.sortHandle.visibility = actionHelper.isSorting.toVisibility()
holder.binding.cbRemove.visibility = actionHelper.isRemoving.toVisibility()
holder.binding.cbRemove.isEnabled = automation.readOnly.not()
holder.binding.enabled.visibility = if (actionHelper.isRemoving) View.INVISIBLE else View.VISIBLE

View file

@ -55,12 +55,12 @@
android:contentDescription="@string/remove_label"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/iconLayout"
app:layout_constraintEnd_toStartOf="@+id/iconSort"
app:layout_constraintEnd_toStartOf="@+id/sortHandle"
app:layout_constraintStart_toEndOf="@+id/eventTitle"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iconSort"
android:id="@+id/sortHandle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"

View file

@ -77,22 +77,28 @@ class ActionHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity?) {
menu.findItem(R.id.nav_sort_items)?.isVisible = enableSort
}
fun startAction() {
if (actionMode == null) {
fun startAction(): Boolean {
if (isNoAction) {
actionMode = activity?.startActionMode(ActionModeCallback())
return true
}
return false
}
fun startRemove() {
fun startRemove(): Boolean {
if (removeActionMode == null) {
removeActionMode = activity?.startActionMode(RemoveActionModeCallback())
return true
}
return false
}
fun startSort() {
fun startSort(): Boolean {
if (sortActionMode == null) {
sortActionMode = activity?.startActionMode(SortActionModeCallback())
return true
}
return false
}
fun isSelected(position: Int) =