diff --git a/vector/src/main/java/im/vector/app/core/epoxy/profiles/notifications/BottomSheetRadioButtonItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/profiles/notifications/BottomSheetRadioButtonItem.kt new file mode 100644 index 0000000000..fbfc97ab26 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/epoxy/profiles/notifications/BottomSheetRadioButtonItem.kt @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 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.epoxy.profiles.notifications + +import android.widget.ImageView +import android.widget.TextView +import androidx.annotation.AttrRes +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.core.content.ContextCompat +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.features.themes.ThemeUtils + +/** + * SC: copy of RadioButtonItem, but with extra icon + different layout + */ +@EpoxyModelClass(layout = R.layout.bottom_sheet_item_radio) +abstract class BottomSheetRadioButtonItem : VectorEpoxyModel() { + + @EpoxyAttribute + var title: CharSequence? = null + + @StringRes + @EpoxyAttribute + var titleRes: Int? = null + + @EpoxyAttribute + var selected = false + + @EpoxyAttribute + @DrawableRes + var iconRes: Int? = null + + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + lateinit var listener: ClickListener + + override fun bind(holder: Holder) { + super.bind(holder) + holder.view.onClick(listener) + if (titleRes != null) { + holder.titleText.setText(titleRes!!) + } else { + holder.titleText.text = title + } + + if (selected) { + holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_on)) + holder.radioImage.contentDescription = holder.view.context.getString(R.string.a11y_checked) + } else { + holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_off)) + holder.radioImage.contentDescription = holder.view.context.getString(R.string.a11y_unchecked) + } + + holder.icon.setImageResource(iconRes ?: 0) + } + + class Holder : VectorEpoxyHolder() { + val icon by bind(R.id.actionIcon) + val titleText by bind(R.id.actionTitle) + val radioImage by bind(R.id.radioIcon) + } +} diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt index 7b4ea25e42..0e064769e5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt @@ -15,6 +15,7 @@ */ package im.vector.app.features.home.room.list.actions +import androidx.annotation.DrawableRes import androidx.annotation.StringRes import com.airbnb.epoxy.TypedEpoxyController import im.vector.app.BuildConfig @@ -22,6 +23,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.bottomSheetDividerItem import im.vector.app.core.epoxy.bottomsheet.bottomSheetActionItem import im.vector.app.core.epoxy.bottomsheet.bottomSheetRoomPreviewItem +import im.vector.app.core.epoxy.profiles.notifications.bottomSheetRadioButtonItem import im.vector.app.core.epoxy.profiles.notifications.radioButtonItem import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider @@ -91,9 +93,11 @@ class RoomListQuickActionsEpoxyController @Inject constructor( if (isV2) { notificationViewState.notificationOptions.forEach { notificationState -> val title = titleForNotificationState(notificationState) - radioButtonItem { + val icon = iconForNotificationState(notificationState) + bottomSheetRadioButtonItem { id(notificationState.name) titleRes(title) + iconRes(icon) selected(notificationViewState.notificationStateMapped() == notificationState) listener { host.listener?.didSelectRoomNotificationState(notificationState) @@ -109,7 +113,7 @@ class RoomListQuickActionsEpoxyController @Inject constructor( } if (showFull) { - RoomListQuickActionsSharedAction.Leave(roomSummary.roomId, showIcon = !isV2).toBottomSheetItem(5) + RoomListQuickActionsSharedAction.Leave(roomSummary.roomId, showIcon = true /*!isV2*/).toBottomSheetItem(5) } } @@ -120,6 +124,16 @@ class RoomListQuickActionsEpoxyController @Inject constructor( RoomNotificationState.MUTE -> R.string.room_settings_none else -> null } + + @DrawableRes + private fun iconForNotificationState(notificationState: RoomNotificationState): Int? = when (notificationState) { + RoomNotificationState.ALL_MESSAGES_NOISY -> R.drawable.ic_room_actions_notifications_all_noisy + RoomNotificationState.ALL_MESSAGES -> R.drawable.ic_room_actions_notifications_all + RoomNotificationState.MENTIONS_ONLY -> R.drawable.ic_room_actions_notifications_mentions + RoomNotificationState.MUTE -> R.drawable.ic_room_actions_notifications_mutes + else -> null + } + private fun RoomListQuickActionsSharedAction.toBottomSheetItem(index: Int, roomNotificationState: RoomNotificationState? = null) { val host = this@RoomListQuickActionsEpoxyController val selected = when (this) { diff --git a/vector/src/main/res/layout/bottom_sheet_item_radio.xml b/vector/src/main/res/layout/bottom_sheet_item_radio.xml new file mode 100644 index 0000000000..a1730091f9 --- /dev/null +++ b/vector/src/main/res/layout/bottom_sheet_item_radio.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + diff --git a/vector/src/main/res/layout/item_radio.xml b/vector/src/main/res/layout/item_radio.xml index 4cd5312dc0..75b2b958d1 100644 --- a/vector/src/main/res/layout/item_radio.xml +++ b/vector/src/main/res/layout/item_radio.xml @@ -8,6 +8,7 @@ android:focusable="true" android:minHeight="64dp" android:foreground="?attr/selectableItemBackground" + android:background="?android:colorBackground" android:paddingStart="@dimen/layout_horizontal_margin" android:paddingEnd="@dimen/layout_horizontal_margin"> @@ -37,4 +38,4 @@ tools:ignore="MissingPrefix" tools:src="@drawable/ic_radio_on" /> - \ No newline at end of file +