Skip to content

Commit

Permalink
initial working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Jan 10, 2025
1 parent e9309da commit 1bcf306
Show file tree
Hide file tree
Showing 29 changed files with 493 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import dev.dimension.flare.ui.component.status.FlareDividerDefaults
import kotlinx.coroutines.launch
import kotlin.math.roundToInt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dimension.flare.ui.screen.dm

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -60,12 +59,12 @@ import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.ui.common.items
import dev.dimension.flare.ui.component.BackButton
import dev.dimension.flare.ui.component.FAIcon
import dev.dimension.flare.ui.component.FlareDividerDefaults
import dev.dimension.flare.ui.component.FlareScaffold
import dev.dimension.flare.ui.component.FlareTopAppBar
import dev.dimension.flare.ui.component.LocalBottomBarHeight
import dev.dimension.flare.ui.component.OutlinedTextField2
import dev.dimension.flare.ui.component.RichText
import dev.dimension.flare.ui.component.status.FlareDividerDefaults
import dev.dimension.flare.ui.model.UiDMItem
import dev.dimension.flare.ui.model.localizedShortTime
import dev.dimension.flare.ui.model.onSuccess
Expand All @@ -79,7 +78,6 @@ import moe.tlaster.precompose.molecule.producePresenter
@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalLayoutApi::class,
ExperimentalFoundationApi::class,
)
@Composable
internal fun DMConversationScreen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package dev.dimension.flare.ui.screen.home

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.dimension.flare.ui.component.status.LazyStatusVerticalStaggeredGrid
import dev.dimension.flare.ui.component.status.status
import dev.dimension.flare.ui.presenter.home.HomeTimelinePresenter
import dev.dimension.flare.ui.presenter.invoke
import moe.tlaster.precompose.molecule.producePresenter

@Composable
internal fun HomeTimelineScreen() {
val state by producePresenter {
presenter()
}
Box(
modifier =
Modifier
.fillMaxSize(),
) {
LazyStatusVerticalStaggeredGrid(
contentPadding = PaddingValues(16.dp),
) {
status(state.listState)
}
}
}

@Composable
private fun presenter() =
run {
remember { HomeTimelinePresenter(dev.dimension.flare.model.AccountType.Guest) }.invoke()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.dimension.flare.ui.render

import kotlinx.datetime.Instant
import java.time.LocalDateTime

internal expect fun Instant.shortTime(): LocalizedShortTime

public actual data class UiDateTime internal constructor(
val value: Instant,
) {
val shortTime: LocalizedShortTime
get() = value.shortTime()
}

internal actual fun Instant.toUi(): UiDateTime = UiDateTime(this)

public sealed interface LocalizedShortTime {
public data class String(
val value: kotlin.String,
) : LocalizedShortTime

public data class YearMonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime

public data class MonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,64 @@ import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDateTime
import kotlinx.datetime.toLocalDateTime
import java.time.LocalDateTime

public actual data class UiDateTime(
val value: Instant,
// val value: LocalizedShortTime,
) {
public val shortTime: LocalizedShortTime by lazy {
val compareTo = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
val time = value.toLocalDateTime(timeZone)
val diff = compareTo - value
when {
// dd MMM yy
compareTo.toLocalDateTime(timeZone).year != time.year -> {
LocalizedShortTime.YearMonthDay(time.toJavaLocalDateTime())
}
// dd MMM
diff.inWholeDays >= 7 -> {
LocalizedShortTime.MonthDay(time.toJavaLocalDateTime())
}
// xx day(s)
diff.inWholeDays >= 1 -> {
DateUtils
.getRelativeTimeSpanString(
value.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx hr(s)
diff.inWholeHours >= 1 -> {
DateUtils
.getRelativeTimeSpanString(
value.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.HOUR_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx sec(s)
diff.inWholeMinutes < 1 -> {
DateUtils
.getRelativeTimeSpanString(
value.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.SECOND_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx min(s)
else -> {
DateUtils
.getRelativeTimeSpanString(
value.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
internal actual fun Instant.shortTime(): LocalizedShortTime {
val compareTo = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
val time = this.toLocalDateTime(timeZone)
val diff = compareTo - this
return when {
// dd MMM yy
compareTo.toLocalDateTime(timeZone).year != time.year -> {
LocalizedShortTime.YearMonthDay(time.toJavaLocalDateTime())
}
// dd MMM
diff.inWholeDays >= 7 -> {
LocalizedShortTime.MonthDay(time.toJavaLocalDateTime())
}
// xx day(s)
diff.inWholeDays >= 1 -> {
DateUtils
.getRelativeTimeSpanString(
this.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx hr(s)
diff.inWholeHours >= 1 -> {
DateUtils
.getRelativeTimeSpanString(
this.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.HOUR_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx sec(s)
diff.inWholeMinutes < 1 -> {
DateUtils
.getRelativeTimeSpanString(
this.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.SECOND_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
// xx min(s)
else -> {
DateUtils
.getRelativeTimeSpanString(
this.toEpochMilliseconds(),
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
.let(LocalizedShortTime::String)
}
}
}

internal actual fun Instant.toUi(): UiDateTime = UiDateTime(this)

public sealed interface LocalizedShortTime {
public data class String(
val value: kotlin.String,
) : LocalizedShortTime

public data class YearMonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime

public data class MonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,89 @@ import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDateTime
import kotlinx.datetime.toLocalDateTime
import java.time.LocalDateTime

public actual data class UiDateTime(
val value: Instant,
) {
public val shortTime: LocalizedShortTime by lazy {
val compareTo = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
val time = value.toLocalDateTime(timeZone)
val diff = compareTo - value
when {
// dd MMM yy
compareTo.toLocalDateTime(timeZone).year != time.year -> {
LocalizedShortTime.YearMonthDay(time.toJavaLocalDateTime())
}
// dd MMM
diff.inWholeDays >= 7 -> {
LocalizedShortTime.MonthDay(time.toJavaLocalDateTime())
}
// xx day(s)
diff.inWholeDays >= 1 -> {
LocalizedShortTime.String(diff.inWholeDays.toString() + " d")
}
// xx hr(s)
diff.inWholeHours >= 1 -> {
LocalizedShortTime.String(diff.inWholeHours.toString() + " h")
}
// xx sec(s)
diff.inWholeMinutes < 1 -> {
LocalizedShortTime.String(diff.inWholeSeconds.toString() + " s")
}
// xx min(s)
else -> {
LocalizedShortTime.String(diff.inWholeMinutes.toString() + " m")
}
internal actual fun Instant.shortTime(): LocalizedShortTime {
val compareTo = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
val time = this.toLocalDateTime(timeZone)
val diff = compareTo - this
return when {
// dd MMM yy
compareTo.toLocalDateTime(timeZone).year != time.year -> {
LocalizedShortTime.YearMonthDay(time.toJavaLocalDateTime())
}
// dd MMM
diff.inWholeDays >= 7 -> {
LocalizedShortTime.MonthDay(time.toJavaLocalDateTime())
}
// xx day(s)
diff.inWholeDays >= 1 -> {
LocalizedShortTime.String(diff.inWholeDays.toString() + " d")
}
// xx hr(s)
diff.inWholeHours >= 1 -> {
LocalizedShortTime.String(diff.inWholeHours.toString() + " h")
}
// xx sec(s)
diff.inWholeMinutes < 1 -> {
LocalizedShortTime.String(diff.inWholeSeconds.toString() + " s")
}
// xx min(s)
else -> {
LocalizedShortTime.String(diff.inWholeMinutes.toString() + " m")
}
}
}

internal actual fun Instant.toUi(): UiDateTime = UiDateTime(this)

public sealed interface LocalizedShortTime {
public data class String(
val value: kotlin.String,
) : LocalizedShortTime
// public actual data class UiDateTime(
// val value: Instant,
// ) {
// public val shortTime: LocalizedShortTime by lazy {
// val compareTo = Clock.System.now()
// val timeZone = TimeZone.currentSystemDefault()
// val time = value.toLocalDateTime(timeZone)
// val diff = compareTo - value
// when {
// // dd MMM yy
// compareTo.toLocalDateTime(timeZone).year != time.year -> {
// LocalizedShortTime.YearMonthDay(time.toJavaLocalDateTime())
// }
// // dd MMM
// diff.inWholeDays >= 7 -> {
// LocalizedShortTime.MonthDay(time.toJavaLocalDateTime())
// }
// // xx day(s)
// diff.inWholeDays >= 1 -> {
// LocalizedShortTime.String(diff.inWholeDays.toString() + " d")
// }
// // xx hr(s)
// diff.inWholeHours >= 1 -> {
// LocalizedShortTime.String(diff.inWholeHours.toString() + " h")
// }
// // xx sec(s)
// diff.inWholeMinutes < 1 -> {
// LocalizedShortTime.String(diff.inWholeSeconds.toString() + " s")
// }
// // xx min(s)
// else -> {
// LocalizedShortTime.String(diff.inWholeMinutes.toString() + " m")
// }
// }
// }
// }
//
// internal actual fun Instant.toUi(): UiDateTime = UiDateTime(this)

public data class YearMonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime

public data class MonthDay(
val localDateTime: LocalDateTime,
) : LocalizedShortTime
}
// public sealed interface LocalizedShortTime {
// public data class String(
// val value: kotlin.String,
// ) : LocalizedShortTime
//
// public data class YearMonthDay(
// val localDateTime: LocalDateTime,
// ) : LocalizedShortTime
//
// public data class MonthDay(
// val localDateTime: LocalDateTime,
// ) : LocalizedShortTime
// }
Loading

0 comments on commit 1bcf306

Please sign in to comment.