@@ -10,10 +10,7 @@ import androidx.appcompat.widget.AppCompatTextView
1010import io.nekohasekai.sagernet.R
1111import java.util.Calendar
1212
13- /* *
14- * Custom TextView that displays speech based on time
15- * and automatically changes when the clock changes.
16- */
13+
1714class Greetings @JvmOverloads constructor(
1815 context : Context ,
1916 attrs : AttributeSet ? = null ,
@@ -22,7 +19,6 @@ class Greetings @JvmOverloads constructor(
2219
2320 private val timeChangeReceiver = object : BroadcastReceiver () {
2421 override fun onReceive (context : Context ? , intent : Intent ? ) {
25- // Will be called every time the hour changes, or when the time is changed
2622 if (intent?.action == Intent .ACTION_TIME_TICK ||
2723 intent?.action == Intent .ACTION_TIME_CHANGED ||
2824 intent?.action == Intent .ACTION_TIMEZONE_CHANGED
@@ -38,7 +34,6 @@ class Greetings @JvmOverloads constructor(
3834
3935 override fun onAttachedToWindow () {
4036 super .onAttachedToWindow()
41- // Register the receiver for hourly updates.
4237 val filter = IntentFilter ().apply {
4338 addAction(Intent .ACTION_TIME_TICK )
4439 addAction(Intent .ACTION_TIME_CHANGED )
@@ -50,7 +45,6 @@ class Greetings @JvmOverloads constructor(
5045
5146 override fun onDetachedFromWindow () {
5247 super .onDetachedFromWindow()
53- // Avoid memory leaks
5448 context.unregisterReceiver(timeChangeReceiver)
5549 }
5650
@@ -59,10 +53,10 @@ class Greetings @JvmOverloads constructor(
5953 private fun updateGreeting () {
6054 val hour = Calendar .getInstance().get(Calendar .HOUR_OF_DAY )
6155 @StringRes val greetingResId = when (hour) {
62- in 4 .. 8 -> R .string.uwu_greeting_morning
63- in 9 .. 15 -> R .string.uwu_greeting_afternoon
64- in 16 .. 20 -> R .string.uwu_greeting_evening
65- in 21 .. 23 -> R .string.uwu_greeting_night
56+ in 5 .. 10 -> R .string.uwu_greeting_morning
57+ in 11 .. 14 -> R .string.uwu_greeting_afternoon
58+ in 15 .. 18 -> R .string.uwu_greeting_evening
59+ in 19 .. 23 -> R .string.uwu_greeting_night
6660 else -> R .string.uwu_greeting_late_night
6761 }
6862 setText(greetingResId)
0 commit comments