Enable selectMode when long pressing on list item

This commit is contained in:
Maxime NATUREL 2022-10-18 17:06:39 +02:00
parent 2e155b1acc
commit ab2e91ae80
5 changed files with 26 additions and 1 deletions

View file

@ -331,6 +331,10 @@ class VectorSettingsDevicesFragment :
views.waitingView.root.isVisible = isLoading
}
override fun onOtherSessionLongClicked(deviceId: String) {
// do nothing
}
override fun onOtherSessionClicked(deviceId: String) {
navigateToSessionOverview(deviceId)
}

View file

@ -17,6 +17,7 @@
package im.vector.app.features.settings.devices.v2.list
import android.graphics.drawable.Drawable
import android.view.View.OnLongClickListener
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
@ -59,11 +60,15 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var clickListener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var onLongClickListener: OnLongClickListener? = null
private val setDeviceTypeIconUseCase = SetDeviceTypeIconUseCase()
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.onClick(clickListener)
holder.view.setOnLongClickListener(onLongClickListener)
if (clickListener == null) {
holder.view.isClickable = false
}

View file

@ -16,6 +16,7 @@
package im.vector.app.features.settings.devices.v2.list
import android.view.View
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
@ -38,6 +39,7 @@ class OtherSessionsController @Inject constructor(
var callback: Callback? = null
interface Callback {
fun onItemLongClicked(deviceId: String)
fun onItemClicked(deviceId: String)
}
@ -72,6 +74,10 @@ class OtherSessionsController @Inject constructor(
sessionDescriptionColor(descriptionColor)
stringProvider(this@OtherSessionsController.stringProvider)
clickListener { device.deviceInfo.deviceId?.let { host.callback?.onItemClicked(it) } }
onLongClickListener(View.OnLongClickListener {
device.deviceInfo.deviceId?.let { host.callback?.onItemLongClicked(it) }
true
})
}
}
}

View file

@ -40,6 +40,7 @@ class OtherSessionsView @JvmOverloads constructor(
) : ConstraintLayout(context, attrs, defStyleAttr), OtherSessionsController.Callback {
interface Callback {
fun onOtherSessionLongClicked(deviceId: String)
fun onOtherSessionClicked(deviceId: String)
fun onViewAllOtherSessionsClicked()
}
@ -107,4 +108,8 @@ class OtherSessionsView @JvmOverloads constructor(
override fun onItemClicked(deviceId: String) {
callback?.onOtherSessionClicked(deviceId)
}
override fun onItemLongClicked(deviceId: String) {
callback?.onOtherSessionLongClicked(deviceId)
}
}

View file

@ -89,7 +89,6 @@ class OtherSessionsFragment :
}
}
// TODO call enableSelectMode(true) on long press of an item when disabled
private fun enableSelectMode(isEnabled: Boolean) {
val action = if (isEnabled) OtherSessionsAction.EnableSelectMode else OtherSessionsAction.DisableSelectMode
viewModel.handle(action)
@ -253,6 +252,12 @@ class OtherSessionsFragment :
SessionLearnMoreBottomSheet.show(childFragmentManager, args)
}
override fun onOtherSessionLongClicked(deviceId: String) = withState(viewModel) { state ->
if (!state.isSelectModeEnabled) {
enableSelectMode(true)
}
}
override fun onOtherSessionClicked(deviceId: String) {
viewNavigator.navigateToSessionOverview(
context = requireActivity(),