Open image from URL Preview (#2705)

This commit is contained in:
Benoit Marty 2021-02-07 15:00:07 +01:00
parent f6ad67f1c8
commit ed99b503f5
6 changed files with 28 additions and 6 deletions

View file

@ -5,7 +5,7 @@ Features ✨:
-
Improvements 🙌:
-
- Open image from URL Preview (#2705)
Bugfix 🐛:
- Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776)

View file

@ -1687,6 +1687,10 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.DoNotShowPreviewUrlFor(eventId, url))
}
override fun onPreviewUrlImageClicked(sharedView: View?, mxcUrl: String?, title: String?) {
navigator.openBigImageViewer(requireActivity(), sharedView, mxcUrl, title)
}
private fun onShareActionClicked(action: EventSharedAction.Share) {
if (action.messageContent is MessageTextContent) {
shareText(requireContext(), action.messageContent.body)

View file

@ -130,6 +130,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
interface PreviewUrlCallback {
fun onPreviewUrlClicked(url: String)
fun onPreviewUrlCloseClicked(eventId: String, url: String)
fun onPreviewUrlImageClicked(sharedView: View?, mxcUrl: String?, title: String?)
}
// Map eventId to adapter position

View file

@ -80,6 +80,19 @@ class PreviewUrlView @JvmOverloads constructor(
}
}
private fun onImageClick() {
when (val finalState = state) {
is PreviewUrlUiState.Data -> {
delegate?.onPreviewUrlImageClicked(
sharedView = views.urlPreviewImage,
mxcUrl = finalState.previewUrlData.mxcUrl,
title = finalState.previewUrlData.title
)
}
else -> Unit
}
}
private fun onCloseClick() {
when (val finalState = state) {
is PreviewUrlUiState.Data -> delegate?.onPreviewUrlCloseClicked(finalState.eventId, finalState.url)
@ -94,6 +107,7 @@ class PreviewUrlView @JvmOverloads constructor(
views = UrlPreviewBinding.bind(this)
setOnClickListener(this)
views.urlPreviewImage.setOnClickListener { onImageClick() }
views.urlPreviewClose.setOnClickListener { onCloseClick() }
}

View file

@ -73,7 +73,6 @@ import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryDat
import org.matrix.android.sdk.api.session.terms.TermsService
import org.matrix.android.sdk.api.session.widgets.model.Widget
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
import org.matrix.android.sdk.api.util.MatrixItem
import javax.inject.Inject
import javax.inject.Singleton
@ -256,11 +255,11 @@ class DefaultNavigator @Inject constructor(
context.startActivity(RoomProfileActivity.newIntent(context, roomId, directAccess))
}
override fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem) {
matrixItem.avatarUrl
override fun openBigImageViewer(activity: Activity, sharedElement: View?, mxcUrl: String?, title: String?) {
mxcUrl
?.takeIf { it.isNotBlank() }
?.let { avatarUrl ->
val intent = BigImageViewerActivity.newIntent(activity, matrixItem.getBestName(), avatarUrl)
val intent = BigImageViewerActivity.newIntent(activity, title, avatarUrl)
val options = sharedElement?.let {
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, it, ViewCompat.getTransitionName(it) ?: "")
}

View file

@ -80,7 +80,11 @@ interface Navigator {
fun openRoomProfile(context: Context, roomId: String, directAccess: Int? = null)
fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem)
fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem) {
openBigImageViewer(activity, sharedElement, matrixItem.avatarUrl, matrixItem.getBestName())
}
fun openBigImageViewer(activity: Activity, sharedElement: View?, mxcUrl: String?, title: String?)
fun openPinCode(context: Context,
activityResultLauncher: ActivityResultLauncher<Intent>,