Skip to content

Commit

Permalink
feat: Update Android release timeline dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Hu Shenghao <[email protected]>
  • Loading branch information
hushenghao committed Nov 25, 2024
1 parent 794ef45 commit 1ba4de8
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 147 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Add 'Animator duration scale' alert
- Update App theme colors
- Update App monochrome logo
- Update Android release timeline dialog
- Fix Android U platlogo
- Project modularization
- Upgrade project dependencies
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 添加 ‘Animator 时长缩放’ 检查
- 更新 App 主题色
- 更新 App 单色图标
- 更新 Android 发布时间线弹框
- 修复 Android U 彩蛋图标
- 项目模块化
- 升级项目依赖项
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.dede.android_eggs.views.main.util.EasterEggShortcutsHelp
import com.dede.android_eggs.views.main.util.EggActionHelp
import com.dede.basic.provider.BaseEasterEgg
import com.dede.basic.provider.EasterEgg
import com.dede.basic.utils.AppLocaleDateFormatter

@Composable
@Preview
Expand All @@ -55,7 +56,7 @@ fun EasterEggHighestItem(
EasterEggHelp.ApiLevelFormatter.create(egg.apiLevelRange).format(context)
}
val dateFormat = remember(egg, context.resources.configuration) {
EasterEggHelp.DateFormatter.getInstance("MM yyyy")
AppLocaleDateFormatter.getInstance("MM yyyy")
}

Card(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.dede.android_eggs.views.main.util

import android.content.Context
import android.icu.text.SimpleDateFormat
import android.os.Build
import android.util.SparseArray
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalInspectionMode
import com.dede.android_eggs.R
import com.dede.android_eggs.inject.EasterEggModules
import com.dede.basic.provider.EasterEgg
import com.dede.basic.provider.EasterEggProvider
import dagger.Module
import java.text.Format
import java.util.Date
import java.util.Locale


object EasterEggHelp {
Expand All @@ -39,34 +34,6 @@ object EasterEggHelp {
return EasterEggModules.providePureEasterEggList(baseEasterEggs)
}

class DateFormatter private constructor(pattern: String, locale: Locale) {

companion object {
fun getInstance(pattern: String): DateFormatter {
return DateFormatter(pattern, getApplicationLocale())
}

private fun getApplicationLocale(): Locale {
val locales = AppCompatDelegate.getApplicationLocales()
return if (locales.isEmpty) {
Locale.getDefault()
} else {
locales.get(0) ?: Locale.getDefault()
}
}
}

private val format: Format = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat(pattern, locale)
} else {
java.text.SimpleDateFormat(pattern, locale)
}

fun format(date: Date): String {
return format.format(date)
}
}

class VersionFormatter private constructor(
@StringRes val nicknameRes: Int,
private vararg val versionNames: CharSequence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import com.dede.android_eggs.views.main.util.EasterEggHelp
import com.dede.basic.provider.TimelineEvent
import com.dede.basic.utils.AppLocaleDateFormatter
import java.util.Calendar
import java.util.TimeZone

Expand Down Expand Up @@ -37,14 +37,14 @@ object TimelineEventHelp {
get() {
val calendar = Calendar.getInstance(TimeZone.getDefault())
calendar.set(Calendar.YEAR, year)
return EasterEggHelp.DateFormatter.getInstance("yyyy").format(calendar.time)
return AppLocaleDateFormatter.getInstance("yyyy").format(calendar.time)
}

val TimelineEvent.localMonth: String
get() {
val calendar = Calendar.getInstance(TimeZone.getDefault())
calendar.set(Calendar.MONTH, month)
return EasterEggHelp.DateFormatter.getInstance("MMMM").format(calendar.time)
return AppLocaleDateFormatter.getInstance("MMMM").format(calendar.time)
}

val TimelineEvent.eventAnnotatedString: AnnotatedString
Expand Down
49 changes: 49 additions & 0 deletions basic/src/main/java/com/dede/basic/utils/AppLocaleDateFormatter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.dede.basic.utils

import android.icu.text.SimpleDateFormat
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import java.text.DateFormat
import java.text.FieldPosition
import java.text.Format
import java.text.ParsePosition
import java.util.Date
import java.util.Locale


class AppLocaleDateFormatter private constructor(pattern: String, locale: Locale) : DateFormat() {

companion object {
fun getInstance(pattern: String): AppLocaleDateFormatter {
return AppLocaleDateFormatter(pattern, getApplicationLocale())
}

private fun getApplicationLocale(): Locale {
val locales = AppCompatDelegate.getApplicationLocales()
return if (locales.isEmpty) {
Locale.getDefault()
} else {
locales.get(0) ?: Locale.getDefault()
}
}
}

private val format: Format = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat(pattern, locale)
} else {
java.text.SimpleDateFormat(pattern, locale)
}

override fun format(
date: Date,
toAppendTo: StringBuffer,
fieldPosition: FieldPosition
): StringBuffer {
return format.format(date, toAppendTo, fieldPosition)
}

override fun parse(source: String, pos: ParsePosition): Date? {
return format.parseObject(source, pos) as? Date
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.inject.Singleton
object AndroidNextEasterEgg : EasterEggProvider {

const val RELEASE_YEAR = 2025
private const val RELEASE_MONTH = Calendar.SEPTEMBER
const val RELEASE_MONTH = Calendar.MAY

// private const val NEXT_API = Build.VERSION_CODES.CUR_DEVELOPMENT// android next
private const val NEXT_API = 36// android 16
Expand All @@ -41,16 +41,6 @@ object AndroidNextEasterEgg : EasterEggProvider {
@DrawableRes
private val PLATLOGO_RES = R.drawable.ic_android_16_platlogo

fun getTimelineMessage(context: Context): String {
val calendar = Calendar.getInstance()
val year = calendar.get(Calendar.YEAR)
return if (year > RELEASE_YEAR) {
context.getString(R.string.summary_android_release_pushed)
} else {
context.getString(R.string.summary_android_waiting)
}
}

@Provides
@IntoSet
@Singleton
Expand Down
Loading

0 comments on commit 1ba4de8

Please sign in to comment.