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:
@@ -22,9 +22,9 @@ data class DayShift(
|
|||||||
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)
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,20 @@ class CalendarAdapter(
|
|||||||
val item = days[position]
|
val item = days[position]
|
||||||
val context = holder.itemView.context
|
val context = holder.itemView.context
|
||||||
|
|
||||||
|
// Dynamically adjust item height based on row count (5 or 6 rows)
|
||||||
|
val displayMetrics = context.resources.displayMetrics
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
val layoutParams = holder.itemView.layoutParams
|
||||||
|
layoutParams.height = itemHeight
|
||||||
|
holder.itemView.layoutParams = layoutParams
|
||||||
|
|
||||||
if (item.date == null) {
|
if (item.date == null) {
|
||||||
holder.itemView.visibility = View.INVISIBLE
|
holder.itemView.visibility = View.INVISIBLE
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -202,6 +202,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
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() {
|
||||||
@@ -257,6 +268,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun setupCalendar() {
|
private fun setupCalendar() {
|
||||||
binding.calendarGrid.layoutManager = GridLayoutManager(this, 7)
|
binding.calendarGrid.layoutManager = GridLayoutManager(this, 7)
|
||||||
|
binding.calendarGrid.setHasFixedSize(false) // Allow dynamic item sizing
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,11 +308,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val days = generateDaysForMonthWithData(currentViewMonth, currentViewTeam, factory, overrides, memos)
|
val days = generateDaysForMonthWithData(currentViewMonth, currentViewTeam, factory, overrides, memos)
|
||||||
|
|
||||||
|
// Calculate row count (5 or 6 rows)
|
||||||
|
val daysInMonth = currentViewMonth.lengthOfMonth()
|
||||||
|
val firstDayOfMonth = currentViewMonth.atDay(1).dayOfWeek.value % 7
|
||||||
|
val actualDayCount = firstDayOfMonth + daysInMonth
|
||||||
|
val rowCount = if (actualDayCount <= 35) 5 else 6
|
||||||
|
|
||||||
val adapter = CalendarAdapter(days, object : CalendarAdapter.OnDayClickListener {
|
val adapter = CalendarAdapter(days, object : CalendarAdapter.OnDayClickListener {
|
||||||
override fun onDayClick(date: LocalDate, currentShift: String) {
|
override fun onDayClick(date: LocalDate, currentShift: String) {
|
||||||
showDaySettingsDialog(date, currentShift)
|
showDaySettingsDialog(date, currentShift)
|
||||||
}
|
}
|
||||||
}, binding.cbShowHolidays.isChecked)
|
}, 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월"))
|
||||||
@@ -316,8 +334,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +402,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (currentViewTeam != t) {
|
if (currentViewTeam != t) {
|
||||||
currentViewTeam = t
|
currentViewTeam = t
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
Toast.makeText(context, "${t}반 근무표를 표시합니다.", Toast.LENGTH_SHORT).show()
|
showCustomToast(context, "${t}반 근무표를 표시합니다.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user