From 9929d6a4ebf2655139b27625bc321d314911f602 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 27 Jun 2022 10:13:18 +0200 Subject: [PATCH] Update button design --- .../ButtonPositiveDestructiveButtonBarItem.kt | 59 +++++++++++++++++++ .../VerificationChooseMethodController.kt | 19 +++--- .../item_positive_destrutive_buttons.xml | 25 ++++++++ 3 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/core/ui/list/ButtonPositiveDestructiveButtonBarItem.kt create mode 100644 vector/src/main/res/layout/item_positive_destrutive_buttons.xml diff --git a/vector/src/main/java/im/vector/app/core/ui/list/ButtonPositiveDestructiveButtonBarItem.kt b/vector/src/main/java/im/vector/app/core/ui/list/ButtonPositiveDestructiveButtonBarItem.kt new file mode 100644 index 0000000000..95c1a4457d --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/ui/list/ButtonPositiveDestructiveButtonBarItem.kt @@ -0,0 +1,59 @@ +/* + * 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.core.ui.list + +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass +import com.google.android.material.button.MaterialButton +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.lib.core.utils.epoxy.charsequence.EpoxyCharSequence + +/** + * A generic button list item. + */ +@EpoxyModelClass(layout = R.layout.item_positive_destrutive_buttons) +abstract class ButtonPositiveDestructiveButtonBarItem : VectorEpoxyModel() { + + @EpoxyAttribute + var positiveText: EpoxyCharSequence? = null + + @EpoxyAttribute + var destructiveText: EpoxyCharSequence? = null + + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + var positiveButtonClickAction: ClickListener? = null + + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + var destructiveButtonClickAction: ClickListener? = null + + override fun bind(holder: Holder) { + super.bind(holder) + positiveText?.charSequence?.let { holder.positiveButton.text = it } + destructiveText?.charSequence?.let { holder.destructiveButton.text = it } + + holder.positiveButton.onClick(positiveButtonClickAction) + holder.destructiveButton.onClick(destructiveButtonClickAction) + } + + class Holder : VectorEpoxyHolder() { + val destructiveButton by bind(R.id.destructive_button) + val positiveButton by bind(R.id.positive_button) + } +} diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt index 85dbd7d462..d8fb5b81c4 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt @@ -21,7 +21,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.bottomSheetDividerItem import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider -import im.vector.app.core.ui.list.genericButtonItem +import im.vector.app.core.ui.list.buttonPositiveDestructiveButtonBarItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationQrCodeItem @@ -111,17 +111,12 @@ class VerificationChooseMethodController @Inject constructor( } } else if (!state.isReadied) { // a bit of a special case, if you tapped on the timeline cell but not on a button - genericButtonItem { - id("accept_request") - textColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary)) - text(host.stringProvider.getString(R.string.action_accept)) - buttonClickAction { host.listener?.acceptRequest() } - } - genericButtonItem { - id("decline_request") - textColor(host.colorProvider.getColorFromAttribute(R.attr.colorError)) - text(host.stringProvider.getString(R.string.action_decline)) - buttonClickAction { host.listener?.declineRequest() } + buttonPositiveDestructiveButtonBarItem { + id("accept_decline") + positiveText(host.stringProvider.getString(R.string.action_accept).toEpoxyCharSequence()) + destructiveText(host.stringProvider.getString(R.string.action_decline).toEpoxyCharSequence()) + positiveButtonClickAction { host.listener?.acceptRequest() } + destructiveButtonClickAction { host.listener?.declineRequest() } } } diff --git a/vector/src/main/res/layout/item_positive_destrutive_buttons.xml b/vector/src/main/res/layout/item_positive_destrutive_buttons.xml new file mode 100644 index 0000000000..1e0ab34458 --- /dev/null +++ b/vector/src/main/res/layout/item_positive_destrutive_buttons.xml @@ -0,0 +1,25 @@ + + + +