From da4695ff2a17d8617af4fd585846dcd294480acf Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 28 Aug 2020 18:35:04 +0200 Subject: [PATCH] Improve UI of threePid screen --- .../settings/threepids/ThreePidItem.kt | 64 +++++++++++++++++++ .../threepids/ThreePidsSettingsController.kt | 21 +++--- .../res/layout/item_settings_three_pid.xml | 47 ++++++++++++++ 3 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidItem.kt create mode 100644 vector/src/main/res/layout/item_settings_three_pid.xml diff --git a/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidItem.kt b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidItem.kt new file mode 100644 index 0000000000..6b05c9f96e --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidItem.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package im.vector.app.features.settings.threepids + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.annotation.DrawableRes +import androidx.core.view.isVisible +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass +import com.airbnb.epoxy.EpoxyModelWithHolder +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.onClick + +@EpoxyModelClass(layout = R.layout.item_settings_three_pid) +abstract class ThreePidItem : EpoxyModelWithHolder() { + + @EpoxyAttribute + var title: String? = null + + @EpoxyAttribute + @DrawableRes + var iconResId: Int? = null + + @EpoxyAttribute + var deleteClickListener: ClickListener? = null + + override fun bind(holder: Holder) { + super.bind(holder) + val safeIconResId = iconResId + if (safeIconResId != null) { + holder.icon.isVisible = true + holder.icon.setImageResource(safeIconResId) + } else { + holder.icon.isVisible = false + } + + holder.title.text = title + holder.delete.onClick { deleteClickListener?.invoke() } + holder.delete.isVisible = deleteClickListener != null + } + + class Holder : VectorEpoxyHolder() { + val icon by bind(R.id.item_settings_three_pid_icon) + val title by bind(R.id.item_settings_three_pid_title) + val delete by bind(R.id.item_settings_three_pid_delete) + } +} diff --git a/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsController.kt b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsController.kt index 406ca50101..3899ac9166 100644 --- a/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsController.kt @@ -26,10 +26,8 @@ import im.vector.app.R import im.vector.app.core.epoxy.loadingItem import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider -import im.vector.app.core.ui.list.GenericItem import im.vector.app.core.ui.list.genericButtonItem import im.vector.app.core.ui.list.genericFooterItem -import im.vector.app.core.ui.list.genericItem import im.vector.app.features.discovery.settingsContinueCancelItem import im.vector.app.features.discovery.settingsInformationItem import im.vector.app.features.discovery.settingsSectionTitleItem @@ -88,7 +86,7 @@ class ThreePidsSettingsController @Inject constructor( // Pending threePids pendingThreePids.invoke() ?.filterIsInstance(ThreePid.Email::class.java) - ?.forEach { buildPendingThreePid("email ", it) } + ?.forEach { buildPendingThreePid("p_email ", it) } genericButtonItem { id("addEmail") @@ -107,7 +105,7 @@ class ThreePidsSettingsController @Inject constructor( // Pending threePids pendingThreePids.invoke() ?.filterIsInstance(ThreePid.Msisdn::class.java) - ?.forEach { buildPendingThreePid("msisdn ", it) } + ?.forEach { buildPendingThreePid("p_msisdn ", it) } genericButtonItem { id("addMsisdn") @@ -118,21 +116,20 @@ class ThreePidsSettingsController @Inject constructor( } private fun buildThreePid(idPrefix: String, threePid: ThreePid) { - genericItem { + threePidItem { id(idPrefix + threePid.value) + // TODO Add an icon for emails + iconResId(if (threePid is ThreePid.Msisdn) R.drawable.ic_phone else null) title(threePid.value) - destructiveButtonAction( - GenericItem.Action(stringProvider.getString(R.string.remove)) - .apply { - perform = Runnable { interactionListener?.deleteThreePid(threePid) } - } - ) + deleteClickListener { interactionListener?.deleteThreePid(threePid) } } } private fun buildPendingThreePid(idPrefix: String, threePid: ThreePid) { - genericItem { + threePidItem { id(idPrefix + threePid.value) + // TODO Add an icon for emails + iconResId(if (threePid is ThreePid.Msisdn) R.drawable.ic_phone else null) title(threePid.value) } diff --git a/vector/src/main/res/layout/item_settings_three_pid.xml b/vector/src/main/res/layout/item_settings_three_pid.xml new file mode 100644 index 0000000000..fd3443ac17 --- /dev/null +++ b/vector/src/main/res/layout/item_settings_three_pid.xml @@ -0,0 +1,47 @@ + + + + + + + + + + \ No newline at end of file