mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 14:08:44 +03:00
Timeline: add glide preloading
This commit is contained in:
parent
3f5b1083f3
commit
8bc0afa75e
3 changed files with 26 additions and 10 deletions
|
@ -326,6 +326,7 @@ dependencies {
|
||||||
implementation 'com.jakewharton.rxbinding3:rxbinding-material:3.0.0'
|
implementation 'com.jakewharton.rxbinding3:rxbinding-material:3.0.0'
|
||||||
|
|
||||||
implementation("com.airbnb.android:epoxy:$epoxy_version")
|
implementation("com.airbnb.android:epoxy:$epoxy_version")
|
||||||
|
implementation "com.airbnb.android:epoxy-glide-preloading:$epoxy_version"
|
||||||
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
|
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
|
||||||
implementation "com.airbnb.android:epoxy-paging:$epoxy_version"
|
implementation "com.airbnb.android:epoxy-paging:$epoxy_version"
|
||||||
implementation 'com.airbnb.android:mvrx:1.3.0'
|
implementation 'com.airbnb.android:mvrx:1.3.0'
|
||||||
|
|
|
@ -53,6 +53,8 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import butterknife.BindView
|
import butterknife.BindView
|
||||||
import com.airbnb.epoxy.EpoxyModel
|
import com.airbnb.epoxy.EpoxyModel
|
||||||
import com.airbnb.epoxy.OnModelBuildFinishedListener
|
import com.airbnb.epoxy.OnModelBuildFinishedListener
|
||||||
|
import com.airbnb.epoxy.addGlidePreloader
|
||||||
|
import com.airbnb.epoxy.glidePreloader
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -75,9 +77,11 @@ import im.vector.app.core.extensions.setTextOrHide
|
||||||
import im.vector.app.core.extensions.showKeyboard
|
import im.vector.app.core.extensions.showKeyboard
|
||||||
import im.vector.app.core.extensions.trackItemsVisibilityChange
|
import im.vector.app.core.extensions.trackItemsVisibilityChange
|
||||||
import im.vector.app.core.glide.GlideApp
|
import im.vector.app.core.glide.GlideApp
|
||||||
|
import im.vector.app.core.glide.GlideRequests
|
||||||
import im.vector.app.core.intent.getMimeTypeFromUri
|
import im.vector.app.core.intent.getMimeTypeFromUri
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.core.resources.ColorProvider
|
import im.vector.app.core.resources.ColorProvider
|
||||||
|
import im.vector.app.core.ui.model.Size
|
||||||
import im.vector.app.core.ui.views.ActiveCallView
|
import im.vector.app.core.ui.views.ActiveCallView
|
||||||
import im.vector.app.core.ui.views.ActiveCallViewHolder
|
import im.vector.app.core.ui.views.ActiveCallViewHolder
|
||||||
import im.vector.app.core.ui.views.ActiveConferenceView
|
import im.vector.app.core.ui.views.ActiveConferenceView
|
||||||
|
@ -218,7 +222,8 @@ class RoomDetailFragment @Inject constructor(
|
||||||
private val colorProvider: ColorProvider,
|
private val colorProvider: ColorProvider,
|
||||||
private val notificationUtils: NotificationUtils,
|
private val notificationUtils: NotificationUtils,
|
||||||
private val webRtcPeerConnectionManager: WebRtcPeerConnectionManager,
|
private val webRtcPeerConnectionManager: WebRtcPeerConnectionManager,
|
||||||
private val matrixItemColorProvider: MatrixItemColorProvider
|
private val matrixItemColorProvider: MatrixItemColorProvider,
|
||||||
|
private val imageContentRenderer: ImageContentRenderer
|
||||||
) :
|
) :
|
||||||
VectorBaseFragment(),
|
VectorBaseFragment(),
|
||||||
TimelineEventController.Callback,
|
TimelineEventController.Callback,
|
||||||
|
@ -921,6 +926,16 @@ class RoomDetailFragment @Inject constructor(
|
||||||
val touchHelper = ItemTouchHelper(swipeCallback)
|
val touchHelper = ItemTouchHelper(swipeCallback)
|
||||||
touchHelper.attachToRecyclerView(recyclerView)
|
touchHelper.attachToRecyclerView(recyclerView)
|
||||||
}
|
}
|
||||||
|
recyclerView.addGlidePreloader(
|
||||||
|
epoxyController = timelineEventController,
|
||||||
|
requestManager = GlideApp.with(this),
|
||||||
|
preloader = glidePreloader { requestManager, epoxyModel: MessageImageVideoItem, _ ->
|
||||||
|
imageContentRenderer.createGlideRequest(
|
||||||
|
epoxyModel.mediaData,
|
||||||
|
ImageContentRenderer.Mode.THUMBNAIL,
|
||||||
|
requestManager as GlideRequests
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateJumpToReadMarkerViewVisibility() {
|
private fun updateJumpToReadMarkerViewVisibility() {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.glide.GlideApp
|
import im.vector.app.core.glide.GlideApp
|
||||||
import im.vector.app.core.glide.GlideRequest
|
import im.vector.app.core.glide.GlideRequest
|
||||||
|
import im.vector.app.core.glide.GlideRequests
|
||||||
import im.vector.app.core.ui.model.Size
|
import im.vector.app.core.ui.model.Size
|
||||||
import im.vector.app.core.utils.DimensionConverter
|
import im.vector.app.core.utils.DimensionConverter
|
||||||
import im.vector.app.core.utils.isLocalFile
|
import im.vector.app.core.utils.isLocalFile
|
||||||
|
@ -206,12 +207,14 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
||||||
.into(imageView)
|
.into(imageView)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createGlideRequest(data: Data, mode: Mode, imageView: ImageView, size: Size): GlideRequest<Drawable> {
|
fun createGlideRequest(data: Data, mode: Mode, imageView: ImageView, size: Size): GlideRequest<Drawable> {
|
||||||
|
return createGlideRequest(data, mode, GlideApp.with(imageView), size)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createGlideRequest(data: Data, mode: Mode, glideRequests: GlideRequests, size: Size = processSize(data, mode)): GlideRequest<Drawable> {
|
||||||
return if (data.elementToDecrypt != null) {
|
return if (data.elementToDecrypt != null) {
|
||||||
// Encrypted image
|
// Encrypted image
|
||||||
GlideApp
|
glideRequests.load(data)
|
||||||
.with(imageView)
|
|
||||||
.load(data)
|
|
||||||
} else {
|
} else {
|
||||||
// Clear image
|
// Clear image
|
||||||
val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver()
|
val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver()
|
||||||
|
@ -223,15 +226,12 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
||||||
// Fallback to base url
|
// Fallback to base url
|
||||||
?: data.url.takeIf { it?.startsWith("content://") == true }
|
?: data.url.takeIf { it?.startsWith("content://") == true }
|
||||||
|
|
||||||
GlideApp
|
glideRequests
|
||||||
.with(imageView)
|
|
||||||
.load(resolvedUrl)
|
.load(resolvedUrl)
|
||||||
.apply {
|
.apply {
|
||||||
if (mode == Mode.THUMBNAIL) {
|
if (mode == Mode.THUMBNAIL) {
|
||||||
error(
|
error(
|
||||||
GlideApp
|
glideRequests.load(resolveUrl(data))
|
||||||
.with(imageView)
|
|
||||||
.load(resolveUrl(data))
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue