Create FakeLastMessageFormatter
This commit is contained in:
parent
674a813f3b
commit
dfeb9d8c7f
5 changed files with 84 additions and 14 deletions
|
|
@ -175,6 +175,7 @@ dependencies {
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
implementation(libs.androidx.startup)
|
implementation(libs.androidx.startup)
|
||||||
implementation(libs.coil)
|
implementation(libs.coil)
|
||||||
|
implementation(libs.datetime)
|
||||||
|
|
||||||
implementation(libs.dagger)
|
implementation(libs.dagger)
|
||||||
kapt(libs.dagger.compiler)
|
kapt(libs.dagger.compiler)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.roomlist
|
||||||
|
|
||||||
|
import io.element.android.libraries.dateformatter.LastMessageFormatter
|
||||||
|
|
||||||
|
class FakeLastMessageFormatter : LastMessageFormatter {
|
||||||
|
private var format = ""
|
||||||
|
fun givenFormat(format: String) {
|
||||||
|
this.format = format
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun format(timestamp: Long?): String {
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.features.roomlist.model.RoomListEvents
|
import io.element.android.features.roomlist.model.RoomListEvents
|
||||||
import io.element.android.features.roomlist.model.RoomListRoomSummary
|
import io.element.android.features.roomlist.model.RoomListRoomSummary
|
||||||
import io.element.android.libraries.dateformatter.impl.DefaultLastMessageFormatter
|
import io.element.android.libraries.dateformatter.LastMessageFormatter
|
||||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.libraries.matrix.core.SessionId
|
import io.element.android.libraries.matrix.core.SessionId
|
||||||
import io.element.android.libraries.matrixtest.FakeMatrixClient
|
import io.element.android.libraries.matrixtest.FakeMatrixClient
|
||||||
|
|
@ -46,7 +46,7 @@ class RoomListPresenterTests {
|
||||||
FakeMatrixClient(
|
FakeMatrixClient(
|
||||||
SessionId("sessionId")
|
SessionId("sessionId")
|
||||||
),
|
),
|
||||||
DefaultLastMessageFormatter()
|
createDateFormatter()
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -64,7 +64,7 @@ class RoomListPresenterTests {
|
||||||
FakeMatrixClient(
|
FakeMatrixClient(
|
||||||
SessionId("sessionId")
|
SessionId("sessionId")
|
||||||
),
|
),
|
||||||
DefaultLastMessageFormatter()
|
createDateFormatter()
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -86,7 +86,7 @@ class RoomListPresenterTests {
|
||||||
sessionId = SessionId("sessionId"),
|
sessionId = SessionId("sessionId"),
|
||||||
roomSummaryDataSource = roomSummaryDataSource
|
roomSummaryDataSource = roomSummaryDataSource
|
||||||
),
|
),
|
||||||
DefaultLastMessageFormatter()
|
createDateFormatter()
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -112,7 +112,7 @@ class RoomListPresenterTests {
|
||||||
sessionId = SessionId("sessionId"),
|
sessionId = SessionId("sessionId"),
|
||||||
roomSummaryDataSource = roomSummaryDataSource
|
roomSummaryDataSource = roomSummaryDataSource
|
||||||
),
|
),
|
||||||
DefaultLastMessageFormatter()
|
createDateFormatter()
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -143,7 +143,7 @@ class RoomListPresenterTests {
|
||||||
sessionId = SessionId("sessionId"),
|
sessionId = SessionId("sessionId"),
|
||||||
roomSummaryDataSource = roomSummaryDataSource
|
roomSummaryDataSource = roomSummaryDataSource
|
||||||
),
|
),
|
||||||
DefaultLastMessageFormatter()
|
createDateFormatter()
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -171,14 +171,22 @@ class RoomListPresenterTests {
|
||||||
assertThat(roomSummaryDataSource.latestSlidingSyncRange).isEqualTo(IntRange(129, 279))
|
assertThat(roomSummaryDataSource.latestSlidingSyncRange).isEqualTo(IntRange(129, 279))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createDateFormatter(): LastMessageFormatter {
|
||||||
|
return FakeLastMessageFormatter().apply {
|
||||||
|
givenFormat(A_FORMATTED_DATE)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val A_FORMATTED_DATE = "formatted_date"
|
||||||
|
|
||||||
private val aRoomListRoomSummary = RoomListRoomSummary(
|
private val aRoomListRoomSummary = RoomListRoomSummary(
|
||||||
id = A_ROOM_ID_VALUE,
|
id = A_ROOM_ID_VALUE,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
name = A_ROOM_NAME,
|
name = A_ROOM_NAME,
|
||||||
hasUnread = true,
|
hasUnread = true,
|
||||||
timestamp = "",
|
timestamp = A_FORMATTED_DATE,
|
||||||
lastMessage = A_LAST_MESSAGE,
|
lastMessage = A_LAST_MESSAGE,
|
||||||
avatarData = AvatarData(name = A_ROOM_NAME),
|
avatarData = AvatarData(name = A_ROOM_NAME),
|
||||||
isPlaceholder = false,
|
isPlaceholder = false,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.dateformatter.di
|
||||||
|
|
||||||
|
import com.squareup.anvil.annotations.ContributesTo
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import io.element.android.libraries.di.AppScope
|
||||||
|
import kotlinx.datetime.Clock
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@ContributesTo(AppScope::class)
|
||||||
|
object DateFormatterModule {
|
||||||
|
@Provides
|
||||||
|
fun providesClock(): Clock = Clock.System
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesLocale(): Locale = Locale.getDefault()
|
||||||
|
}
|
||||||
|
|
@ -36,13 +36,10 @@ import javax.inject.Inject
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class DefaultLastMessageFormatter @Inject constructor() : LastMessageFormatter {
|
class DefaultLastMessageFormatter @Inject constructor(
|
||||||
|
private val clock: Clock,
|
||||||
// TODO Inject in constructor
|
private val locale: Locale,
|
||||||
private val clock: Clock = Clock.System
|
) : LastMessageFormatter {
|
||||||
// TODO Inject in constructor
|
|
||||||
private val locale: Locale = Locale.getDefault()
|
|
||||||
|
|
||||||
private val onlyTimeFormatter: DateTimeFormatter by lazy {
|
private val onlyTimeFormatter: DateTimeFormatter by lazy {
|
||||||
val pattern = DateFormat.getBestDateTimePattern(locale, "HH:mm")
|
val pattern = DateFormat.getBestDateTimePattern(locale, "HH:mm")
|
||||||
DateTimeFormatter.ofPattern(pattern)
|
DateTimeFormatter.ofPattern(pattern)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue