Format date in the exported trail

This commit is contained in:
Benoit Marty 2020-10-29 14:46:42 +01:00 committed by Benoit Marty
parent 909ee2cc85
commit e8dcdc7182

View File

@ -33,6 +33,7 @@ import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewEvents
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.platform.VectorViewModelAction import im.vector.app.core.platform.VectorViewModelAction
import im.vector.app.core.resources.DateProvider
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import me.gujun.android.span.span import me.gujun.android.span.span
@ -45,6 +46,7 @@ import org.matrix.android.sdk.internal.crypto.model.rest.ForwardedRoomKeyContent
import org.matrix.android.sdk.internal.crypto.model.rest.GossipingToDeviceObject import org.matrix.android.sdk.internal.crypto.model.rest.GossipingToDeviceObject
import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyShareRequest import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyShareRequest
import org.matrix.android.sdk.internal.crypto.model.rest.SecretShareRequest import org.matrix.android.sdk.internal.crypto.model.rest.SecretShareRequest
import org.threeten.bp.format.DateTimeFormatter
sealed class KeyRequestAction : VectorViewModelAction { sealed class KeyRequestAction : VectorViewModelAction {
data class ExportAudit(val uri: Uri) : KeyRequestAction() data class ExportAudit(val uri: Uri) : KeyRequestAction()
@ -68,6 +70,10 @@ class KeyRequestViewModel @AssistedInject constructor(
fun create(initialState: KeyRequestViewState): KeyRequestViewModel fun create(initialState: KeyRequestViewState): KeyRequestViewModel
} }
private val full24DateFormatter by lazy {
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
}
companion object : MvRxViewModelFactory<KeyRequestViewModel, KeyRequestViewState> { companion object : MvRxViewModelFactory<KeyRequestViewModel, KeyRequestViewState> {
@JvmStatic @JvmStatic
@ -95,7 +101,7 @@ class KeyRequestViewModel @AssistedInject constructor(
val raw = buildString { val raw = buildString {
eventList.forEach { eventList.forEach {
val clearType = it.getClearType() val clearType = it.getClearType()
append("[${it.ageLocalTs}] : $clearType from:${it.senderId} - ") append("[${getFormattedDate(it.ageLocalTs)}] $clearType from:${it.senderId} - ")
when (clearType) { when (clearType) {
EventType.ROOM_KEY_REQUEST -> { EventType.ROOM_KEY_REQUEST -> {
val content = it.getClearContent().toModel<RoomKeyShareRequest>() val content = it.getClearContent().toModel<RoomKeyShareRequest>()
@ -151,4 +157,11 @@ class KeyRequestViewModel @AssistedInject constructor(
} }
} }
} }
private fun getFormattedDate(ageLocalTs: Long?): String {
return ageLocalTs
?.let { DateProvider.toLocalDateTime(it) }
?.let { full24DateFormatter.format(it) }
?: "?"
}
} }