From 93cb7b8ce6475c0133e80f2aeca81df76f3d62dc Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 9 May 2019 18:43:10 +0200 Subject: [PATCH] Cleaning --- CHANGES.md | 2 +- .../home/room/detail/RoomDetailFragment.kt | 10 +------- .../detail/timeline/action/ActionsHandler.kt | 15 ++++++++++++ .../action/BaseMvRxBottomSheetDialog.kt | 4 +++- .../action/MessageActionsBottomSheet.kt | 17 ++++--------- .../action/MessageActionsViewModel.kt | 24 ++++++++++++++----- .../timeline/action/MessageMenuFragment.kt | 18 ++++++++++++++ .../timeline/action/MessageMenuViewModel.kt | 23 ++++++++++++++---- .../timeline/action/QuickReactionFragment.kt | 11 +++------ .../timeline/action/QuickReactionViewModel.kt | 4 ++++ 10 files changed, 86 insertions(+), 42 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ad6294c176..7b52a03795 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ Changes in RiotX 0.XX (2019-XX-XX) =================================================== Features: - - + - Contextual action menu for messages in room Improvements: - diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index dd6e4407fc..2168c03edc 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -426,17 +426,9 @@ class RoomDetailFragment : } override fun onEventCellClicked(eventId: String, informationData: MessageInformationData, messageContent: MessageContent, view: View) { - val roomId = (arguments?.get(MvRx.KEY_ARG) as? RoomDetailArgs)?.roomId - if (roomId.isNullOrBlank()) { - Timber.e("Missing RoomId, cannot open bottomsheet") - return - } - MessageActionsBottomSheet - .newInstance(eventId, roomId, informationData) - .show(requireActivity().supportFragmentManager, "MESSAGE_CONTEXTUAL_ACTIONS") + } - // AutocompleteUserPresenter.Callback override fun onEventLongClicked(eventId: String, informationData: MessageInformationData, messageContent: MessageContent, view: View): Boolean { view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) val roomId = (arguments?.get(MvRx.KEY_ARG) as? RoomDetailArgs)?.roomId diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt index 4b876a499d..84cfc40f0f 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.riotredesign.features.home.room.detail.timeline.action import androidx.lifecycle.MutableLiveData diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt index 7001d730b6..504e99c04b 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt @@ -20,7 +20,9 @@ import com.airbnb.mvrx.MvRxView import com.airbnb.mvrx.MvRxViewModelStore import com.google.android.material.bottomsheet.BottomSheetDialogFragment - +/** + * Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment) + */ abstract class BaseMvRxBottomSheetDialog() : BottomSheetDialogFragment(), MvRxView { override val mvrxViewModelStore by lazy { MvRxViewModelStore(viewModelStore) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index 5f268e61bc..7f1609d9c5 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -38,7 +38,10 @@ import im.vector.riotredesign.features.home.AvatarRenderer import im.vector.riotredesign.features.home.room.detail.timeline.item.MessageInformationData import kotlinx.android.parcel.Parcelize - +/** + * Bottom sheet fragment that shows a message preview with list of contextual actions + * (Includes fragments for quick reactions and list of actions) + */ class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { private val viewModel: MessageActionsViewModel by fragmentViewModel(MessageActionsViewModel::class) @@ -137,9 +140,6 @@ class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { val eventId: String, val roomId: String, val informationData: MessageInformationData -// val body: String, -// val type: String, -// var url: String? = null ) : Parcelable companion object { @@ -149,16 +149,7 @@ class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { eventId, roomId, informationData -// messageContent.body, -// messageContent.type ) -// if (messageContent is MessageImageContent) { -// parcelableArgs.url = messageContent.url -// } -// if (messageContent is MessageVideoContent) { -// parcelableArgs.url = messageContent.url -// } - args.putParcelable(MvRx.KEY_ARG, parcelableArgs) return MessageActionsBottomSheet().apply { arguments = args } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 3c6a0b65c0..f8728c5f73 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.riotredesign.features.home.room.detail.timeline.action import com.airbnb.mvrx.MvRxState @@ -22,16 +37,13 @@ data class MessageActionState( val senderAvatarPath: String? = null) : MvRxState - +/** + * Information related to an event and used to display preview in contextual bottomsheet. + */ class MessageActionsViewModel(initialState: MessageActionState) : VectorViewModel(initialState) { companion object : MvRxViewModelFactory { -// override fun create(viewModelContext: ViewModelContext, state: MessageActionState): MessageActionsViewModel? { -// //val currentSession = viewModelContext.activity.get() -// return MessageActionsViewModel(state/*,currentSession*/) -// } - val dateFormat = SimpleDateFormat("EEE, d MMM yyyy HH:mm") override fun initialState(viewModelContext: ViewModelContext): MessageActionState? { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt index ae3eda31a1..8191cd88da 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.riotredesign.features.home.room.detail.timeline.action import android.os.Bundle @@ -17,6 +32,9 @@ import im.vector.riotredesign.R import im.vector.riotredesign.features.home.room.detail.timeline.item.MessageInformationData import im.vector.riotredesign.features.themes.ThemeUtils +/** + * Fragment showing the list of available contextual action for a given message. + */ class MessageMenuFragment : BaseMvRxFragment() { private val viewModel: MessageMenuViewModel by fragmentViewModel(MessageMenuViewModel::class) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index 6f3f55f9c7..ebe02f122c 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2019 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.riotredesign.features.home.room.detail.timeline.action import com.airbnb.mvrx.MvRxState @@ -17,13 +32,13 @@ import im.vector.riotredesign.core.platform.VectorViewModel import org.json.JSONObject import org.koin.android.ext.android.get - data class SimpleAction(val uid: String, val titleRes: Int, val iconResId: Int?, val data: Any? = null) -data class MessageMenuState( - val actions: List -) : MvRxState +data class MessageMenuState(val actions: List) : MvRxState +/** + * Manages list actions for a given message (copy / paste / forward...) + */ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel(initialState) { companion object : MvRxViewModelFactory { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt index 838083bb3e..1e3a7b6ba8 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt @@ -15,7 +15,6 @@ */ package im.vector.riotredesign.features.home.room.detail.timeline.action -import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -30,12 +29,13 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.R - +/** + * Quick Reaction Fragment (agree / like reactions) + */ class QuickReactionFragment : BaseMvRxFragment() { private val viewModel: QuickReactionViewModel by fragmentViewModel(QuickReactionViewModel::class) - @BindView(R.id.root_layout) lateinit var rootLayout: ConstraintLayout @@ -49,7 +49,6 @@ class QuickReactionFragment : BaseMvRxFragment() { @BindView(R.id.quick_react_4) lateinit var quickReact4: View - @BindView(R.id.quick_react_1_text) lateinit var quickReact1Text: TextView @@ -70,10 +69,6 @@ class QuickReactionFragment : BaseMvRxFragment() { return view } - override fun onAttach(context: Context) { - super.onAttach(context) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionViewModel.kt index 73126b3b2b..eb0fed967d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionViewModel.kt @@ -31,6 +31,10 @@ enum class TriggleState { data class QuickReactionState(val agreeTrigleState: TriggleState, val likeTriggleState: TriggleState, val selectionResult: List? = null) : MvRxState +/** + * Quick reaction view model + * TODO: configure initial state from event + */ class QuickReactionViewModel(initialState: QuickReactionState) : VectorViewModel(initialState) { val agreePositive = "👍"