Skip to content

Commit

Permalink
Merge pull request #121 from dmzz-yyhyy/time_counter
Browse files Browse the repository at this point in the history
计数器修复
  • Loading branch information
dmzz-yyhyy authored Oct 26, 2024
2 parents 38e8af4 + 9f97fbc commit 94f7714
Showing 6 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ android {
minSdk = 24
targetSdk = 34
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*100+debug版本号(开发需要时迭代, 两位数)
versionCode = 1_00_00_001
versionCode = 1_00_00_002
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ abstract class UserData<T> (
abstract fun get(): T?
abstract fun getFlow(): Flow<T?>
fun getFlowWithDefault(default: T): Flow<T> = getFlow().map { it ?: default }
.map { println("${this.path}: $it");it }
/**
* 此函数为阻塞函数,请务必不要在初始化阶段或主线程上调用
*/
Original file line number Diff line number Diff line change
@@ -177,6 +177,7 @@ fun Content(
onPauseOrDispose {
isRunning = false
viewModel.updateTotalReadingTime(bookId, totalReadingTime)
totalReadingTime = 0
}
}
LaunchedEffect(viewModel.settingState.keepScreenOn) {
@@ -188,6 +189,10 @@ fun Content(
LaunchedEffect(isRunning) {
while (isRunning) {
totalReadingTime += 1
if (totalReadingTime > 300) {
viewModel.updateTotalReadingTime(bookId, totalReadingTime)
totalReadingTime = 0
}
delay(1000)
}
}
Original file line number Diff line number Diff line change
@@ -127,6 +127,8 @@ class ContentViewModel @Inject constructor(
}

fun updateTotalReadingTime(bookId: Int, totalReadingTime: Int) {
println("wasdsfafdasfasdf")
println(totalReadingTime)
viewModelScope.launch(Dispatchers.IO) {
bookRepository.updateUserReadingData(bookId) {
it.copy(
Original file line number Diff line number Diff line change
@@ -376,7 +376,7 @@ fun ExportDialog(
title = "书架",
supportingText = "包括书架及书本信息",
checked = mutableExportContext.bookshelf,
onCheckedChange = { mutableExportContext.bookshelf = it;println(it) }
onCheckedChange = { mutableExportContext.bookshelf = it }
)
HorizontalDivider(Modifier.padding(horizontal = 14.dp))
CheckBoxListItem(
Original file line number Diff line number Diff line change
@@ -3,22 +3,39 @@ package indi.dmzz_yyhyy.lightnovelreader.utils
import android.annotation.SuppressLint
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*


@SuppressLint("NewApi")
fun formTime(time: LocalDateTime): String {
val now = LocalDateTime.now()
val yearDiff = now.year - time.year
val monthDiff = now.monthValue - time.monthValue
val dayDiff = now.dayOfYear - time.dayOfYear
val hourDiff = now.hour - time.hour
val minuteDiff = now.minute - time.minute

return when {
time == LocalDateTime.MIN -> "从未"
time.isAfter(now) -> {
val formatter = DateTimeFormatter.ofPattern("MM/dd HH:mm")
time.format(formatter)
}
time.year < now.year -> "去年"
yearDiff > 1 ->
if (Locale.getDefault().language.equals(Locale.CHINESE.language))
DateTimeFormatter
.ofPattern("uuuu年 MMM d日", Locale.CHINESE)
.format(time)
else
DateTimeFormatter
.ofPattern("d MMM uuuu", Locale.ENGLISH)
.format(time)
yearDiff == 1 -> "去年"
(dayDiff > 3 || monthDiff > 1) ->
if (Locale.getDefault().language.equals(Locale.CHINESE.language))
DateTimeFormatter
.ofPattern("MMM d日", Locale.CHINESE)
.format(time)
else
DateTimeFormatter
.ofPattern("d MMM", Locale.ENGLISH)
.format(time)
dayDiff in 1..3 -> {
val prefix = when (dayDiff) {
1 -> "昨天"
@@ -33,8 +50,8 @@ fun formTime(time: LocalDateTime): String {
}
}
hourDiff in 1..24 -> "$hourDiff 小时前"
minuteDiff == 0 -> "刚刚"
minuteDiff in 1 until 60 -> "$minuteDiff 分钟前"
else -> "很久之前"
minuteDiff == 0 -> "刚刚"
else -> "很久以前"
}
}

0 comments on commit 94f7714

Please sign in to comment.