Skip to content

Commit ed685fc

Browse files
committed
feat: Add no Egg toast for android 2.2
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent 21e8445 commit ed685fc

File tree

7 files changed

+49
-7
lines changed

7 files changed

+49
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### v4.2.1
4+
- Add no Easter egg toast for Android 2.2
5+
- Update translations
6+
- Upgrade project dependencies
7+
38
### v4.2.0 (2025-08-25)
49

510
- Use Composable wavy line

CHANGELOG_zh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# 更新日志
22

3+
### v4.2.1
4+
- 新增 Android 2.2 无彩蛋提示
5+
- 更新翻译
6+
- 升级项目依赖项
7+
38
### v4.2.0 (2025-08-25)
49

510
- 使用 Composable 波浪线

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424

2525
defaultConfig {
2626
applicationId = "com.dede.android_eggs"
27-
versionCode = 66
28-
versionName = "4.2.0"
27+
versionCode = 67
28+
versionName = "4.2.1"
2929
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3030

3131
base.archivesName.set("easter_eggs_${versionName}_${versionCode}")

app/src/main/java/com/dede/android_eggs/views/main/util/EggActionHelp.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.ComponentName
77
import android.content.Context
88
import android.content.Intent
99
import android.os.Build
10+
import android.widget.Toast
1011
import androidx.core.content.getSystemService
1112
import com.dede.android_eggs.R
1213
import com.dede.android_eggs.util.SplitUtils
@@ -15,6 +16,9 @@ import com.dede.android_eggs.views.settings.compose.prefs.RetainInRecentsPrefUti
1516
import com.dede.basic.Utils
1617
import com.dede.basic.provider.EasterEgg
1718
import com.dede.basic.toast
19+
import com.dede.basic.uiHandler
20+
import java.lang.ref.WeakReference
21+
import com.dede.android_eggs.resources.R as StringR
1822

1923

2024
object EggActionHelp {
@@ -45,11 +49,36 @@ object EggActionHelp {
4549
}
4650
}
4751

52+
private object NoEggAction : Function1<Context, Unit>, Runnable {
53+
private const val RESET_DELAY = 3000L
54+
55+
private var showDetail = false
56+
private var toastRef: WeakReference<Toast>? = null
57+
58+
override fun invoke(context: Context) {
59+
if (!showDetail) {
60+
toastRef = WeakReference(context.toast(R.string.toast_no_egg))
61+
showDetail = true
62+
return
63+
}
64+
// show detail toast, for rookies
65+
toastRef?.get()?.cancel()
66+
context.toast(StringR.string.toast_no_egg_detail)
67+
68+
uiHandler.removeCallbacks(this)
69+
uiHandler.postDelayed(this, RESET_DELAY)
70+
}
71+
72+
override fun run() {
73+
showDetail = false
74+
}
75+
}
76+
4877
fun launchEgg(context: Context, egg: EasterEgg) {
4978
val targetClass = egg.actionClass
5079
if (targetClass == null) {
5180
if (!egg.onEasterEggAction(context)) {
52-
context.toast(R.string.toast_no_egg)
81+
NoEggAction.invoke(context)
5382
}
5483
return
5584
}

basic/src/main/java/com/dede/basic/ContextExt.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ fun Context.getActivity(): Activity? {
5555
return null
5656
}
5757

58-
fun Context.toast(@StringRes resId: Int, duration: Int = Toast.LENGTH_SHORT) {
59-
Toast.makeText(this, resId, duration).show()
58+
fun Context.toast(@StringRes resId: Int, duration: Int = Toast.LENGTH_SHORT): Toast {
59+
return Toast.makeText(this, resId, duration).apply(Toast::show)
6060
}
6161

62-
fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
63-
Toast.makeText(this, text, duration).show()
62+
fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT): Toast {
63+
return Toast.makeText(this, text, duration).apply(Toast::show)
6464
}
6565

6666
fun Context.createChooser(target: Intent, title: CharSequence? = null): Intent {

core/resources/src/main/res/values-zh/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<string name="preference_on">开启</string>
3434
<string name="preference_off">关闭</string>
3535
<string name="toast_shortcut_added">已添加快捷方式</string>
36+
<string name="toast_no_egg_detail">这个安卓版本没有 Easter Egg</string>
3637
<string name="app_widget_description">这是 Easter Eggs 模拟时钟</string>
3738
<string name="action_agree">同意</string>
3839
<string name="summary_browse_privacy_policy">继续即表示您同意 Easter Eggs 的隐私政策</string>

core/resources/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
<string name="preference_off">Off</string>
4141

4242
<string name="toast_shortcut_added">Shortcut added to home screen</string>
43+
<string name="toast_no_egg_detail">This Android version doesn\'t have an Easter Egg</string>
44+
4345
<string name="app_widget_description">This is the Easter Eggs analog clock</string>
4446
<string name="action_agree">I agree</string>
4547
<string name="summary_browse_privacy_policy">By continuing you agree to the Easter Egg\'s privacy policy.</string>

0 commit comments

Comments
 (0)