Skip to content

Commit 08e5f3d

Browse files
authored
Merge pull request #196 from PsPLoG/feature/#187
체크 포인트가 제대로 동작안하는 버그 수정
2 parents 9090bf6 + ac369bf commit 08e5f3d

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

app/src/main/java/com/drunkenboys/calendarun/ui/maincalendar/MainCalendarFragment.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class MainCalendarFragment : BaseFragment<FragmentMainCalendarBinding>(R.layout.
9494
// TODO: 2021-11-11 테마 설정 화면으로 이동
9595
val action = MainCalendarFragmentDirections.toThemeFragment()
9696
navController.navigate(action)
97+
binding.layoutDrawer.closeDrawer(GravityCompat.START)
9798
true
9899
}
99100
}
@@ -119,7 +120,13 @@ class MainCalendarFragment : BaseFragment<FragmentMainCalendarBinding>(R.layout.
119120

120121
private fun collectCalendarSet() {
121122
stateCollect(mainCalendarViewModel.calendarSetList) { calendarSetList ->
122-
binding.calendarMonth.setCalendarSetList(calendarSetList)
123+
if (calendarSetList.isEmpty()) return@stateCollect
124+
125+
if (calendarSetList.firstOrNull()?.id == 1) { // CalendarSet 기본캘린더 ID에 대한 Unique 값이 필요함
126+
binding.calendarMonth.setupDefaultCalendarSet()
127+
} else {
128+
binding.calendarMonth.setCalendarSetList(calendarSetList)
129+
}
123130
}
124131
}
125132

app/src/main/java/com/drunkenboys/calendarun/ui/maincalendar/MainCalendarViewModel.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ import com.drunkenboys.calendarun.data.checkpoint.entity.CheckPoint
99
import com.drunkenboys.calendarun.data.checkpoint.local.CheckPointLocalDataSource
1010
import com.drunkenboys.calendarun.data.schedule.entity.Schedule
1111
import com.drunkenboys.calendarun.data.schedule.local.ScheduleLocalDataSource
12-
import com.drunkenboys.calendarun.util.nextDay
1312
import com.drunkenboys.calendarun.ui.theme.toCalendarDesignObject
13+
import com.drunkenboys.calendarun.util.nextDay
1414
import com.drunkenboys.ckscalendar.data.CalendarScheduleObject
1515
import com.drunkenboys.ckscalendar.data.CalendarSet
1616
import dagger.hilt.android.lifecycle.HiltViewModel
1717
import kotlinx.coroutines.Job
18-
import kotlinx.coroutines.flow.MutableSharedFlow
19-
import kotlinx.coroutines.flow.MutableStateFlow
20-
import kotlinx.coroutines.flow.SharedFlow
21-
import kotlinx.coroutines.flow.StateFlow
2218
import kotlinx.coroutines.flow.*
2319
import kotlinx.coroutines.launch
2420
import java.time.LocalDate
@@ -60,7 +56,7 @@ class MainCalendarViewModel @Inject constructor(
6056
_calendar.emit(calendar)
6157
fetchCheckPointList(calendar.id).join()
6258
fetchScheduleList(calendar.id)
63-
createCalendarSetList()
59+
createCalendarSetList(calendar.id)
6460
}
6561
}
6662

@@ -110,7 +106,7 @@ class MainCalendarViewModel @Inject constructor(
110106
}
111107
}
112108

113-
private fun createCalendarSetList() {
109+
private fun createCalendarSetList(id: Long) {
114110
viewModelScope.launch {
115111
val calendarNameList = createCalendarSetNameList() ?: return@launch
116112
val calendarDateList = createCalendarSetDateList() ?: return@launch
@@ -121,7 +117,7 @@ class MainCalendarViewModel @Inject constructor(
121117
for (i in calendarNameList.indices) {
122118
calendarSetList.add(
123119
CalendarSet(
124-
id = i,
120+
id = id.toInt(), // CalendarSet 기본캘린더 ID에 대한 Unique 값이 필요함
125121
name = calendarNameList[i],
126122
startDate = calendarStartDateList[i],
127123
endDate = calendarEndDateList[i]
@@ -160,7 +156,7 @@ class MainCalendarViewModel @Inject constructor(
160156

161157
return calendarStartDateList to calendarEndDateList
162158
}
163-
159+
164160
fun fetchCalendarDesignObject() = calendarThemeDataSource.fetchCalendarTheme()
165161
.map { it.toCalendarDesignObject() }
166162
}

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdk 21
1313
targetSdk 31
1414
versionCode 1
15-
versionName "0.0.1"
15+
versionName "0.0.3"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
consumerProguardFiles "consumer-rules.pro"
@@ -90,7 +90,7 @@ afterEvaluate {
9090
from components.release
9191
groupId = 'com.github.boostcampwm-2021'
9292
artifactId = 'android01-CalendaRun'
93-
version = '0.0.1'
93+
version = '0.0.3'
9494
}
9595
}
9696
}

library/src/main/java/com/drunkenboys/ckscalendar/month/MonthCalendarView.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ class MonthCalendarView @JvmOverloads constructor(
6969
binding.vpMonthPage.registerOnPageChangeCallback(onPageChange)
7070

7171
setupDefaultCalendarSet()
72-
calendarList.forEachIndexed { index, calendarSet ->
73-
if (calendarSet.startDate.monthValue == today.monthValue) {
74-
binding.vpMonthPage.setCurrentItem(Int.MAX_VALUE / 2 + index, false)
75-
return@forEachIndexed
76-
}
77-
}
7872

7973
// xml에서 넘어온 attribute 값 적용
8074
val attr = context.obtainStyledAttributes(attrs, R.styleable.MonthCalendarView)
@@ -100,19 +94,23 @@ class MonthCalendarView @JvmOverloads constructor(
10094
}
10195
}
10296

103-
private fun initAttribute() {
104-
105-
}
106-
10797
fun setCalendarSetList(calendarList: List<CalendarSet>) {
10898
this.calendarList = calendarList
10999
pageAdapter.setItems(calendarList, false)
100+
binding.tvMonthCalendarViewCurrentMonth.text = calendarList.first().name
110101
}
111102

112103
fun setupDefaultCalendarSet() {
113104
calendarList = CalendarSet.generateCalendarOfYear(context, today.year)
114105
pageAdapter.setItems(calendarList, true)
115-
binding.vpMonthPage.setCurrentItem(Int.MAX_VALUE / 2, false)
106+
107+
calendarList.forEachIndexed { index, calendarSet -> //오늘 날짜로 이동
108+
if (calendarSet.startDate.monthValue == today.monthValue) {
109+
binding.tvMonthCalendarViewCurrentMonth.text = calendarSet.name
110+
binding.vpMonthPage.setCurrentItem(Int.MAX_VALUE / 2 + index, false)
111+
return@forEachIndexed
112+
}
113+
}
116114
}
117115

118116
fun setOnDayClickListener(onDayClickListener: OnDayClickListener) {

library/src/main/java/com/drunkenboys/ckscalendar/month/MonthCellFactory.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ class MonthCellFactory {
2323
}
2424

2525
// add Start Dates
26-
dates.addAll(makeDates(item.startDate, month))
26+
if (startMonth == endMonth) {
27+
dates.addAll(makeDates(item.startDate.dayOfMonth, item.endDate.dayOfMonth, month, item.startDate.year))
28+
} else {
29+
dates.addAll(makeDates(item.startDate.dayOfMonth, item.startDate.lengthOfMonth(), month, item.startDate.year))
30+
}
31+
}
32+
endMonth -> {
33+
dates.addAll(makeDates(1, item.endDate.dayOfMonth, month, item.endDate.year))
2734
}
2835
else -> {
2936
// add Normal Dates
30-
dates.addAll(makeDates(item.endDate, month))
37+
val monthDate = LocalDate.of(item.endDate.year, month, 1)
38+
dates.addAll(makeDates(1, monthDate.lengthOfMonth(), month, monthDate.year))
3139
}
3240
}
3341
}
@@ -44,10 +52,9 @@ class MonthCellFactory {
4452
return dates
4553
}
4654

47-
private fun makeDates(selectedDate: LocalDate, month: Int): List<CalendarDate> {
48-
val monthDate = LocalDate.of(selectedDate.year, month, 1)
49-
return (1..monthDate.lengthOfMonth()).map { day ->
50-
val date = LocalDate.of(selectedDate.year, month, day)
55+
private fun makeDates(startDay: Int, endDay: Int, month: Int, year: Int): List<CalendarDate> {
56+
return (startDay..endDay).map { day ->
57+
val date = LocalDate.of(year, month, day)
5158
val dayType = TimeUtils.parseDayWeekToDayType(date.dayOfWeek)
5259
CalendarDate(date, dayType)
5360
}
@@ -59,7 +66,7 @@ class MonthCellFactory {
5966
}
6067
}
6168

62-
companion object{
69+
companion object {
6370

6471
private const val WEEK_SIZE = 7
6572
private const val CALENDAR_FULL_SIZE = 42

0 commit comments

Comments
 (0)