@@ -7,6 +7,7 @@ import android.content.ComponentName
7
7
import android.content.Context
8
8
import android.content.Intent
9
9
import android.os.Build
10
+ import android.widget.Toast
10
11
import androidx.core.content.getSystemService
11
12
import com.dede.android_eggs.R
12
13
import com.dede.android_eggs.util.SplitUtils
@@ -15,6 +16,9 @@ import com.dede.android_eggs.views.settings.compose.prefs.RetainInRecentsPrefUti
15
16
import com.dede.basic.Utils
16
17
import com.dede.basic.provider.EasterEgg
17
18
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
18
22
19
23
20
24
object EggActionHelp {
@@ -45,11 +49,36 @@ object EggActionHelp {
45
49
}
46
50
}
47
51
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
+
48
77
fun launchEgg (context : Context , egg : EasterEgg ) {
49
78
val targetClass = egg.actionClass
50
79
if (targetClass == null ) {
51
80
if (! egg.onEasterEggAction(context)) {
52
- context.toast( R .string.toast_no_egg )
81
+ NoEggAction .invoke(context )
53
82
}
54
83
return
55
84
}
0 commit comments