당직근무 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
@@ -12,8 +12,8 @@ android {
|
||||
applicationId = "kr.co.itosm.dutycalendar"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 34
|
||||
versionName = "0.16.0"
|
||||
versionCode = 35
|
||||
versionName = "0.16.1"
|
||||
testInstrumentationRunner = "kr.co.itosm.dutycalendar.StorageSyncCheck"
|
||||
}
|
||||
buildTypes {
|
||||
|
||||
@@ -184,7 +184,7 @@ object WidgetAppearanceCheck {
|
||||
ScheduleStore.saveDisplay(app,current.dutyAsWeekday,current.showLunar,current.offAsHoliday,start,fromSync=true)
|
||||
for(dimensions in listOf(kind.width to kind.height,320 to 440)) {
|
||||
val (width,height)=dimensions
|
||||
positions.edit().putString("month_99004","2026-08").commit()
|
||||
positions.edit().putString("month_99004","2026-08").putString("monthBase_99004",java.time.YearMonth.now().toString()).commit()
|
||||
WidgetStyle.save(app,99004,WidgetStyle(monthFit=true,scale=scale,transparency=50))
|
||||
val options=Bundle().apply {
|
||||
putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,width);putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,width)
|
||||
@@ -235,15 +235,25 @@ object WidgetAppearanceCheck {
|
||||
for(kind in WidgetKind.entries) {
|
||||
val id=manager.getAppWidgetIds(kind.component(app)).firstOrNull()?:continue
|
||||
WidgetStyle.save(app,id,WidgetStyle(monthFit=true))
|
||||
positions.edit().putString("month_$id","2026-12").putInt("offset_$id",14).commit()
|
||||
val now=java.time.YearMonth.now()
|
||||
positions.edit().putString("month_$id",now.plusMonths(3).toString()).putString("monthBase_$id",now.toString()).putInt("offset_$id",14).commit()
|
||||
val receiver=kind.receiver.getDeclaredConstructor().newInstance()
|
||||
receiver.onReceive(app,android.content.Intent(DutyWidget.NEXT).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,id))
|
||||
check(positions.getString("month_$id",null)=="2027-01")
|
||||
check(positions.getString("month_$id",null)==now.plusMonths(4).toString()&&positions.getString("monthBase_$id",null)==now.toString())
|
||||
check(positions.getInt("offset_$id",0)==14)
|
||||
receiver.onReceive(app,android.content.Intent(DutyWidget.PREVIOUS).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,id))
|
||||
check(positions.getString("month_$id",null)=="2026-12")
|
||||
check(positions.getString("month_$id",null)==now.plusMonths(3).toString())
|
||||
// 지금 달로 돌아오면 저장을 지워 다음 달이 되면 위젯도 따라간다.
|
||||
positions.edit().putString("month_$id",now.plusMonths(1).toString()).commit()
|
||||
receiver.onReceive(app,android.content.Intent(DutyWidget.PREVIOUS).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,id))
|
||||
check(!positions.contains("month_$id")&&!positions.contains("monthBase_$id")&&DutyWidget.selectedMonth(app,id)==now){"지금 달로 돌아온 위젯 저장"}
|
||||
// 지난달에 옮겨 둔 달은 버리고 지금 달을 보인다(2026-12-01: 12월 1일인데 11월 달력이 보이던 문제).
|
||||
positions.edit().putString("month_$id",now.minusMonths(1).toString()).putString("monthBase_$id",now.minusMonths(1).toString()).commit()
|
||||
check(DutyWidget.selectedMonth(app,id)==now){"지난달에 옮겨 둔 위젯 달"}
|
||||
positions.edit().putString("month_$id",now.minusMonths(1).toString()).remove("monthBase_$id").commit()
|
||||
check(DutyWidget.selectedMonth(app,id)==now){"옛 버전이 저장한 위젯 달"}
|
||||
receiver.onReceive(app,android.content.Intent(DutyWidget.TODAY).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,id))
|
||||
check(!positions.contains("month_$id")&&!positions.contains("offset_$id"))
|
||||
check(!positions.contains("month_$id")&&!positions.contains("monthBase_$id")&&!positions.contains("offset_$id"))
|
||||
WidgetStyle.save(app,id,WidgetStyle())
|
||||
}
|
||||
// 실제 홈 화면에 배치된 새 종류는 자신의 날짜 범위만 이동하고 오늘로 돌아와야 한다.
|
||||
@@ -260,7 +270,7 @@ object WidgetAppearanceCheck {
|
||||
}
|
||||
failure?.let{throw it}
|
||||
success=true
|
||||
message="근무 순서 이름 세 가지 표시와 줄마다 표시 및 옛 일반근무 이름 무시와 일반근무 글자 숨기기 확인. 네 종류의 기본 배치와 한 달 전체 선택 확인. 월·일 시작과 80·100·120% 및 최소·확장 크기에서 42칸과 모든 날짜 및 마지막 주의 글자 높이와 생략 없음 확인. 날짜 옆 + 없음과 연차 빨강·반차 파랑 숫자 확인. 월 이동과 연말 넘김 및 오늘 복귀와 개별 저장 및 구버전 설정 보존 확인."
|
||||
message="근무 순서 이름 세 가지 표시와 줄마다 표시 및 옛 일반근무 이름 무시와 일반근무 글자 숨기기 확인. 네 종류의 기본 배치와 한 달 전체 선택 확인. 월·일 시작과 80·100·120% 및 최소·확장 크기에서 42칸과 모든 날짜 및 마지막 주의 글자 높이와 생략 없음 확인. 날짜 옆 + 없음과 연차 빨강·반차 파랑 숫자 확인. 월 이동과 연말 넘김 및 오늘 복귀와 개별 저장 및 구버전 설정 보존 확인. 지난달에 옮겨 둔 위젯 달은 지금 달로 돌아옴 확인."
|
||||
} catch(error:Throwable) {message=error.stackTraceToString()}
|
||||
finally {
|
||||
val scheduleRestore=schedulePrefs.edit()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package kr.co.itosm.dutycalendar
|
||||
|
||||
import java.time.LocalDate
|
||||
import java.time.YearMonth
|
||||
|
||||
/**
|
||||
* 날짜가 바뀐 뒤 앱 첫 화면과 달력 위젯이 지난달에 머물지 않게 한다.
|
||||
* (2026-12-01 사용자 지적: 12월 1일인데 11월 달력의 회색 칸에 오늘이 표시됐다.)
|
||||
*
|
||||
* 앱 첫 화면: 보던 달과 고른 날이 그 전 '오늘'이었으면 새 오늘로 옮긴다. 사용자가 일부러 옮겨 둔 다른 달과 날짜는 그대로 둔다.
|
||||
* 달력 위젯: 달을 옮긴 때의 달(base)과 지금 달이 다르면 옮겨 둔 달을 버리고 지금 달을 보인다.
|
||||
*/
|
||||
object DayRollover {
|
||||
data class View(val month: YearMonth, val selected: LocalDate, val shownDay: LocalDate)
|
||||
|
||||
fun follow(view: View, today: LocalDate): View {
|
||||
if (today == view.shownDay) return view
|
||||
val month = if (view.month == YearMonth.from(view.shownDay)) YearMonth.from(today) else view.month
|
||||
val selected = if (view.selected == view.shownDay) today else view.selected
|
||||
return View(month, selected, today)
|
||||
}
|
||||
|
||||
/** 위젯에 저장한 달. 저장한 달이 없거나 읽지 못하거나 옮긴 때의 달이 지금 달과 다르면 지금 달이다. */
|
||||
fun widgetMonth(stored: String?, base: String?, now: YearMonth): YearMonth {
|
||||
val month = stored?.let { runCatching { YearMonth.parse(it) }.getOrNull() } ?: return now
|
||||
val from = base?.let { runCatching { YearMonth.parse(it) }.getOrNull() } ?: return now
|
||||
return if (from == now) month else now
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ open class DutyWidget : AppWidgetProvider() {
|
||||
override fun onAppWidgetOptionsChanged(context: Context, manager: AppWidgetManager, id: Int, options: Bundle) { update(context, manager, id) }
|
||||
override fun onDeleted(context: Context, ids: IntArray) {
|
||||
val editor = context.getSharedPreferences("widget", Context.MODE_PRIVATE).edit()
|
||||
ids.forEach { editor.remove("month_$it");editor.remove("offset_$it") }
|
||||
ids.forEach { editor.remove("month_$it");editor.remove("monthBase_$it");editor.remove("offset_$it") }
|
||||
editor.apply()
|
||||
context.getSharedPreferences("widget_style",0).edit().apply { ids.forEach { remove("style_$it") } }.apply()
|
||||
}
|
||||
@@ -47,8 +47,14 @@ open class DutyWidget : AppWidgetProvider() {
|
||||
val kind=WidgetKind.of(context,id)
|
||||
val prefs = context.getSharedPreferences("widget", Context.MODE_PRIVATE)
|
||||
val editor = prefs.edit()
|
||||
if (action == TODAY) { editor.remove("month_$id");editor.remove("offset_$id") }
|
||||
else if(kind==WidgetKind.MONTH||WidgetStyle.load(context,id).monthFit)editor.putString("month_$id", selectedMonth(context, id).plusMonths(if (action == NEXT) 1 else -1).toString())
|
||||
if (action == TODAY) { editor.remove("month_$id");editor.remove("monthBase_$id");editor.remove("offset_$id") }
|
||||
else if(kind==WidgetKind.MONTH||WidgetStyle.load(context,id).monthFit) {
|
||||
// 옮긴 때의 달(monthBase)을 같이 둔다. 지금 달로 돌아오면 저장을 지워 다음 달이 되면 따라가게 한다.
|
||||
val now=YearMonth.now()
|
||||
val next=selectedMonth(context, id).plusMonths(if (action == NEXT) 1 else -1)
|
||||
if(next==now){editor.remove("month_$id");editor.remove("monthBase_$id")}
|
||||
else{editor.putString("month_$id", next.toString());editor.putString("monthBase_$id", now.toString())}
|
||||
}
|
||||
else {
|
||||
val step=if(kind==WidgetKind.WIDE)14 else 7
|
||||
editor.putInt("offset_$id",(prefs.getInt("offset_$id",0)+(if(action==NEXT)step else -step)).coerceIn(-36500,36500))
|
||||
@@ -76,10 +82,11 @@ open class DutyWidget : AppWidgetProvider() {
|
||||
R.id.day_28, R.id.day_29, R.id.day_30, R.id.day_31, R.id.day_32, R.id.day_33, R.id.day_34,
|
||||
R.id.day_35, R.id.day_36, R.id.day_37, R.id.day_38, R.id.day_39, R.id.day_40, R.id.day_41
|
||||
)
|
||||
// 저장된 월을 읽지 못해도 위젯을 비워 두지 않는다. 현재 달로 복구해 정상적인 표시를 유지한다.
|
||||
internal fun selectedMonth(context: Context, id: Int): YearMonth = runCatching {
|
||||
YearMonth.parse(context.getSharedPreferences("widget", Context.MODE_PRIVATE).getString("month_$id", YearMonth.now().toString()))
|
||||
}.getOrDefault(YearMonth.now())
|
||||
// 저장된 월을 읽지 못하거나 옮긴 때의 달이 지났으면 지금 달을 보인다(DayRollover.widgetMonth).
|
||||
internal fun selectedMonth(context: Context, id: Int): YearMonth {
|
||||
val prefs=context.getSharedPreferences("widget", Context.MODE_PRIVATE)
|
||||
return DayRollover.widgetMonth(prefs.getString("month_$id", null), prefs.getString("monthBase_$id", null), YearMonth.now())
|
||||
}
|
||||
|
||||
fun updateAll(context: Context) {
|
||||
val manager = AppWidgetManager.getInstance(context)
|
||||
|
||||
@@ -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보다 창 표시가 늦을 수 있다. 저장된 새 버전도 창이 준비된 뒤 안내한다.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package kr.co.itosm.dutycalendar
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.YearMonth
|
||||
|
||||
class DayRolloverTest {
|
||||
private val nov30 = LocalDate.of(2026, 11, 30)
|
||||
private val dec1 = LocalDate.of(2026, 12, 1)
|
||||
|
||||
@Test
|
||||
fun monthAndSelectedDayFollowNewToday() {
|
||||
val after = DayRollover.follow(DayRollover.View(YearMonth.of(2026, 11), nov30, nov30), dec1)
|
||||
assertEquals(DayRollover.View(YearMonth.of(2026, 12), dec1, dec1), after)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openedLongAgoStillMovesToThisMonth() {
|
||||
val nov26 = LocalDate.of(2026, 11, 26)
|
||||
val after = DayRollover.follow(DayRollover.View(YearMonth.of(2026, 11), nov26, nov26), dec1)
|
||||
assertEquals(YearMonth.of(2026, 12), after.month)
|
||||
assertEquals(dec1, after.selected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun movedMonthAndPickedDayStay() {
|
||||
val picked = LocalDate.of(2027, 1, 15)
|
||||
val after = DayRollover.follow(DayRollover.View(YearMonth.of(2027, 1), picked, nov30), dec1)
|
||||
assertEquals(YearMonth.of(2027, 1), after.month)
|
||||
assertEquals(picked, after.selected)
|
||||
assertEquals(dec1, after.shownDay)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sameDayChangesNothing() {
|
||||
val view = DayRollover.View(YearMonth.of(2026, 10), LocalDate.of(2026, 10, 3), dec1)
|
||||
assertEquals(view, DayRollover.follow(view, dec1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun widgetMonthDropsOldNavigation() {
|
||||
val dec = YearMonth.of(2026, 12)
|
||||
assertEquals(dec, DayRollover.widgetMonth(null, null, dec))
|
||||
assertEquals(dec, DayRollover.widgetMonth("2026-11", null, dec))
|
||||
assertEquals(dec, DayRollover.widgetMonth("2026-11", "2026-11", dec))
|
||||
assertEquals(dec, DayRollover.widgetMonth("2027-02", "2026-11", dec))
|
||||
assertEquals(YearMonth.of(2027, 2), DayRollover.widgetMonth("2027-02", "2026-12", dec))
|
||||
assertEquals(dec, DayRollover.widgetMonth("망가진 값", "2026-12", dec))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user