Add blank item to use pagedlist load around method

This commit is contained in:
ganfra 2018-11-02 09:52:10 +01:00
parent 6d9907563e
commit eda88030a3
3 changed files with 21 additions and 29 deletions

View File

@ -1,19 +0,0 @@
package im.vector.riotredesign.features.home

import android.content.Context
import android.graphics.drawable.Drawable
import android.support.v4.content.ContextCompat
import com.amulyakhare.textdrawable.TextDrawable
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.firstCharAsString

class RoomSummaryViewHelper(private val roomSummary: RoomSummary) {

fun avatarDrawable(context: Context): Drawable {
val avatarColor = ContextCompat.getColor(context, R.color.pale_teal)
return TextDrawable.builder().buildRound(roomSummary.displayName.firstCharAsString().toUpperCase(), avatarColor)
}


}

View File

@ -0,0 +1,8 @@
package im.vector.riotredesign.features.home.room.detail

import android.content.Context
import android.widget.FrameLayout
import com.airbnb.epoxy.ModelView

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class BlankItem(context: Context) : FrameLayout(context)

View File

@ -53,6 +53,10 @@ class TimelineEventController(private val context: Context) : EpoxyController(
val event = data[index] val event = data[index]
val nextEvent = if (index + 1 < data.size) data[index + 1] else null val nextEvent = if (index + 1 < data.size) data[index + 1] else null


val date = event.root.localDateTime()
val nextDate = nextEvent?.root?.localDateTime()
val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate()

if (event.root.type == EventType.MESSAGE) { if (event.root.type == EventType.MESSAGE) {
val messageContent = event.root.content<MessageContent>() val messageContent = event.root.content<MessageContent>()
val roomMember = event.roomMember() val roomMember = event.roomMember()
@ -60,10 +64,6 @@ class TimelineEventController(private val context: Context) : EpoxyController(
continue continue
} }


val date = event.root.localDateTime()
val nextDate = nextEvent?.root?.localDateTime()
val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate()

val nextRoomMember = nextEvent?.roomMember() val nextRoomMember = nextEvent?.roomMember()
if (addDaySeparator || nextRoomMember != roomMember) { if (addDaySeparator || nextRoomMember != roomMember) {
messagesDisplayedWithInformation.add(event.root.eventId) messagesDisplayedWithInformation.add(event.root.eventId)
@ -80,14 +80,17 @@ class TimelineEventController(private val context: Context) : EpoxyController(
.onBind { timeline?.loadAround(index) } .onBind { timeline?.loadAround(index) }
.id(event.root.eventId) .id(event.root.eventId)
.addTo(this) .addTo(this)

} else {

BlankItemModel_()
.id(event.root.eventId)
.onBind { _, _, _ -> timeline?.loadAround(index) }
.addTo(this)
}
if (addDaySeparator) { if (addDaySeparator) {
val formattedDay = date.toLocalDate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)) val formattedDay = date.toLocalDate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))
TimelineDaySeparatorItem(formattedDay).id(formattedDay).addTo(this) TimelineDaySeparatorItem(formattedDay).id(formattedDay).addTo(this)
} }
} }
}


//It's a hack at the moment //It's a hack at the moment
val isLastEvent = data.last().root.type == EventType.STATE_ROOM_CREATE val isLastEvent = data.last().root.type == EventType.STATE_ROOM_CREATE