fix: limit sort interaction to handle
This commit is contained in:
parent
b2bfd47bcb
commit
47f835469d
6 changed files with 39 additions and 64 deletions
|
@ -77,8 +77,7 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
holder.binding.root.setOnClickListener {
|
||||||
fun click() {
|
|
||||||
if (actionHelper.isNoAction) {
|
if (actionHelper.isNoAction) {
|
||||||
val manager = fragmentManager
|
val manager = fragmentManager
|
||||||
val editQuickWizardDialog = EditQuickWizardDialog()
|
val editQuickWizardDialog = EditQuickWizardDialog()
|
||||||
|
@ -91,23 +90,18 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
|
||||||
actionHelper.updateSelection(position, entry, holder.binding.cbRemove.isChecked)
|
actionHelper.updateSelection(position, entry, holder.binding.cbRemove.isChecked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For accessibility add click lister too, unfortunately sort can not made accessible
|
holder.binding.sortHandle.setOnTouchListener { _, event ->
|
||||||
holder.binding.root.setOnClickListener {
|
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
click()
|
|
||||||
}
|
|
||||||
holder.binding.root.setOnTouchListener { _, event ->
|
|
||||||
if (event.actionMasked == MotionEvent.ACTION_UP) {
|
|
||||||
click()
|
|
||||||
} else if (event.actionMasked == MotionEvent.ACTION_DOWN && actionHelper.isSorting) {
|
|
||||||
onStartDrag(holder)
|
onStartDrag(holder)
|
||||||
}
|
|
||||||
return@setOnTouchListener true
|
return@setOnTouchListener true
|
||||||
}
|
}
|
||||||
|
return@setOnTouchListener false
|
||||||
|
}
|
||||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||||
actionHelper.updateSelection(position, entry, 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()
|
holder.binding.cbRemove.visibility = actionHelper.isRemoving.toVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,10 +147,12 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.binding.root.setOnLongClickListener {
|
holder.binding.root.setOnLongClickListener {
|
||||||
actionHelper.startRemove()
|
if (actionHelper.startRemove()) {
|
||||||
holder.binding.cbRemove.toggle()
|
holder.binding.cbRemove.toggle()
|
||||||
actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked)
|
actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked)
|
||||||
true
|
return@setOnLongClickListener true
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
holder.binding.root.setOnClickListener {
|
holder.binding.root.setOnClickListener {
|
||||||
if (actionHelper.isRemoving) {
|
if (actionHelper.isRemoving) {
|
||||||
|
|
|
@ -81,7 +81,7 @@
|
||||||
tools:ignore="RtlSymmetry" />
|
tools:ignore="RtlSymmetry" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/handleView"
|
android:id="@+id/sortHandle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:adjustViewBounds="false"
|
android:adjustViewBounds="false"
|
||||||
|
|
|
@ -26,9 +26,6 @@ import info.nightscout.androidaps.extensions.toVisibility
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog
|
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.EventAutomationDataChanged
|
||||||
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
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.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
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.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
|
@ -206,22 +206,14 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
||||||
for (res in actionIcons) {
|
for (res in actionIcons) {
|
||||||
addImage(res, holder.context, holder.binding.iconLayout)
|
addImage(res, holder.context, holder.binding.iconLayout)
|
||||||
}
|
}
|
||||||
// enabled event
|
holder.binding.aapsLogo.visibility = (automation.systemAction).toVisibility()
|
||||||
|
// Enabled events
|
||||||
holder.binding.enabled.setOnClickListener {
|
holder.binding.enabled.setOnClickListener {
|
||||||
automation.isEnabled = holder.binding.enabled.isChecked
|
automation.isEnabled = holder.binding.enabled.isChecked
|
||||||
rxBus.send(EventAutomationDataChanged())
|
rxBus.send(EventAutomationDataChanged())
|
||||||
}
|
}
|
||||||
holder.binding.aapsLogo.visibility = (automation.systemAction).toVisibility()
|
holder.binding.rootLayout.setOnClickListener {
|
||||||
|
if (actionHelper.isNoAction) {
|
||||||
var longPress = false
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
|
||||||
val mLongPressed = Runnable {
|
|
||||||
longPress = true
|
|
||||||
actionHelper.startAction()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun click() {
|
|
||||||
if (actionHelper.isNoAction && !longPress) {
|
|
||||||
val dialog = EditEventDialog()
|
val dialog = EditEventDialog()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putString("event", automation.toJSON())
|
args.putString("event", automation.toJSON())
|
||||||
|
@ -233,40 +225,21 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
||||||
actionHelper.updateSelection(position, automation, holder.binding.cbRemove.isChecked)
|
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 {
|
holder.binding.rootLayout.setOnLongClickListener {
|
||||||
actionHelper.startAction()
|
actionHelper.startAction()
|
||||||
true
|
|
||||||
}
|
}
|
||||||
holder.binding.rootLayout.setOnTouchListener { _, touchEvent ->
|
holder.binding.sortHandle.setOnTouchListener { _, touchEvent ->
|
||||||
when (touchEvent.actionMasked) {
|
if (touchEvent.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
MotionEvent.ACTION_UP -> {
|
|
||||||
handler.removeCallbacks(mLongPressed)
|
|
||||||
click()
|
|
||||||
longPress = false
|
|
||||||
}
|
|
||||||
|
|
||||||
MotionEvent.ACTION_DOWN -> {
|
|
||||||
if (actionHelper.isSorting) {
|
|
||||||
onStartDrag(holder)
|
onStartDrag(holder)
|
||||||
}
|
|
||||||
if (actionHelper.isNoAction && !actionHelper.inMenu) {
|
|
||||||
handler.postDelayed(mLongPressed, ViewConfiguration.getLongPressTimeout().toLong())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return@setOnTouchListener true
|
return@setOnTouchListener true
|
||||||
}
|
}
|
||||||
|
return@setOnTouchListener false
|
||||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
}
|
||||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||||
actionHelper.updateSelection(position, automation, 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.visibility = actionHelper.isRemoving.toVisibility()
|
||||||
holder.binding.cbRemove.isEnabled = automation.readOnly.not()
|
holder.binding.cbRemove.isEnabled = automation.readOnly.not()
|
||||||
holder.binding.enabled.visibility = if (actionHelper.isRemoving) View.INVISIBLE else View.VISIBLE
|
holder.binding.enabled.visibility = if (actionHelper.isRemoving) View.INVISIBLE else View.VISIBLE
|
||||||
|
|
|
@ -55,12 +55,12 @@
|
||||||
android:contentDescription="@string/remove_label"
|
android:contentDescription="@string/remove_label"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/iconLayout"
|
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_constraintStart_toEndOf="@+id/eventTitle"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iconSort"
|
android:id="@+id/sortHandle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
|
|
|
@ -77,22 +77,28 @@ class ActionHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity?) {
|
||||||
menu.findItem(R.id.nav_sort_items)?.isVisible = enableSort
|
menu.findItem(R.id.nav_sort_items)?.isVisible = enableSort
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startAction() {
|
fun startAction(): Boolean {
|
||||||
if (actionMode == null) {
|
if (isNoAction) {
|
||||||
actionMode = activity?.startActionMode(ActionModeCallback())
|
actionMode = activity?.startActionMode(ActionModeCallback())
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startRemove() {
|
fun startRemove(): Boolean {
|
||||||
if (removeActionMode == null) {
|
if (removeActionMode == null) {
|
||||||
removeActionMode = activity?.startActionMode(RemoveActionModeCallback())
|
removeActionMode = activity?.startActionMode(RemoveActionModeCallback())
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startSort() {
|
fun startSort(): Boolean {
|
||||||
if (sortActionMode == null) {
|
if (sortActionMode == null) {
|
||||||
sortActionMode = activity?.startActionMode(SortActionModeCallback())
|
sortActionMode = activity?.startActionMode(SortActionModeCallback())
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSelected(position: Int) =
|
fun isSelected(position: Int) =
|
||||||
|
|
Loading…
Reference in a new issue