- 옵션 → 근무 순서 이름: 당직 다음 날(비번)부터 순서 자리마다 그날 당직 서는 사람 이름. 근무 종류는 글자로만 보이고 당직 기초 설정 화면은 그대로 - 달력에 보일 것: 근무와 이름 둘 다 · 이름만 · 근무만(nameDisplay). 앱 달력·위젯·근무표 그림, 웹 달력·그림, 기본 달력 반영과 구독 제목 - 근무표 names(순서와 같은 길이) 저장·검사, 구버전 저장 때 보존, 소속 공유 제외. 날짜별 변경 날은 이름 없음 - 앱 0.15.0 / 설치 번호 24. APK 875878바이트, SHA-256 22f4070a33d0d4c553f0391cb13f473dbec73d2174ba7a5e653318b394c3c55e - 검사: 서버 106개, 앱 단위 59개, 웹 이름 계산, 위젯 기기 검사(세 가지 표시)
134 lines
9.5 KiB
Kotlin
134 lines
9.5 KiB
Kotlin
package kr.co.itosm.dutycalendar
|
|
|
|
import android.app.PendingIntent
|
|
import android.appwidget.AppWidgetManager
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.graphics.Color
|
|
import android.graphics.Typeface
|
|
import android.net.Uri
|
|
import android.text.SpannableString
|
|
import android.text.Spanned
|
|
import android.text.style.ForegroundColorSpan
|
|
import android.text.style.RelativeSizeSpan
|
|
import android.text.style.StyleSpan
|
|
import android.util.TypedValue
|
|
import android.widget.RemoteViews
|
|
import java.time.LocalDate
|
|
import java.time.YearMonth
|
|
|
|
/** 한 달 전체를 고른 위젯은 종류에 관계없이 같은 7열과 6주를 표시한다.
|
|
* 홈 화면이 알려 준 실제 폭과 높이에서 제목과 이동 버튼의 공간을 먼저 뺀다.
|
|
* 남은 칸에 날짜를 우선 배치하고 근무와 추가 정보는 들어갈 때만 붙인다.
|
|
* 작은 위젯을 기존 큰 달력의 고정 여백으로 채우거나 마지막 주를 잘라 내지 않는다.
|
|
*/
|
|
object MonthWidgetViews {
|
|
fun build(context:Context,id:Int,kind:WidgetKind,width:Int,height:Int,style:WidgetStyle):RemoteViews {
|
|
val density=context.resources.displayMetrics.density
|
|
val padding=if(width<180||height<180)3 else 8
|
|
val short=height<180
|
|
val header=if(short)18 else 28
|
|
val weekday=if(short)12 else 20
|
|
val footer=if(short)18 else 26
|
|
val cellWidth=(width-padding*2)/7f
|
|
val cellHeight=(height-padding*2-header-weekday-footer)/6f
|
|
val showShift=cellHeight>=24f
|
|
val showExtra=cellHeight>=47f&&cellWidth>=28f&&style.detail!="COMPACT"
|
|
val lines=if(showExtra)3 else if(showShift)2 else 1
|
|
// 글자 확대보다 한 달 전체를 지키는 것이 이 배치의 목적이다. 여유가 있는 크기에서는
|
|
// 선택한 배율을 적용하고 좁은 칸에서는 폭과 높이의 상한을 함께 적용한다.
|
|
// DIP 단위로 정한 실제 글자 크기는 휴대폰의 글꼴 배율이 커져도 날짜 칸을 넘지 않는다.
|
|
val limit=minOf((cellWidth-2)/(if(showExtra)3.0f else if(showShift&&cellWidth>=24)2.2f else 1.85f),cellHeight/(lines*1.4f))
|
|
val font=minOf(16f*style.scale/100f,limit).coerceAtLeast(1f)
|
|
val month=DutyWidget.selectedMonth(context,id)
|
|
val schedule=ScheduleStore.load(context)
|
|
val today=LocalDate.now()
|
|
val views=RemoteViews(context.packageName,R.layout.duty_widget_month_fit)
|
|
views.setInt(R.id.widget_root,"setBackgroundColor",style.background)
|
|
views.setViewPadding(R.id.widget_root,(padding*density).toInt(),(padding*density).toInt(),(padding*density).toInt(),(padding*density).toInt())
|
|
val open=PendingIntent.getActivity(context,0,AppNavigation.main(context),PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
|
views.setOnClickPendingIntent(R.id.widget_root,open)
|
|
views.setTextViewText(R.id.widget_title,if(width<180)"${month.year}.${month.monthValue}" else "${month.year}년 ${month.monthValue}월")
|
|
val titleFont=if(width<180||short)11f else 17f
|
|
for(control in listOf(R.id.widget_title,R.id.widget_customize)) {
|
|
views.setInt(control,"setHeight",(header*density).toInt())
|
|
views.setTextColor(control,style.ink)
|
|
views.setTextViewTextSize(control,TypedValue.COMPLEX_UNIT_DIP,if(control==R.id.widget_title)titleFont else 9f)
|
|
}
|
|
val customize=AppNavigation.widgetStyle(context,id)
|
|
views.setOnClickPendingIntent(R.id.widget_customize,PendingIntent.getActivity(context,id,customize,PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE))
|
|
val headers=intArrayOf(R.id.widget_sun,R.id.widget_mon,R.id.widget_tue,R.id.widget_wed,R.id.widget_thu,R.id.widget_fri,R.id.widget_saturday)
|
|
calendarWeekdays(schedule.weekStart).forEachIndexed { index,day ->
|
|
val control=headers[index]
|
|
views.setTextViewText(control,listOf("일","월","화","수","목","금","토")[day])
|
|
views.setInt(control,"setHeight",(weekday*density).toInt())
|
|
views.setTextViewTextSize(control,TypedValue.COMPLEX_UNIT_DIP,if(short)8f else 10f)
|
|
views.setTextColor(control,when(day){0->style.color(0xFFBD5163.toInt());6->style.color(schedule.saturdayColor);else->style.muted})
|
|
}
|
|
listOf(R.id.widget_previous to DutyWidget.PREVIOUS,R.id.widget_today to DutyWidget.TODAY,R.id.widget_next to DutyWidget.NEXT).forEach { (control,action) ->
|
|
views.setInt(control,"setHeight",(footer*density).toInt())
|
|
views.setTextColor(control,style.ink)
|
|
views.setTextViewTextSize(control,TypedValue.COMPLEX_UNIT_DIP,if(short)9f else 11f)
|
|
// 같은 월간 모양이라도 원래 등록된 제공자로 보내야 작은 위젯의 이동 요청이 거절되지 않는다.
|
|
val intent=Intent(context,kind.receiver).setAction(action).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,id)
|
|
views.setOnClickPendingIntent(control,PendingIntent.getBroadcast(context,id,intent,PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE))
|
|
}
|
|
val snapshot=CalendarSnapshot.load(context)
|
|
val people=if(style.people)snapshot.people else emptyList()
|
|
calendarDays(month,schedule.weekStart).forEachIndexed { index,date ->
|
|
val shift=schedule.shiftOn(date)
|
|
val holiday=Holidays.name(context,date)
|
|
val events=snapshot.eventsOn(date)
|
|
val anniversaries=snapshot.anniversariesOn(date)
|
|
val names=if(style.people)snapshot.workNames(date,schedule) else emptyList()
|
|
val colleagues=People.onDuty(people,date)
|
|
val lunar=if(style.lunar&&schedule.showLunar)LunarDates.label(context,date) else null
|
|
val slot=ShiftNames.slotView(schedule,date)
|
|
val extra=slot.name.takeIf{it.isNotEmpty()}
|
|
?:names.firstOrNull()?.name
|
|
?:holiday?.takeIf{style.holidays}
|
|
?:lunar
|
|
?:anniversaries.firstOrNull()?.takeIf{style.anniversaries}?.getJSONObject("data")?.getString("title")
|
|
?:colleagues.firstOrNull()?.name
|
|
val mark=style.eventMark&&(events.isNotEmpty()||anniversaries.isNotEmpty())
|
|
val number=date.dayOfMonth.toString()+if(mark&&cellWidth>=24)"+" else ""
|
|
val shiftLabel=if(slot.nameOnly)slot.name.take(if(cellWidth>=24)3 else 1) else if(ShiftNames.cellLabel(shift).isEmpty())" " else if(cellWidth>=24)shift.shortTitle else when{shift==Shift.REGULAR&&ShiftNames.regular.isBlank()->"근";else->shift.shortTitle.take(1)}
|
|
// 음력의 마지막 숫자를 자르면 16일이 1일처럼 보인다. 이름은 줄일 수 있지만
|
|
// 날짜 정보는 전체를 유지한다. 숫자 폭이 좁아 여섯 글자 음력도 같은 칸에 들어간다.
|
|
val extraLabel=if(extra==lunar)extra else extra?.take(4)
|
|
val label=number+(if(showShift)"\n$shiftLabel" else "")+(if(showExtra&&!extraLabel.isNullOrBlank())"\n$extraLabel" else "")
|
|
val text=SpannableString(label)
|
|
text.setSpan(StyleSpan(Typeface.BOLD),0,number.length,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
text.setSpan(ForegroundColorSpan(style.color(schedule.dateColor(date,holiday!=null))),0,number.length,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
if(showShift) {
|
|
val end=number.length+1+shiftLabel.length
|
|
text.setSpan(ForegroundColorSpan(style.color(schedule.shiftColor(date))),number.length+1,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
text.setSpan(RelativeSizeSpan(0.85f),number.length+1,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
if(end<label.length) {
|
|
text.setSpan(RelativeSizeSpan(0.7f),end+1,label.length,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
text.setSpan(ForegroundColorSpan(names.firstOrNull()?.let{style.color(it.color)}?:style.muted),end+1,label.length,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
}
|
|
}
|
|
val outside=YearMonth.from(date)!=month
|
|
if(outside)text.setSpan(ForegroundColorSpan(style.muted),0,label.length,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
val cell=DutyWidget.DAY_IDS[index]
|
|
views.setTextViewText(cell,text)
|
|
views.setTextViewTextSize(cell,TypedValue.COMPLEX_UNIT_DIP,font)
|
|
views.setInt(cell,"setMaxLines",lines)
|
|
views.setTextColor(cell,style.ink)
|
|
// 날짜만 표시할 만큼 낮은 위젯은 당직 칸의 옅은 바탕으로 근무를 구분한다.
|
|
// 오늘 강조와 날짜의 빨간색 선택은 각각 유지한다. 완전 투명 배경도 그대로 지원한다.
|
|
val background=when {
|
|
style.today&&date==today->if(style.dark)0x665679A1 else 0x5594ABC8
|
|
!showShift&&shift==Shift.DUTY&&!outside->if(style.dark)0x665E3E29 else 0x44D18451
|
|
else->Color.TRANSPARENT
|
|
}
|
|
views.setInt(cell,"setBackgroundColor",background)
|
|
views.setContentDescription(cell,"${date.year}년 ${date.monthValue}월 ${date.dayOfMonth}일 ${shift.title}. ${holiday.orEmpty()} ${lunar.orEmpty()}. 이름 ${names.joinToString{it.name}}. 함께 당직 ${colleagues.joinToString{it.name}}. 일정 ${events.size}개. 기념일 ${anniversaries.joinToString{it.getJSONObject("data").getString("title")}}")
|
|
val intent=AppNavigation.date(context,date)
|
|
views.setOnClickPendingIntent(cell,PendingIntent.getActivity(context,id*1000+index+1,intent,PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE))
|
|
}
|
|
return views
|
|
}
|
|
}
|