From 8f80f375f01afc4bb912af18e5ecee12c3d33616 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 Nov 2020 06:37:55 +0100 Subject: [PATCH] Prepare alias bottom sheet --- .../app/core/epoxy/profiles/ProfileActionItem.kt | 6 ++++-- .../core/epoxy/profiles/ProfileItemExtensions.kt | 4 +--- .../roomprofile/alias/RoomAliasController.kt | 16 +++++++--------- .../roomprofile/alias/RoomAliasFragment.kt | 4 ++++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileActionItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileActionItem.kt index 3bef38d4cb..f52051f989 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileActionItem.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileActionItem.kt @@ -26,8 +26,10 @@ import androidx.core.widget.ImageViewCompat import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass 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.VectorEpoxyModel +import im.vector.app.core.epoxy.onClick import im.vector.app.core.extensions.setTextOrHide import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.themes.ThemeUtils @@ -67,11 +69,11 @@ abstract class ProfileActionItem : VectorEpoxyModel() var destructive: Boolean = false @EpoxyAttribute - var listener: View.OnClickListener? = null + var listener: ClickListener? = null override fun bind(holder: Holder) { super.bind(holder) - holder.view.setOnClickListener(listener) + holder.view.onClick(listener) if (listener == null) { holder.view.isClickable = false } diff --git a/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileItemExtensions.kt b/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileItemExtensions.kt index fdbe9f7f94..99acd6cb36 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileItemExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/profiles/ProfileItemExtensions.kt @@ -59,9 +59,7 @@ fun EpoxyController.buildProfileAction( accessoryRes(accessory) accessoryMatrixItem(accessoryMatrixItem) avatarRenderer(avatarRenderer) - listener { _ -> - action?.invoke() - } + listener(action) } if (divider) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt index fe19f65629..a8c1222a5f 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt @@ -24,6 +24,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.errorWithRetryItem import im.vector.app.core.epoxy.loadingItem 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.resources.ColorProvider 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.roomdirectory.createroom.RoomAliasErrorFormatter 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 javax.inject.Inject @@ -48,12 +48,14 @@ class RoomAliasController @Inject constructor( fun toggleManualPublishForm() fun setNewAlias(value: String) fun addAlias() + // TODO Delete some methods below fun removeAlias(altAlias: String) fun setCanonicalAlias(alias: String?) fun removeLocalAlias(alias: String) fun toggleLocalAliasForm() fun setNewLocalAliasLocalPart(value: String) fun addLocalAlias() + fun openAlias(alias: String, isPublished: Boolean) } var callback: Callback? = null @@ -97,13 +99,10 @@ class RoomAliasController @Inject constructor( helperTextResId(R.string.room_alias_published_other) } data.alternativeAliases.forEachIndexed { idx, altAlias -> - // TODO Rename this item to a more generic name - threePidItem { + profileActionItem { id("alt_$idx") title(altAlias) - if (data.actionPermissions.canChangeCanonicalAlias) { - deleteClickListener { callback?.removeAlias(altAlias) } - } + listener { callback?.openAlias(altAlias, true) } } } } @@ -161,11 +160,10 @@ class RoomAliasController @Inject constructor( } is Success -> { localAliases().forEachIndexed { idx, localAlias -> - // TODO Rename this item to a more generic name - threePidItem { + profileActionItem { id("loc_$idx") title(localAlias) - deleteClickListener { callback?.removeLocalAlias(localAlias) } + listener { callback?.openAlias(localAlias, false) } } } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt index 20ea7a8901..b14783d9cd 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt @@ -140,6 +140,10 @@ class RoomAliasFragment @Inject constructor( viewModel.handle(RoomAliasAction.AddLocalAlias) } + override fun openAlias(alias: String, isPublished: Boolean) { + TODO() + } + override fun removeLocalAlias(alias: String) { AlertDialog.Builder(requireContext()) .setTitle(R.string.dialog_title_confirmation)