app: fix time i18n

This commit is contained in:
vvb2060 2025-07-05 12:57:52 +00:00 committed by John Wu
parent a897e82fa4
commit 2a42ca2b8f
4 changed files with 24 additions and 23 deletions

View File

@ -27,10 +27,15 @@ android {
aidl = true aidl = true
buildConfig = true buildConfig = true
} }
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
} }
dependencies { dependencies {
api(project(":shared")) api(project(":shared"))
coreLibraryDesugaring(libs.jdk.libs)
api(libs.timber) api(libs.timber)
api(libs.markwon.core) api(libs.markwon.core)

View File

@ -14,10 +14,11 @@ import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.lang.reflect.Field import java.lang.reflect.Field
import java.text.DateFormat import java.time.Instant
import java.text.SimpleDateFormat import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Collections import java.util.Collections
import java.util.Locale
inline fun <In : Closeable, Out : Closeable> withInOut( inline fun <In : Closeable, Out : Closeable> withInOut(
input: In, input: In,
@ -83,19 +84,15 @@ inline fun <T, R> Flow<T>.concurrentMap(crossinline transform: suspend (T) -> R)
} }
} }
fun Long.toTime(format: DateFormat) = format.format(this).orEmpty() fun Long.toTime(format: DateTimeFormatter): String = format.format(Instant.ofEpochMilli(this))
// Some devices don't allow filenames containing ":" // Some devices don't allow filenames containing ":"
val timeFormatStandard by lazy { val timeFormatStandard: DateTimeFormatter by lazy {
SimpleDateFormat( DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH.mm.ss").withZone(ZoneId.systemDefault())
"yyyy-MM-dd'T'HH.mm.ss",
Locale.ROOT
)
} }
val timeDateFormat: DateFormat by lazy { val timeDateFormat: DateTimeFormatter by lazy {
DateFormat.getDateTimeInstance( DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.systemDefault())
DateFormat.DEFAULT, }
DateFormat.DEFAULT, val dateFormat: DateTimeFormatter by lazy {
Locale.ROOT DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.systemDefault())
)
} }

View File

@ -7,8 +7,7 @@ import com.squareup.moshi.JsonClass
import com.squareup.moshi.JsonQualifier import com.squareup.moshi.JsonQualifier
import com.squareup.moshi.ToJson import com.squareup.moshi.ToJson
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import java.time.LocalDateTime import java.time.Instant
import java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
class UpdateJson( class UpdateJson(
@ -40,13 +39,13 @@ data class ReleaseAssets(
class DateTimeAdapter { class DateTimeAdapter {
@ToJson @ToJson
fun toJson(date: LocalDateTime): String { fun toJson(date: Instant): String {
return date.toString() return date.toString()
} }
@FromJson @FromJson
fun fromJson(date: String): LocalDateTime { fun fromJson(date: String): Instant {
return LocalDateTime.parse(date, ISO_OFFSET_DATE_TIME) return Instant.parse(date)
} }
} }
@ -57,7 +56,7 @@ data class Release(
val prerelease: Boolean, val prerelease: Boolean,
val assets: List<ReleaseAssets>, val assets: List<ReleaseAssets>,
val body: String, val body: String,
@Json(name = "created_at") val createdTime: LocalDateTime, @Json(name = "created_at") val createdTime: Instant,
) { ) {
val versionCode: Int get() { val versionCode: Int get() {
return if (tag[0] == 'v') { return if (tag[0] == 'v') {

View File

@ -10,13 +10,13 @@ import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.data.GithubApiServices import com.topjohnwu.magisk.core.data.GithubApiServices
import com.topjohnwu.magisk.core.data.RawUrl import com.topjohnwu.magisk.core.data.RawUrl
import com.topjohnwu.magisk.core.ktx.dateFormat
import com.topjohnwu.magisk.core.model.Release import com.topjohnwu.magisk.core.model.Release
import com.topjohnwu.magisk.core.model.ReleaseAssets import com.topjohnwu.magisk.core.model.ReleaseAssets
import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.core.model.UpdateInfo
import retrofit2.HttpException import retrofit2.HttpException
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
import java.time.format.DateTimeFormatter
class NetworkService( class NetworkService(
private val raw: RawUrl, private val raw: RawUrl,
@ -74,7 +74,7 @@ class NetworkService(
private inline fun Release.asPublicInfo(selector: (ReleaseAssets) -> Boolean): UpdateInfo { private inline fun Release.asPublicInfo(selector: (ReleaseAssets) -> Boolean): UpdateInfo {
val version = tag.drop(1) val version = tag.drop(1)
val date = createdTime.format(DateTimeFormatter.ofPattern("yyyy.M.d")) val date = dateFormat.format(createdTime)
return UpdateInfo( return UpdateInfo(
version = version, version = version,
versionCode = versionCode, versionCode = versionCode,