mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Try to centralise the usage of fragment args
This commit is contained in:
parent
2c9526543b
commit
0d97fa201e
@ -20,6 +20,7 @@ import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.MavericksState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
||||
import im.vector.app.features.share.SharedData
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||
@ -77,6 +78,8 @@ data class RoomDetailViewState(
|
||||
val threadNotificationBadgeState: ThreadNotificationBadgeState = ThreadNotificationBadgeState(),
|
||||
val typingUsers: List<SenderInfo>? = null,
|
||||
val isSharingLiveLocation: Boolean = false,
|
||||
val showKeyboardWhenPresented: Boolean = false,
|
||||
val sharedData: SharedData? = null,
|
||||
) : MavericksState {
|
||||
|
||||
constructor(args: TimelineArgs) : this(
|
||||
@ -86,7 +89,9 @@ data class RoomDetailViewState(
|
||||
// Also highlight the target event, if any
|
||||
highlightedEventId = args.eventId,
|
||||
switchToParentSpace = args.switchToParentSpace,
|
||||
rootThreadEventId = args.threadTimelineArgs?.rootThreadEventId
|
||||
rootThreadEventId = args.threadTimelineArgs?.rootThreadEventId,
|
||||
showKeyboardWhenPresented = args.threadTimelineArgs?.showKeyboard.orFalse(),
|
||||
sharedData = args.sharedData,
|
||||
)
|
||||
|
||||
fun isCallOptionAvailable(): Boolean {
|
||||
|
@ -300,17 +300,13 @@ class TimelineFragment :
|
||||
|
||||
childFragmentManager.findFragmentById(R.id.composerContainer) as? MessageComposerFragment ?: run {
|
||||
childFragmentManager.commitTransaction {
|
||||
val fragment = MessageComposerFragment()
|
||||
fragment.arguments = timelineArgs.toMvRxBundle()
|
||||
replace(R.id.composerContainer, fragment)
|
||||
replace(R.id.composerContainer, MessageComposerFragment())
|
||||
}
|
||||
}
|
||||
|
||||
childFragmentManager.findFragmentById(R.id.voiceMessageRecorderContainer) as? VoiceRecorderFragment ?: run {
|
||||
childFragmentManager.commitTransaction {
|
||||
val fragment = VoiceRecorderFragment()
|
||||
fragment.arguments = timelineArgs.toMvRxBundle()
|
||||
replace(R.id.voiceMessageRecorderContainer, fragment)
|
||||
replace(R.id.voiceMessageRecorderContainer, VoiceRecorderFragment())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2010,7 +2006,7 @@ class TimelineFragment :
|
||||
/**
|
||||
* Returns true if the current room is a Thread room, false otherwise.
|
||||
*/
|
||||
private fun isThreadTimeLine(): Boolean = timelineArgs.threadTimelineArgs?.rootThreadEventId != null
|
||||
private fun isThreadTimeLine(): Boolean = withState(timelineViewModel) { it.isThreadTimeline() }
|
||||
|
||||
/**
|
||||
* Returns true if the current room is a local room, false otherwise.
|
||||
@ -2020,5 +2016,5 @@ class TimelineFragment :
|
||||
/**
|
||||
* Returns the root thread event if we are in a thread room, otherwise returns null.
|
||||
*/
|
||||
fun getRootThreadEventId(): String? = timelineArgs.threadTimelineArgs?.rootThreadEventId
|
||||
fun getRootThreadEventId(): String? = withState(timelineViewModel) { it.rootThreadEventId }
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.existingViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@ -74,7 +73,6 @@ import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.room.detail.AutoCompleter
|
||||
import im.vector.app.features.home.room.detail.RoomDetailAction
|
||||
import im.vector.app.features.home.room.detail.TimelineViewModel
|
||||
import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
||||
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView
|
||||
import im.vector.app.features.home.room.detail.timeline.action.MessageSharedActionViewModel
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
||||
@ -131,14 +129,14 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
@Inject lateinit var buildMeta: BuildMeta
|
||||
@Inject lateinit var session: Session
|
||||
|
||||
private val timelineArgs: TimelineArgs by args()
|
||||
private val roomId: String get() = withState(timelineViewModel) { it.roomId }
|
||||
|
||||
private val autoCompleter: AutoCompleter by lazy {
|
||||
autoCompleterFactory.create(timelineArgs.roomId, isThreadTimeLine())
|
||||
autoCompleterFactory.create(roomId, isThreadTimeLine())
|
||||
}
|
||||
|
||||
private val pillsPostProcessor by lazy {
|
||||
pillsPostProcessorFactory.create(timelineArgs.roomId)
|
||||
pillsPostProcessorFactory.create(roomId)
|
||||
}
|
||||
|
||||
private val emojiPopup: EmojiPopup by lifecycleAwareLazy {
|
||||
@ -267,7 +265,8 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
|
||||
views.composerLayout.views.composerEmojiButton.isVisible = vectorPreferences.showEmojiKeyboard()
|
||||
|
||||
if (isThreadTimeLine() && timelineArgs.threadTimelineArgs?.showKeyboard == true) {
|
||||
val showKeyboard = withState(timelineViewModel) { it.showKeyboardWhenPresented }
|
||||
if (isThreadTimeLine() && showKeyboard) {
|
||||
// Show keyboard when the user started a thread
|
||||
views.composerLayout.views.composerEditText.showKeyboard(andRequestFocus = true)
|
||||
}
|
||||
@ -555,7 +554,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
views.composerLayout.setTextIfDifferent("")
|
||||
when (parsedCommand) {
|
||||
is ParsedCommand.DevTools -> {
|
||||
navigator.openDevTools(requireContext(), timelineArgs.roomId)
|
||||
navigator.openDevTools(requireContext(), roomId)
|
||||
}
|
||||
is ParsedCommand.SetMarkdown -> {
|
||||
showSnackWithMessage(getString(if (parsedCommand.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled))
|
||||
@ -578,12 +577,13 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
|
||||
private fun handleShowRoomUpgradeDialog(roomDetailViewEvents: MessageComposerViewEvents.ShowRoomUpgradeDialog) {
|
||||
val tag = MigrateRoomBottomSheet::javaClass.name
|
||||
MigrateRoomBottomSheet.newInstance(timelineArgs.roomId, roomDetailViewEvents.newVersion)
|
||||
val roomId = withState(timelineViewModel) { it.roomId }
|
||||
MigrateRoomBottomSheet.newInstance(roomId, roomDetailViewEvents.newVersion)
|
||||
.show(parentFragmentManager, tag)
|
||||
}
|
||||
|
||||
private fun openRoomMemberProfile(userId: String) {
|
||||
navigator.openRoomMemberProfile(userId = userId, roomId = timelineArgs.roomId, context = requireActivity())
|
||||
navigator.openRoomMemberProfile(userId = userId, roomId = roomId, context = requireActivity())
|
||||
}
|
||||
|
||||
private val contentAttachmentActivityResultLauncher = registerStartForActivityResult { activityResult ->
|
||||
@ -598,12 +598,12 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
/**
|
||||
* Returns the root thread event if we are in a thread room, otherwise returns null.
|
||||
*/
|
||||
fun getRootThreadEventId(): String? = timelineArgs.threadTimelineArgs?.rootThreadEventId
|
||||
fun getRootThreadEventId(): String? = withState(timelineViewModel) { it.rootThreadEventId }
|
||||
|
||||
/**
|
||||
* Returns true if the current room is a Thread room, false otherwise.
|
||||
*/
|
||||
private fun isThreadTimeLine(): Boolean = timelineArgs.threadTimelineArgs?.rootThreadEventId != null
|
||||
private fun isThreadTimeLine(): Boolean = withState(timelineViewModel) { it.isThreadTimeline() }
|
||||
|
||||
|
||||
// AttachmentsHelper.Callback
|
||||
@ -656,12 +656,12 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
AttachmentTypeSelectorView.Type.GALLERY -> attachmentsHelper.selectGallery(attachmentMediaActivityResultLauncher)
|
||||
AttachmentTypeSelectorView.Type.CONTACT -> attachmentsHelper.selectContact(attachmentContactActivityResultLauncher)
|
||||
AttachmentTypeSelectorView.Type.STICKER -> timelineViewModel.handle(RoomDetailAction.SelectStickerAttachment)
|
||||
AttachmentTypeSelectorView.Type.POLL -> navigator.openCreatePoll(requireContext(), timelineArgs.roomId, null, PollMode.CREATE)
|
||||
AttachmentTypeSelectorView.Type.POLL -> navigator.openCreatePoll(requireContext(), roomId, null, PollMode.CREATE)
|
||||
AttachmentTypeSelectorView.Type.LOCATION -> {
|
||||
navigator
|
||||
.openLocationSharing(
|
||||
context = requireContext(),
|
||||
roomId = timelineArgs.roomId,
|
||||
roomId = roomId,
|
||||
mode = LocationSharingMode.STATIC_SHARING,
|
||||
initialLocationData = null,
|
||||
locationOwnerId = session.myUserId
|
||||
@ -716,7 +716,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
}
|
||||
|
||||
private fun handleShareData() {
|
||||
when (val sharedData = timelineArgs.sharedData) {
|
||||
when (val sharedData = withState(timelineViewModel) { it.sharedData }) {
|
||||
is SharedData.Text -> {
|
||||
messageComposerViewModel.handle(MessageComposerAction.OnTextChanged(sharedData.text))
|
||||
messageComposerViewModel.handle(MessageComposerAction.EnterRegularMode(fromSharing = true))
|
||||
|
@ -21,7 +21,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.existingViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@ -35,7 +34,6 @@ import im.vector.app.core.utils.onPermissionDeniedSnackbar
|
||||
import im.vector.app.core.utils.registerForPermissionsResult
|
||||
import im.vector.app.databinding.FragmentVoiceRecorderBinding
|
||||
import im.vector.app.features.home.room.detail.TimelineViewModel
|
||||
import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
||||
import im.vector.app.features.home.room.detail.composer.MessageComposerAction
|
||||
import im.vector.app.features.home.room.detail.composer.MessageComposerViewEvents
|
||||
import im.vector.app.features.home.room.detail.composer.MessageComposerViewModel
|
||||
@ -48,8 +46,6 @@ class VoiceRecorderFragment : VectorBaseFragment<FragmentVoiceRecorderBinding>()
|
||||
@Inject lateinit var audioMessagePlaybackTracker: AudioMessagePlaybackTracker
|
||||
@Inject lateinit var clock: Clock
|
||||
|
||||
private val timelineArgs: TimelineArgs by args()
|
||||
|
||||
private val timelineViewModel: TimelineViewModel by existingViewModel()
|
||||
private val messageComposerViewModel: MessageComposerViewModel by existingViewModel()
|
||||
|
||||
@ -191,6 +187,6 @@ class VoiceRecorderFragment : VectorBaseFragment<FragmentVoiceRecorderBinding>()
|
||||
/**
|
||||
* Returns the root thread event if we are in a thread room, otherwise returns null.
|
||||
*/
|
||||
fun getRootThreadEventId(): String? = timelineArgs.threadTimelineArgs?.rootThreadEventId
|
||||
fun getRootThreadEventId(): String? = withState(timelineViewModel) { it.rootThreadEventId }
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user