Fix the rotate screen issue
This commit is contained in:
parent
c603ec0b38
commit
7869d731d4
@ -98,4 +98,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
|
|||||||
data class SetAvatarAction(val newAvatarUri: Uri, val newAvatarFileName: String) : RoomDetailAction()
|
data class SetAvatarAction(val newAvatarUri: Uri, val newAvatarFileName: String) : RoomDetailAction()
|
||||||
object QuickActionSetTopic : RoomDetailAction()
|
object QuickActionSetTopic : RoomDetailAction()
|
||||||
data class ShowRoomAvatarFullScreen(val matrixItem: MatrixItem?, val transitionView: View?) : RoomDetailAction()
|
data class ShowRoomAvatarFullScreen(val matrixItem: MatrixItem?, val transitionView: View?) : RoomDetailAction()
|
||||||
|
|
||||||
|
// Preview URL
|
||||||
|
data class DoNotShowPreviewUrlFor(val eventId: String, val url: String) : RoomDetailAction()
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,6 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val timelineEventController: TimelineEventController,
|
private val timelineEventController: TimelineEventController,
|
||||||
private val previewUrlRetriever: PreviewUrlRetriever,
|
|
||||||
autoCompleterFactory: AutoCompleter.Factory,
|
autoCompleterFactory: AutoCompleter.Factory,
|
||||||
private val permalinkHandler: PermalinkHandler,
|
private val permalinkHandler: PermalinkHandler,
|
||||||
private val notificationDrawerManager: NotificationDrawerManager,
|
private val notificationDrawerManager: NotificationDrawerManager,
|
||||||
@ -1632,6 +1631,10 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
roomDetailViewModel.handle(itemAction)
|
roomDetailViewModel.handle(itemAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPreviewUrlRetriever(): PreviewUrlRetriever {
|
||||||
|
return roomDetailViewModel.previewUrlRetriever
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRoomCreateLinkClicked(url: String) {
|
override fun onRoomCreateLinkClicked(url: String) {
|
||||||
permalinkHandler
|
permalinkHandler
|
||||||
.launch(requireContext(), url, object : NavigationInterceptor {
|
.launch(requireContext(), url, object : NavigationInterceptor {
|
||||||
@ -1659,7 +1662,7 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreviewUrlCloseClicked(eventId: String, url: String) {
|
override fun onPreviewUrlCloseClicked(eventId: String, url: String) {
|
||||||
previewUrlRetriever.doNotShowPreviewUrlFor(eventId, url)
|
roomDetailViewModel.handle(RoomDetailAction.DoNotShowPreviewUrlFor(eventId, url))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
||||||
|
@ -113,7 +113,6 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||||||
private val rainbowGenerator: RainbowGenerator,
|
private val rainbowGenerator: RainbowGenerator,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val rawService: RawService,
|
private val rawService: RawService,
|
||||||
private val previewUrlRetriever: PreviewUrlRetriever,
|
|
||||||
private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider,
|
private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider,
|
||||||
private val stickerPickerActionHandler: StickerPickerActionHandler,
|
private val stickerPickerActionHandler: StickerPickerActionHandler,
|
||||||
private val roomSummaryHolder: RoomSummaryHolder,
|
private val roomSummaryHolder: RoomSummaryHolder,
|
||||||
@ -130,6 +129,9 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||||||
private var timelineEvents = PublishRelay.create<List<TimelineEvent>>()
|
private var timelineEvents = PublishRelay.create<List<TimelineEvent>>()
|
||||||
val timeline = room.createTimeline(eventId, timelineSettings)
|
val timeline = room.createTimeline(eventId, timelineSettings)
|
||||||
|
|
||||||
|
// Same lifecycle than the ViewModel (survive to screen rotation)
|
||||||
|
val previewUrlRetriever = PreviewUrlRetriever(session)
|
||||||
|
|
||||||
// Slot to keep a pending action during permission request
|
// Slot to keep a pending action during permission request
|
||||||
var pendingAction: RoomDetailAction? = null
|
var pendingAction: RoomDetailAction? = null
|
||||||
|
|
||||||
@ -288,9 +290,14 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||||||
RoomDetailViewEvents.ShowRoomAvatarFullScreen(action.matrixItem, action.transitionView)
|
RoomDetailViewEvents.ShowRoomAvatarFullScreen(action.matrixItem, action.transitionView)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
is RoomDetailAction.DoNotShowPreviewUrlFor -> handleDoNotShowPreviewUrlFor(action)
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleDoNotShowPreviewUrlFor(action: RoomDetailAction.DoNotShowPreviewUrlFor) {
|
||||||
|
previewUrlRetriever.doNotShowPreviewUrlFor(action.eventId, action.url)
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleSetNewAvatar(action: RoomDetailAction.SetAvatarAction) {
|
private fun handleSetNewAvatar(action: RoomDetailAction.SetAvatarAction) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
|
@ -48,6 +48,7 @@ import im.vector.app.features.home.room.detail.timeline.item.DaySeparatorItem_
|
|||||||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData
|
import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.TimelineReadMarkerItem_
|
import im.vector.app.features.home.room.detail.timeline.item.TimelineReadMarkerItem_
|
||||||
|
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
||||||
import im.vector.app.features.media.ImageContentRenderer
|
import im.vector.app.features.media.ImageContentRenderer
|
||||||
import im.vector.app.features.media.VideoContentRenderer
|
import im.vector.app.features.media.VideoContentRenderer
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
@ -97,6 +98,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
|||||||
|
|
||||||
// TODO move all callbacks to this?
|
// TODO move all callbacks to this?
|
||||||
fun onTimelineItemAction(itemAction: RoomDetailAction)
|
fun onTimelineItemAction(itemAction: RoomDetailAction)
|
||||||
|
|
||||||
|
fun getPreviewUrlRetriever(): PreviewUrlRetriever
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReactionPillCallback {
|
interface ReactionPillCallback {
|
||||||
|
@ -58,7 +58,6 @@ import im.vector.app.features.home.room.detail.timeline.item.VerificationRequest
|
|||||||
import im.vector.app.features.home.room.detail.timeline.item.VerificationRequestItem_
|
import im.vector.app.features.home.room.detail.timeline.item.VerificationRequestItem_
|
||||||
import im.vector.app.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
import im.vector.app.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||||
import im.vector.app.features.home.room.detail.timeline.tools.linkify
|
import im.vector.app.features.home.room.detail.timeline.tools.linkify
|
||||||
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
|
||||||
import im.vector.app.features.html.CodeVisitor
|
import im.vector.app.features.html.CodeVisitor
|
||||||
import im.vector.app.features.html.EventHtmlRenderer
|
import im.vector.app.features.html.EventHtmlRenderer
|
||||||
import im.vector.app.features.html.PillsPostProcessor
|
import im.vector.app.features.html.PillsPostProcessor
|
||||||
@ -108,7 +107,6 @@ class MessageItemFactory @Inject constructor(
|
|||||||
private val defaultItemFactory: DefaultItemFactory,
|
private val defaultItemFactory: DefaultItemFactory,
|
||||||
private val noticeItemFactory: NoticeItemFactory,
|
private val noticeItemFactory: NoticeItemFactory,
|
||||||
private val avatarSizeProvider: AvatarSizeProvider,
|
private val avatarSizeProvider: AvatarSizeProvider,
|
||||||
private val previewUrlRetriever: PreviewUrlRetriever,
|
|
||||||
private val pillsPostProcessorFactory: PillsPostProcessor.Factory,
|
private val pillsPostProcessorFactory: PillsPostProcessor.Factory,
|
||||||
private val session: Session) {
|
private val session: Session) {
|
||||||
|
|
||||||
@ -426,7 +424,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
.useBigFont(linkifiedBody.length <= MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT * 2 && containsOnlyEmojis(linkifiedBody.toString()))
|
.useBigFont(linkifiedBody.length <= MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT * 2 && containsOnlyEmojis(linkifiedBody.toString()))
|
||||||
.searchForPills(isFormatted)
|
.searchForPills(isFormatted)
|
||||||
.previewUrlRetriever(previewUrlRetriever)
|
.previewUrlRetriever(callback?.getPreviewUrlRetriever())
|
||||||
.imageContentRenderer(imageContentRenderer)
|
.imageContentRenderer(imageContentRenderer)
|
||||||
.previewUrlCallback(callback)
|
.previewUrlCallback(callback)
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
@ -534,7 +532,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
.previewUrlRetriever(previewUrlRetriever)
|
.previewUrlRetriever(callback?.getPreviewUrlRetriever())
|
||||||
.imageContentRenderer(imageContentRenderer)
|
.imageContentRenderer(imageContentRenderer)
|
||||||
.previewUrlCallback(callback)
|
.previewUrlCallback(callback)
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
|
@ -89,6 +89,8 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
|||||||
|
|
||||||
override fun unbind(holder: Holder) {
|
override fun unbind(holder: Holder) {
|
||||||
super.unbind(holder)
|
super.unbind(holder)
|
||||||
|
previewUrlViewUpdater.previewUrlView = null
|
||||||
|
previewUrlViewUpdater.imageContentRenderer = null
|
||||||
previewUrlRetriever?.removeListener(attributes.informationData.eventId, previewUrlViewUpdater)
|
previewUrlRetriever?.removeListener(attributes.informationData.eventId, previewUrlViewUpdater)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,18 +17,15 @@
|
|||||||
package im.vector.app.features.home.room.detail.timeline.url
|
package im.vector.app.features.home.room.detail.timeline.url
|
||||||
|
|
||||||
import im.vector.app.BuildConfig
|
import im.vector.app.BuildConfig
|
||||||
import im.vector.app.core.di.ScreenScope
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.cache.CacheStrategy
|
import org.matrix.android.sdk.api.cache.CacheStrategy
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@ScreenScope
|
class PreviewUrlRetriever(session: Session) {
|
||||||
class PreviewUrlRetriever @Inject constructor(
|
private val mediaService = session.mediaService()
|
||||||
private val session: Session
|
|
||||||
) {
|
|
||||||
private val data = mutableMapOf<String, PreviewUrlUiState>()
|
private val data = mutableMapOf<String, PreviewUrlUiState>()
|
||||||
private val listeners = mutableMapOf<String, MutableSet<PreviewUrlRetrieverListener>>()
|
private val listeners = mutableMapOf<String, MutableSet<PreviewUrlRetrieverListener>>()
|
||||||
|
|
||||||
@ -41,7 +38,7 @@ class PreviewUrlRetriever @Inject constructor(
|
|||||||
synchronized(data) {
|
synchronized(data) {
|
||||||
if (data[eventId] == null) {
|
if (data[eventId] == null) {
|
||||||
// Keep only the first URL for the moment
|
// Keep only the first URL for the moment
|
||||||
val url = session.mediaService().extractUrls(event)
|
val url = mediaService.extractUrls(event)
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?.takeIf { it !in blockedUrl }
|
?.takeIf { it !in blockedUrl }
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
@ -57,7 +54,7 @@ class PreviewUrlRetriever @Inject constructor(
|
|||||||
}?.let { urlToRetrieve ->
|
}?.let { urlToRetrieve ->
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
session.mediaService().getPreviewUrl(
|
mediaService.getPreviewUrl(
|
||||||
url = urlToRetrieve,
|
url = urlToRetrieve,
|
||||||
timestamp = null,
|
timestamp = null,
|
||||||
cacheStrategy = if (BuildConfig.DEBUG) CacheStrategy.NoCache else CacheStrategy.TtlCache(CACHE_VALIDITY, false)
|
cacheStrategy = if (BuildConfig.DEBUG) CacheStrategy.NoCache else CacheStrategy.TtlCache(CACHE_VALIDITY, false)
|
||||||
|
Loading…
Reference in New Issue
Block a user