From 5a65eddf599c827780b3652b3aa1a10cd72340ee Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 10 Jul 2020 12:48:35 +0200 Subject: [PATCH] Cleanup Navigator --- .../home/room/detail/RoomDetailFragment.kt | 16 ++++-- .../media/VectorAttachmentViewerActivity.kt | 5 +- .../features/navigation/DefaultNavigator.kt | 52 +------------------ .../riotx/features/navigation/Navigator.kt | 11 +--- .../uploads/media/RoomUploadsMediaFragment.kt | 19 +++++-- 5 files changed, 34 insertions(+), 69 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index a457587aa8..938ae6a1bb 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -1171,14 +1171,24 @@ class RoomDetailFragment @Inject constructor( } override fun onImageMessageClicked(messageImageContent: MessageImageInfoContent, mediaData: ImageContentRenderer.Data, view: View) { - navigator.openImageViewer(requireActivity(), roomDetailArgs.roomId, mediaData, view) { pairs -> + navigator.openMediaViewer( + activity = requireActivity(), + roomId = roomDetailArgs.roomId, + mediaData = mediaData, + view = view + ) { pairs -> pairs.add(Pair(roomToolbar, ViewCompat.getTransitionName(roomToolbar) ?: "")) pairs.add(Pair(composerLayout, ViewCompat.getTransitionName(composerLayout) ?: "")) } } override fun onVideoMessageClicked(messageVideoContent: MessageVideoContent, mediaData: VideoContentRenderer.Data, view: View) { - navigator.openVideoViewer(requireActivity(), roomDetailArgs.roomId, mediaData, view) { pairs -> + navigator.openMediaViewer( + activity = requireActivity(), + roomId = roomDetailArgs.roomId, + mediaData = mediaData, + view = view + ) { pairs -> pairs.add(Pair(roomToolbar, ViewCompat.getTransitionName(roomToolbar) ?: "")) pairs.add(Pair(composerLayout, ViewCompat.getTransitionName(composerLayout) ?: "")) } @@ -1199,7 +1209,7 @@ class RoomDetailFragment @Inject constructor( override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { if (allGranted(grantResults)) { when (requestCode) { - SAVE_ATTACHEMENT_REQUEST_CODE -> { + SAVE_ATTACHEMENT_REQUEST_CODE -> { sharedActionViewModel.pendingAction?.let { handleActions(it) sharedActionViewModel.pendingAction = null diff --git a/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt index c0b822c13a..38e3ccc69c 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VectorAttachmentViewerActivity.kt @@ -237,7 +237,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen } companion object { - const val EXTRA_ARGS = "EXTRA_ARGS" const val EXTRA_IMAGE_DATA = "EXTRA_IMAGE_DATA" const val EXTRA_IN_MEMORY_DATA = "EXTRA_IN_MEMORY_DATA" @@ -246,11 +245,11 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen mediaData: AttachmentData, roomId: String?, eventId: String, - inMemoryData: List?, + inMemoryData: List, sharedTransitionName: String?) = Intent(context, VectorAttachmentViewerActivity::class.java).also { it.putExtra(EXTRA_ARGS, Args(roomId, eventId, sharedTransitionName)) it.putExtra(EXTRA_IMAGE_DATA, mediaData) - if (inMemoryData != null) { + if (inMemoryData.isNotEmpty()) { it.putParcelableArrayListExtra(EXTRA_IN_MEMORY_DATA, ArrayList(inMemoryData)) } } diff --git a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt index 6acd041ecf..99eb69f539 100644 --- a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt @@ -19,7 +19,6 @@ package im.vector.riotx.features.navigation import android.app.Activity import android.content.Context import android.content.Intent -import android.os.Build import android.view.View import android.view.Window import androidx.core.app.ActivityOptionsCompat @@ -52,7 +51,6 @@ import im.vector.riotx.features.invite.InviteUsersToRoomActivity import im.vector.riotx.features.media.AttachmentData import im.vector.riotx.features.media.BigImageViewerActivity import im.vector.riotx.features.media.VectorAttachmentViewerActivity -import im.vector.riotx.features.media.VideoContentRenderer import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewActivity @@ -245,11 +243,11 @@ class DefaultNavigator @Inject constructor( context.startActivity(WidgetActivity.newIntent(context, widgetArgs)) } - override fun openImageViewer(activity: Activity, + override fun openMediaViewer(activity: Activity, roomId: String, mediaData: AttachmentData, view: View, - inMemory: List?, + inMemory: List, options: ((MutableList>) -> Unit)?) { VectorAttachmentViewerActivity.newIntent(activity, mediaData, @@ -268,52 +266,6 @@ class DefaultNavigator @Inject constructor( pairs.add(Pair(view, ViewCompat.getTransitionName(view) ?: "")) options?.invoke(pairs) - val bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *pairs.toTypedArray()).toBundle() - activity.startActivity(intent, bundle) - } -// val intent = ImageMediaViewerActivity.newIntent(activity, mediaData, ViewCompat.getTransitionName(view)) -// val pairs = ArrayList>() -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// activity.window.decorView.findViewById(android.R.id.statusBarBackground)?.let { -// pairs.add(Pair(it, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME)) -// } -// activity.window.decorView.findViewById(android.R.id.navigationBarBackground)?.let { -// pairs.add(Pair(it, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME)) -// } -// } -// pairs.add(Pair(view, ViewCompat.getTransitionName(view) ?: "")) -// options?.invoke(pairs) -// -// val bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *pairs.toTypedArray()).toBundle() -// activity.startActivity(intent, bundle) - } - - override fun openVideoViewer(activity: Activity, - roomId: String, - mediaData: AttachmentData, - view: View, - inMemory: List?, - options: ((MutableList>) -> Unit)?) { -// val intent = VideoMediaViewerActivity.newIntent(activity, mediaData) -// activity.startActivity(intent) - VectorAttachmentViewerActivity.newIntent(activity, - mediaData, - roomId, - mediaData.eventId, - inMemory, - ViewCompat.getTransitionName(view)).let { intent -> - val pairs = ArrayList>() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - activity.window.decorView.findViewById(android.R.id.statusBarBackground)?.let { - pairs.add(Pair(it, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME)) - } - activity.window.decorView.findViewById(android.R.id.navigationBarBackground)?.let { - pairs.add(Pair(it, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME)) - } - } - pairs.add(Pair(view, ViewCompat.getTransitionName(view) ?: "")) - options?.invoke(pairs) - val bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *pairs.toTypedArray()).toBundle() activity.startActivity(intent, bundle) } diff --git a/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt index 6d036f1468..273734916d 100644 --- a/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt @@ -91,17 +91,10 @@ interface Navigator { fun openRoomWidget(context: Context, roomId: String, widget: Widget) - fun openImageViewer(activity: Activity, + fun openMediaViewer(activity: Activity, roomId: String, mediaData: AttachmentData, view: View, - inMemory: List? = null, - options: ((MutableList>) -> Unit)?) - - fun openVideoViewer(activity: Activity, - roomId: String, - mediaData: VideoContentRenderer.Data, - view: View, - inMemory: List? = null, + inMemory: List = emptyList(), options: ((MutableList>) -> Unit)?) } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt index e0758c7d72..dda070bf48 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/media/RoomUploadsMediaFragment.kt @@ -89,7 +89,7 @@ class RoomUploadsMediaFragment @Inject constructor( // It's very strange i can't just access // the app bar using find by id... - private fun trickFindAppBar() : AppBarLayout? { + private fun trickFindAppBar(): AppBarLayout? { return activity?.supportFragmentManager?.fragments ?.filterIsInstance() ?.firstOrNull() @@ -97,9 +97,14 @@ class RoomUploadsMediaFragment @Inject constructor( } override fun onOpenImageClicked(view: View, mediaData: ImageContentRenderer.Data) = withState(uploadsViewModel) { state -> - val inMemory = getItemsArgs(state) - navigator.openImageViewer(requireActivity(), state.roomId, mediaData, view, inMemory) { pairs -> + navigator.openMediaViewer( + activity = requireActivity(), + roomId = state.roomId, + mediaData = mediaData, + view = view, + inMemory = inMemory + ) { pairs -> trickFindAppBar()?.let { pairs.add(Pair(it, ViewCompat.getTransitionName(it) ?: "")) } @@ -151,7 +156,13 @@ class RoomUploadsMediaFragment @Inject constructor( override fun onOpenVideoClicked(view: View, mediaData: VideoContentRenderer.Data) = withState(uploadsViewModel) { state -> val inMemory = getItemsArgs(state) - navigator.openVideoViewer(requireActivity(), state.roomId, mediaData, view, inMemory) { pairs -> + navigator.openMediaViewer( + activity = requireActivity(), + roomId = state.roomId, + mediaData = mediaData, + view = view, + inMemory = inMemory + ) { pairs -> trickFindAppBar()?.let { pairs.add(Pair(it, ViewCompat.getTransitionName(it) ?: "")) }