Quick & dirty avatar display (to be removed)

This commit is contained in:
ganfra 2018-10-31 16:54:02 +01:00
parent 536d7c33fe
commit ea51420c74
7 changed files with 60 additions and 7 deletions

View file

@ -0,0 +1,7 @@
package im.vector.riotredesign.core.glide;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

View file

@ -0,0 +1,8 @@
package im.vector.riotredesign.core.utils
object Constants {
const val MEDIA_URL = "https://matrix.org/_matrix/media/v1/download/"
}

View file

@ -7,14 +7,17 @@ import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.request.RequestOptions
import im.vector.matrix.android.api.Matrix
import im.vector.matrix.android.api.session.events.model.EnrichedEvent
import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.avatarDrawable
import im.vector.riotredesign.core.glide.GlideApp
import im.vector.riotredesign.core.platform.RiotFragment
import im.vector.riotredesign.core.platform.ToolbarConfigurable
import im.vector.riotredesign.core.utils.Constants
import im.vector.riotredesign.core.utils.FragmentArgumentDelegate
import kotlinx.android.synthetic.main.fragment_room_detail.*
import org.koin.android.ext.android.inject
@ -67,6 +70,14 @@ class RoomDetailFragment : RiotFragment() {
private fun renderRoomSummary(roomSummary: RoomSummary?) {
roomSummary?.let {
toolbarTitleView.text = it.displayName
val avatarUrl = it.avatarUrl.replace("mxc://", Constants.MEDIA_URL)
GlideApp
.with(this)
.load(avatarUrl)
.placeholder(riotActivity.avatarDrawable(it.displayName))
.apply(RequestOptions.circleCropTransform())
.into(toolbarAvatarImageView)
toolbarAvatarImageView.setImageDrawable(riotActivity.avatarDrawable(it.displayName))
if (it.topic.isNotEmpty()) {
toolbarSubtitleView.visibility = View.VISIBLE

View file

@ -10,6 +10,7 @@ import im.vector.matrix.android.api.session.events.model.roomMember
import im.vector.matrix.android.api.session.room.model.MessageContent
import im.vector.riotredesign.core.extensions.avatarDrawable
import im.vector.riotredesign.core.extensions.localDateTime
import im.vector.riotredesign.core.utils.Constants
import im.vector.riotredesign.features.home.LoadingItemModel_
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle
@ -71,12 +72,16 @@ class TimelineEventController(private val context: Context) : EpoxyController(
}
val showInformation = messagesDisplayedWithInformation.contains(event.root.eventId)
val avatarDrawable = context.avatarDrawable(roomMember.displayName ?: "")
val avatarUrl = roomMember.avatarUrl?.replace("mxc://", Constants.MEDIA_URL) ?: ""
TimelineMessageItem(
message = messageContent.body,
avatarUrl = avatarUrl,
showInformation = showInformation,
time = date.toLocalTime().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)),
avatarDrawable = avatarDrawable,
fallbackAvatarDrawable = context.avatarDrawable(roomMember.displayName
?: ""),
memberName = roomMember.displayName
)
.onBind { timeline?.loadAround(index) }

View file

@ -4,13 +4,16 @@ import android.graphics.drawable.Drawable
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.request.RequestOptions
import im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.KotlinModel
import im.vector.riotredesign.core.glide.GlideApp
data class TimelineMessageItem(
val message: CharSequence? = null,
val time: CharSequence? = null,
val avatarDrawable: Drawable? = null,
val avatarUrl: String,
val fallbackAvatarDrawable: Drawable? = null,
val memberName: CharSequence? = null,
val showInformation: Boolean = true
) : KotlinModel(R.layout.item_event_message) {
@ -27,7 +30,13 @@ data class TimelineMessageItem(
memberNameView.visibility = View.VISIBLE
timeView.visibility = View.VISIBLE
avatarImageView.setImageDrawable(avatarDrawable)
GlideApp
.with(avatarImageView)
.load(avatarUrl)
.placeholder(fallbackAvatarDrawable)
.apply(RequestOptions.circleCropTransform())
.into(avatarImageView)
timeView.text = time
memberNameView.text = memberName
} else {

View file

@ -4,6 +4,7 @@ import android.content.Context
import com.airbnb.epoxy.Typed2EpoxyController
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotredesign.core.extensions.avatarDrawable
import im.vector.riotredesign.core.utils.Constants
class RoomSummaryController(private val context: Context,
private val callback: Callback? = null
@ -51,10 +52,14 @@ class RoomSummaryController(private val context: Context,
}
private fun buildRoomModels(summaries: List<RoomSummary>, selected: RoomSummary?) {
summaries.forEach {
val avatarUrl = it.avatarUrl.replace("mxc://", Constants.MEDIA_URL)
RoomSummaryItem(
title = it.displayName,
avatarDrawable = context.avatarDrawable(it.displayName),
avatarUrl = avatarUrl,
fallbackAvatarDrawable = context.avatarDrawable(it.displayName),
isSelected = it.roomId == selected?.roomId,
listener = { callback?.onRoomSelected(it) }
)

View file

@ -3,14 +3,17 @@ package im.vector.riotredesign.features.home.room.list
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.request.RequestOptions
import im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.KotlinModel
import im.vector.riotredesign.core.glide.GlideApp
import im.vector.riotredesign.core.platform.CheckableFrameLayout
data class RoomSummaryItem(
val title: CharSequence,
val avatarDrawable: Drawable,
val avatarUrl: String,
val fallbackAvatarDrawable: Drawable,
val isSelected: Boolean,
val listener: (() -> Unit)? = null
) : KotlinModel(R.layout.item_room) {
@ -23,6 +26,11 @@ data class RoomSummaryItem(
rootView.isChecked = isSelected
rootView.setOnClickListener { listener?.invoke() }
titleView.text = title
avatarImageView.setImageDrawable(avatarDrawable)
GlideApp
.with(avatarImageView)
.load(avatarUrl)
.placeholder(fallbackAvatarDrawable)
.apply(RequestOptions.circleCropTransform())
.into(avatarImageView)
}
}