From 0a79b8b315cb202d3090b885d8f107d372768aa8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 10 Oct 2019 15:29:31 +0200 Subject: [PATCH] Cleanup --- .../action/MessageActionsBottomSheet.kt | 25 +------------------ .../action/MessageActionsEpoxyController.kt | 15 +++++------ .../bottom_sheet_epoxylist_with_title.xml | 1 - .../bottom_sheet_generic_recycler_epoxy.xml | 1 - .../res/layout/item_bottom_sheet_action.xml | 3 +-- 5 files changed, 10 insertions(+), 35 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index 39116b59b5..53ac1bd430 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -15,22 +15,16 @@ */ package im.vector.riotx.features.home.room.detail.timeline.action -import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState -import com.google.android.material.bottomsheet.BottomSheetBehavior -import com.google.android.material.bottomsheet.BottomSheetDialog -import im.vector.riotx.EmojiCompatFontProvider import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment -import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData import kotlinx.android.synthetic.main.bottom_sheet_generic_recycler_epoxy.* import javax.inject.Inject @@ -40,12 +34,10 @@ import javax.inject.Inject */ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), MessageActionsEpoxyController.MessageActionsEpoxyControllerListener { @Inject lateinit var messageActionViewModelFactory: MessageActionsViewModel.Factory - @Inject lateinit var avatarRenderer: AvatarRenderer - @Inject lateinit var fontProvider: EmojiCompatFontProvider + @Inject lateinit var messageActionsEpoxyController: MessageActionsEpoxyController private val viewModel: MessageActionsViewModel by fragmentViewModel(MessageActionsViewModel::class) - private lateinit var messageActionsEpoxyController: MessageActionsEpoxyController private lateinit var actionHandlerModel: ActionsHandler override fun injectWith(screenComponent: ScreenComponent) { @@ -60,7 +52,6 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message super.onActivityCreated(savedInstanceState) actionHandlerModel = ViewModelProviders.of(requireActivity()).get(ActionsHandler::class.java) - messageActionsEpoxyController = MessageActionsEpoxyController(requireContext(), avatarRenderer, fontProvider) bottomSheetEpoxyRecyclerView.setController(messageActionsEpoxyController) messageActionsEpoxyController.listener = this } @@ -70,20 +61,6 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message dismiss() } - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val dialog = super.onCreateDialog(savedInstanceState) - // We want to force the bottom sheet initial state to expanded - (dialog as? BottomSheetDialog)?.let { bottomSheetDialog -> - bottomSheetDialog.setOnShowListener { dialog -> - val d = dialog as BottomSheetDialog - (d.findViewById(com.google.android.material.R.id.design_bottom_sheet) as? FrameLayout)?.let { - BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_COLLAPSED - } - } - } - return dialog - } - override fun invalidate() = withState(viewModel) { messageActionsEpoxyController.setData(it) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt index 1de7302820..66c1949631 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt @@ -15,20 +15,21 @@ */ package im.vector.riotx.features.home.room.detail.timeline.action -import android.content.Context import android.view.View import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.Success import im.vector.riotx.EmojiCompatFontProvider import im.vector.riotx.R +import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.features.home.AvatarRenderer +import javax.inject.Inject /** * Epoxy controller for message action list */ -class MessageActionsEpoxyController(private val context: Context, - private val avatarRenderer: AvatarRenderer, - private val fontProvider: EmojiCompatFontProvider) : TypedEpoxyController() { +class MessageActionsEpoxyController @Inject constructor(private val stringProvider: StringProvider, + private val avatarRenderer: AvatarRenderer, + private val fontProvider: EmojiCompatFontProvider) : TypedEpoxyController() { var listener: MessageActionsEpoxyControllerListener? = null @@ -51,13 +52,13 @@ class MessageActionsEpoxyController(private val context: Context, bottomSheetItemSendState { id("send_state") showProgress(true) - text(context.getString(R.string.event_status_sending_message)) + text(stringProvider.getString(R.string.event_status_sending_message)) } } else if (state.informationData.sendState.hasFailed()) { bottomSheetItemSendState { id("send_state") showProgress(false) - text(context.getString(R.string.unable_to_send_message)) + text(stringProvider.getString(R.string.unable_to_send_message)) drawableStart(R.drawable.ic_warning_small) } } @@ -73,7 +74,7 @@ class MessageActionsEpoxyController(private val context: Context, id("quick_reaction") fontProvider(fontProvider) texts(state.quickStates()?.map { it.reaction }.orEmpty()) - selecteds(state.quickStates()?.map { it.isSelected }.orEmpty()) + selecteds(state.quickStates.invoke().map { it.isSelected }) listener(object : BottomSheetItemQuickReactions.Listener { override fun didSelect(emoji: String, selected: Boolean) { listener?.didSelectMenuAction(SimpleAction.QuickReact(state.eventId, emoji, selected)) diff --git a/vector/src/main/res/layout/bottom_sheet_epoxylist_with_title.xml b/vector/src/main/res/layout/bottom_sheet_epoxylist_with_title.xml index 0cc2e16ed9..a5e9c980a3 100644 --- a/vector/src/main/res/layout/bottom_sheet_epoxylist_with_title.xml +++ b/vector/src/main/res/layout/bottom_sheet_epoxylist_with_title.xml @@ -22,7 +22,6 @@ android:layout_height="0dp" android:layout_weight="1" android:fadeScrollbars="false" - android:orientation="vertical" android:scrollbars="vertical" tools:itemCount="15" tools:listitem="@layout/item_simple_reaction_info" /> diff --git a/vector/src/main/res/layout/bottom_sheet_generic_recycler_epoxy.xml b/vector/src/main/res/layout/bottom_sheet_generic_recycler_epoxy.xml index 5ca952272f..55d3492cf9 100644 --- a/vector/src/main/res/layout/bottom_sheet_generic_recycler_epoxy.xml +++ b/vector/src/main/res/layout/bottom_sheet_generic_recycler_epoxy.xml @@ -14,7 +14,6 @@ android:layout_height="0dp" android:layout_weight="1" android:fadeScrollbars="false" - android:orientation="vertical" android:scrollbars="vertical" tools:itemCount="5" tools:listitem="@layout/item_bottom_sheet_action" /> diff --git a/vector/src/main/res/layout/item_bottom_sheet_action.xml b/vector/src/main/res/layout/item_bottom_sheet_action.xml index 44145e7bf5..4f56e3c126 100644 --- a/vector/src/main/res/layout/item_bottom_sheet_action.xml +++ b/vector/src/main/res/layout/item_bottom_sheet_action.xml @@ -11,8 +11,7 @@ android:paddingLeft="@dimen/layout_horizontal_margin" android:paddingTop="8dp" android:paddingRight="@dimen/layout_horizontal_margin" - android:paddingBottom="8dp" - tools:layout_height="50dp"> + android:paddingBottom="8dp">