Talaria/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt

57 lines
1.8 KiB
Kotlin
Raw Normal View History

2022-10-11 15:52:25 +00:00
package dev.lonami.talaria.data
import uniffi.talaria.Dialog
import uniffi.talaria.MessageAck
import uniffi.talaria.MessagePreview
import uniffi.talaria.getDialogs
import java.time.Instant
2022-10-11 15:52:25 +00:00
interface DialogRepository {
fun loadDialogs(): List<Dialog>
2022-10-21 12:19:34 +00:00
}
class NativeDialogRepository : DialogRepository {
2022-10-21 12:19:34 +00:00
override fun loadDialogs(): List<Dialog> {
return getDialogs()
2022-10-11 15:52:25 +00:00
}
}
2022-10-21 12:19:34 +00:00
class MockDialogRepository : DialogRepository {
2022-10-21 12:19:34 +00:00
override fun loadDialogs(): List<Dialog> {
val dialogs = mutableListOf<Dialog>()
for (i in 0 until 10) {
dialogs.add(
Dialog(
2022-10-23 18:25:45 +00:00
id = "$i",
title = "Sample Dialog $i",
lastMessage = if (i % 4 == 3) {
null
} else {
MessagePreview(
sender = if (i % 2 == 0) {
"Sender A"
} else {
"Sender B"
},
text = if (i % 3 == 2) {
"Very Long Sample Message $i, with a Lot of Text, which makes it hard to Preview"
} else {
"Sample Message $i"
},
date = Instant.now(),
ack = when (i % 3) {
0 -> MessageAck.RECEIVED
1 -> MessageAck.SENT
2 -> MessageAck.SEEN
else -> throw RuntimeException()
}
)
},
pinned = i < 4
)
)
2022-10-21 12:19:34 +00:00
}
return dialogs
}
}