mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Enable selectMode when long pressing on list item
This commit is contained in:
parent
2e155b1acc
commit
ab2e91ae80
5 changed files with 26 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue