Prepare alias bottom sheet

This commit is contained in:
Benoit Marty 2020-11-24 06:37:55 +01:00 committed by Benoit Marty
parent 2cf2233643
commit 8f80f375f0
4 changed files with 16 additions and 14 deletions

View file

@ -26,8 +26,10 @@ import androidx.core.widget.ImageViewCompat
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
@ -67,11 +69,11 @@ abstract class ProfileActionItem : VectorEpoxyModel<ProfileActionItem.Holder>()
var destructive: Boolean = false var destructive: Boolean = false
@EpoxyAttribute @EpoxyAttribute
var listener: View.OnClickListener? = null var listener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.view.setOnClickListener(listener) holder.view.onClick(listener)
if (listener == null) { if (listener == null) {
holder.view.isClickable = false holder.view.isClickable = false
} }

View file

@ -59,9 +59,7 @@ fun EpoxyController.buildProfileAction(
accessoryRes(accessory) accessoryRes(accessory)
accessoryMatrixItem(accessoryMatrixItem) accessoryMatrixItem(accessoryMatrixItem)
avatarRenderer(avatarRenderer) avatarRenderer(avatarRenderer)
listener { _ -> listener(action)
action?.invoke()
}
} }
if (divider) { if (divider) {

View file

@ -24,6 +24,7 @@ import im.vector.app.R
import im.vector.app.core.epoxy.errorWithRetryItem import im.vector.app.core.epoxy.errorWithRetryItem
import im.vector.app.core.epoxy.loadingItem import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.epoxy.profiles.buildProfileSection import im.vector.app.core.epoxy.profiles.buildProfileSection
import im.vector.app.core.epoxy.profiles.profileActionItem
import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
@ -33,7 +34,6 @@ import im.vector.app.features.discovery.settingsInfoItem
import im.vector.app.features.form.formEditTextItem import im.vector.app.features.form.formEditTextItem
import im.vector.app.features.roomdirectory.createroom.RoomAliasErrorFormatter import im.vector.app.features.roomdirectory.createroom.RoomAliasErrorFormatter
import im.vector.app.features.roomdirectory.createroom.roomAliasEditItem import im.vector.app.features.roomdirectory.createroom.roomAliasEditItem
import im.vector.app.features.settings.threepids.threePidItem
import org.matrix.android.sdk.api.session.room.alias.RoomAliasError import org.matrix.android.sdk.api.session.room.alias.RoomAliasError
import javax.inject.Inject import javax.inject.Inject
@ -48,12 +48,14 @@ class RoomAliasController @Inject constructor(
fun toggleManualPublishForm() fun toggleManualPublishForm()
fun setNewAlias(value: String) fun setNewAlias(value: String)
fun addAlias() fun addAlias()
// TODO Delete some methods below
fun removeAlias(altAlias: String) fun removeAlias(altAlias: String)
fun setCanonicalAlias(alias: String?) fun setCanonicalAlias(alias: String?)
fun removeLocalAlias(alias: String) fun removeLocalAlias(alias: String)
fun toggleLocalAliasForm() fun toggleLocalAliasForm()
fun setNewLocalAliasLocalPart(value: String) fun setNewLocalAliasLocalPart(value: String)
fun addLocalAlias() fun addLocalAlias()
fun openAlias(alias: String, isPublished: Boolean)
} }
var callback: Callback? = null var callback: Callback? = null
@ -97,13 +99,10 @@ class RoomAliasController @Inject constructor(
helperTextResId(R.string.room_alias_published_other) helperTextResId(R.string.room_alias_published_other)
} }
data.alternativeAliases.forEachIndexed { idx, altAlias -> data.alternativeAliases.forEachIndexed { idx, altAlias ->
// TODO Rename this item to a more generic name profileActionItem {
threePidItem {
id("alt_$idx") id("alt_$idx")
title(altAlias) title(altAlias)
if (data.actionPermissions.canChangeCanonicalAlias) { listener { callback?.openAlias(altAlias, true) }
deleteClickListener { callback?.removeAlias(altAlias) }
}
} }
} }
} }
@ -161,11 +160,10 @@ class RoomAliasController @Inject constructor(
} }
is Success -> { is Success -> {
localAliases().forEachIndexed { idx, localAlias -> localAliases().forEachIndexed { idx, localAlias ->
// TODO Rename this item to a more generic name profileActionItem {
threePidItem {
id("loc_$idx") id("loc_$idx")
title(localAlias) title(localAlias)
deleteClickListener { callback?.removeLocalAlias(localAlias) } listener { callback?.openAlias(localAlias, false) }
} }
} }
} }

View file

@ -140,6 +140,10 @@ class RoomAliasFragment @Inject constructor(
viewModel.handle(RoomAliasAction.AddLocalAlias) viewModel.handle(RoomAliasAction.AddLocalAlias)
} }
override fun openAlias(alias: String, isPublished: Boolean) {
TODO()
}
override fun removeLocalAlias(alias: String) { override fun removeLocalAlias(alias: String) {
AlertDialog.Builder(requireContext()) AlertDialog.Builder(requireContext())
.setTitle(R.string.dialog_title_confirmation) .setTitle(R.string.dialog_title_confirmation)