위젯별 투명도와 밝은·어두운 색상 및 글자 크기와 표시 항목을 추가했다. 모든 위젯에 함께 적용하는 기본값과 개별 설정을 구분하고 크기에 따라 배치를 바꾼다. 포럼에 APK와 전체 소스 및 사용법과 제작 매뉴얼을 함께 배포한다. 앱 단위 검사 34개와 서버 검사 63개 및 웹 날짜·업데이트 검사 통과. 공개 소스에서 APK 빌드와 정적 검사 오류 0개 확인. 경고는 69개다. Android 16 가상 기기에서 기존 앱 위에 설치하고 투명 위젯과 큰 글자 및 RemoteViews 검사를 확인했다. 실제 휴대폰과 다른 홈 화면 앱의 절전·크기 동작은 별도 확인이 필요하다. 회원 DB와 인증 정보 및 배포 서명 키와 내부 운영 기록은 공개 자료에 포함하지 않았다.
74 lines
5.4 KiB
Kotlin
74 lines
5.4 KiB
Kotlin
package kr.co.itosm.dutycalendar
|
|
|
|
import android.app.Activity
|
|
import android.app.AlertDialog
|
|
import android.app.DatePickerDialog
|
|
import android.graphics.Typeface
|
|
import android.text.InputFilter
|
|
import android.view.View
|
|
import android.widget.*
|
|
import org.json.JSONArray
|
|
import org.json.JSONObject
|
|
import java.time.LocalDate
|
|
import java.util.UUID
|
|
|
|
/** 이름과 표시 색 및 개인별 반복 순서를 한 번에 저장한다. 편집 중의 값은 저장 전까지 원본에 반영하지 않는다. */
|
|
class PeopleDialogs(private val activity: Activity, private val changed: () -> Unit) {
|
|
private fun dp(n: Int) = (n * activity.resources.displayMetrics.density).toInt()
|
|
fun edit(person: PersonDuty? = null) {
|
|
if (!SyncClient.connected(activity)) { Toast.makeText(activity, "함께 보는 근무표는 회원 로그인 후 사용할 수 있습니다.", Toast.LENGTH_LONG).show(); return }
|
|
var anchor = person?.schedule?.anchor ?: LocalDate.now()
|
|
val form = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL; setPadding(dp(20), dp(8), dp(20), dp(16)) }
|
|
fun caption(value: String) { form.addView(TextView(activity).apply { text = value; textSize = 14f; setPadding(0, dp(14), 0, dp(6)) }) }
|
|
val name = EditText(activity).apply { hint = "함께 볼 사람의 이름"; contentDescription = "함께 볼 사람 이름"; setSingleLine(true); filters = arrayOf(InputFilter.LengthFilter(30)); setText(person?.name.orEmpty()) }
|
|
caption("이름"); form.addView(name)
|
|
val colors = People.colors.keys.toList()
|
|
val preview = TextView(activity).apply { text = "이름 표시 색상"; textSize = 15f; setTypeface(typeface, Typeface.BOLD) }
|
|
val color = Spinner(activity).apply {
|
|
adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_dropdown_item, People.colors.values.map { it.first })
|
|
contentDescription = "이름 표시 색상"
|
|
setSelection(colors.indexOf(person?.colorKey ?: "BLUE"))
|
|
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
|
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { preview.setTextColor(People.colors.getValue(colors[position]).second) }
|
|
}
|
|
}
|
|
caption("표시 색상"); form.addView(color); form.addView(preview)
|
|
caption("당직 기초 설정")
|
|
val patternEditor = ShiftPatternEditor(activity, person?.schedule?.pattern ?: Schedule.preset(3), person?.schedule?.workWeek ?: 6)
|
|
form.addView(patternEditor)
|
|
caption("첫째 날의 날짜")
|
|
lateinit var dateButton: Button
|
|
dateButton = Button(activity).apply { text = anchor.toString(); setOnClickListener {
|
|
DatePickerDialog(activity, { _, y, m, d -> anchor = LocalDate.of(y, m + 1, d); dateButton.text = anchor.toString() }, anchor.year, anchor.monthValue - 1, anchor.dayOfMonth).show()
|
|
} }; form.addView(dateButton)
|
|
caption("표시 옵션")
|
|
val weekdayDuty = CheckBox(activity).apply { text = "당직일은 평일색으로 표시"; textSize = 14f; minHeight = dp(48); isChecked = person?.schedule?.dutyAsWeekday ?: false }
|
|
form.addView(weekdayDuty)
|
|
caption("직접 입력한 근무표를 이 캘린더에서 함께 봅니다. 상대방에게 계정이나 접근 권한을 부여하지 않습니다.")
|
|
val error = TextView(activity).apply { setTextColor(0xFFAD3D6E.toInt()) }; form.addView(error)
|
|
val builder = AlertDialog.Builder(activity).setTitle(if (person == null) "함께 볼 사람 추가" else "${person.name} 근무표 수정")
|
|
.setView(ScrollView(activity).apply { addView(form) }).setNegativeButton("취소", null).setPositiveButton("저장", null)
|
|
if (person != null) builder.setNeutralButton("삭제", null)
|
|
val dialog = builder.create()
|
|
dialog.setOnShowListener {
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
|
try {
|
|
val data = JSONObject().put("name", name.text.toString().trim()).put("color", colors[color.selectedItemPosition])
|
|
.put("anchor", anchor.toString()).put("pattern", JSONArray(patternEditor.pattern().map { it.name })).put("workWeek", patternEditor.workWeek()).put("dutyAsWeekday", weekdayDuty.isChecked)
|
|
PlannerStore.put(activity, person?.id ?: UUID.randomUUID().toString(), "person", data)
|
|
SyncClient.sync(activity); changed(); dialog.dismiss()
|
|
} catch (problem: Exception) { error.text = problem.message ?: "입력 내용을 확인해 주세요." }
|
|
}
|
|
if (person != null) dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
|
|
AlertDialog.Builder(activity).setTitle("${person.name} 근무표를 삭제할까요?").setMessage("이 캘린더에 직접 등록한 근무표만 삭제합니다.")
|
|
.setNegativeButton("취소", null).setPositiveButton("삭제") { _, _ ->
|
|
runCatching { PlannerStore.put(activity, person.id, "person", JSONObject(), true) }
|
|
.onSuccess { SyncClient.sync(activity); changed(); dialog.dismiss() }
|
|
.onFailure { error.text = "저장 공간을 확인해 주세요." }
|
|
}.show()
|
|
}
|
|
}; dialog.show()
|
|
}
|
|
}
|