당직근무 0.16.0 (웹 2026-12-01.1): 관리자 공지 메뉴와 앱 첫 화면 공지 띠
This commit is contained in:
1 parent
2116ef5607
commit
5f2e2f6952
22 files changed
+265
-27
No files matched your search
@@ -138,6 +138,20 @@ class MainActivity : Activity() {
|
||||
space(content, 8)
|
||||
content.addView(label(if (SyncClient.connected(this)) SyncClient.message else "나의 근무 기록 · 이 기기에 저장", 12f, muted))
|
||||
space(content, 20)
|
||||
// 관리자 '공지'에서 켠 공지 띠를 홈페이지와 같은 색으로 맨 위에 보인다(0.16.0).
|
||||
val notice = Notice.load(this)
|
||||
if (notice.shown) {
|
||||
val bar = row().apply {
|
||||
background = background(if (notice.warn) 0xFFF8ECE5.toInt() else 0xFFE9EEF5.toInt(), 5, if (notice.warn) 0xFFE8CBBB.toInt() else 0xFFCFD8E3.toInt())
|
||||
setPadding(dp(14), dp(11), dp(14), dp(11))
|
||||
contentDescription = "공지 " + notice.text
|
||||
}
|
||||
bar.addView(View(this).apply { background = GradientDrawable().apply { shape = GradientDrawable.OVAL; setColor(if (notice.warn) 0xFFB65B3C.toInt() else 0xFF365FAD.toInt()) } },
|
||||
LinearLayout.LayoutParams(dp(8), dp(8)).apply { marginEnd = dp(10) })
|
||||
bar.addView(label(notice.text, 14f, ink), LinearLayout.LayoutParams(0, -2, 1f))
|
||||
content.addView(bar, LinearLayout.LayoutParams(-1, -2))
|
||||
space(content, 12)
|
||||
}
|
||||
val todayCard = card(content, 0xFFFFFEFA.toInt())
|
||||
todayCard.addView(label(today.format(DateTimeFormatter.ofPattern("M월 d일 EEEE", Locale.KOREAN)), 12f, muted))
|
||||
space(todayCard, 6)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package kr.co.itosm.dutycalendar
|
||||
|
||||
import android.content.Context
|
||||
|
||||
/**
|
||||
* 관리자 '공지'에서 켠 공지 띠. 홈페이지 맨 위와 같은 글을 앱 첫 화면 맨 위에 한 줄로 보인다.
|
||||
* 서버는 버전 확인(api/version)에 notice를 함께 준다. 마지막으로 받은 공지를 기기에 두어 연결이 없어도 보인다.
|
||||
* 예전 서버처럼 notice가 없는 응답이면 보관한 공지를 바꾸지 않는다. 회원 정보는 보내지 않는다.
|
||||
*/
|
||||
data class Notice(val text: String, val warn: Boolean) {
|
||||
val shown: Boolean get() = text.isNotEmpty()
|
||||
|
||||
companion object {
|
||||
const val MAX = 200
|
||||
private const val PREFS = "site_notice"
|
||||
val NONE = Notice("", false)
|
||||
|
||||
/** 서버 값을 화면에 쓸 모양으로 정리한다. 줄바꿈·제어 문자는 빈칸 하나로 바꾸고 200자까지 쓴다. */
|
||||
fun of(text: String?, tone: String?): Notice {
|
||||
val clean = text.orEmpty().replace(Regex("[\\p{Cc}\\s]+"), " ").trim().take(MAX)
|
||||
return if (clean.isEmpty()) NONE else Notice(clean, tone == "warn")
|
||||
}
|
||||
|
||||
fun load(context: Context): Notice {
|
||||
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
return of(prefs.getString("text", ""), if (prefs.getBoolean("warn", false)) "warn" else "info")
|
||||
}
|
||||
|
||||
/** 보관한 공지와 다를 때만 저장하고 true를 돌려준다. */
|
||||
fun save(context: Context, notice: Notice): Boolean {
|
||||
if (load(context) == notice) return false
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putString("text", notice.text).putBoolean("warn", notice.warn).apply()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import javax.net.ssl.HttpsURLConnection
|
||||
* 홈페이지에 공개된 버전 정보를 읽고 새 앱이 있으면 설치 파일을 받을지 묻는다.
|
||||
* 회원 인증값과 개인 자료를 보내지 않는다. 동의하면 앱 안에서 내려받아 검증한다. 적용과 필요한 사용자 확인은 설치 관리자가 담당한다.
|
||||
* 창을 띄울 수 없는 상태에서는 공개 정보만 보관했다가 다음 실행 때 다시 확인한다.
|
||||
* 같은 응답의 공지 띠(notice)를 보관하고 바뀌면 첫 화면을 다시 그린다(0.16.0).
|
||||
*/
|
||||
object UpdateChecker {
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
@@ -58,6 +59,11 @@ object UpdateChecker {
|
||||
if (holidayRevision.isNotBlank() && holidayRevision != Holidays.revision(app)) {
|
||||
Holidays.refresh(app, force = true, changedOnly = true) { reference.get()?.let { screen -> screen.runOnUiThread { if (screen is MainActivity && !screen.isDestroyed) screen.render() } } }
|
||||
}
|
||||
result.optJSONObject("notice")?.let { item ->
|
||||
if (Notice.save(app, Notice.of(item.optString("text"), item.optString("tone")))) {
|
||||
reference.get()?.let { screen -> screen.runOnUiThread { if (screen is MainActivity && !screen.isDestroyed) screen.render() } }
|
||||
}
|
||||
}
|
||||
prefs.edit().putString("release", result.toString()).putLong("checkedAt", System.currentTimeMillis()).apply()
|
||||
reference.get()?.let { screen -> screen.runOnUiThread { if (force) prefs.edit().remove("deferred").remove("deferredUntil").apply(); prompt(screen, result); if (force && result.optLong("appVersionCode") <= AppUpdate.installed(app)) android.widget.Toast.makeText(screen, "현재 최신 버전입니다.", android.widget.Toast.LENGTH_SHORT).show() } }
|
||||
} catch (_: Exception) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package kr.co.itosm.dutycalendar
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class NoticeTest {
|
||||
@Test
|
||||
fun emptyOrBlankMeansNoNotice() {
|
||||
assertFalse(Notice.of(null, "warn").shown)
|
||||
assertFalse(Notice.of(" \n\t ", "info").shown)
|
||||
assertEquals(Notice.NONE, Notice.of("", "warn"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toneAndTextAreCleaned() {
|
||||
val notice = Notice.of(" 12월 3일 점검\n안내\u0007 ", "warn")
|
||||
assertTrue(notice.shown)
|
||||
assertTrue(notice.warn)
|
||||
assertEquals("12월 3일 점검 안내", notice.text)
|
||||
assertFalse(Notice.of("안내", "info").warn)
|
||||
assertFalse(Notice.of("안내", "red").warn)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longTextIsCut() {
|
||||
assertEquals(Notice.MAX, Notice.of("가".repeat(500), "info").text.length)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user