mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Pill: fix blink and clean files
This commit is contained in:
parent
00f316ba5d
commit
833a5a37a2
22 changed files with 35 additions and 40 deletions
|
@ -49,7 +49,4 @@ enum class Membership(val value: String) {
|
|||
return listOf(INVITE, JOIN)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package im.vector.matrix.android.internal.database.helper
|
|||
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMemberContent
|
||||
import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
||||
import im.vector.matrix.android.internal.database.model.*
|
||||
|
|
|
@ -18,8 +18,6 @@ package im.vector.matrix.android.internal.database.query
|
|||
|
||||
import im.vector.matrix.android.internal.database.model.RoomMemberEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomMemberEntityFields
|
||||
import im.vector.matrix.android.internal.database.model.UserEntity
|
||||
import im.vector.matrix.android.internal.database.model.UserEntityFields
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
|
|
|
@ -20,10 +20,8 @@ import com.zhuinden.monarchy.Monarchy
|
|||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.RoomAvatarContent
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.model.EventEntityFields
|
||||
import im.vector.matrix.android.internal.database.model.RoomMemberEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.prev
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
|
@ -59,5 +57,4 @@ internal class RoomAvatarResolver @Inject constructor(private val monarchy: Mona
|
|||
}
|
||||
return res
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.network.executeRequest
|
|||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
||||
import im.vector.matrix.android.internal.session.sync.SyncTokenStore
|
||||
import im.vector.matrix.android.internal.session.user.UserEntityFactory
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||
import io.realm.Realm
|
||||
|
|
|
@ -22,7 +22,7 @@ import im.vector.matrix.android.internal.database.model.RoomMemberEntity
|
|||
internal object RoomMemberEntityFactory {
|
||||
|
||||
fun create(roomId: String, userId: String, roomMember: RoomMemberContent): RoomMemberEntity {
|
||||
val primaryKey = "${roomId}_${userId}"
|
||||
val primaryKey = "${roomId}_$userId"
|
||||
return RoomMemberEntity(
|
||||
primaryKey = primaryKey,
|
||||
userId = userId,
|
||||
|
|
|
@ -20,7 +20,6 @@ import im.vector.matrix.android.api.session.events.model.Event
|
|||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMemberContent
|
||||
import im.vector.matrix.android.internal.session.user.UserEntityFactory
|
||||
import io.realm.Realm
|
||||
|
@ -42,6 +41,4 @@ internal class RoomMemberEventHandler @Inject constructor() {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
package im.vector.matrix.android.internal.session.room.membership
|
||||
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||
import im.vector.matrix.android.internal.database.model.*
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomMemberEntity
|
||||
|
|
|
@ -28,8 +28,6 @@ import im.vector.matrix.android.internal.database.query.create
|
|||
import im.vector.matrix.android.internal.database.query.find
|
||||
import im.vector.matrix.android.internal.database.query.findAllIncludingEvents
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomMemberEventHandler
|
||||
import im.vector.matrix.android.internal.session.user.UserEntityFactory
|
||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||
import io.realm.kotlin.createObject
|
||||
import timber.log.Timber
|
||||
|
|
|
@ -37,7 +37,6 @@ import im.vector.matrix.android.internal.session.room.membership.RoomMemberEvent
|
|||
import im.vector.matrix.android.internal.session.room.read.FullyReadContent
|
||||
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
|
||||
import im.vector.matrix.android.internal.session.sync.model.*
|
||||
import im.vector.matrix.android.internal.session.user.UserEntityFactory
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import timber.log.Timber
|
||||
|
|
|
@ -20,7 +20,6 @@ import com.zhuinden.monarchy.Monarchy
|
|||
import im.vector.matrix.android.api.pushrules.RuleScope
|
||||
import im.vector.matrix.android.api.pushrules.RuleSetKey
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMemberContent
|
||||
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
|
||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||
|
|
|
@ -18,14 +18,25 @@ package im.vector.riotx.core.epoxy
|
|||
|
||||
import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||
import com.airbnb.epoxy.VisibilityState
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
|
||||
/**
|
||||
* EpoxyModelWithHolder which can listen to visibility state change
|
||||
*/
|
||||
abstract class VectorEpoxyModel<H : VectorEpoxyHolder> : EpoxyModelWithHolder<H>() {
|
||||
|
||||
protected val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||
|
||||
private var onModelVisibilityStateChangedListener: OnVisibilityStateChangedListener? = null
|
||||
|
||||
override fun unbind(holder: H) {
|
||||
coroutineScope.coroutineContext.cancelChildren()
|
||||
super.unbind(holder)
|
||||
}
|
||||
|
||||
override fun onVisibilityStateChanged(visibilityState: Int, view: H) {
|
||||
onModelVisibilityStateChangedListener?.onVisibilityStateChanged(visibilityState)
|
||||
super.onVisibilityStateChanged(visibilityState, view)
|
||||
|
|
|
@ -51,7 +51,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
|
|||
holder.sender.setTextOrHide(matrixItem.displayName)
|
||||
holder.body.movementMethod = movementMethod
|
||||
holder.body.text = body
|
||||
body.findPillsAndProcess { it.bind(holder.body) }
|
||||
body.findPillsAndProcess(coroutineScope) { it.bind(holder.body) }
|
||||
holder.timestamp.setTextOrHide(time)
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,14 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active
|
|||
.into(target)
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun getCachedDrawable(glideRequest: GlideRequests, matrixItem: MatrixItem): Drawable {
|
||||
return buildGlideRequest(glideRequest, matrixItem.avatarUrl)
|
||||
.onlyRetrieveFromCache(true)
|
||||
.submit()
|
||||
.get()
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun getPlaceholderDrawable(context: Context, matrixItem: MatrixItem): Drawable {
|
||||
val avatarColor = when (matrixItem) {
|
||||
|
|
|
@ -68,7 +68,6 @@ import im.vector.matrix.android.api.session.room.send.SendState
|
|||
import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||
import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.matrix.android.api.util.MatrixItem
|
||||
import im.vector.matrix.android.api.util.toMatrixItem
|
||||
import im.vector.matrix.android.api.util.toRoomAliasMatrixItem
|
||||
|
|
|
@ -28,7 +28,6 @@ import im.vector.matrix.android.api.session.group.model.GroupSummary
|
|||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.features.home.room.detail.RoomDetailFragment
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.airbnb.mvrx.Uninitialized
|
|||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.riotx.features.home.room.detail.RoomDetailArgs
|
||||
|
||||
data class TextComposerViewState(val roomId: String,
|
||||
|
|
|
@ -27,6 +27,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
|||
import im.vector.riotx.core.platform.CheckableView
|
||||
import im.vector.riotx.core.ui.views.ReadReceiptsView
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/**
|
||||
* Children must override getViewType()
|
||||
|
|
|
@ -49,7 +49,7 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
|||
holder.messageView.setOnClickListener(attributes.itemClickListener)
|
||||
holder.messageView.setOnLongClickListener(attributes.itemLongClickListener)
|
||||
if (searchForPills) {
|
||||
message?.findPillsAndProcess { it.bind(holder.messageView) }
|
||||
message?.findPillsAndProcess(coroutineScope) { it.bind(holder.messageView) }
|
||||
}
|
||||
val textFuture = PrecomputedTextCompat.getTextFuture(
|
||||
message ?: "",
|
||||
|
|
|
@ -25,14 +25,11 @@ import im.vector.riotx.core.linkify.VectorLinkify
|
|||
import im.vector.riotx.core.utils.isValidUrl
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.html.PillImageSpan
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.*
|
||||
import me.saket.bettermovementmethod.BetterLinkMovementMethod
|
||||
|
||||
fun CharSequence.findPillsAndProcess(processBlock: (PillImageSpan) -> Unit) {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
fun CharSequence.findPillsAndProcess(scope: CoroutineScope, processBlock: (PillImageSpan) -> Unit) {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
withContext(Dispatchers.IO) {
|
||||
toSpannable().let { spannable ->
|
||||
spannable.getSpans(0, spannable.length, PillImageSpan::class.java)
|
||||
|
|
|
@ -88,25 +88,27 @@ class PillImageSpan(private val glideRequests: GlideRequests,
|
|||
}
|
||||
|
||||
internal fun updateAvatarDrawable(drawable: Drawable?) {
|
||||
pillDrawable.apply {
|
||||
chipIcon = drawable
|
||||
}
|
||||
tv?.get()?.apply {
|
||||
invalidate()
|
||||
}
|
||||
pillDrawable.chipIcon = drawable
|
||||
tv?.get()?.invalidate()
|
||||
}
|
||||
|
||||
// Private methods *****************************************************************************
|
||||
|
||||
private fun createChipDrawable(): ChipDrawable {
|
||||
val textPadding = context.resources.getDimension(R.dimen.pill_text_padding)
|
||||
val icon = try {
|
||||
avatarRenderer.getCachedDrawable(glideRequests, matrixItem)
|
||||
} catch (exception: Exception) {
|
||||
avatarRenderer.getPlaceholderDrawable(context, matrixItem)
|
||||
}
|
||||
|
||||
return ChipDrawable.createFromResource(context, R.xml.pill_view).apply {
|
||||
text = matrixItem.getBestName()
|
||||
textEndPadding = textPadding
|
||||
textStartPadding = textPadding
|
||||
setChipMinHeightResource(R.dimen.pill_min_height)
|
||||
setChipIconSizeResource(R.dimen.pill_avatar_size)
|
||||
chipIcon = avatarRenderer.getPlaceholderDrawable(context, matrixItem)
|
||||
chipIcon = icon
|
||||
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import im.vector.matrix.android.api.session.events.model.Event
|
|||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMemberContent
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||
import im.vector.matrix.android.api.session.room.timeline.getEditedEventId
|
||||
|
|
Loading…
Reference in a new issue