forked from GitHub-Mirror/riotX-android
Timeline : quickly manage dates (need to be clean)
This commit is contained in:
parent
6f2beef726
commit
900217b90e
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -47,6 +47,8 @@ dependencies {
|
|||||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
|
|
||||||
|
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.1'
|
||||||
|
|
||||||
implementation 'com.jakewharton.timber:timber:4.7.1'
|
implementation 'com.jakewharton.timber:timber:4.7.1'
|
||||||
|
|
||||||
implementation("com.airbnb.android:epoxy:$epoxy_version")
|
implementation("com.airbnb.android:epoxy:$epoxy_version")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package im.vector.riotredesign
|
package im.vector.riotredesign
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import com.jakewharton.threetenabp.AndroidThreeTen
|
||||||
import im.vector.matrix.android.BuildConfig
|
import im.vector.matrix.android.BuildConfig
|
||||||
import im.vector.riotredesign.core.di.AppModule
|
import im.vector.riotredesign.core.di.AppModule
|
||||||
import org.koin.log.EmptyLogger
|
import org.koin.log.EmptyLogger
|
||||||
@ -14,6 +15,7 @@ class Riot : Application() {
|
|||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
}
|
}
|
||||||
|
AndroidThreeTen.init(this)
|
||||||
startKoin(listOf(AppModule(this)), logger = EmptyLogger())
|
startKoin(listOf(AppModule(this)), logger = EmptyLogger())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package im.vector.riotredesign.core.extensions
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
|
import org.threeten.bp.Instant
|
||||||
|
import org.threeten.bp.LocalDateTime
|
||||||
|
import org.threeten.bp.ZoneOffset
|
||||||
|
|
||||||
|
|
||||||
|
fun Event.localDateTime(): LocalDateTime {
|
||||||
|
val instant = Instant.ofEpochMilli(originServerTs ?: 0)
|
||||||
|
return LocalDateTime.ofInstant(instant, ZoneOffset.UTC)
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package im.vector.riotredesign.features.home.room.detail
|
||||||
|
|
||||||
|
import android.widget.TextView
|
||||||
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.epoxy.KotlinModel
|
||||||
|
|
||||||
|
data class TimelineDaySeparatorItem(
|
||||||
|
val formattedDay: CharSequence
|
||||||
|
) : KotlinModel(R.layout.item_event_day_separator) {
|
||||||
|
|
||||||
|
private val dayTextView by bind<TextView>(R.id.itemDayTextView)
|
||||||
|
|
||||||
|
override fun bind() {
|
||||||
|
dayTextView.text = formattedDay
|
||||||
|
}
|
||||||
|
}
|
@ -9,14 +9,17 @@ import im.vector.matrix.android.api.session.events.model.EventType
|
|||||||
import im.vector.matrix.android.api.session.events.model.roomMember
|
import im.vector.matrix.android.api.session.events.model.roomMember
|
||||||
import im.vector.matrix.android.api.session.room.model.MessageContent
|
import im.vector.matrix.android.api.session.room.model.MessageContent
|
||||||
import im.vector.riotredesign.core.extensions.avatarDrawable
|
import im.vector.riotredesign.core.extensions.avatarDrawable
|
||||||
|
import im.vector.riotredesign.core.extensions.localDateTime
|
||||||
import im.vector.riotredesign.features.home.LoadingItemModel_
|
import im.vector.riotredesign.features.home.LoadingItemModel_
|
||||||
|
import org.threeten.bp.format.DateTimeFormatter
|
||||||
|
import org.threeten.bp.format.FormatStyle
|
||||||
|
|
||||||
class TimelineEventController(private val context: Context) : EpoxyController(
|
class TimelineEventController(private val context: Context) : EpoxyController(
|
||||||
EpoxyAsyncUtil.getAsyncBackgroundHandler(),
|
EpoxyAsyncUtil.getAsyncBackgroundHandler(),
|
||||||
EpoxyAsyncUtil.getAsyncBackgroundHandler()
|
EpoxyAsyncUtil.getAsyncBackgroundHandler()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val messagesLoadedWithInformation = HashSet<String?>()
|
private val messagesDisplayedWithInformation = HashSet<String?>()
|
||||||
|
|
||||||
private val pagedListCallback = object : PagedList.Callback() {
|
private val pagedListCallback = object : PagedList.Callback() {
|
||||||
override fun onChanged(position: Int, count: Int) {
|
override fun onChanged(position: Int, count: Int) {
|
||||||
@ -57,22 +60,34 @@ class TimelineEventController(private val context: Context) : EpoxyController(
|
|||||||
if (messageContent == null || roomMember == null) {
|
if (messageContent == null || roomMember == null) {
|
||||||
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 (nextRoomMember != roomMember) {
|
if (addDaySeparator || nextRoomMember != roomMember) {
|
||||||
messagesLoadedWithInformation.add(event.root.eventId)
|
messagesDisplayedWithInformation.add(event.root.eventId)
|
||||||
}
|
}
|
||||||
val showInformation = messagesLoadedWithInformation.contains(event.root.eventId)
|
val showInformation = messagesDisplayedWithInformation.contains(event.root.eventId)
|
||||||
|
|
||||||
val avatarDrawable = context.avatarDrawable(roomMember.displayName ?: "")
|
val avatarDrawable = context.avatarDrawable(roomMember.displayName ?: "")
|
||||||
TimelineMessageItem(
|
TimelineMessageItem(
|
||||||
message = messageContent.body,
|
message = messageContent.body,
|
||||||
showInformation = showInformation,
|
showInformation = showInformation,
|
||||||
|
time = date.toLocalTime().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)),
|
||||||
avatarDrawable = avatarDrawable,
|
avatarDrawable = avatarDrawable,
|
||||||
memberName = roomMember.displayName
|
memberName = roomMember.displayName
|
||||||
)
|
)
|
||||||
.onBind { timeline?.loadAround(index) }
|
.onBind { timeline?.loadAround(index) }
|
||||||
.id(event.root.eventId)
|
.id(event.root.eventId)
|
||||||
.addTo(this)
|
.addTo(this)
|
||||||
|
|
||||||
|
|
||||||
|
if (addDaySeparator) {
|
||||||
|
val formattedDay = date.toLocalDate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))
|
||||||
|
TimelineDaySeparatorItem(formattedDay).id(formattedDay).addTo(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,52 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="80dp"
|
android:padding="8dp">
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/itemDayLineViewLeft"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@color/pale_grey_two"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/itemDayTextView"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/itemDayTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/light_grey_blue"
|
||||||
|
android:textSize="15sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:text="@tools:sample/date/day_of_week" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/itemDayLineViewRight"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="32dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@color/pale_grey_two"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/itemDayTextView"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user