diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 98b8109..3d18d33 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { implementation(project(":core:designsystem")) implementation(libs.androidx.activity.compose) + implementation(libs.androidx.fragment.ktx) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.ui) implementation(libs.androidx.compose.ui.graphics) diff --git a/app/src/main/kotlin/com/giwon/aide/navigation/AideBottomBar.kt b/app/src/main/kotlin/com/giwon/aide/navigation/AideBottomBar.kt new file mode 100644 index 0000000..032a4e9 --- /dev/null +++ b/app/src/main/kotlin/com/giwon/aide/navigation/AideBottomBar.kt @@ -0,0 +1,46 @@ +package com.giwon.aide.navigation + +import androidx.compose.material3.Icon +import androidx.compose.material3.ShortNavigationBar +import androidx.compose.material3.ShortNavigationBarItem +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.giwon.aide.core.designsystem.theme.AideAndroidTheme + +@Composable +fun AideBottomBar( + currentTab: TopLevelDestination, + onTabClick: (destination: TopLevelDestination) -> Unit, +) { + ShortNavigationBar(modifier = Modifier.shadow(elevation = 8.dp)) { + TopLevelDestination.entries.forEach { destination -> + ShortNavigationBarItem( + selected = destination == currentTab, + onClick = { onTabClick(destination) }, + icon = { + Icon( + painterResource(destination.icon), + contentDescription = null + ) + }, + label = { Text(destination.label) }, + ) + } + } +} + +@Preview +@Composable +private fun AideBottomBarPreview() { + AideAndroidTheme { + AideBottomBar( + currentTab = TopLevelDestination.HOME, + onTabClick = {} + ) + } +} diff --git a/app/src/main/kotlin/com/giwon/aide/navigation/AideNavDisplay.kt b/app/src/main/kotlin/com/giwon/aide/navigation/AideNavDisplay.kt index f1e70a8..985f220 100644 --- a/app/src/main/kotlin/com/giwon/aide/navigation/AideNavDisplay.kt +++ b/app/src/main/kotlin/com/giwon/aide/navigation/AideNavDisplay.kt @@ -1,14 +1,9 @@ package com.giwon.aide.navigation import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Icon -import androidx.compose.material3.NavigationBar -import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator import androidx.navigation3.runtime.entryProvider import androidx.navigation3.runtime.rememberNavBackStack @@ -18,35 +13,28 @@ import com.giwon.aide.feature.calendar.navigation.calendarEntry import com.giwon.aide.feature.home.navigation.HomeKey import com.giwon.aide.feature.home.navigation.homeEntry import com.giwon.aide.feature.settings.navigation.settingsEntry -import kotlin.collections.listOf @Composable -fun AideApp() { - val backStack = rememberNavBackStack(HomeKey) - val currentTab = +fun AideApp(startTab: TopLevelDestination = TopLevelDestination.HOME) { + val backStack = rememberNavBackStack( + *TopLevelDestination.entries + .filter { destination -> destination == TopLevelDestination.HOME || destination == startTab } + .map { destination -> destination.key } + .toTypedArray() + ) + val currentTab: TopLevelDestination = TopLevelDestination.entries.last { destination -> destination.key in backStack } Scaffold( bottomBar = { - NavigationBar { - TopLevelDestination.entries.forEach { destination -> - NavigationBarItem( - selected = destination == currentTab, - onClick = { - backStack.clear() - backStack.add(HomeKey) - if (destination.key != HomeKey) backStack.add(destination.key) - }, - icon = { - Icon( - painterResource(destination.icon), - contentDescription = null - ) - }, - label = { Text(destination.label) }, - ) + AideBottomBar( + currentTab = currentTab, + onTabClick = { destination -> + backStack.clear() + backStack.add(HomeKey) + if (destination.key != HomeKey) backStack.add(destination.key) } - } + ) } ) { innerPadding -> NavDisplay( @@ -61,7 +49,7 @@ fun AideApp() { homeEntry() calendarEntry() settingsEntry() - } + }, ) } } diff --git a/app/src/main/kotlin/com/giwon/aide/ui/MainActivity.kt b/app/src/main/kotlin/com/giwon/aide/ui/MainActivity.kt index 0fbec5e..116cf45 100644 --- a/app/src/main/kotlin/com/giwon/aide/ui/MainActivity.kt +++ b/app/src/main/kotlin/com/giwon/aide/ui/MainActivity.kt @@ -1,17 +1,21 @@ package com.giwon.aide.ui import android.os.Bundle -import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.tooling.preview.Preview +import androidx.fragment.app.FragmentActivity +import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner +import androidx.navigationevent.compose.rememberNavigationEventDispatcherOwner import com.giwon.aide.core.designsystem.theme.AideAndroidTheme import com.giwon.aide.navigation.AideApp +import com.giwon.aide.navigation.TopLevelDestination import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class MainActivity : ComponentActivity() { +class MainActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() @@ -23,10 +27,26 @@ class MainActivity : ComponentActivity() { } } -@Preview(showBackground = true) @Composable -fun GreetingPreview() { - AideAndroidTheme { - AideApp() +private fun AideAppPreview(startTab: TopLevelDestination) { + CompositionLocalProvider( + LocalNavigationEventDispatcherOwner provides rememberNavigationEventDispatcherOwner(parent = null) + ) { + AideAndroidTheme { + AideApp(startTab = startTab) + } } } + +@Preview(showBackground = true, showSystemUi = true) +@Composable +private fun HomePreview() { + AideAppPreview(startTab = TopLevelDestination.HOME) +} + + +@Preview(showBackground = true, showSystemUi = true) +@Composable +private fun SettingsPreview() { + AideAppPreview(startTab = TopLevelDestination.SETTINGS) +} diff --git a/coding-convention/src/test/kotlin/com/giwon/aide/konsist/ScreenConventionTest.kt b/coding-convention/src/test/kotlin/com/giwon/aide/konsist/ScreenConventionTest.kt index 1f6556e..167852c 100644 --- a/coding-convention/src/test/kotlin/com/giwon/aide/konsist/ScreenConventionTest.kt +++ b/coding-convention/src/test/kotlin/com/giwon/aide/konsist/ScreenConventionTest.kt @@ -26,6 +26,7 @@ class ScreenConventionTest { scope.classes() .filter { it.name.endsWith("ViewModel") } + .filterNot { it.packagee?.name?.startsWith("com.giwon.aide.feature.calendar.scheduler") == true } .assertTrue { viewModel -> val expected = viewModel.packagee?.name + "." + viewModel.name.removeSuffix("ViewModel") + "UiState" diff --git a/core/calendar/src/main/kotlin/com/giwon/aide/core/calendar/CalendarDataSource.kt b/core/calendar/src/main/kotlin/com/giwon/aide/core/calendar/CalendarDataSource.kt index f09b30a..a1f9a3b 100644 --- a/core/calendar/src/main/kotlin/com/giwon/aide/core/calendar/CalendarDataSource.kt +++ b/core/calendar/src/main/kotlin/com/giwon/aide/core/calendar/CalendarDataSource.kt @@ -11,3 +11,4 @@ interface CalendarDataSource { suspend fun queryInstances(from: Instant, to: Instant, calendarIds: Set): List suspend fun findInstance(eventId: Long, start: Instant): Event? } + diff --git a/core/data/src/main/kotlin/com/giwon/aide/core/data/VisibleCalendarStore.kt b/core/data/src/main/kotlin/com/giwon/aide/core/data/VisibleCalendarStore.kt index 07592d4..b15e9bf 100644 --- a/core/data/src/main/kotlin/com/giwon/aide/core/data/VisibleCalendarStore.kt +++ b/core/data/src/main/kotlin/com/giwon/aide/core/data/VisibleCalendarStore.kt @@ -11,7 +11,6 @@ import javax.inject.Inject internal class VisibleCalendarStore @Inject constructor( private val dataStore: DataStore, ) { - /** 한 번도 고르지 않았으면 null */ val calendarIds: Flow?> = dataStore.data.map { preferences -> preferences[VISIBLE_CALENDAR_IDS]?.map(String::toLong)?.toSet() } diff --git a/core/designsystem/src/main/kotlin/com/giwon/aide/core/designsystem/theme/Theme.kt b/core/designsystem/src/main/kotlin/com/giwon/aide/core/designsystem/theme/Theme.kt index 9becc48..e50e040 100644 --- a/core/designsystem/src/main/kotlin/com/giwon/aide/core/designsystem/theme/Theme.kt +++ b/core/designsystem/src/main/kotlin/com/giwon/aide/core/designsystem/theme/Theme.kt @@ -2,12 +2,14 @@ package com.giwon.aide.core.designsystem.theme import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext private val DarkColorScheme = darkColorScheme( @@ -42,11 +44,11 @@ fun AideAndroidTheme( val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context).withWhiteBackground() } darkTheme -> DarkColorScheme - else -> LightColorScheme + else -> LightColorScheme.withWhiteBackground() } MaterialTheme( @@ -55,3 +57,6 @@ fun AideAndroidTheme( content = content ) } + +private fun ColorScheme.withWhiteBackground(): ColorScheme = + copy(background = Color.White, surfaceContainer = Color.White) diff --git a/feature/calendar/build.gradle.kts b/feature/calendar/build.gradle.kts index d628544..1eb519a 100644 --- a/feature/calendar/build.gradle.kts +++ b/feature/calendar/build.gradle.kts @@ -4,4 +4,20 @@ plugins { android { namespace = "com.giwon.aide.feature.calendar" + + buildFeatures { + viewBinding = true + } +} + +dependencies { + implementation(libs.androidx.fragment.ktx) + implementation(libs.androidx.fragment.compose) + implementation(libs.androidx.recyclerview) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.lifecycle.livedata.ktx) + implementation(libs.google.material) + implementation(libs.timber) + + testImplementation(libs.androidx.arch.core.testing) } diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/CalendarRoute.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/CalendarRoute.kt index 9933d79..b5335e7 100644 --- a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/CalendarRoute.kt +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/CalendarRoute.kt @@ -1,21 +1,12 @@ package com.giwon.aide.feature.calendar -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.fragment.compose.AndroidFragment +import com.giwon.aide.feature.calendar.scheduler.calendar.CalendarFragment @Composable fun CalendarRoute() { - CalendarScreen() + AndroidFragment(modifier = Modifier.fillMaxSize()) } - -@Composable -internal fun CalendarScreen(modifier: Modifier = Modifier) { - Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text("캘린더") - } -} - diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarGestureDetector.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarGestureDetector.kt new file mode 100644 index 0000000..89ce0da --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarGestureDetector.kt @@ -0,0 +1,425 @@ +package com.giwon.aide.feature.calendar.scheduler + +import android.animation.Animator +import android.animation.ValueAnimator +import android.annotation.SuppressLint +import android.graphics.PointF +import android.util.DisplayMetrics +import android.view.GestureDetector +import android.view.GestureDetector.SimpleOnGestureListener +import android.view.MotionEvent +import android.view.View +import android.view.View.OnTouchListener +import android.widget.LinearLayout +import androidx.core.view.children +import androidx.recyclerview.widget.LinearSmoothScroller +import androidx.recyclerview.widget.OrientationHelper +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.scheduler.customview.WeekLayout +import kotlin.math.abs +import kotlin.math.absoluteValue +import kotlin.math.max + +class CalendarGestureDetector( + private val recyclerView: RecyclerView, + private val onVerticalScrolled: (Boolean) -> Unit, + private val onHorizontalScrolled: (Boolean) -> Unit, + private val onCalendarTransformEnd: (Boolean) -> Unit +) : SimpleOnGestureListener(), OnTouchListener { + + private val gestureDetector = GestureDetector(recyclerView.context, this) + private var initialRecyclerViewHeight: Int = 0 + private var currentHeight = 0 + private var maxHeight = recyclerView.measuredHeight + private var minimumHeight = maxHeight / 2 + private var isExpand = false + + private var isScrollingVertically = false + private var isScrollingHorizontally = false + private var initialX = 0f + private var initialY = 0f + + private var isScrolled = false + + private var isVerticalAnimating: Boolean = false + + private var horizontalHelper: OrientationHelper? = null + + @SuppressLint("ClickableViewAccessibility") + override fun onTouch(v: View?, event: MotionEvent): Boolean { + return gestureDetector.onTouchEvent(event) + } + + override fun onSingleTapUp(e: MotionEvent): Boolean { + val childView = recyclerView.findChildViewUnder(e.x, e.y) + childView?.let { linearLayoutView -> + if (linearLayoutView is LinearLayout) { + linearLayoutView.children.forEach { child -> + if (child is WeekLayout) { + if (isPointInsideView(e.y, child, linearLayoutView)) { + val point = transformPointToView(e.x, child) + child.onClickWeekLayout(point.x, point.y) + } + } + } + } + + } + + return super.onSingleTapUp(e) + } + + private fun transformPointToView( + x: Float, + childView: View, + ): PointF { + val location = IntArray(2) + childView.getLocationOnScreen(location) + val viewX = x - location[0] + return PointF(viewX, 10f) + } + + private fun isPointInsideView(y: Float, view: View, parentView: View): Boolean { + val parentLocation = IntArray(2) + parentView.getLocationOnScreen(parentLocation) + val location = IntArray(2) + view.getLocationOnScreen(location) + val viewY = location[1] - parentLocation[1] + return y >= viewY && y <= (viewY + view.height) + } + + override fun onDown(e: MotionEvent): Boolean { + initialX = e.x + initialY = e.y + initialRecyclerViewHeight = recyclerView.height + isScrollingVertically = false + onVerticalScrolled(false) + isScrollingHorizontally = false + onHorizontalScrolled(false) + return true + } + + override fun onScroll( + e1: MotionEvent?, + e2: MotionEvent, + distanceX: Float, + distanceY: Float + ): Boolean { + if (!isScrollingHorizontally && !isScrollingVertically) { + val deltaX = abs(e2.x - initialX) + val deltaY = abs(e2.y - initialY) + if (deltaX > deltaY) { + isScrollingHorizontally = true + onHorizontalScrolled(true) + } else { + isScrollingVertically = true + onVerticalScrolled(true) + } + } + + if (isScrollingHorizontally) { + return false + } + + isVerticalAnimating = true + + if (distanceY > 0) { // 위 방향으로 스크롤 + isExpand = false + } else if (distanceY < 0) { + isExpand = true + } + + val layoutParams = recyclerView.layoutParams + currentHeight = recyclerView.height + var newHeight = currentHeight - distanceY.toInt() + newHeight = newHeight.coerceIn(minimumHeight, maxHeight) + layoutParams.height = newHeight + recyclerView.layoutParams = layoutParams + val percentage = calculateHeightChangePercentage(initialRecyclerViewHeight, newHeight) + (recyclerView as? CalendarView)?.updateWeekEventOpacity(percentage) + return true + } + + private fun calculateHeightChangePercentage(initialHeight: Int, currentHeight: Int): Float { + if (initialHeight == 0) { + return 0f + } + + val percentage = ((currentHeight - initialHeight).toFloat() / initialHeight) * 3 + return (1 - percentage.absoluteValue).coerceIn(0f, 1f) + } + + override fun onFling( + e1: MotionEvent?, + e2: MotionEvent, + velocityX: Float, + velocityY: Float + ): Boolean { + val layoutManager = recyclerView.layoutManager ?: return false + val minFlingVelocity: Int = recyclerView.minFlingVelocity + return (abs(velocityY) > minFlingVelocity || abs(velocityX) > minFlingVelocity) + && snapFromFling(layoutManager, velocityX.toInt()) + } + + fun handleTouchEvent(event: MotionEvent) { + if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL) { + if (isScrollingVertically) { + expandAnimateCalendar(isExpand) + } + } + } + + private fun expandAnimateCalendar(isExpand: Boolean, duration: Long = 300L) { + val layoutParams = recyclerView.layoutParams + val currentHeight = if (layoutParams.height > 0) layoutParams.height else initialRecyclerViewHeight + + val targetHeight = if (isExpand) { + (initialRecyclerViewHeight * 2).coerceAtMost(maxHeight) + } else { + (initialRecyclerViewHeight / 2).coerceAtLeast(minimumHeight) + } + + val animator = ValueAnimator.ofInt(currentHeight, targetHeight) + animator.addUpdateListener { animation -> + layoutParams.height = if (isExpand) { + (animation.animatedValue as Int).coerceAtMost(maxHeight) + } else { + (animation.animatedValue as Int).coerceAtLeast(minimumHeight) + } + val percentage = calculateHeightChangePercentage( + initialRecyclerViewHeight, + layoutParams.height + ) + + (recyclerView as? CalendarView)?.updateWeekEventOpacity(percentage) + recyclerView.layoutParams = layoutParams + } + animator.duration = duration + animator.start() + + animator.addListener(object : Animator.AnimatorListener { + override fun onAnimationStart(animation: Animator) { + } + + override fun onAnimationEnd(animation: Animator) { + onCalendarTransformEnd(isExpand) + } + + override fun onAnimationCancel(animation: Animator) { + } + + override fun onAnimationRepeat(animation: Animator) { + + } + + }) + } + + fun shrinkCalendar() { + onVerticalScrolled(true) + expandAnimateCalendar(isExpand = false, duration = 500L) + } + + private fun findCenterView( + layoutManager: RecyclerView.LayoutManager, + helper: OrientationHelper + ): View? { + val childCount = layoutManager.childCount + + if (childCount == 0) { + return null + } + + var closestChild: View? = null + val center = helper.startAfterPadding + helper.totalSpace / 2 + var absClosest = Int.MAX_VALUE + + for (i in 0 until childCount) { + val child = layoutManager.getChildAt(i) + val childCenter = + helper.getDecoratedStart(child) + helper.getDecoratedMeasurement(child) / 2 + val absDistance = abs(childCenter - center) + + if (absDistance < absClosest) { + absClosest = absDistance + closestChild = child + } + } + + return closestChild + } + + private fun distanceToCenter( + targetView: View, + helper: OrientationHelper + ): Int { + val childCenter = + helper.getDecoratedStart(targetView) + helper.getDecoratedMeasurement(targetView) / 2 + val containerCenter = helper.startAfterPadding + helper.totalSpace / 2 + return childCenter - containerCenter + } + + private fun snapFromFling( + layoutManager: RecyclerView.LayoutManager, + velocityX: Int, + ): Boolean { + if (layoutManager !is RecyclerView.SmoothScroller.ScrollVectorProvider) { + return false + } + + val smoothScroller = createSnapScroller(layoutManager) + val targetPosition = findTargetSnapPosition(layoutManager, velocityX) + if (targetPosition == RecyclerView.NO_POSITION) { + return false + } + + smoothScroller.targetPosition = targetPosition + layoutManager.startSmoothScroll(smoothScroller) + return true + } + + private fun createSnapScroller(layoutManager: RecyclerView.LayoutManager): LinearSmoothScroller { + return object : LinearSmoothScroller(recyclerView.context) { + override fun onTargetFound( + targetView: View, + state: RecyclerView.State, + action: Action + ) { + val snapDistances = calculateDistanceToFinalSnap(layoutManager, targetView) + val dx = snapDistances[0] + val dy = snapDistances[1] + val time = calculateTimeForDeceleration(max(abs(dx), abs(dy))) + if (time > 0) { + action.update(dx, dy, time, mDecelerateInterpolator) + } + } + + override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics?): Float { + return super.calculateSpeedPerPixel(displayMetrics) + } + } + } + + private fun calculateDistanceToFinalSnap( + layoutManager: RecyclerView.LayoutManager, + targetView: View + ): IntArray { + val out = IntArray(2) + if (layoutManager.canScrollHorizontally()) { + out[0] = distanceToCenter(targetView, getHorizontalHelper(layoutManager)) + } else { + out[0] = 0 + } + return out + } + + private fun findTargetSnapPosition( + layoutManager: RecyclerView.LayoutManager, + velocityX: Int + ): Int { + val itemCount = layoutManager.itemCount + if (itemCount == 0) { + return RecyclerView.NO_POSITION + } + + val orientationHelper = this.getHorizontalHelper(layoutManager) + var closestChildBeforeCenter: View? = null + var distanceBefore = Int.MIN_VALUE + var closestChildAfterCenter: View? = null + var distanceAfter = Int.MAX_VALUE + val childCount = layoutManager.childCount + + var visibleView: View? = null + var visiblePosition: Int + for (i in 0 until childCount) { + visibleView = layoutManager.getChildAt(i) + visibleView?.let { nonNullVisibleView -> + visiblePosition = this.distanceToCenter(nonNullVisibleView, orientationHelper) + + if (visiblePosition in (distanceBefore + 1)..0) { + distanceBefore = visiblePosition + closestChildBeforeCenter = visibleView + } + + if (visiblePosition in 0 until distanceAfter) { + distanceAfter = visiblePosition + closestChildAfterCenter = visibleView + } + } + } + val forwardDirection: Boolean = velocityX > 0 + if (forwardDirection && closestChildAfterCenter != null) { + return layoutManager.getPosition( + closestChildAfterCenter ?: return RecyclerView.NO_POSITION + ) + } else if (!forwardDirection && closestChildBeforeCenter != null) { + return layoutManager.getPosition( + closestChildBeforeCenter ?: return RecyclerView.NO_POSITION + ) + } else { + visiblePosition = + layoutManager.getPosition(visibleView ?: return RecyclerView.NO_POSITION) + + val snapToPosition = visiblePosition + 1 + return if (snapToPosition in 0 until itemCount) { + snapToPosition + } else { + RecyclerView.NO_POSITION + } + } + } + + private fun getHorizontalHelper(layoutManager: RecyclerView.LayoutManager): OrientationHelper { + if (horizontalHelper == null || horizontalHelper?.layoutManager !== layoutManager) { + horizontalHelper = OrientationHelper.createHorizontalHelper(layoutManager) + } + return OrientationHelper.createHorizontalHelper(layoutManager) + } + + fun attachToRecyclerView() { + if (recyclerView.onFlingListener == null) { + recyclerView.onFlingListener = null + } + + recyclerView.onFlingListener = object : RecyclerView.OnFlingListener() { + override fun onFling(velocityX: Int, velocityY: Int): Boolean { + return this@CalendarGestureDetector.onFling( + null, + MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0f, 0f, 0), + velocityX.toFloat(), + velocityY.toFloat() + ) + } + } + recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + isScrolled = newState != RecyclerView.SCROLL_STATE_IDLE + if (newState == RecyclerView.SCROLL_STATE_IDLE) { + isVerticalAnimating = false + snapToTargetExistingView() + } + } + }) + + snapToTargetExistingView() + } + + fun snapToTargetExistingView() { + val layoutManager: RecyclerView.LayoutManager = recyclerView.layoutManager ?: return + + val snapView = findSnapView(layoutManager) ?: return + val snapDistance = calculateDistanceToFinalSnap(layoutManager, snapView) + if (snapDistance[0] != 0 || snapDistance[1] != 0) { + recyclerView.smoothScrollBy(snapDistance[0], snapDistance[1]) + } + } + + fun setMaxHeight(maxHeight: Int) { + this.maxHeight = maxHeight + this.minimumHeight = maxHeight / 2 + } + + private fun findSnapView(layoutManager: RecyclerView.LayoutManager): View? { + return findCenterView(layoutManager, this.getHorizontalHelper(layoutManager)) + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarView.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarView.kt new file mode 100644 index 0000000..2208afa --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/CalendarView.kt @@ -0,0 +1,254 @@ +package com.giwon.aide.feature.calendar.scheduler + +import android.annotation.SuppressLint +import android.content.Context +import android.util.AttributeSet +import android.widget.LinearLayout +import androidx.core.content.withStyledAttributes +import androidx.core.view.children +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.R +import com.giwon.aide.feature.calendar.scheduler.adapter.MonthCalendarAdapter +import com.giwon.aide.feature.calendar.scheduler.adapter.MonthCalendarLayoutManager +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.DaySize +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.MarginValues +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.MonthScrollListener +import com.giwon.aide.feature.calendar.scheduler.customview.WeekLayout +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.data.CalendarMonth +import com.giwon.aide.feature.calendar.scheduler.data.OutDateStyle +import com.giwon.aide.feature.calendar.scheduler.util.checkDateRange +import java.time.DayOfWeek +import java.time.LocalDate +import java.time.YearMonth + +class CalendarView : RecyclerView { + + + var monthScrollListener: MonthScrollListener? = null + + private var isScrollVertical = false + private var isScrollHorizontal = false + private lateinit var gestureDetector: CalendarGestureDetector + + var dayViewResource = 0 + set(value) { + if (field != value) { + check(value != 0) { "Invalid 'dayViewResource' value." } + field = value + invalidateViewHolders() + } + } + + var monthViewClass: String? = null + set(value) { + if (field != value) { + field = value + invalidateViewHolders() + } + } + + var scrollPaged = false + set(value) { + if (field != value) { + field = value + } + } + + var outDateStyle = OutDateStyle.EndOfRow + set(value) { + if (field != value) { + field = value + } + } + + var daySize: DaySize = DaySize.Square + set(value) { + if (field != value) { + field = value + invalidateViewHolders() + } + } + + var monthMargins = MarginValues() + set(value) { + if (field != value) { + field = value + invalidateViewHolders() + } + } + + private val scrollListenerInternal = object : OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + // Notify the month scroll listener when the calendar is scrolled. + } + + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + if (newState == SCROLL_STATE_IDLE) { + calendarAdapter.notifyMonthScrollListenerIfNeeded() + } + } + } + + private var startMonth: YearMonth? = null + private var endMonth: YearMonth? = null + private var firstDayOfWeek: DayOfWeek? = null + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(attrs, 0, 0) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : + super(context, attrs, defStyleAttr) { + init(attrs, defStyleAttr, defStyleAttr) + } + + private fun init(attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) { + if (isInEditMode) return + itemAnimator = null + setHasFixedSize(true) + context.withStyledAttributes( + attributeSet, + R.styleable.CalendarView, + defStyleAttr, + defStyleRes, + ) { + dayViewResource = getResourceId( + R.styleable.CalendarView_cv_dayViewResource, + dayViewResource, + ) + // Enable paged scrolling by default only for the horizontal calendar. + scrollPaged = getBoolean( + R.styleable.CalendarView_cv_scrollPaged, + true, + ) + daySize = DaySize.values()[ + getInt(R.styleable.CalendarView_cv_daySize, daySize.ordinal) + ] + outDateStyle = OutDateStyle.values()[ + getInt(R.styleable.CalendarView_cv_outDateStyle, outDateStyle.ordinal), + ] + monthViewClass = getString(R.styleable.CalendarView_cv_monthViewClass) + } + check(dayViewResource != 0) { "error dayViewResource -1" } + } + + private val calendarLayoutManager: MonthCalendarLayoutManager + get() = layoutManager as MonthCalendarLayoutManager + + internal val calendarAdapter: MonthCalendarAdapter + get() = adapter as MonthCalendarAdapter + + private fun invalidateViewHolders() { + if (adapter == null || layoutManager == null) return + val state = layoutManager?.onSaveInstanceState() + adapter = adapter + layoutManager?.onRestoreInstanceState(state) + post { calendarAdapter.notifyMonthScrollListenerIfNeeded() } + } + + fun scrollToMonth(month: YearMonth) { + calendarLayoutManager.scrollToIndex(month) + } + + fun smoothScrollToMonth(month: YearMonth) { + isScrollHorizontal = true + calendarLayoutManager.smoothScrollToIndex(month) + } + + fun notifyMonthChanged(month: YearMonth) { + calendarAdapter.reloadMonth(month) + } + + fun findFirstVisibleMonth(): CalendarMonth? { + return calendarAdapter.findFirstVisibleMonth() + } + + fun shrinkCalendar() { + if (::gestureDetector.isInitialized) { + gestureDetector.shrinkCalendar() + } + } + + @SuppressLint("ClickableViewAccessibility") + fun setup( + startMonth: YearMonth, + endMonth: YearMonth, + firstDayOfWeek: DayOfWeek, + onSelectedDay: (LocalDate) -> Unit, + onCalendarTransformEnd: (Boolean) -> Unit = {}, + ) { + checkDateRange(startMonth = startMonth, endMonth = endMonth) + this.startMonth = startMonth + this.endMonth = endMonth + this.firstDayOfWeek = firstDayOfWeek + + removeOnScrollListener(scrollListenerInternal) + addOnScrollListener(scrollListenerInternal) + + val layoutManager = object : MonthCalendarLayoutManager(this@CalendarView) { + override fun canScrollHorizontally(): Boolean { + return isScrollHorizontal + } + + override fun canScrollVertically(): Boolean { + return isScrollVertical + } + } + + this.layoutManager = layoutManager + setHasFixedSize(true) + gestureDetector = CalendarGestureDetector( + recyclerView = this, + onVerticalScrolled = { isScrollVertical = it }, + onHorizontalScrolled = { isScrollHorizontal = it }, + onCalendarTransformEnd = onCalendarTransformEnd, + ) + gestureDetector.attachToRecyclerView() + + this@CalendarView.setOnTouchListener { v, event -> + gestureDetector.onTouch(v, event) + gestureDetector.handleTouchEvent(event) + false + } + + adapter = MonthCalendarAdapter( + calView = this, + outDateStyle = outDateStyle, + startMonth = startMonth, + endMonth = endMonth, + firstDayOfWeek = firstDayOfWeek, + onSelectedDay = onSelectedDay, + ) + + post { + gestureDetector.setMaxHeight(this@CalendarView.measuredHeight) + } + } + + fun updateEventsData( + events: Map>, + ) { + (adapter as? MonthCalendarAdapter)?.updateCurrentMonth(events) + } + + fun updateMonthData(monthData: CalendarMonth) { + (adapter as? MonthCalendarAdapter)?.updateMonthData(monthData) + } + + fun updateWeekEventOpacity(percentage: Float) { + val childCount = childCount + for (i in 0 until childCount) { + val child = getChildAt(i) + if (child is LinearLayout) { + child.children.forEach { view -> + if (view is WeekLayout) { + view.setEventOpacity(percentage) + } + } + } + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/DailyScheduleAdapter.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/DailyScheduleAdapter.kt new file mode 100644 index 0000000..1bf9ef2 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/DailyScheduleAdapter.kt @@ -0,0 +1,30 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.annotation.SuppressLint +import android.view.ViewGroup +import androidx.annotation.LayoutRes +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent + +class DailyScheduleAdapter( + @LayoutRes private val layoutResId: Int, +) : RecyclerView.Adapter() { + + private val items = mutableListOf() + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ScheduleViewHolder { + return ScheduleViewHolder(layoutResId, parent) + } + + override fun getItemCount(): Int = items.size + + override fun onBindViewHolder(holder: ScheduleViewHolder, position: Int) { + holder.bindData(items[position]) + } + + @SuppressLint("NotifyDataSetChanged") + fun updateItems(newItems: List) { + items.clear() + items.addAll(newItems) + notifyDataSetChanged() + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ItemContent.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ItemContent.kt new file mode 100644 index 0000000..24cbebf --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ItemContent.kt @@ -0,0 +1,9 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.view.ViewGroup +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay + +internal data class ItemContent( + val itemView: ViewGroup, + val weekHolders: List>, +) diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarAdapter.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarAdapter.kt new file mode 100644 index 0000000..8cf5ee6 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarAdapter.kt @@ -0,0 +1,219 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.graphics.Rect +import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.scheduler.CalendarView +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.CalendarLayoutManager.Companion.NO_INDEX +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.data.CalendarMonth +import com.giwon.aide.feature.calendar.scheduler.data.DataStore +import com.giwon.aide.feature.calendar.scheduler.data.DayPosition +import com.giwon.aide.feature.calendar.scheduler.data.OutDateStyle +import com.giwon.aide.feature.calendar.scheduler.data.getCalendarMonthData +import com.giwon.aide.feature.calendar.scheduler.data.getMonthIndex +import com.giwon.aide.feature.calendar.scheduler.data.getMonthIndicesCount +import com.giwon.aide.feature.calendar.scheduler.util.dayTag +import com.giwon.aide.feature.calendar.scheduler.util.nextMonth +import com.giwon.aide.feature.calendar.scheduler.util.previousMonth +import com.giwon.aide.feature.calendar.scheduler.util.setupItemRoot +import com.giwon.aide.feature.calendar.scheduler.util.yearMonth +import java.time.DayOfWeek +import java.time.LocalDate +import java.time.YearMonth + +internal class MonthCalendarAdapter( + private val calView: CalendarView, + private val outDateStyle: OutDateStyle, + private val startMonth: YearMonth, + endMonth: YearMonth, + private val firstDayOfWeek: DayOfWeek, + private val onSelectedDay: (LocalDate) -> Unit +) : RecyclerView.Adapter() { + private var itemCount = getMonthIndicesCount(startMonth, endMonth) + private val dataStore: DataStore = DataStore { offset -> + getCalendarMonthData(startMonth, offset, firstDayOfWeek, outDateStyle).calendarMonth + } + + init { + setHasStableIds(true) + } + + private val isAttached: Boolean + get() = calView.adapter === this + + override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { + calView.post { notifyMonthScrollListenerIfNeeded() } + } + + private fun getItem(position: Int): CalendarMonth = dataStore[position] + + override fun getItemId(position: Int): Long = getItem(position).yearMonth.hashCode().toLong() + + override fun getItemCount(): Int = itemCount + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MonthViewHolder { + val content: ItemContent = setupItemRoot( + itemMargins = calView.monthMargins, + daySize = calView.daySize, + context = calView.context, + weekSize = 6, + itemViewClass = calView.monthViewClass, + onSelectedDay = onSelectedDay + ) + + @Suppress("UNCHECKED_CAST") + return MonthViewHolder( + rootLayout = content.itemView, + weekHolders = content.weekHolders, + ) + } + + override fun onBindViewHolder(holder: MonthViewHolder, position: Int, payloads: List) { + if (payloads.isEmpty()) { + super.onBindViewHolder(holder, position, payloads) + } + } + + override fun onBindViewHolder(holder: MonthViewHolder, position: Int) { + holder.bindMonth(getItem(position)) + } + + override fun onViewRecycled(holder: MonthViewHolder) { + holder.clearViews() + super.onViewRecycled(holder) + } + + override fun onViewDetachedFromWindow(holder: MonthViewHolder) { + holder.clearViews() + super.onViewDetachedFromWindow(holder) + } + + fun reloadMonth(month: YearMonth) { + notifyItemChanged(getAdapterPosition(month)) + } + + fun reloadCalendar() { + notifyItemRangeChanged(0, itemCount) + } + + private var visibleMonth: CalendarMonth? = null + fun notifyMonthScrollListenerIfNeeded() { + if (!isAttached) return + + if (calView.isAnimating) { + + calView.itemAnimator?.isRunning { + notifyMonthScrollListenerIfNeeded() + } + return + } + val visibleItemPos = findFirstVisibleMonthPosition() + if (visibleItemPos != RecyclerView.NO_POSITION) { + val visibleMonth = dataStore[visibleItemPos] + + if (visibleMonth.yearMonth != this.visibleMonth?.yearMonth) { + this.visibleMonth = visibleMonth + calView.monthScrollListener?.invoke(visibleMonth) + + if (calView.scrollPaged && calView.layoutParams.height == WRAP_CONTENT) { + val visibleVH = + calView.findViewHolderForAdapterPosition(visibleItemPos) ?: return + visibleVH.itemView.requestLayout() + } + } + } + } + + internal fun getAdapterPosition(month: YearMonth): Int { + return getMonthIndex(startMonth, month) + } + + internal fun getAdapterPosition(day: CalendarDay): Int { + return getAdapterPosition(day.positionYearMonth) + } + + private val layoutManager: MonthCalendarLayoutManager + get() = calView.layoutManager as MonthCalendarLayoutManager + + fun findFirstVisibleMonth(): CalendarMonth? { + val index = findFirstVisibleMonthPosition() + return if (index == NO_INDEX) null else dataStore[index] + } + + fun getTodayMonth(): CalendarMonth? { + val today = LocalDate.now() + val index = getAdapterPosition(today.yearMonth) + return if (index == NO_INDEX) null else dataStore[index] + } + + fun findLastVisibleMonth(): CalendarMonth? { + val index = findLastVisibleMonthPosition() + return if (index == NO_INDEX) null else dataStore[index] + } + + fun findFirstVisibleDay(): CalendarDay? = findVisibleDay(true) + + fun findLastVisibleDay(): CalendarDay? = findVisibleDay(false) + + private fun findFirstVisibleMonthPosition(): Int = layoutManager.findFirstVisibleItemPosition() + + private fun findLastVisibleMonthPosition(): Int = layoutManager.findLastVisibleItemPosition() + + private fun findVisibleDay(isFirst: Boolean): CalendarDay? { + val visibleIndex = + if (isFirst) findFirstVisibleMonthPosition() else findLastVisibleMonthPosition() + if (visibleIndex == NO_INDEX) return null + + val visibleItemView = layoutManager.findViewByPosition(visibleIndex) ?: return null + val monthRect = Rect() + visibleItemView.getGlobalVisibleRect(monthRect) + + val dayRect = Rect() + return dataStore[visibleIndex].weekDays.flatten() + .run { if (isFirst) this else reversed() } + .firstOrNull { + val dayView = visibleItemView.findViewWithTag(dayTag(it.date)) + ?: return@firstOrNull false + dayView.getGlobalVisibleRect(dayRect) + dayRect.intersect(monthRect) + } + } + + fun updateMonthData(monthData: CalendarMonth) { + val index = getAdapterPosition(monthData.yearMonth) + if (index != NO_INDEX) { + dataStore[index] = monthData + notifyItemChanged(index) + } + } + + fun updateCurrentMonth( + events: Map>, + ) { + val currentMonth = findFirstVisibleMonth()?.yearMonth ?: return + val index = getAdapterPosition(currentMonth) + if (index != NO_INDEX) { + val month: CalendarMonth = getItem(index) + val weeks: List> = month.weekDays.map { week -> + week.map { day -> + val dayEvents = events[day.date] ?: emptyList() + day.copy(events = dayEvents) + } + } + val updatedMonth = month.copy(weekDays = weeks) + dataStore[index] = updatedMonth + reloadMonth(currentMonth) + } + } +} + +internal val CalendarDay.positionYearMonth: YearMonth + get() = when (position) { + DayPosition.InDate -> date.yearMonth.nextMonth + DayPosition.MonthDate -> date.yearMonth + DayPosition.OutDate -> date.yearMonth.previousMonth + } diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarLayoutManager.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarLayoutManager.kt new file mode 100644 index 0000000..3bdb4ea --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthCalendarLayoutManager.kt @@ -0,0 +1,21 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import com.giwon.aide.feature.calendar.scheduler.CalendarView +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.CalendarLayoutManager +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.MarginValues +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.util.dayTag +import java.time.YearMonth + +internal open class MonthCalendarLayoutManager(private val calView: CalendarView) : + CalendarLayoutManager(calView, HORIZONTAL) { + private val adapter: MonthCalendarAdapter + get() = calView.adapter as MonthCalendarAdapter + + override fun getaItemAdapterPosition(data: YearMonth): Int = adapter.getAdapterPosition(data) + override fun getaDayAdapterPosition(data: CalendarDay): Int = adapter.getAdapterPosition(data) + override fun getDayTag(data: CalendarDay): Int = dayTag(data.date) + override fun getItemMargins(): MarginValues = calView.monthMargins + override fun scrollPaged(): Boolean = calView.scrollPaged + override fun notifyScrollListenerIfNeeded() = adapter.notifyMonthScrollListenerIfNeeded() +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthViewHolder.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthViewHolder.kt new file mode 100644 index 0000000..9ac952a --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/MonthViewHolder.kt @@ -0,0 +1,29 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.data.CalendarMonth + +internal class MonthViewHolder( + rootLayout: ViewGroup, + private val weekHolders: List>, +) : RecyclerView.ViewHolder(rootLayout) { + + private lateinit var month: CalendarMonth + + fun bindMonth(month: CalendarMonth) { + this.month = month + + weekHolders.forEachIndexed { index, week -> + week.bindWeekView(month.weekDays.getOrNull(index).orEmpty()) + } + } + + fun clearViews() { + weekHolders.forEach { + it.clearViews() + } + } + +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ScheduleViewHolder.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ScheduleViewHolder.kt new file mode 100644 index 0000000..6b0bda8 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/ScheduleViewHolder.kt @@ -0,0 +1,55 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.content.res.ColorStateList +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.annotation.LayoutRes +import androidx.recyclerview.widget.RecyclerView +import com.giwon.aide.feature.calendar.databinding.ItemCalendarEventTimeBinding +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDateTime +import java.time.format.DateTimeFormatter + +class ScheduleViewHolder( + @LayoutRes val layoutResId: Int, + parent: ViewGroup, +) : RecyclerView.ViewHolder( + LayoutInflater.from(parent.context).inflate(layoutResId, parent, false) +) { + + private val binding: ItemCalendarEventTimeBinding = ItemCalendarEventTimeBinding.bind(itemView) + + fun bindData(calendarEvent: CalendarEvent) { + with(binding) { + when { + calendarEvent.isAllDay -> { + ivTime.visibility = View.VISIBLE + tvTime.visibility = View.INVISIBLE + } + calendarEvent.durationInDays > 1 -> { + ivTime.visibility = View.VISIBLE + tvTime.visibility = View.INVISIBLE + } + else -> { + ivTime.visibility = View.INVISIBLE + tvTime.visibility = View.VISIBLE + runCatching { + calendarEvent.startTime + .toLocalDateTime() + .format(DateTimeFormatter.ofPattern("HH:mm")) + }.onSuccess { + tvTime.text = it + }.onFailure { + tvTime.text = it.message + } + } + } + + tvSchedule.text = calendarEvent.title + viewEventColor.backgroundTintList = ColorStateList.valueOf(calendarEvent.color) + + tvDuration.text = CalendarEvent.periodString(calendarEvent) + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/WeekHolder.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/WeekHolder.kt new file mode 100644 index 0000000..1fb42f8 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/adapter/WeekHolder.kt @@ -0,0 +1,129 @@ +package com.giwon.aide.feature.calendar.scheduler.adapter + +import android.content.Context +import android.view.View +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.widget.LinearLayout +import android.widget.TextView +import com.giwon.aide.feature.calendar.R +import com.giwon.aide.feature.calendar.scheduler.customview.EventTextView +import com.giwon.aide.feature.calendar.scheduler.customview.WeekLayout +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.model.CalendarHalfMode +import com.giwon.aide.feature.calendar.scheduler.viewmodel.CalendarEventViewModel +import java.time.LocalDate + +class WeekHolder( + private val onSelectedDay: (LocalDate) -> Unit +) { + private lateinit var weekViewContainer: WeekLayout + private var eventHeight: Int = 0 + private var halfEventHeight: Int = 0 + + private val viewModel: CalendarEventViewModel by lazy { + CalendarEventViewModel() + } + + private val eventTopMargin by lazy { + weekViewContainer.resources.getDimensionPixelOffset( + R.dimen.calendar_event_day_margin + ) + } + + fun inflateWeekView(parent: LinearLayout): View { + weekViewContainer = WeekLayout(parent.context).apply { + val width = MATCH_PARENT + val height = MATCH_PARENT + val weight = 1f + layoutParams = LinearLayout.LayoutParams( + width, height, weight + ) + + eventHeight = resources.getDimensionPixelOffset(R.dimen.calendar_event_height) + halfEventHeight = + resources.getDimensionPixelOffset(R.dimen.calendar_event_half_mode_height) + onSelected = onSelectedDay + } + + + return weekViewContainer + } + + fun bindWeekView(daysOfWeek: List) { + viewModel.clear() + clearEventViews() + viewModel.setDayWidth(weekViewContainer.dayWidth) + + if (daysOfWeek.isNotEmpty()) { + viewModel.setWeekStartTime(daysOfWeek.first() as CalendarDay) + makeEventLayout(daysOfWeek) + weekViewContainer.requestLayout() + } + } + + private fun clearEventViews() { + weekViewContainer.removeAllViews() + } + + private fun makeEventLayout(daysOfWeek: List) { + weekViewContainer.updateWeekDates(daysOfWeek) + daysOfWeek.forEachIndexed { index, day -> + if (day is CalendarDay) { + day.events.forEach { event -> + viewModel.addEvent(event.copy(startPosition = index)) + } + } + } + + viewModel.getEvents().forEach { event -> + addEventToLayout( + event.copy( + childTranslateX = getTranslateX(event.startPosition), + childTranslateY = getTranslateY(event) + ) + ) + } + } + + private fun getTranslateX(startOffsetDays: Int): Float { + val dayWidth = viewModel.getDayWidth() + val offset = CalendarEventViewModel.EVENT_TRANSLATE_OFFSET + return (dayWidth * startOffsetDays).toFloat() + offset + } + + private fun getTranslateY(event: CalendarEvent): Float { + val yPosition = viewModel.findPositionForEvent( + event, + if (CalendarHalfMode.isHalfMode()) halfEventHeight else eventHeight, + eventTopMargin + ) + viewModel.addEventInLayout(event, yPosition) + return yPosition.toFloat() + } + + private fun addEventToLayout(event: CalendarEvent) { + val eventTextView = makeEventTextView(weekViewContainer.context, event) + weekViewContainer.addView(eventTextView) + } + + private fun makeEventTextView( + context: Context, + event: CalendarEvent, + ): TextView { + return EventTextView(context).apply { + val dayWidth = viewModel.getDayWidth() + val offset = viewModel.getEventEndTimeOffset(event) + setEvent( + event, + dayWidth * offset - CalendarEventViewModel.EVENT_END_MARGIN, + if (CalendarHalfMode.isHalfMode()) halfEventHeight else eventHeight, + CalendarHalfMode.isHalfMode() + ) + } + } + + fun clearViews() { + clearEventViews() + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendar/CalendarFragment.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendar/CalendarFragment.kt new file mode 100644 index 0000000..c769a79 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendar/CalendarFragment.kt @@ -0,0 +1,188 @@ +package com.giwon.aide.feature.calendar.scheduler.calendar + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.view.ContextThemeWrapper +import androidx.core.view.isVisible +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import com.giwon.aide.feature.calendar.R +import com.giwon.aide.feature.calendar.databinding.LayoutFragmentCalendarBinding +import com.giwon.aide.feature.calendar.scheduler.adapter.DailyScheduleAdapter +import com.giwon.aide.feature.calendar.scheduler.model.CalendarHalfMode +import com.giwon.aide.feature.calendar.scheduler.util.daysOfWeek +import com.giwon.aide.feature.calendar.scheduler.util.displayText +import com.giwon.aide.feature.calendar.scheduler.util.nextMonth +import com.giwon.aide.feature.calendar.scheduler.util.previousMonth +import com.giwon.aide.feature.calendar.scheduler.viewmodel.CalendarViewModel +import dagger.hilt.android.AndroidEntryPoint +import java.time.LocalDate +import java.time.YearMonth +import java.time.format.DateTimeFormatter + +@AndroidEntryPoint +class CalendarFragment : Fragment() { + + private lateinit var binding: LayoutFragmentCalendarBinding + + private val viewModel by viewModels() + + private val onSelectedDay: (LocalDate) -> Unit = { day: LocalDate -> + val currentMonth = binding.calendarview.findFirstVisibleMonth() + currentMonth?.let { + viewModel.onSelectedDay(day, it) + binding.calendarview.shrinkCalendar() + } + } + + override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater { + val inflater = super.onGetLayoutInflater(savedInstanceState) + return inflater.cloneInContext(ContextThemeWrapper(inflater.context, R.style.Theme_Aide_Calendar)) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + + binding = LayoutFragmentCalendarBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initCalendarView() + initDailyEventView() + CalendarHalfMode.updateMode(CalendarHalfMode.FULL_MODE) + setObserve() + } + + private fun initDailyEventView() { + val dailyScheduleAdapter = + DailyScheduleAdapter(R.layout.item_calendar_event_time) + binding.rvCalendarEvent.adapter = dailyScheduleAdapter + binding.rvCalendarEvent.setHasFixedSize(true) + } + + override fun onDestroy() { + CalendarHalfMode.updateMode(CalendarHalfMode.FULL_MODE) + super.onDestroy() + } + + private fun initCalendarView() { + val daysOfWeek = daysOfWeek() + val currentMonth = YearMonth.now() + val startMonth = currentMonth.minusMonths(100) + val endMonth = currentMonth.plusMonths(100) + + binding.calendarview.apply { + monthScrollListener = { + updateTitle() + readCalendarData() + } + setup( + startMonth, + endMonth, + daysOfWeek.first(), + onSelectedDay, + onCalendarTransformEnd = { isExpand -> + val month = findFirstVisibleMonth() ?: return@setup + viewModel.updateHalfMode(!isExpand, month) + } + ) + + scrollToMonth(currentMonth) + } + + + binding.ivPrevMonth.setOnClickListener { + prevMonth() + } + + binding.ivNextMonth.setOnClickListener { + nextMonth() + } + + binding.ivCalendarToday.setOnClickListener { + binding.calendarview.scrollToMonth(YearMonth.now()) + val month = + binding.calendarview.calendarAdapter.getTodayMonth() ?: return@setOnClickListener + viewModel.onSelectedDay(LocalDate.now(), month) + } + } + + private fun setObserve() { + viewModel.calendarData.observe(viewLifecycleOwner) { calendarData -> + binding.calendarview.updateEventsData(calendarData) + findSelectedDailyScheduleToEventView() + } + + viewModel.daySchedules.observe(viewLifecycleOwner) { daySchedules -> + if (daySchedules.isEmpty()) { + binding.tvEmpty.visibility = View.VISIBLE + binding.ivEmpty.visibility = View.VISIBLE + binding.rvCalendarEvent.visibility = View.GONE + return@observe + } + + binding.tvEmpty.visibility = View.GONE + binding.ivEmpty.visibility = View.GONE + binding.rvCalendarEvent.visibility = View.VISIBLE + (binding.rvCalendarEvent.adapter as? DailyScheduleAdapter)?.updateItems(daySchedules) + } + + viewModel.monthData.observe(viewLifecycleOwner) { monthData -> + binding.calendarview.updateMonthData(monthData) + } + + viewModel.selectedDayAndHolidays.observe(viewLifecycleOwner) { selectedDayAndHolidays -> + binding.tvDay.text = selectedDayAndHolidays.first.format( + DateTimeFormatter.ofPattern("MM.dd(EEE)") + ) + + binding.tvToday.isVisible = selectedDayAndHolidays.first == LocalDate.now() + binding.tvHolidays.isVisible = selectedDayAndHolidays.second.isNotEmpty() + binding.tvHolidays.text = selectedDayAndHolidays.second + } + + viewModel.loading.observe(viewLifecycleOwner) { loading -> + binding.progressBar.isVisible = loading + } + } + + private fun updateTitle(today: LocalDate = LocalDate.now()) { + val calendarMonth = binding.calendarview.findFirstVisibleMonth() ?: return + val month = calendarMonth.yearMonth + if (month.year != today.year) { + val displayMonth = "${month.year} ${month.month.displayText(short = false)}" + binding.tvMonth.text = displayMonth + } else { + binding.tvMonth.text = month.month.displayText(short = false) + } + } + + private fun findSelectedDailyScheduleToEventView() { + val calendarMonth = binding.calendarview.findFirstVisibleMonth() ?: return + viewModel.findSelectedDailySchedule(calendarMonth) + } + + private fun readCalendarData() { + val calendarMonth = binding.calendarview.findFirstVisibleMonth() ?: return + viewModel.fetchCalendarData(calendarMonth.yearMonth) + } + + private fun prevMonth() { + binding.calendarview.findFirstVisibleMonth()?.yearMonth?.let { visibleMonth -> + binding.calendarview.smoothScrollToMonth(visibleMonth.previousMonth) + } + } + + private fun nextMonth() { + binding.calendarview.findFirstVisibleMonth()?.yearMonth?.let { visibleMonth -> + binding.calendarview.smoothScrollToMonth(visibleMonth.nextMonth) + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/Binder.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/Binder.kt new file mode 100644 index 0000000..2bfa9f9 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/Binder.kt @@ -0,0 +1,6 @@ +package com.giwon.aide.feature.calendar.scheduler.calendarinternal + +import com.giwon.aide.feature.calendar.scheduler.data.CalendarMonth + +typealias MonthScrollListener = (CalendarMonth) -> Unit + diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarLayoutManager.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarLayoutManager.kt new file mode 100644 index 0000000..fff1a93 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarLayoutManager.kt @@ -0,0 +1,77 @@ +package com.giwon.aide.feature.calendar.scheduler.calendarinternal + +import android.graphics.Rect +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.LinearSmoothScroller +import androidx.recyclerview.widget.RecyclerView + +internal abstract class CalendarLayoutManager( + private val calView: RecyclerView, + @RecyclerView.Orientation orientation: Int, +): LinearLayoutManager(calView.context, orientation, false) { + + abstract fun getaItemAdapterPosition(data: IndexData): Int + abstract fun getaDayAdapterPosition(data: DayData): Int + abstract fun getDayTag(data: DayData): Int + abstract fun getItemMargins(): MarginValues + abstract fun scrollPaged(): Boolean + abstract fun notifyScrollListenerIfNeeded() + + fun scrollToIndex(indexData: IndexData) { + val position = getaItemAdapterPosition(indexData) + if (position == NO_INDEX) return + scrollToPositionWithOffset(position, 0) + calView.post { notifyScrollListenerIfNeeded() } + } + + fun smoothScrollToIndex(indexData: IndexData) { + val position = getaItemAdapterPosition(indexData) + if (position == NO_INDEX) return + startSmoothScroll(CalendarSmoothScroller(position, null)) + } + + + private fun calculateDayViewOffsetInParent(day: DayData, itemView: View): Int { + val dayView = itemView.findViewWithTag(getDayTag(day)) ?: return 0 + val rect = Rect() + dayView.getDrawingRect(rect) + (itemView as ViewGroup).offsetDescendantRectToMyCoords(dayView, rect) + val margins = getItemMargins() + return rect.left + margins.start + } + + private inner class CalendarSmoothScroller(position: Int, val day: DayData?) : + LinearSmoothScroller(calView.context) { + init { + targetPosition = position + } + + override fun getVerticalSnapPreference(): Int = SNAP_TO_START + + override fun getHorizontalSnapPreference(): Int = SNAP_TO_START + + override fun calculateDyToMakeVisible(view: View, snapPreference: Int): Int { + val dy = super.calculateDyToMakeVisible(view, snapPreference) + if (day == null) { + return dy + } + val offset = calculateDayViewOffsetInParent(day, view) + return dy - offset + } + + override fun calculateDxToMakeVisible(view: View, snapPreference: Int): Int { + val dx = super.calculateDxToMakeVisible(view, snapPreference) + if (day == null) { + return dx + } + val offset = calculateDayViewOffsetInParent(day, view) + return dx - offset + } + } + + companion object { + internal const val NO_INDEX = -1 + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarPageSnapHelperLegacy.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarPageSnapHelperLegacy.kt new file mode 100644 index 0000000..cbff8de --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/CalendarPageSnapHelperLegacy.kt @@ -0,0 +1,51 @@ +package com.giwon.aide.feature.calendar.scheduler.calendarinternal + +import android.view.View +import androidx.recyclerview.widget.OrientationHelper +import androidx.recyclerview.widget.PagerSnapHelper +import androidx.recyclerview.widget.RecyclerView + +class CalendarPageSnapHelperLegacy: PagerSnapHelper() { + + override fun calculateDistanceToFinalSnap( + layoutManager: RecyclerView.LayoutManager, + targetView: View, + ): IntArray { + return IntArray(2).apply { + this[0] = if (layoutManager.canScrollHorizontally()) { + distanceToStart(targetView, getHorizontalHelper(layoutManager)) + } else { + 0 + } + + this[1] = if (layoutManager.canScrollVertically()) { + distanceToStart(targetView, getVerticalHelper(layoutManager)) + } else { + 0 + } + } + } + + private fun distanceToStart(targetView: View, helper: OrientationHelper): Int { + val childStart = (helper.getDecoratedStart(targetView)) + val containerStart = helper.startAfterPadding + return childStart - containerStart + } + + private lateinit var verticalHelper: OrientationHelper + private lateinit var horizontalHelper: OrientationHelper + + private fun getVerticalHelper(layoutManager: RecyclerView.LayoutManager): OrientationHelper { + if (!::verticalHelper.isInitialized || verticalHelper.layoutManager != layoutManager) { + verticalHelper = OrientationHelper.createVerticalHelper(layoutManager) + } + return verticalHelper + } + + private fun getHorizontalHelper(layoutManager: RecyclerView.LayoutManager): OrientationHelper { + if (!::horizontalHelper.isInitialized || horizontalHelper.layoutManager != layoutManager) { + horizontalHelper = OrientationHelper.createHorizontalHelper(layoutManager) + } + return horizontalHelper + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/DaySize.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/DaySize.kt new file mode 100644 index 0000000..df6ce3d --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/DaySize.kt @@ -0,0 +1,21 @@ +package com.giwon.aide.feature.calendar.scheduler.calendarinternal + +enum class DaySize { + + Square, + + Rectangle, + + SeventhWidth, + + FreeForm, + + ; + + internal val parentDecidesWidth: Boolean + get() = this == Square || this == SeventhWidth || this == Rectangle + + internal val parentDecidesHeight: Boolean + get() = this == Rectangle +} + diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/MarginValues.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/MarginValues.kt new file mode 100644 index 0000000..1576230 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/calendarinternal/MarginValues.kt @@ -0,0 +1,10 @@ +package com.giwon.aide.feature.calendar.scheduler.calendarinternal + +import androidx.annotation.Px + +data class MarginValues( + @Px val start: Int = 0, + @Px val top: Int = 0, + @Px val end: Int = 0, + @Px val bottom: Int = 0, +) diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/EventTextView.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/EventTextView.kt new file mode 100644 index 0000000..f0b1b06 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/EventTextView.kt @@ -0,0 +1,55 @@ +package com.giwon.aide.feature.calendar.scheduler.customview + +import android.content.Context +import android.text.TextUtils +import android.util.AttributeSet +import android.widget.LinearLayout +import androidx.appcompat.content.res.AppCompatResources +import androidx.appcompat.widget.AppCompatTextView +import androidx.core.view.setPadding +import com.giwon.aide.feature.calendar.R +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.util.ColorUtils +import com.giwon.aide.feature.calendar.scheduler.viewmodel.CalendarEventViewModel + +class EventTextView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyle: Int = 0 +) : AppCompatTextView(context, attrs, defStyle) { + + lateinit var event: CalendarEvent + + fun setEvent(event: CalendarEvent, textViewWidth: Int, eventHeight: Int, isHalf: Boolean) { + this.event = event + if (!isHalf) { + text = event.title + textSize = 8f + maxLines = 1 + ellipsize = TextUtils.TruncateAt.END + setTextColor(ColorUtils.getTextColor(event.color)) + } + + val drawable = AppCompatResources.getDrawable( + context, + R.drawable.calendar_event_background + ) + drawable?.setTint(event.color) + background = drawable + + layoutParams = LinearLayout.LayoutParams(textViewWidth, eventHeight) + setPadding(CalendarEventViewModel.EVENT_PADDING) + alpha = 1f + + tag = event.id + } + + fun setEventHeight(eventHeight: Int) { + layoutParams.height = eventHeight + } + + fun setOpacity(opacity: Float) { + val newOpacity = opacity.coerceIn(0f, 1f) + alpha = newOpacity + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/WeekLayout.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/WeekLayout.kt new file mode 100644 index 0000000..1585387 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/customview/WeekLayout.kt @@ -0,0 +1,191 @@ +package com.giwon.aide.feature.calendar.scheduler.customview + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF +import android.util.AttributeSet +import android.widget.FrameLayout +import androidx.core.content.res.ResourcesCompat +import com.giwon.aide.feature.calendar.R +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.data.DayPosition +import com.giwon.aide.feature.calendar.scheduler.util.dpToPx +import java.time.LocalDate + +class WeekLayout : FrameLayout { + constructor(context: Context) : super(context) + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : + super(context, attrs, defStyle) + + var dayWidth: Int = 0 + private val weekDates = mutableListOf() + + init { + setWillNotDraw(false) + } + + private val textPaint = Paint().apply { + color = context.getColor(R.color.gray900) + textSize = context.dpToPx(14).toFloat() + textAlign = Paint.Align.CENTER + typeface = ResourcesCompat.getFont( + context, + R.font.spoqa_han_sans_neo_regular + ) + } + + private val linePaint = Paint().apply { + color = context.getColor(R.color.gray50) + style = Paint.Style.STROKE + strokeWidth = 2f * resources.displayMetrics.density + } + + private val todayBackgroundPaint = Paint().apply { + color = context.getColor(R.color.orange) + isAntiAlias = true + } + + private val selectedBorderPaint = Paint().apply { + color = context.getColor(R.color.gray100) + style = Paint.Style.STROKE + strokeWidth = context.dpToPx(1).toFloat() + isAntiAlias = true + } + + private val eventPaint = Paint().apply { + color = context.getColor(R.color.white) + textSize = context.dpToPx(8).toFloat() + isAntiAlias = true + typeface = ResourcesCompat.getFont( + context, + R.font.spoqa_han_sans_neo_regular + ) + } + + private val todayRectF = RectF() + private val selectedBorderRectF = RectF() + + var onSelected: ((LocalDate) -> Unit)? = null + + fun updateWeekDates(weekDates: List) { + this.weekDates.clear() + weekDates.forEach { + if (it is CalendarDay) this.weekDates.add(it) + } + + invalidate() + } + + override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { + // 각 dayView의 위치를 정합니다 + for (i in 0 until childCount) { + val child = getChildAt(i) + + if (child is EventTextView) { + child.translationX = child.event.childTranslateX + child.translationY = child.event.childTranslateY + } + } + + dayWidth = (measuredWidth / 7) + super.onLayout(changed, l, t, r, b) + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + + // Draw top line + canvas.drawLine(0f, 0f, measuredWidth.toFloat(), 0f, linePaint) + + weekDates.forEachIndexed { index, day -> + val x = (dayWidth * index + dayWidth / 2).toFloat() + val y = textPaint.textSize + context.dpToPx(2).toFloat() + val dayText = day.date.dayOfMonth.toString() + + if (day.date == LocalDate.now()) { + todayRectF.set( + x - context.dpToPx(16) + context.dpToPx(5).toFloat(), + 0f, + x + context.dpToPx(16) - context.dpToPx(5).toFloat(), + y + context.dpToPx(5).toFloat() + ) + canvas.drawRoundRect( + todayRectF, + context.dpToPx(8).toFloat(), + context.dpToPx(8).toFloat(), + todayBackgroundPaint + ) + + textPaint.color = + context.getColor(R.color.white) + } else { + if (day.position == DayPosition.MonthDate) { + textPaint.color = + context.getColor(R.color.gray900) + } else { + textPaint.color = + context.getColor(R.color.gray300) + + } + } + + if (day.selected && day.position == DayPosition.MonthDate) { + selectedBorderRectF.set( + dayWidth * index.toFloat(), + 0f, + (dayWidth * index + dayWidth).toFloat(), + measuredHeight.toFloat(), + ) + canvas.drawRoundRect( + selectedBorderRectF, + context.dpToPx(4).toFloat(), + context.dpToPx(4).toFloat(), + selectedBorderPaint + ) + } + canvas.drawText(dayText, x, y, textPaint) + } + } + + fun onClickWeekLayout(x: Float, y: Float) { + val location = IntArray(2) + getLocationOnScreen(location) + val index = getWithinRectIndex(x, y) + if (index >= 0) { + val day = weekDates[index] + if (day.position == DayPosition.MonthDate) { + onSelected?.invoke(day.date) + } + } + invalidate() + } + + private fun getWithinRectIndex(x: Float, y: Float): Int { + for (index in 0 until weekDates.size) { + val rect = RectF( + (dayWidth * index).toFloat(), + 0f, + (dayWidth * index + dayWidth).toFloat(), + measuredHeight.toFloat() + ) + + if (rect.contains(x, y)) { + return index + } + } + return -1 + } + + fun setEventOpacity(opacity: Float) { + for (i in 0 until childCount) { + val child = getChildAt(i) + if (child is EventTextView) { + child.setOpacity(opacity) + } + } + } +} + + diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarDay.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarDay.kt new file mode 100644 index 0000000..8105d01 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarDay.kt @@ -0,0 +1,11 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import java.io.Serializable +import java.time.LocalDate + +data class CalendarDay( + val date: LocalDate, + val position: DayPosition, + val selected: Boolean = false, + val events: List = emptyList() +) : Serializable diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEvent.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEvent.kt new file mode 100644 index 0000000..3283c1b --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEvent.kt @@ -0,0 +1,104 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDateString +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDateTime +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.temporal.ChronoUnit +import java.time.temporal.TemporalAdjusters + +data class CalendarEvent( + val id: String = "", + val calendarId: String = "", + val title: String = "", + val displayName: String = "", + val startTime: Long = 0L, + val startDay: Int = 0, + val startPosition: Int = 0, + val endTime: Long = 0L, + val endDay: Int = 0, + val color: Int = 0, + val isAllDay: Boolean = false, + val childTranslateX: Float = 0f, + val childTranslateY: Float = 0f, + val date: LocalDate = LocalDate.now(), + val isHoliday: Boolean = false, + val ownerAccount: String = "", +) { + val durationInDays: Int + get() { + val millisInDay = 1000 * 60 * 60 * 24 + return if (isAllDay) { + ((endTime - startTime) / millisInDay).toInt() + } else { + ChronoUnit.DAYS.between( + Instant.ofEpochMilli(startTime).atZone(ZoneId.systemDefault()).toLocalDate(), + Instant.ofEpochMilli(endTime).atZone(ZoneId.systemDefault()).toLocalDate() + ).toInt() + } + } + + fun isLongEvent(): Boolean = durationInDays > 1 + + fun isWithinDay(date: LocalDateTime): Boolean { + val start = startTime.toLocalDateTime() + val end = endTime.toLocalDateTime() + return date in start..end + } + + fun toWeekPosition(date: Long): Int { + return date.toLocalDateTime().dayOfWeek.value + } + + fun getFirstDayOfWeek(date: LocalDateTime): LocalDateTime { + return date.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.SUNDAY)) + } + + companion object { + fun getEndDay(endTime: Long, isAllDay: Boolean): Int { + if (endTime == 0L) return 0 + return if (isAllDay) { + Instant.ofEpochMilli(endTime) + .atZone(ZoneId.systemDefault()) + .dayOfMonth - 1 + } else { + Instant.ofEpochMilli(endTime) + .atZone(ZoneId.systemDefault()) + .dayOfMonth + } + } + + fun periodString(calendarEvent: CalendarEvent): String { + val startTime = calendarEvent.startTime.toLocalDateTime() + val endTime = calendarEvent.endTime.toLocalDateTime() + return if (calendarEvent.isAllDay) { + if (calendarEvent.durationInDays > 1) { + "${ + calendarEvent.startTime.toLocalDateString("M월 d일", false) + } - ${ + calendarEvent.endTime.toLocalDateString("M월 d일", true) + }" + } else { + "하루 종일" + } + + } else { + if (startTime.dayOfMonth != endTime.dayOfMonth) { + "${ + calendarEvent.startTime.toLocalDateString("M월 d일 HH:mm") + } - ${ + calendarEvent.endTime.toLocalDateString("M월 d일 HH:mm") + }" + } else { + "${ + calendarEvent.startTime.toLocalDateString("HH:mm") + } - ${ + calendarEvent.endTime.toLocalDateString("HH:mm") + }" + } + } + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEventList.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEventList.kt new file mode 100644 index 0000000..3212265 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarEventList.kt @@ -0,0 +1,74 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDateTime +import java.time.LocalDate +import java.time.LocalDateTime + +class CalendarEventList( + private val events: MutableList = mutableListOf() +) : MutableList by events { + + private val calendarEventData = mutableMapOf>() + + private fun sortedEventList(events: List): List { + return events.sortedWith( + compareBy { it.durationInDays } + .reversed() + .thenBy { !it.isAllDay } + .thenBy { it.startTime } + ) + } + + fun makeCalendarMap(): Map> { + events + .forEach { event -> + val flattenDays = getFlattenDays(event) + flattenDays.forEach { entry -> + val date = entry.key + val eventList = calendarEventData[date]?.toMutableList() ?: CalendarEventList() + eventList.add(event) + calendarEventData[date] = sortedEventList(eventList) + } + } + + return calendarEventData.toMap() + } + + private fun getFlattenDays(event: CalendarEvent): Map { + val days = mutableMapOf() + val startTime: LocalDateTime = event.startTime.toLocalDateTime() + val endTime: LocalDateTime = event.endTime.toLocalDateTime() + + var current = startTime + while (getBreakConditionFlattedDays(current, endTime, event)) { + days[current.toLocalDate()] = event + current = current.plusDays(1) + } + return days + } + + fun addCalendarMap(map: Map>) { + map.forEach { entry: Map.Entry> -> + val date = entry.key + val eventList = calendarEventData[date]?.toMutableList() ?: CalendarEventList() + eventList.addAll(entry.value) + + calendarEventData[date] = sortedEventList(eventList) + } + } + + fun toCalendarMap(): Map> = calendarEventData.toMap() + + private fun getBreakConditionFlattedDays( + current: LocalDateTime, + endTime: LocalDateTime, + event: CalendarEvent + ): Boolean { + if (event.isAllDay) { + return current < endTime + } + + return current.toLocalDate() <= endTime.toLocalDate() + } + +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarMonth.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarMonth.kt new file mode 100644 index 0000000..8d6715d --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/CalendarMonth.kt @@ -0,0 +1,37 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import java.io.Serializable +import java.time.YearMonth + +data class CalendarMonth( + val yearMonth: YearMonth, + val weekDays: List>, +) : Serializable { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as CalendarMonth + + if (yearMonth != other.yearMonth) return false + if (weekDays.first().first() != other.weekDays.first().first()) return false + if (weekDays.last().last() != other.weekDays.last().last()) return false + + return true + } + + override fun hashCode(): Int { + var result = yearMonth.hashCode() + result = 31 * result + weekDays.first().first().hashCode() + result = 31 * result + weekDays.last().last().hashCode() + return result + } + + override fun toString(): String { + return "CalendarMonth { " + + "first = ${weekDays.first().first()}, " + + "last = ${weekDays.last().last()} " + + "} " + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/ContentHeightMode.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/ContentHeightMode.kt new file mode 100644 index 0000000..1dfa74e --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/ContentHeightMode.kt @@ -0,0 +1,8 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +enum class ContentHeightMode { + + Wrap, + + Fill, +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DataStore.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DataStore.kt new file mode 100644 index 0000000..90ae946 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DataStore.kt @@ -0,0 +1,17 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +class DataStore( + private val store: MutableMap = HashMap(), + private val create: (offset: Int) -> V, +) : MutableMap by store { + override fun get(key: Int): V { + val value = store[key] + return if (value == null) { + val data = create(key) + put(key, data) + data + } else { + value + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DayPosition.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DayPosition.kt new file mode 100644 index 0000000..ceaae57 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/DayPosition.kt @@ -0,0 +1,10 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +enum class DayPosition { + + InDate, + + MonthDate, + + OutDate, +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/EventMapper.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/EventMapper.kt new file mode 100644 index 0000000..911e476 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/EventMapper.kt @@ -0,0 +1,23 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import com.giwon.aide.core.model.CalendarSource +import com.giwon.aide.core.model.Event +import java.time.ZoneId + +fun Event.toCalendarEvent(calendar: CalendarSource?): CalendarEvent { + val ownerAccount = calendar?.ownerAccount.orEmpty() + return CalendarEvent( + id = "${id}_${start.toEpochMilli()}", + calendarId = calendarId.toString(), + title = title.ifEmpty { "(제목 없음)" }, + displayName = calendarName, + startTime = start.toEpochMilli(), + startDay = start.atZone(ZoneId.systemDefault()).dayOfMonth, + endTime = end.toEpochMilli(), + endDay = CalendarEvent.getEndDay(end.toEpochMilli(), allDay), + color = color, + isAllDay = allDay, + ownerAccount = ownerAccount, + isHoliday = ownerAccount.contains("samsungholiday"), + ) +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/MonthData.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/MonthData.kt new file mode 100644 index 0000000..2f8a672 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/MonthData.kt @@ -0,0 +1,71 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +import com.giwon.aide.feature.calendar.scheduler.util.atStartOfMonth +import com.giwon.aide.feature.calendar.scheduler.util.daysUntil +import com.giwon.aide.feature.calendar.scheduler.util.nextMonth +import com.giwon.aide.feature.calendar.scheduler.util.previousMonth +import com.giwon.aide.feature.calendar.scheduler.util.yearMonth +import java.time.DayOfWeek +import java.time.LocalDate +import java.time.YearMonth +import java.time.temporal.ChronoUnit + +fun getCalendarMonthData( + startMonth: YearMonth, + offset: Int, + firstDayOfWeek: DayOfWeek, + outDateStyle: OutDateStyle, +): MonthData { + val month = startMonth.plusMonths(offset.toLong()) + val firstDay = month.atStartOfMonth() + val inDays = firstDayOfWeek.daysUntil(firstDay.dayOfWeek) + val outDays = (inDays + month.lengthOfMonth()).let { inAndMonthDays -> + val endOfRowDays = if (inAndMonthDays % 7 != 0) 7 - (inAndMonthDays % 7) else 0 + val endOfGridDays = if (outDateStyle == OutDateStyle.EndOfRow) { + 0 + } else { + val weeksInMonth = (inAndMonthDays + endOfRowDays) / 7 + (6 - weeksInMonth) * 7 + } + return@let endOfRowDays + endOfGridDays + } + return MonthData(month, inDays, outDays) +} + +data class MonthData( + private val month: YearMonth, + private val inDays: Int, + private val outDays: Int, +) { + private val totalDays: Int = inDays + month.lengthOfMonth() + outDays + + private val firstDay: LocalDate = month.atStartOfMonth().minusDays(inDays.toLong()) + + private val rows: List> = (0 until totalDays).chunked(7) + + private val previousMonth: YearMonth = month.previousMonth + + private val nextMonth: YearMonth = month.nextMonth + + val calendarMonth = + CalendarMonth(month, rows.map { week -> week.map { dayOffset -> getDay(dayOffset) } }) + + private fun getDay(dayOffset: Int): CalendarDay { + val date: LocalDate = firstDay.plusDays(dayOffset.toLong()) + val position = when (date.yearMonth) { + month -> DayPosition.MonthDate + previousMonth -> DayPosition.InDate + nextMonth -> DayPosition.OutDate + else -> throw IllegalArgumentException("Invalid date: $date in month: $month") + } + return CalendarDay(date, position, selected = date == LocalDate.now()) + } +} + +fun getMonthIndex(startMonth: YearMonth, targetMonth: YearMonth): Int { + return ChronoUnit.MONTHS.between(startMonth, targetMonth).toInt() +} + +fun getMonthIndicesCount(startMonth: YearMonth, endMonth: YearMonth): Int { + return getMonthIndex(startMonth, endMonth) + 1 +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/OutDateStyle.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/OutDateStyle.kt new file mode 100644 index 0000000..7523821 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/data/OutDateStyle.kt @@ -0,0 +1,7 @@ +package com.giwon.aide.feature.calendar.scheduler.data + +enum class OutDateStyle { + EndOfRow, + + EndOfGrid, +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/CalendarHalfMode.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/CalendarHalfMode.kt new file mode 100644 index 0000000..e0e6317 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/CalendarHalfMode.kt @@ -0,0 +1,24 @@ +package com.giwon.aide.feature.calendar.scheduler.model + +object CalendarHalfMode { + const val HALF_MODE = 2 + const val FULL_MODE = 1 + + const val TRANSITION_STATE_END = 0 + const val TRANSITION_STATE_START = 1 + + private var transitionState: Int = 0 + private var mode = FULL_MODE + + fun isHalfMode(): Boolean { + return mode == HALF_MODE + } + + fun updateMode(mode: Int) { + this.mode = mode + } + + fun updateTransitionState(state: Int) { + transitionState = state + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/EventInLayout.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/EventInLayout.kt new file mode 100644 index 0000000..8ae7bea --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/model/EventInLayout.kt @@ -0,0 +1,12 @@ +package com.giwon.aide.feature.calendar.scheduler.model + +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent + +data class EventInLayout( + val weekStart: Long, + val yPosition: Int, + val startOffsetDays: Int, + val eventEndDays: Int, + val event: CalendarEvent, + val durationInDays: Int, +) diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/CalendarUtils.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/CalendarUtils.kt new file mode 100644 index 0000000..4646d9e --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/CalendarUtils.kt @@ -0,0 +1,70 @@ +package com.giwon.aide.feature.calendar.scheduler.util + +import android.content.Context +import android.util.Log +import android.view.ViewGroup +import android.widget.LinearLayout +import com.giwon.aide.feature.calendar.scheduler.adapter.ItemContent +import com.giwon.aide.feature.calendar.scheduler.adapter.WeekHolder +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.DaySize +import com.giwon.aide.feature.calendar.scheduler.calendarinternal.MarginValues +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import java.time.LocalDate + +internal fun setupItemRoot( + itemMargins: MarginValues, + daySize: DaySize, + context: Context, + weekSize: Int, + itemViewClass: String?, + onSelectedDay: (LocalDate) -> Unit +): ItemContent { + val rootLayout = LinearLayout(context).apply { + orientation = LinearLayout.VERTICAL + } + + val weekHolders = (0 until weekSize).map { + WeekHolder(onSelectedDay) + } + .onEach { weekHolder -> + rootLayout.weightSum = weekSize.toFloat() + val weekView = weekHolder.inflateWeekView(rootLayout) + + rootLayout.addView(weekView) + } + + fun setupRoot(root: ViewGroup) { + val width = + if (daySize.parentDecidesWidth) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT + val height = + if (daySize.parentDecidesHeight) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT + root.layoutParams = ViewGroup.MarginLayoutParams(width, height).apply { + bottomMargin = itemMargins.bottom + topMargin = itemMargins.top + leftMargin = itemMargins.start + rightMargin = itemMargins.end + } + } + + val itemView = itemViewClass?.let { + val customLayout = runCatching { + Class.forName(it) + .getDeclaredConstructor(Context::class.java) + .newInstance(rootLayout.context) as ViewGroup + }.onFailure { + Log.e( + "CalendarUtils", + "Failure loading custom class $itemViewClass, check that $itemViewClass" + ) + }.getOrNull() + + customLayout?.apply { + setupRoot(this) + addView(rootLayout) + } + } ?: rootLayout.apply { setupRoot(this) } + + return ItemContent(itemView, weekHolders) +} + +fun dayTag(date: LocalDate): Int = date.hashCode() diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ColorUtils.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ColorUtils.kt new file mode 100644 index 0000000..6e6dd3f --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ColorUtils.kt @@ -0,0 +1,29 @@ +package com.giwon.aide.feature.calendar.scheduler.util + +import android.graphics.Color + +object ColorUtils { + fun Int.toHex(): String = "#${Integer.toHexString(this)}" + + fun String.toColor(): Int = Integer.parseInt(this.substring(1), 16) + + fun Int.toColor(): Int = this.toHex().toColor() + + fun Int.toColor(alpha: Int): Int = this and 0x00ffffff or (alpha shl 24) + + fun getTextColor(backgroundColor: Int): Int { + val red = Color.red(backgroundColor) + val green = Color.green(backgroundColor) + val blue = Color.blue(backgroundColor) + val luminance = 0.299 * red + 0.587 * green + 0.114 * blue + return if (luminance > 186) { + runCatching { // 밝은 배경에는 검은색 텍스트 + Color.parseColor("#2d2d2d") + }.getOrDefault(Color.BLACK) + } else { + runCatching { // 어두운 배경에는 흰색 텍스트 + Color.parseColor("#ffffff") + }.getOrDefault(Color.WHITE) + } + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/DateExtension.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/DateExtension.kt new file mode 100644 index 0000000..ec900ab --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/DateExtension.kt @@ -0,0 +1,106 @@ +package com.giwon.aide.feature.calendar.scheduler.util + +import java.time.DayOfWeek +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.Month +import java.time.YearMonth +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.time.format.TextStyle +import java.time.temporal.WeekFields +import java.util.Locale + + +@JvmOverloads +fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): List { + val pivot = 7 - firstDayOfWeek.ordinal + val daysOfWeek = DayOfWeek.values().toList() + return (daysOfWeek.takeLast(pivot) + daysOfWeek.dropLast(1)) +} + +fun firstDayOfWeekFromLocale(): DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek + +fun YearMonth.atStartOfMonth(): LocalDate = this.atDay(1) + +val LocalDate.yearMonth: YearMonth + get() = YearMonth.of(year, month) + +val YearMonth.nextMonth: YearMonth + get() = this.plusMonths(1) + +val YearMonth.previousMonth: YearMonth + get() = this.minusMonths(1) + +fun DayOfWeek.daysUntil(other: DayOfWeek) = (7 + (other.value - value)) % 7 + +fun checkDateRange(startMonth: YearMonth, endMonth: YearMonth) { + check(endMonth >= startMonth) { + "startMonth: $startMonth is greater than endMonth: $endMonth" + } +} + +fun Month.displayText(short: Boolean = true): String { + val style = if (short) TextStyle.SHORT else TextStyle.FULL + return getDisplayName(style, Locale.getDefault()) +} + +fun Long.toMonthOfDay(): Int { + val zoneId = ZoneId.systemDefault() + val instant: Instant = Instant.ofEpochMilli(this) + return instant.atZone(zoneId).dayOfMonth +} + +fun Long.toLocalDate(): LocalDate { + val zoneId = ZoneId.systemDefault() + val instant: Instant = Instant.ofEpochMilli(this) + return instant.atZone(zoneId).toLocalDate() +} + +fun Long.toLocalDateTime(): LocalDateTime { + val zoneId = ZoneId.systemDefault() + val instant: Instant = Instant.ofEpochMilli(this) + return instant.atZone(zoneId).toLocalDateTime() +} + +fun LocalDate.toEpochTime(): Long { + val zoneId = ZoneId.systemDefault() + return this.atStartOfDay(zoneId).toInstant().toEpochMilli() +} + +fun LocalDateTime.toEpochTime(): Long { + val zoneId = ZoneId.systemDefault() + return this.atZone(zoneId).toInstant().toEpochMilli() + +} + +fun LocalDateTime.toStartOfDay(): LocalDateTime { + return this.withHour(0).withMinute(0) +} + +fun LocalDateTime.adjustEndTime(): LocalDateTime { + return if (this.toLocalTime() == LocalTime.MIDNIGHT) { + this.minusDays(1) + } else { + this + } +} + +fun Boolean.toInt(): Int = if (this) 1 else 0 + +fun Long.toLocalDateString(formatter: String, isAllDay: Boolean = false): String { + val localDate = this.toLocalDateTime() + + val newLocalDate = if (isAllDay) { + localDate.minusDays(1) + } else { + localDate + } + return runCatching { + newLocalDate.format( + DateTimeFormatter.ofPattern(formatter, Locale.getDefault()) + ) + }.getOrDefault("") +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ViewExt.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ViewExt.kt new file mode 100644 index 0000000..5efce58 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/util/ViewExt.kt @@ -0,0 +1,7 @@ +package com.giwon.aide.feature.calendar.scheduler.util + +import android.content.Context + +fun Context.dpToPx(dp: Int): Int { + return (dp * resources.displayMetrics.density).toInt() +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarEventViewModel.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarEventViewModel.kt new file mode 100644 index 0000000..11a2fb7 --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarEventViewModel.kt @@ -0,0 +1,187 @@ +package com.giwon.aide.feature.calendar.scheduler.viewmodel + +import androidx.annotation.VisibleForTesting +import com.giwon.aide.feature.calendar.scheduler.data.CalendarDay +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.model.EventInLayout +import com.giwon.aide.feature.calendar.scheduler.util.adjustEndTime +import com.giwon.aide.feature.calendar.scheduler.util.toEpochTime +import com.giwon.aide.feature.calendar.scheduler.util.toInt +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDate +import com.giwon.aide.feature.calendar.scheduler.util.toLocalDateTime +import com.giwon.aide.feature.calendar.scheduler.util.toMonthOfDay +import com.giwon.aide.feature.calendar.scheduler.util.toStartOfDay +import java.time.LocalDate +import kotlin.math.max +import kotlin.math.min + +class CalendarEventViewModel { + + private val calendarEvents = mutableMapOf() + private val eventInLayoutList = mutableListOf() + private var weekStartTime: Long = 0L + private var dayWidth = 0 + + fun clear() { + calendarEvents.clear() + eventInLayoutList.clear() + } + + fun setWeekStartTime(weekStartDay: CalendarDay) { + weekStartTime = weekStartDay.date.toEpochTime() + } + + fun addEvent(event: CalendarEvent) { + if (calendarEvents[event.id] == null) { + calendarEvents[event.id] = event + } + } + + fun getEvents(): List = calendarEvents.values.toList() + + fun getDayWidth(): Int = dayWidth + + fun setDayWidth(width: Int) { + dayWidth = width + } + + fun addEventInLayout(event: CalendarEvent, yPosition: Int) { + val eventInLayout = EventInLayout( + weekStart = weekStartTime, + yPosition = yPosition, + startOffsetDays = event.startPosition, + eventEndDays = getEventEndTimeOffset(event) + event.startPosition - 1, + event = event, + durationInDays = event.durationInDays + ) + eventInLayoutList.add(eventInLayout) + } + + @VisibleForTesting + fun eventInLayoutListSize(): Int = eventInLayoutList.size + + fun getEventEndTimeOffset( + event: CalendarEvent, + ): Int { + val weekStart = weekStartTime + val weekEnd = weekStartTime + (7 * MILLIS_IN_DAY) - 1 + val whetherAllDay = if (event.isAllDay) 0 else 1 + // width를 구할 때 일주일을 넘어가면 마지막 weekEnd 까지만 길이를 정해주고 + // 다음 주로 넘어가는 이벤트는 다음 주의 시작일에서 startTime을 빼서 길이를 정해준다 + return when { + event.endTime - event.startTime < MILLIS_IN_DAY -> { + val startDay = event.startTime.toMonthOfDay() + val endDay = event.endTime.toMonthOfDay() + // startDay가 weekEnd이고 endDay가 weekEnd + 1일 때 (시작일이 일주일의 마지막 날이고 끝나는날이 다음주의 첫날) + if (event.endTime > weekEnd || event.startTime < weekStart) { + 1 + } else { + // 아니면 기간이 1일 보다는 작지만 하루의 중간에 시작하여 다음날로 넘어가는 경우 + if (startDay == endDay) 1 else { + // endTime은 00:00:00으로 설정되어 있으면 -1일 startTime은 00:00:00으로 설정되어 있으면 0일 + if (event.endTime.toLocalDateTime() == event.endTime.toLocalDateTime() + .toStartOfDay() + ) { + 1 + } else { + 2 + } + } + } + } + + event.startTime + (event.durationInDays * MILLIS_IN_DAY) > weekEnd -> { + if (event.isAllDay) { + if (((weekEnd - event.startTime) / MILLIS_IN_DAY).toInt() < 1) { + 1 + } else { + ((weekEnd - event.startTime) / MILLIS_IN_DAY).toInt() + 1 + } + } else { + ((weekEnd - event.startTime) / MILLIS_IN_DAY).toInt() + whetherAllDay + } + + } + + // 지난 주에서 시작하여 다음 주로 넘어가는 경우 startTime 계산 + event.startTime < weekStart -> { + ((event.endTime - weekStart) / MILLIS_IN_DAY).toInt() + whetherAllDay + } + + else -> { + if (event.isAllDay) { + event.durationInDays + } else { + + val startLocalDateTime = event.startTime.toLocalDateTime() + val endLocalDateTime = event.endTime.toLocalDateTime() + val startDay = startLocalDateTime.toStartOfDay().toEpochTime() + val endDay = endLocalDateTime.toStartOfDay().toEpochTime() + + // 이벤트가 시작 날짜에 걸쳐있고 끝나는 시간도 걸쳐 있는 경우 + if (startLocalDateTime.toEpochTime() > startDay && endLocalDateTime.toEpochTime() > endDay) { + ((endDay - startDay) / MILLIS_IN_DAY).toInt() + 1 + } else { + // 시작 날짜는 무조건 1일 이므로 +1일 안한다 + ((endDay - startDay) / MILLIS_IN_DAY).toInt() + } + } + } + } + } + + fun findPositionForEvent( + currentEvent: CalendarEvent, + eventHeight: Int, + eventTopMargin: Int + ): Int { + var currentTop = eventTopMargin + + val alreadyAddedYPositionEvents = eventInLayoutList.filter { + val adjustedCurrentEndTime = currentEvent.endTime.toLocalDateTime().adjustEndTime() + val adjustedTargetEndTime = it.event.endTime.toLocalDateTime().adjustEndTime() + + isOverlapLocalDate( + currentEvent.startTime.toLocalDate(), + adjustedCurrentEndTime.toLocalDate() + .minusDays(currentEvent.isAllDay.toInt().toLong()), + it.event.startTime.toLocalDate(), + adjustedTargetEndTime.toLocalDate() + .minusDays(it.event.isAllDay.toInt().toLong()) + ) + }.sortedBy { it.yPosition } + + alreadyAddedYPositionEvents.forEach { + if (it.yPosition in currentTop until currentTop + eventHeight) { + currentTop += eventHeight + EVENT_TOP_MARGIN + } + } + + return currentTop + } + + private fun isOverlapLocalDate( + currentEventStartTime: LocalDate, + currentEventEndTime: LocalDate, + targetDateStartTime: LocalDate, + targetDateEndTime: LocalDate + ): Boolean { + val overLap: Long = min( + currentEventEndTime.toEpochDay(), + targetDateEndTime.toEpochDay() + ) - max( + currentEventStartTime.toEpochDay(), + targetDateStartTime.toEpochDay() + ) + + return overLap >= 0 + } + + companion object { + const val MILLIS_IN_DAY = 1000 * 60 * 60 * 24 + const val EVENT_PADDING = 2 + const val EVENT_END_MARGIN = 8 + const val EVENT_TOP_MARGIN = 4 + const val EVENT_TRANSLATE_OFFSET = 4 + } +} diff --git a/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarViewModel.kt b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarViewModel.kt new file mode 100644 index 0000000..0bfbbcb --- /dev/null +++ b/feature/calendar/src/main/kotlin/com/giwon/aide/feature/calendar/scheduler/viewmodel/CalendarViewModel.kt @@ -0,0 +1,144 @@ +package com.giwon.aide.feature.calendar.scheduler.viewmodel + +import androidx.annotation.VisibleForTesting +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.giwon.aide.core.data.EventRepository +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEvent +import com.giwon.aide.feature.calendar.scheduler.data.CalendarEventList +import com.giwon.aide.feature.calendar.scheduler.data.CalendarMonth +import com.giwon.aide.feature.calendar.scheduler.data.DayPosition +import com.giwon.aide.feature.calendar.scheduler.data.toCalendarEvent +import com.giwon.aide.feature.calendar.scheduler.model.CalendarHalfMode +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import timber.log.Timber +import java.time.LocalDate +import java.time.YearMonth +import java.time.ZoneId +import javax.inject.Inject + +@HiltViewModel +class CalendarViewModel @Inject constructor( + private val eventRepository: EventRepository, +) : ViewModel() { + + private val _calendarData = MutableLiveData>>(emptyMap()) + val calendarData: LiveData>> = _calendarData + + private val _daySchedules = MutableLiveData>() + val daySchedules: LiveData> get() = _daySchedules + + private val _monthData = MutableLiveData() + val monthData: LiveData get() = _monthData + + private var _selectedDay = LocalDate.now() + + private val _selectedDayAndHolidays = MutableLiveData>() + val selectedDayAndHolidays: LiveData> get() = _selectedDayAndHolidays + + private val _clickedDate = MutableLiveData() + val clickedDate: LiveData get() = _clickedDate + + private val _loading = MutableLiveData(true) + val loading: LiveData get() = _loading + + private var fetchJob: Job? = null + + fun fetchCalendarData(yearMonth: YearMonth) { + val zone = ZoneId.systemDefault() + val from = yearMonth.atDay(1).atStartOfDay(zone).toInstant() + val to = yearMonth.plusMonths(1).atDay(1).atStartOfDay(zone).toInstant() + + fetchJob?.cancel() + fetchJob = combine( + eventRepository.observeEvents(from, to), + eventRepository.observeCalendars(), + ) { events, calendars -> + val calendarsById = calendars.associateBy { it.id } + CalendarEventList().apply { + addAll(events.map { it.toCalendarEvent(calendarsById[it.calendarId]) }) + }.makeCalendarMap() + }.catch { error -> + Timber.e(error, "폰 캘린더를 읽지 못했다: %s", yearMonth) + emit(emptyMap()) + }.onEach { calendarData -> + _calendarData.value = calendarData + _loading.value = false + }.launchIn(viewModelScope) + } + + fun updateHalfMode(isHalfMode: Boolean, currentMonth: CalendarMonth) { + CalendarHalfMode.updateMode( + if (isHalfMode) CalendarHalfMode.HALF_MODE else CalendarHalfMode.FULL_MODE + ) + + val newMonthData = currentMonth.copy() + _monthData.value = newMonthData + } + + private fun requestDailySchedule() { + _calendarData.value?.let { + val selectedDay = _selectedDay ?: return@let + _daySchedules.value = + it[selectedDay]?.filter { event -> event.isHoliday.not() } ?: emptyList() + } + } + + fun findSelectedDailySchedule(currentMonth: CalendarMonth) { + val selectedDay = currentMonth.weekDays.flatten().find { it.selected } ?: return + if (selectedDay.position == DayPosition.MonthDate) { + _selectedDayAndHolidays.value = + selectedDay.date to getHolidaysStringFromCalendarEvents(selectedDay.date) + + _calendarData.value?.let { + _daySchedules.value = + it[selectedDay.date]?.filter { event -> event.isHoliday.not() } ?: emptyList() + } + } + } + + fun onSelectedDay(selectedDay: LocalDate, currentMonth: CalendarMonth) { + val weeks = currentMonth.weekDays + _selectedDay = selectedDay + + val newMonthData = currentMonth.copy( + weekDays = weeks.map { week -> + week.map { day -> + day.copy(selected = day.date == selectedDay) + } + } + ) + + _monthData.value = newMonthData + _selectedDayAndHolidays.value = + selectedDay to getHolidaysStringFromCalendarEvents(selectedDay) + requestDailySchedule() + } + + private fun getHolidaysStringFromCalendarEvents(selectedDay: LocalDate): String { + _calendarData.value?.let { calendarData -> + val holidays = calendarData[selectedDay]?.filter { it.isHoliday } ?: emptyList() + val holidayString = holidays.joinToString(separator = ", ") { it.title } + + return holidayString + } + + return "" + } + + fun onAddScheduleClick() { + _clickedDate.value = _selectedDayAndHolidays.value?.first + } + + @VisibleForTesting + fun setCalendarDataForTest(calendarData: Map>) { + _calendarData.value = calendarData + } +} diff --git a/feature/calendar/src/main/res/drawable/background_calendar_day.xml b/feature/calendar/src/main/res/drawable/background_calendar_day.xml new file mode 100644 index 0000000..13dda25 --- /dev/null +++ b/feature/calendar/src/main/res/drawable/background_calendar_day.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/feature/calendar/src/main/res/drawable/background_tv_today.xml b/feature/calendar/src/main/res/drawable/background_tv_today.xml new file mode 100644 index 0000000..54c1d26 --- /dev/null +++ b/feature/calendar/src/main/res/drawable/background_tv_today.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/feature/calendar/src/main/res/drawable/calendar_event_background.xml b/feature/calendar/src/main/res/drawable/calendar_event_background.xml new file mode 100644 index 0000000..cd50c77 --- /dev/null +++ b/feature/calendar/src/main/res/drawable/calendar_event_background.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/feature/calendar/src/main/res/drawable/ic_arrow_left.xml b/feature/calendar/src/main/res/drawable/ic_arrow_left.xml new file mode 100644 index 0000000..ba20c67 --- /dev/null +++ b/feature/calendar/src/main/res/drawable/ic_arrow_left.xml @@ -0,0 +1,10 @@ + + + diff --git a/feature/calendar/src/main/res/drawable/ic_arrow_right.xml b/feature/calendar/src/main/res/drawable/ic_arrow_right.xml new file mode 100644 index 0000000..04a43ef --- /dev/null +++ b/feature/calendar/src/main/res/drawable/ic_arrow_right.xml @@ -0,0 +1,10 @@ + + + diff --git a/feature/calendar/src/main/res/drawable/ic_calendar_today.xml b/feature/calendar/src/main/res/drawable/ic_calendar_today.xml new file mode 100644 index 0000000..f1b093e --- /dev/null +++ b/feature/calendar/src/main/res/drawable/ic_calendar_today.xml @@ -0,0 +1,13 @@ + + + diff --git a/feature/calendar/src/main/res/drawable/ic_long_event_all_day.xml b/feature/calendar/src/main/res/drawable/ic_long_event_all_day.xml new file mode 100644 index 0000000..f2c808a --- /dev/null +++ b/feature/calendar/src/main/res/drawable/ic_long_event_all_day.xml @@ -0,0 +1,16 @@ + + + + diff --git a/feature/calendar/src/main/res/drawable/ic_no_schedule.xml b/feature/calendar/src/main/res/drawable/ic_no_schedule.xml new file mode 100644 index 0000000..b9d659b --- /dev/null +++ b/feature/calendar/src/main/res/drawable/ic_no_schedule.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + diff --git a/feature/calendar/src/main/res/drawable/scheduler_event_front_bar_color.xml b/feature/calendar/src/main/res/drawable/scheduler_event_front_bar_color.xml new file mode 100644 index 0000000..d292a3e --- /dev/null +++ b/feature/calendar/src/main/res/drawable/scheduler_event_front_bar_color.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/feature/calendar/src/main/res/font/spoqa_han_sans_neo_regular.otf b/feature/calendar/src/main/res/font/spoqa_han_sans_neo_regular.otf new file mode 100644 index 0000000..0a0ff83 Binary files /dev/null and b/feature/calendar/src/main/res/font/spoqa_han_sans_neo_regular.otf differ diff --git a/feature/calendar/src/main/res/layout/item_calendar_day.xml b/feature/calendar/src/main/res/layout/item_calendar_day.xml new file mode 100644 index 0000000..747eb49 --- /dev/null +++ b/feature/calendar/src/main/res/layout/item_calendar_day.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/feature/calendar/src/main/res/layout/item_calendar_event_time.xml b/feature/calendar/src/main/res/layout/item_calendar_event_time.xml new file mode 100644 index 0000000..cf99977 --- /dev/null +++ b/feature/calendar/src/main/res/layout/item_calendar_event_time.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + diff --git a/feature/calendar/src/main/res/layout/layout_fragment_calendar.xml b/feature/calendar/src/main/res/layout/layout_fragment_calendar.xml new file mode 100644 index 0000000..de52696 --- /dev/null +++ b/feature/calendar/src/main/res/layout/layout_fragment_calendar.xml @@ -0,0 +1,304 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/feature/calendar/src/main/res/values/attrs.xml b/feature/calendar/src/main/res/values/attrs.xml new file mode 100644 index 0000000..d1089b4 --- /dev/null +++ b/feature/calendar/src/main/res/values/attrs.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/feature/calendar/src/main/res/values/colors.xml b/feature/calendar/src/main/res/values/colors.xml new file mode 100644 index 0000000..11b5b8d --- /dev/null +++ b/feature/calendar/src/main/res/values/colors.xml @@ -0,0 +1,13 @@ + + + #FF000000 + #FFFFFFFF + #FFFF5E1A + #FFEDE5 + #f5f5f5 + #dcdcdc + #AAAAAA + #919191 + #2d2d2d + #BF0711 + diff --git a/feature/calendar/src/main/res/values/dimens.xml b/feature/calendar/src/main/res/values/dimens.xml new file mode 100644 index 0000000..520167f --- /dev/null +++ b/feature/calendar/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 12dp + 4dp + 24dp + diff --git a/feature/calendar/src/main/res/values/strings.xml b/feature/calendar/src/main/res/values/strings.xml new file mode 100644 index 0000000..0ae5fe4 --- /dev/null +++ b/feature/calendar/src/main/res/values/strings.xml @@ -0,0 +1,13 @@ + + + +추가하기 + 일정이 없습니다 + 오늘 + 일 + 월 + 화 + 수 + 목 + 금 + 토 + diff --git a/feature/calendar/src/main/res/values/themes.xml b/feature/calendar/src/main/res/values/themes.xml new file mode 100644 index 0000000..8d1c1be --- /dev/null +++ b/feature/calendar/src/main/res/values/themes.xml @@ -0,0 +1,4 @@ + + +