forked from GitHub-Mirror/riotX-android
Perf: eventHtmlRenderer is slow to build, get only one instance
This commit is contained in:
parent
19202cfca6
commit
de9a5a3d12
@ -33,6 +33,7 @@ import im.vector.riotredesign.features.home.AvatarRenderer
|
|||||||
import im.vector.riotredesign.features.home.HomeNavigator
|
import im.vector.riotredesign.features.home.HomeNavigator
|
||||||
import im.vector.riotredesign.features.home.HomeRoomListObservableStore
|
import im.vector.riotredesign.features.home.HomeRoomListObservableStore
|
||||||
import im.vector.riotredesign.features.home.group.SelectedGroupStore
|
import im.vector.riotredesign.features.home.group.SelectedGroupStore
|
||||||
|
import im.vector.riotredesign.features.html.EventHtmlRenderer
|
||||||
import im.vector.riotredesign.features.navigation.Navigator
|
import im.vector.riotredesign.features.navigation.Navigator
|
||||||
import im.vector.riotredesign.features.notifications.NotifiableEventResolver
|
import im.vector.riotredesign.features.notifications.NotifiableEventResolver
|
||||||
import im.vector.riotredesign.features.notifications.NotificationBroadcastReceiver
|
import im.vector.riotredesign.features.notifications.NotificationBroadcastReceiver
|
||||||
@ -68,6 +69,8 @@ interface VectorComponent {
|
|||||||
|
|
||||||
fun emojiCompatFontProvider(): EmojiCompatFontProvider
|
fun emojiCompatFontProvider(): EmojiCompatFontProvider
|
||||||
|
|
||||||
|
fun eventHtmlRenderer(): EventHtmlRenderer
|
||||||
|
|
||||||
fun navigator(): Navigator
|
fun navigator(): Navigator
|
||||||
|
|
||||||
fun homeNavigator(): HomeNavigator
|
fun homeNavigator(): HomeNavigator
|
||||||
|
@ -18,10 +18,9 @@ package im.vector.riotredesign.features.html
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.style.URLSpan
|
import android.text.style.URLSpan
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import im.vector.matrix.android.api.permalinks.PermalinkData
|
import im.vector.matrix.android.api.permalinks.PermalinkData
|
||||||
import im.vector.matrix.android.api.permalinks.PermalinkParser
|
import im.vector.matrix.android.api.permalinks.PermalinkParser
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.riotredesign.core.di.ActiveSessionHolder
|
||||||
import im.vector.riotredesign.core.glide.GlideApp
|
import im.vector.riotredesign.core.glide.GlideApp
|
||||||
import im.vector.riotredesign.core.glide.GlideRequests
|
import im.vector.riotredesign.core.glide.GlideRequests
|
||||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||||
@ -37,12 +36,14 @@ import ru.noties.markwon.html.TagHandler
|
|||||||
import ru.noties.markwon.html.tag.*
|
import ru.noties.markwon.html.tag.*
|
||||||
import java.util.Arrays.asList
|
import java.util.Arrays.asList
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class EventHtmlRenderer @Inject constructor(context: AppCompatActivity,
|
@Singleton
|
||||||
|
class EventHtmlRenderer @Inject constructor(context: Context,
|
||||||
val avatarRenderer: AvatarRenderer,
|
val avatarRenderer: AvatarRenderer,
|
||||||
session: Session) {
|
sessionHolder: ActiveSessionHolder) {
|
||||||
private val markwon = Markwon.builder(context)
|
private val markwon = Markwon.builder(context)
|
||||||
.usePlugin(MatrixPlugin.create(GlideApp.with(context), context, avatarRenderer, session))
|
.usePlugin(MatrixPlugin.create(GlideApp.with(context), context, avatarRenderer, sessionHolder))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
fun render(text: String): CharSequence {
|
fun render(text: String): CharSequence {
|
||||||
@ -54,7 +55,7 @@ class EventHtmlRenderer @Inject constructor(context: AppCompatActivity,
|
|||||||
private class MatrixPlugin private constructor(private val glideRequests: GlideRequests,
|
private class MatrixPlugin private constructor(private val glideRequests: GlideRequests,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val session: Session) : AbstractMarkwonPlugin() {
|
private val session: ActiveSessionHolder) : AbstractMarkwonPlugin() {
|
||||||
|
|
||||||
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||||
builder.htmlParser(MarkwonHtmlParserImpl.create())
|
builder.htmlParser(MarkwonHtmlParserImpl.create())
|
||||||
@ -122,7 +123,7 @@ private class MatrixPlugin private constructor(private val glideRequests: GlideR
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun create(glideRequests: GlideRequests, context: Context, avatarRenderer: AvatarRenderer, session: Session): MatrixPlugin {
|
fun create(glideRequests: GlideRequests, context: Context, avatarRenderer: AvatarRenderer, session: ActiveSessionHolder): MatrixPlugin {
|
||||||
return MatrixPlugin(glideRequests, context, avatarRenderer, session)
|
return MatrixPlugin(glideRequests, context, avatarRenderer, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +132,7 @@ private class MatrixPlugin private constructor(private val glideRequests: GlideR
|
|||||||
private class MxLinkHandler(private val glideRequests: GlideRequests,
|
private class MxLinkHandler(private val glideRequests: GlideRequests,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val session: Session) : TagHandler() {
|
private val sessionHolder: ActiveSessionHolder) : TagHandler() {
|
||||||
|
|
||||||
private val linkHandler = LinkHandler()
|
private val linkHandler = LinkHandler()
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ private class MxLinkHandler(private val glideRequests: GlideRequests,
|
|||||||
val permalinkData = PermalinkParser.parse(link)
|
val permalinkData = PermalinkParser.parse(link)
|
||||||
when (permalinkData) {
|
when (permalinkData) {
|
||||||
is PermalinkData.UserLink -> {
|
is PermalinkData.UserLink -> {
|
||||||
val user = session.getUser(permalinkData.userId)
|
val user = sessionHolder.getSafeActiveSession()?.getUser(permalinkData.userId)
|
||||||
val span = PillImageSpan(glideRequests, avatarRenderer, context, permalinkData.userId, user)
|
val span = PillImageSpan(glideRequests, avatarRenderer, context, permalinkData.userId, user)
|
||||||
SpannableBuilder.setSpans(
|
SpannableBuilder.setSpans(
|
||||||
visitor.builder(),
|
visitor.builder(),
|
||||||
|
Loading…
Reference in New Issue
Block a user