당직근무 0.16.1 (웹 2026-12-01.2): 날짜가 바뀌면 지난달 달력에 머물지 않고 이번 달로 넘어감
This commit is contained in:
1 parent
e678b8520b
commit
3060246e9f
18 files changed
+187
-36
No files matched your search
@@ -24,6 +24,12 @@ import java.util.Locale
|
||||
class MainActivity : Activity() {
|
||||
private var month = YearMonth.now()
|
||||
private var selectedDate = LocalDate.now()
|
||||
// 이 화면이 '오늘'로 삼은 날. 날짜가 바뀌면 DayRollover로 달과 고른 날을 새 오늘로 옮긴다.
|
||||
private var shownDay = LocalDate.now()
|
||||
private var watchingDay = false
|
||||
private val dayWatcher = object : android.content.BroadcastReceiver() {
|
||||
override fun onReceive(context: android.content.Context, intent: android.content.Intent) { if (followToday()) render() }
|
||||
}
|
||||
private val planner by lazy { PlannerDialogs(this) { render() } }
|
||||
private val peopleEditor by lazy { PeopleDialogs(this) { render() } }
|
||||
private val anniversaries by lazy { AnniversaryDialogs(this) { render() } }
|
||||
@@ -66,6 +72,7 @@ class MainActivity : Activity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
savedInstanceState?.getString("month")?.let { month = YearMonth.parse(it) }
|
||||
savedInstanceState?.getString("selectedDate")?.let { selectedDate = LocalDate.parse(it) }
|
||||
savedInstanceState?.getString("shownDay")?.let { shownDay = LocalDate.parse(it) }
|
||||
PlannerStore.migrate(this)
|
||||
if(savedInstanceState==null) receiveNavigation(intent)
|
||||
}
|
||||
@@ -80,9 +87,10 @@ class MainActivity : Activity() {
|
||||
setIntent(incoming);receiveNavigation(incoming)
|
||||
}
|
||||
override fun onDestroy() { WidgetStyleDialog.dismiss(this);super.onDestroy() }
|
||||
override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState); outState.putString("month", month.toString()); outState.putString("selectedDate", selectedDate.toString()) }
|
||||
override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState); outState.putString("month", month.toString()); outState.putString("selectedDate", selectedDate.toString()); outState.putString("shownDay", shownDay.toString()) }
|
||||
override fun onResume() {
|
||||
super.onResume(); render(); DutyWidget.updateAll(this); Reminders.reschedule(this)
|
||||
super.onResume(); followToday(); render(); DutyWidget.updateAll(this); Reminders.reschedule(this)
|
||||
watchDay(true)
|
||||
CalendarMirror.request(this)
|
||||
Holidays.schedule(this)
|
||||
val holidayRevision=Holidays.revision(this)
|
||||
@@ -91,7 +99,26 @@ class MainActivity : Activity() {
|
||||
SyncClient.foreground(this) { runOnUiThread { if (!isFinishing && !isDestroyed) render() } }
|
||||
UpdateChecker.check(this, fresh = true)
|
||||
}
|
||||
override fun onPause() { SyncClient.background(); super.onPause() }
|
||||
override fun onPause() { watchDay(false); SyncClient.background(); super.onPause() }
|
||||
/** 날짜가 바뀌었으면 true. 보던 달과 고른 날이 그 전 오늘이었으면 새 오늘로 옮긴다. */
|
||||
private fun followToday(): Boolean {
|
||||
val today = LocalDate.now()
|
||||
if (today == shownDay) return false
|
||||
val next = DayRollover.follow(DayRollover.View(month, selectedDate, shownDay), today)
|
||||
month = next.month; selectedDate = next.selected; shownDay = next.shownDay
|
||||
return true
|
||||
}
|
||||
// 화면을 켜 둔 채 자정을 넘기거나 시간대·시계를 바꿔도 달력이 지난날에 머물지 않게 한다. 화면이 보일 때만 듣는다.
|
||||
private fun watchDay(on: Boolean) {
|
||||
if (on == watchingDay) return
|
||||
watchingDay = on
|
||||
if (!on) { runCatching { unregisterReceiver(dayWatcher) }; return }
|
||||
val filter = android.content.IntentFilter().apply {
|
||||
addAction(android.content.Intent.ACTION_TIME_TICK); addAction(android.content.Intent.ACTION_DATE_CHANGED)
|
||||
addAction(android.content.Intent.ACTION_TIME_CHANGED); addAction(android.content.Intent.ACTION_TIMEZONE_CHANGED)
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= 33) registerReceiver(dayWatcher, filter, RECEIVER_NOT_EXPORTED) else registerReceiver(dayWatcher, filter)
|
||||
}
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
// 첫 실행에서는 onResume보다 창 표시가 늦을 수 있다. 저장된 새 버전도 창이 준비된 뒤 안내한다.
|
||||
|
||||
Reference in new issue
Block a user