Cleanup PermalinkHandler and Navigation

This commit is contained in:
Benoit Marty 2019-06-19 11:10:36 +02:00
parent 73b55fd975
commit 90f420b287
10 changed files with 42 additions and 65 deletions

View File

@ -51,7 +51,7 @@ class HomeModule {
}

scope(HOME_SCOPE) {
HomePermalinkHandler(get(), get())
PermalinkHandler(get())
}

// Fragment scopes

View File

@ -17,11 +17,9 @@
package im.vector.riotredesign.features.home

import androidx.core.view.GravityCompat
import androidx.fragment.app.FragmentManager
import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.replaceFragment
import im.vector.riotredesign.features.navigation.Navigator
import kotlinx.android.synthetic.main.activity_home.*
import timber.log.Timber

@ -29,8 +27,6 @@ class HomeNavigator {

var activity: HomeActivity? = null

private var rootRoomId: String? = null

fun openSelectedGroup(groupSummary: GroupSummary) {
Timber.v("Open selected group ${groupSummary.groupId}")
activity?.let {
@ -41,36 +37,4 @@ class HomeNavigator {
it.replaceFragment(homeDetailFragment, R.id.homeDetailFragmentContainer)
}
}

fun openRoomDetail(roomId: String,
eventId: String?,
navigator: Navigator) {
Timber.v("Open room detail $roomId - $eventId")
activity?.let {
//TODO enable eventId permalink. It doesn't work enough at the moment.
navigator.openRoom(roomId, it)
}
}

fun openGroupDetail(groupId: String) {
Timber.v("Open group detail $groupId")
}

fun openUserDetail(userId: String) {
Timber.v("Open user detail $userId")
}

// Private Methods *****************************************************************************

private fun clearBackStack(fragmentManager: FragmentManager) {
if (fragmentManager.backStackEntryCount > 0) {
val first = fragmentManager.getBackStackEntryAt(0)
fragmentManager.popBackStack(first.id, FragmentManager.POP_BACK_STACK_INCLUSIVE)
}
}

private fun isRoot(roomId: String): Boolean {
return rootRoomId == roomId
}

}
}

View File

@ -16,41 +16,40 @@

package im.vector.riotredesign.features.home

import android.content.Context
import android.net.Uri
import im.vector.matrix.android.api.permalinks.PermalinkData
import im.vector.matrix.android.api.permalinks.PermalinkParser
import im.vector.riotredesign.core.utils.openUrlInExternalBrowser
import im.vector.riotredesign.features.navigation.Navigator

class HomePermalinkHandler(private val homeNavigator: HomeNavigator,
private val navigator: Navigator) {
class PermalinkHandler(private val navigator: Navigator) {

fun launch(deepLink: String?) {
fun launch(context: Context, deepLink: String?) {
val uri = deepLink?.let { Uri.parse(it) }
launch(uri)
launch(context, uri)
}

fun launch(deepLink: Uri?) {
fun launch(context: Context, deepLink: Uri?) {
if (deepLink == null) {
return
}
val permalinkData = PermalinkParser.parse(deepLink)
when (permalinkData) {
is PermalinkData.EventLink -> {
homeNavigator.openRoomDetail(permalinkData.roomIdOrAlias, permalinkData.eventId, navigator)
when (val permalinkData = PermalinkParser.parse(deepLink)) {
is PermalinkData.EventLink -> {
navigator.openRoom(context, permalinkData.roomIdOrAlias, permalinkData.eventId)
}
is PermalinkData.RoomLink -> {
homeNavigator.openRoomDetail(permalinkData.roomIdOrAlias, null, navigator)
is PermalinkData.RoomLink -> {
navigator.openRoom(context, permalinkData.roomIdOrAlias)
}
is PermalinkData.GroupLink -> {
homeNavigator.openGroupDetail(permalinkData.groupId)
is PermalinkData.GroupLink -> {
navigator.openGroupDetail(permalinkData.groupId, context)
}
is PermalinkData.UserLink -> {
homeNavigator.openUserDetail(permalinkData.userId)
is PermalinkData.UserLink -> {
navigator.openUserDetail(permalinkData.userId, context)
}
is PermalinkData.FallbackLink -> {

openUrlInExternalBrowser(context, permalinkData.uri)
}
}
}

}

View File

@ -74,7 +74,7 @@ import im.vector.riotredesign.features.autocomplete.user.AutocompleteUserPresent
import im.vector.riotredesign.features.command.Command
import im.vector.riotredesign.features.home.AvatarRenderer
import im.vector.riotredesign.features.home.HomeModule
import im.vector.riotredesign.features.home.HomePermalinkHandler
import im.vector.riotredesign.features.home.PermalinkHandler
import im.vector.riotredesign.features.home.getColorFromUserId
import im.vector.riotredesign.features.home.room.detail.composer.TextComposerActions
import im.vector.riotredesign.features.home.room.detail.composer.TextComposerView
@ -167,7 +167,7 @@ class RoomDetailFragment :
private val commandAutocompletePolicy = CommandAutocompletePolicy()
private val autocompleteCommandPresenter: AutocompleteCommandPresenter by inject { parametersOf(this) }
private val autocompleteUserPresenter: AutocompleteUserPresenter by inject { parametersOf(this) }
private val homePermalinkHandler: HomePermalinkHandler by inject()
private val permalinkHandler: PermalinkHandler by inject()

private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback

@ -535,7 +535,8 @@ class RoomDetailFragment :
// TimelineEventController.Callback ************************************************************

override fun onUrlClicked(url: String) {
homePermalinkHandler.launch(url)
// TODO Room can be the same
permalinkHandler.launch(requireActivity(), url)
}

override fun onEventVisible(event: TimelineEvent) {

View File

@ -72,7 +72,7 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback, O
setupRecyclerView()
roomListViewModel.subscribe { renderState(it) }
roomListViewModel.openRoomLiveData.observeEvent(this) {
navigator.openRoom(it, requireActivity())
navigator.openRoom(requireActivity(), it)
}

createChatFabMenu.listener = this

View File

@ -27,12 +27,13 @@ import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity
import im.vector.riotredesign.features.settings.VectorSettingsActivity
import timber.log.Timber

class DefaultNavigator : Navigator {


override fun openRoom(roomId: String, context: Context) {
val args = RoomDetailArgs(roomId)
override fun openRoom(context: Context, roomId: String, eventId: String?) {
val args = RoomDetailArgs(roomId, eventId)
val intent = RoomDetailActivity.newIntent(context, args)
context.startActivity(intent)
}
@ -63,4 +64,12 @@ class DefaultNavigator : Navigator {
override fun openKeysBackupManager(context: Context) {
context.startActivity(KeysBackupManageActivity.intent(context))
}

override fun openGroupDetail(groupId: String, context: Context) {
Timber.v("Open group detail $groupId")
}

override fun openUserDetail(userId: String, context: Context) {
Timber.v("Open user detail $userId")
}
}

View File

@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom

interface Navigator {

fun openRoom(roomId: String, context: Context)
fun openRoom(context: Context, roomId: String, eventId: String? = null)

fun openRoomPreview(publicRoom: PublicRoom, context: Context)

@ -34,4 +34,8 @@ interface Navigator {
fun openKeysBackupSetup(context: Context, showManualExport: Boolean)

fun openKeysBackupManager(context: Context)

fun openGroupDetail(groupId: String, context: Context)

fun openUserDetail(userId: String, context: Context)
}

View File

@ -122,7 +122,7 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback

when (joinState) {
JoinState.JOINED -> {
navigator.openRoom(publicRoom.roomId, requireActivity())
navigator.openRoom(requireActivity(), publicRoom.roomId)
}
JoinState.NOT_JOINED,
JoinState.JOINING_ERROR -> {

View File

@ -100,7 +100,7 @@ class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener {
val async = state.asyncCreateRoomRequest
if (async is Success) {
// Navigate to freshly created room
navigator.openRoom(async(), requireActivity())
navigator.openRoom(requireActivity(), async())

navigationViewModel.goTo(RoomDirectoryActivity.Navigation.Close)
} else {

View File

@ -108,7 +108,7 @@ class RoomPreviewNoPreviewFragment : VectorBaseFragment() {
// Quit this screen
requireActivity().finish()
// Open room
navigator.openRoom(roomPreviewData.roomId, requireActivity())
navigator.openRoom(requireActivity(), roomPreviewData.roomId)
}
}
}