feat: 달력 5행 동적 높이 조정 및 연차 메인 화면 연동
- 달력 5행일 때 아이템 높이를 동적으로 계산하여 화면 꽉 채우기 - 메인 화면 tvAnnualLeave에 남은 연차 표시 기능 추가 - onResume에서 연차 정보 자동 업데이트 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -13,18 +13,18 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
data class DayShift(
|
data class DayShift(
|
||||||
val date: LocalDate?,
|
val date: LocalDate?,
|
||||||
val shift: String?,
|
val shift: String?,
|
||||||
val hasMemo: Boolean = false,
|
val hasMemo: Boolean = false,
|
||||||
val memoContent: String? = null
|
val memoContent: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
class CalendarAdapter(
|
class CalendarAdapter(
|
||||||
var days: List<DayShift>,
|
var days: List<DayShift>,
|
||||||
private val listener: OnDayClickListener,
|
private val listener: OnDayClickListener,
|
||||||
var showHolidays: Boolean = true
|
var showHolidays: Boolean = true,
|
||||||
|
private val rowCount: Int = 6 // Default to 6 rows
|
||||||
) : RecyclerView.Adapter<CalendarAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<CalendarAdapter.ViewHolder>() {
|
||||||
|
|
||||||
interface OnDayClickListener {
|
interface OnDayClickListener {
|
||||||
fun onDayClick(date: LocalDate, currentShift: String)
|
fun onDayClick(date: LocalDate, currentShift: String)
|
||||||
}
|
}
|
||||||
@@ -48,18 +48,32 @@ class CalendarAdapter(
|
|||||||
return (dp * context.resources.displayMetrics.density).toInt()
|
return (dp * context.resources.displayMetrics.density).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val item = days[position]
|
val item = days[position]
|
||||||
val context = holder.itemView.context
|
val context = holder.itemView.context
|
||||||
|
|
||||||
if (item.date == null) {
|
// Dynamically adjust item height based on row count (5 or 6 rows)
|
||||||
holder.itemView.visibility = View.INVISIBLE
|
val displayMetrics = context.resources.displayMetrics
|
||||||
return
|
val screenWidth = displayMetrics.widthPixels
|
||||||
}
|
val itemWidth = screenWidth / 7 // Each cell width
|
||||||
|
val itemHeight = if (rowCount == 5) {
|
||||||
|
(itemWidth * 1.2).toInt() // Taller items for 5 rows to fill space
|
||||||
|
} else {
|
||||||
|
itemWidth // Square items for 6 rows
|
||||||
|
}
|
||||||
|
|
||||||
holder.itemView.visibility = View.VISIBLE
|
val layoutParams = holder.itemView.layoutParams
|
||||||
|
layoutParams.height = itemHeight
|
||||||
|
holder.itemView.layoutParams = layoutParams
|
||||||
|
|
||||||
// Day Number
|
if (item.date == null) {
|
||||||
|
holder.itemView.visibility = View.INVISIBLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.itemView.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
// Day Number
|
||||||
holder.dayNumber.text = item.date.dayOfMonth.toString()
|
holder.dayNumber.text = item.date.dayOfMonth.toString()
|
||||||
|
|
||||||
// Holiday / Weekend logic
|
// Holiday / Weekend logic
|
||||||
|
|||||||
@@ -187,22 +187,33 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
currentViewTeam = prefs.getString(KEY_TEAM, "A") ?: "A"
|
currentViewTeam = prefs.getString(KEY_TEAM, "A") ?: "A"
|
||||||
|
|
||||||
updateTideButtonVisibility()
|
updateTideButtonVisibility()
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
|
|
||||||
// 일원화된 통합 권한 체크 실행 (신뢰도 100% 보장)
|
// 일원화된 통합 권한 체크 실행 (신뢰도 100% 보장)
|
||||||
AlarmPermissionUtil.checkAndRequestAllPermissions(this)
|
AlarmPermissionUtil.checkAndRequestAllPermissions(this)
|
||||||
|
|
||||||
// 설정 변경 시 즉시 반영을 위한 강제 동기화 (30일 스케줄링)
|
// 설정 변경 시 즉시 반영을 위한 강제 동기화 (30일 스케줄링)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
syncAllAlarms(this@MainActivity)
|
syncAllAlarms(this@MainActivity)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 연차 정보 업데이트
|
||||||
|
lifecycleScope.launch {
|
||||||
|
val repo = ShiftRepository(this@MainActivity)
|
||||||
|
val annualLeave = repo.getAnnualLeave()
|
||||||
|
annualLeave?.let {
|
||||||
|
binding.tvAnnualLeave.text = "연차: ${String.format("%.1f", it.remainingDays)}"
|
||||||
|
} ?: run {
|
||||||
|
binding.tvAnnualLeave.text = "연차: --"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showMonthYearPicker() {
|
private fun showMonthYearPicker() {
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_month_year_picker, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_month_year_picker, null)
|
||||||
@@ -255,10 +266,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return (dp * resources.displayMetrics.density).toInt()
|
return (dp * resources.displayMetrics.density).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupCalendar() {
|
private fun setupCalendar() {
|
||||||
binding.calendarGrid.layoutManager = GridLayoutManager(this, 7)
|
binding.calendarGrid.layoutManager = GridLayoutManager(this, 7)
|
||||||
updateCalendar()
|
binding.calendarGrid.setHasFixedSize(false) // Allow dynamic item sizing
|
||||||
}
|
updateCalendar()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateCalendar() {
|
private fun updateCalendar() {
|
||||||
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
@@ -294,13 +306,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dao.getMemosForMonth(monthStr).associateBy { memoItem -> memoItem.date }
|
dao.getMemosForMonth(monthStr).associateBy { memoItem -> memoItem.date }
|
||||||
}
|
}
|
||||||
|
|
||||||
val days = generateDaysForMonthWithData(currentViewMonth, currentViewTeam, factory, overrides, memos)
|
val days = generateDaysForMonthWithData(currentViewMonth, currentViewTeam, factory, overrides, memos)
|
||||||
|
|
||||||
val adapter = CalendarAdapter(days, object : CalendarAdapter.OnDayClickListener {
|
// Calculate row count (5 or 6 rows)
|
||||||
override fun onDayClick(date: LocalDate, currentShift: String) {
|
val daysInMonth = currentViewMonth.lengthOfMonth()
|
||||||
showDaySettingsDialog(date, currentShift)
|
val firstDayOfMonth = currentViewMonth.atDay(1).dayOfWeek.value % 7
|
||||||
}
|
val actualDayCount = firstDayOfMonth + daysInMonth
|
||||||
}, binding.cbShowHolidays.isChecked)
|
val rowCount = if (actualDayCount <= 35) 5 else 6
|
||||||
|
|
||||||
|
val adapter = CalendarAdapter(days, object : CalendarAdapter.OnDayClickListener {
|
||||||
|
override fun onDayClick(date: LocalDate, currentShift: String) {
|
||||||
|
showDaySettingsDialog(date, currentShift)
|
||||||
|
}
|
||||||
|
}, binding.cbShowHolidays.isChecked, rowCount)
|
||||||
|
|
||||||
binding.calendarGrid.adapter = adapter
|
binding.calendarGrid.adapter = adapter
|
||||||
binding.monthTitle.text = currentViewMonth.format(DateTimeFormatter.ofPattern("yyyy년 MM월"))
|
binding.monthTitle.text = currentViewMonth.format(DateTimeFormatter.ofPattern("yyyy년 MM월"))
|
||||||
@@ -314,10 +332,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.todayStatusText.setTextColor(androidx.core.content.ContextCompat.getColor(this@MainActivity, R.color.warning_red))
|
binding.todayStatusText.setTextColor(androidx.core.content.ContextCompat.getColor(this@MainActivity, R.color.warning_red))
|
||||||
} else {
|
} else {
|
||||||
binding.todayStatusText.text = "오늘의 근무: $shiftForViewingTeam$teamSuffix"
|
binding.todayStatusText.text = "오늘의 근무: $shiftForViewingTeam$teamSuffix"
|
||||||
binding.todayStatusText.setTextColor(androidx.core.content.ContextCompat.getColor(this@MainActivity, R.color.text_secondary))
|
binding.todayStatusText.setTextColor(androidx.core.content.ContextCompat.getColor(this@MainActivity, R.color.text_secondary))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Update Annual Leave display
|
||||||
|
val annualLeave = withContext(Dispatchers.IO) { repo.getAnnualLeave() }
|
||||||
|
annualLeave?.let {
|
||||||
|
binding.tvAnnualLeave.text = "연차: ${String.format("%.1f", it.remainingDays)}"
|
||||||
|
} ?: run {
|
||||||
|
binding.tvAnnualLeave.text = "연차: --"
|
||||||
|
}
|
||||||
|
}
|
||||||
updateOtherTeamsLayout(today, factory, prefs)
|
updateOtherTeamsLayout(today, factory, prefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,13 +398,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
setMargins(4, 0, 4, 0)
|
setMargins(4, 0, 4, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (currentViewTeam != t) {
|
if (currentViewTeam != t) {
|
||||||
currentViewTeam = t
|
currentViewTeam = t
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
Toast.makeText(context, "${t}반 근무표를 표시합니다.", Toast.LENGTH_SHORT).show()
|
showCustomToast(context, "${t}반 근무표를 표시합니다.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rowLayout.addView(textView)
|
rowLayout.addView(textView)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user