Create PermalinkUseCase to avoid injecting the Session in the View.
This commit is contained in:
parent
aa806ed2c6
commit
cfca776d01
|
@ -32,6 +32,7 @@ import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.core.utils.startSharePlainTextIntent
|
import im.vector.app.core.utils.startSharePlainTextIntent
|
||||||
import im.vector.app.databinding.FragmentHomeDrawerBinding
|
import im.vector.app.databinding.FragmentHomeDrawerBinding
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
import im.vector.app.features.analytics.plan.MobileScreen
|
||||||
|
import im.vector.app.features.permalink.PermalinkUseCase
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.features.settings.VectorSettingsActivity
|
import im.vector.app.features.settings.VectorSettingsActivity
|
||||||
import im.vector.app.features.spaces.SpaceListFragment
|
import im.vector.app.features.spaces.SpaceListFragment
|
||||||
|
@ -49,6 +50,7 @@ class HomeDrawerFragment :
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||||
@Inject lateinit var buildMeta: BuildMeta
|
@Inject lateinit var buildMeta: BuildMeta
|
||||||
|
@Inject lateinit var permalinkUseCase: PermalinkUseCase
|
||||||
|
|
||||||
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
|
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
|
||||||
|
|
||||||
|
@ -101,7 +103,7 @@ class HomeDrawerFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
views.homeDrawerInviteFriendButton.debouncedClicks {
|
views.homeDrawerInviteFriendButton.debouncedClicks {
|
||||||
session.permalinkService().createPermalink(sharedActionViewModel.session.myUserId)?.let { permalink ->
|
permalinkUseCase.createPermalinkOfCurrentUser()?.let { permalink ->
|
||||||
analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.InviteFriends))
|
analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.InviteFriends))
|
||||||
val text = getString(R.string.invite_friends_text, permalink)
|
val text = getString(R.string.invite_friends_text, permalink)
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ import im.vector.app.features.workers.signout.ServerBackupStatusAction
|
||||||
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
|
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import org.matrix.android.sdk.api.session.Session
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -80,7 +79,6 @@ class NewHomeDetailFragment :
|
||||||
@Inject lateinit var callManager: WebRtcCallManager
|
@Inject lateinit var callManager: WebRtcCallManager
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var spaceStateHandler: SpaceStateHandler
|
@Inject lateinit var spaceStateHandler: SpaceStateHandler
|
||||||
@Inject lateinit var session: Session
|
|
||||||
@Inject lateinit var buildMeta: BuildMeta
|
@Inject lateinit var buildMeta: BuildMeta
|
||||||
|
|
||||||
private val viewModel: HomeDetailViewModel by fragmentViewModel()
|
private val viewModel: HomeDetailViewModel by fragmentViewModel()
|
||||||
|
|
|
@ -169,6 +169,7 @@ import im.vector.app.features.notifications.NotificationDrawerManager
|
||||||
import im.vector.app.features.notifications.NotificationUtils
|
import im.vector.app.features.notifications.NotificationUtils
|
||||||
import im.vector.app.features.permalink.NavigationInterceptor
|
import im.vector.app.features.permalink.NavigationInterceptor
|
||||||
import im.vector.app.features.permalink.PermalinkHandler
|
import im.vector.app.features.permalink.PermalinkHandler
|
||||||
|
import im.vector.app.features.permalink.PermalinkUseCase
|
||||||
import im.vector.app.features.poll.PollMode
|
import im.vector.app.features.poll.PollMode
|
||||||
import im.vector.app.features.reactions.EmojiReactionPickerActivity
|
import im.vector.app.features.reactions.EmojiReactionPickerActivity
|
||||||
import im.vector.app.features.roomprofile.RoomProfileActivity
|
import im.vector.app.features.roomprofile.RoomProfileActivity
|
||||||
|
@ -247,6 +248,7 @@ class TimelineFragment :
|
||||||
@Inject lateinit var clock: Clock
|
@Inject lateinit var clock: Clock
|
||||||
@Inject lateinit var vectorFeatures: VectorFeatures
|
@Inject lateinit var vectorFeatures: VectorFeatures
|
||||||
@Inject lateinit var galleryOrCameraDialogHelperFactory: GalleryOrCameraDialogHelperFactory
|
@Inject lateinit var galleryOrCameraDialogHelperFactory: GalleryOrCameraDialogHelperFactory
|
||||||
|
@Inject lateinit var permalinkUseCase: PermalinkUseCase
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MAX_TYPING_MESSAGE_USERS_COUNT = 4
|
const val MAX_TYPING_MESSAGE_USERS_COUNT = 4
|
||||||
|
@ -867,7 +869,7 @@ class TimelineFragment :
|
||||||
}
|
}
|
||||||
R.id.menu_thread_timeline_copy_link -> {
|
R.id.menu_thread_timeline_copy_link -> {
|
||||||
getRootThreadEventId()?.let {
|
getRootThreadEventId()?.let {
|
||||||
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, it)
|
val permalink = permalinkUseCase.createPermalink(timelineArgs.roomId, it)
|
||||||
copyToClipboard(requireContext(), permalink, false)
|
copyToClipboard(requireContext(), permalink, false)
|
||||||
showSnackWithMessage(getString(R.string.copied_to_clipboard))
|
showSnackWithMessage(getString(R.string.copied_to_clipboard))
|
||||||
}
|
}
|
||||||
|
@ -879,7 +881,7 @@ class TimelineFragment :
|
||||||
}
|
}
|
||||||
R.id.menu_thread_timeline_share -> {
|
R.id.menu_thread_timeline_share -> {
|
||||||
getRootThreadEventId()?.let {
|
getRootThreadEventId()?.let {
|
||||||
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, it)
|
val permalink = permalinkUseCase.createPermalink(timelineArgs.roomId, it)
|
||||||
shareText(requireContext(), permalink)
|
shareText(requireContext(), permalink)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -1788,7 +1790,7 @@ class TimelineFragment :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is EventSharedAction.CopyPermalink -> {
|
is EventSharedAction.CopyPermalink -> {
|
||||||
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, action.eventId)
|
val permalink = permalinkUseCase.createPermalink(timelineArgs.roomId, action.eventId)
|
||||||
copyToClipboard(requireContext(), permalink, false)
|
copyToClipboard(requireContext(), permalink, false)
|
||||||
showSnackWithMessage(getString(R.string.copied_to_clipboard))
|
showSnackWithMessage(getString(R.string.copied_to_clipboard))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 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.features.permalink
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains synchronous methods to create permalinks from the Session.
|
||||||
|
*/
|
||||||
|
class PermalinkUseCase @Inject constructor(
|
||||||
|
private val session: Session,
|
||||||
|
) {
|
||||||
|
fun createPermalinkOfCurrentUser(): String? {
|
||||||
|
return createPermalink(session.myUserId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createPermalink(id: String): String? {
|
||||||
|
return session.permalinkService().createPermalink(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createPermalink(roomId: String, eventId: String): String {
|
||||||
|
return session.permalinkService().createPermalink(roomId, eventId)
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,11 +38,11 @@ import im.vector.app.databinding.FragmentPublicRoomsBinding
|
||||||
import im.vector.app.features.analytics.plan.ViewRoom
|
import im.vector.app.features.analytics.plan.ViewRoom
|
||||||
import im.vector.app.features.permalink.NavigationInterceptor
|
import im.vector.app.features.permalink.NavigationInterceptor
|
||||||
import im.vector.app.features.permalink.PermalinkHandler
|
import im.vector.app.features.permalink.PermalinkHandler
|
||||||
|
import im.vector.app.features.permalink.PermalinkUseCase
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
|
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
|
||||||
import reactivecircus.flowbinding.appcompat.queryTextChanges
|
import reactivecircus.flowbinding.appcompat.queryTextChanges
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -60,7 +60,7 @@ class PublicRoomsFragment :
|
||||||
|
|
||||||
@Inject lateinit var publicRoomsController: PublicRoomsController
|
@Inject lateinit var publicRoomsController: PublicRoomsController
|
||||||
@Inject lateinit var permalinkHandler: PermalinkHandler
|
@Inject lateinit var permalinkHandler: PermalinkHandler
|
||||||
@Inject lateinit var session: Session
|
@Inject lateinit var permalinkUseCase: PermalinkUseCase
|
||||||
|
|
||||||
private val viewModel: RoomDirectoryViewModel by activityViewModel()
|
private val viewModel: RoomDirectoryViewModel by activityViewModel()
|
||||||
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
|
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
|
||||||
|
@ -128,7 +128,7 @@ class PublicRoomsFragment :
|
||||||
|
|
||||||
override fun onUnknownRoomClicked(roomIdOrAlias: String) {
|
override fun onUnknownRoomClicked(roomIdOrAlias: String) {
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
val permalink = session.permalinkService().createPermalink(roomIdOrAlias)
|
val permalink = permalinkUseCase.createPermalink(roomIdOrAlias)
|
||||||
val isHandled = permalinkHandler
|
val isHandled = permalinkHandler
|
||||||
.launch(requireActivity(), permalink, object : NavigationInterceptor {
|
.launch(requireActivity(), permalink, object : NavigationInterceptor {
|
||||||
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {
|
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {
|
||||||
|
|
Loading…
Reference in New Issue