Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issues generated #80

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ android {
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Expand All @@ -56,7 +55,6 @@ dependencies {
implementation("androidx.compose.material3:material3:1.0.0-alpha15")
implementation("androidx.navigation:navigation-compose:2.5.1")
// jetpack compose
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5") // <- this dependency is required
implementation(Deps.Compose.ui)
implementation(Deps.Compose.material)
implementation(Deps.Compose.activity)
Expand Down
22 changes: 15 additions & 7 deletions app/src/main/java/com/himanshoe/sample/demo/KalendarDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ fun KalendarDemo() {
Kalendar(
kalendarType = KalendarType.Oceanic,
kalendarEvents = listOf(
KalendarEvent(LocalDate(2022, 8, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 8, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 8, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 8, 28), "Anniversary"),
KalendarEvent(LocalDate(2022, 8, 28), "Party"),
KalendarEvent(LocalDate(2022, 8, 29), "Club"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 28), "Anniversary"),
KalendarEvent(LocalDate(2022, 10, 28), "Party"),
KalendarEvent(LocalDate(2022, 10, 29), "Club"),
)
)
Text(
Expand All @@ -46,7 +46,15 @@ fun KalendarDemo() {
)
Kalendar(
kalendarType = KalendarType.Firey,
modifier = Modifier.padding(16.dp)
modifier = Modifier.padding(16.dp),
kalendarEvents = listOf(
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 28), "Party"),
KalendarEvent(LocalDate(2022, 10, 29), "Club"),
)
)
Text(
text = "Kalendar Firey Type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.himanshoe.kalendar.endlos.Kalendar
import com.himanshoe.kalendar.endlos.model.KalendarEvent
import kotlinx.datetime.Clock
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.plus
import kotlinx.datetime.todayIn
Expand All @@ -20,9 +21,12 @@ fun KalendarEndlossDemo() {
Kalendar(
Modifier.background(Color.White),
kalendarEvents = listOf(
KalendarEvent(oneWeekFromNow, "Himanshu"),
KalendarEvent(oneWeekFromNow, "Himanshu"),
KalendarEvent(oneWeekFromNow, "Himanshu")
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 25), "Birthday"),
KalendarEvent(LocalDate(2022, 10, 28), "Anniversary"),
KalendarEvent(LocalDate(2022, 10, 28), "Party"),
KalendarEvent(LocalDate(2022, 10, 29), "Club"),
)
)
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package com.himanshoe.kalendar.endlos

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.items
import com.himanshoe.kalendar.endlos.color.KalendarColors
import com.himanshoe.kalendar.endlos.color.KalendarThemeColor
import com.himanshoe.kalendar.endlos.component.day.config.KalendarDayColors
import com.himanshoe.kalendar.endlos.component.day.config.KalendarDayDefaultColors
import com.himanshoe.kalendar.endlos.model.KalendarDay
import com.himanshoe.kalendar.endlos.model.KalendarEvent
import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn

@Composable
fun Kalendar(
Expand Down Expand Up @@ -61,41 +48,3 @@ fun Kalendar(
kalendarThemeColors = listOf(kalendarThemeColor),
)
}

@Composable
private fun KalendarEndloss(
modifier: Modifier,
kalendarItems: LazyPagingItems<LocalDate>,
kalendarEvents: List<KalendarEvent>,
onCurrentDayClick: (KalendarDay, List<KalendarEvent>) -> Unit,
kalendarDayColors: KalendarDayColors,
kalendarThemeColors: List<KalendarThemeColor>
) {
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
val clickedDay = remember { mutableStateOf(today) }

LazyColumn(modifier = modifier.fillMaxWidth()) {
items(kalendarItems) { date: LocalDate? ->
if (date != null) {
val kalendarThemeColor = if (kalendarThemeColors.count() == 1) {
kalendarThemeColors.first()
} else kalendarThemeColors[date.monthNumber.minus(1)]

KalendarMonth(
date = date,
modifier = modifier
.padding(horizontal = 12.dp, vertical = 6.dp)
.background(kalendarThemeColor.backgroundColor),
kalendarEvents = kalendarEvents.filter { it.date.monthNumber == date.monthNumber },
onCurrentDayClick = { day, events ->
clickedDay.value = day.localDate
onCurrentDayClick(day, events)
},
kalendarDayColors = kalendarDayColors,
selectedDay = clickedDay.value,
kalendarThemeColors = kalendarThemeColor
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.himanshoe.kalendar.endlos

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.items
import com.himanshoe.kalendar.endlos.color.KalendarThemeColor
import com.himanshoe.kalendar.endlos.component.day.config.KalendarDayColors
import com.himanshoe.kalendar.endlos.model.KalendarDay
import com.himanshoe.kalendar.endlos.model.KalendarEvent
import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn

@Composable
internal fun KalendarEndloss(
modifier: Modifier,
kalendarItems: LazyPagingItems<LocalDate>,
kalendarEvents: List<KalendarEvent>,
onCurrentDayClick: (KalendarDay, List<KalendarEvent>) -> Unit,
kalendarDayColors: KalendarDayColors,
kalendarThemeColors: List<KalendarThemeColor>
) {
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
val clickedDay = remember { mutableStateOf(today) }

LazyColumn(modifier = modifier.fillMaxWidth()) {
items(kalendarItems) { date: LocalDate? ->
if (date != null) {
val kalendarThemeColor = if (kalendarThemeColors.count() == 1) {
kalendarThemeColors.first()
} else kalendarThemeColors[date.monthNumber.minus(1)]

KalendarMonth(
date = date,
modifier = modifier
.padding(horizontal = 12.dp, vertical = 6.dp)
.background(kalendarThemeColor.backgroundColor),
kalendarEvents = kalendarEvents.filter { it.date.monthNumber == date.monthNumber },
onCurrentDayClick = { day, events ->
clickedDay.value = day.localDate
onCurrentDayClick(day, events)
},
kalendarDayColors = kalendarDayColors,
selectedDay = clickedDay.value,
kalendarThemeColors = kalendarThemeColor
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import com.himanshoe.kalendar.endlos.component.text.KalendarNormalText
import com.himanshoe.kalendar.endlos.model.KalendarDay
import com.himanshoe.kalendar.endlos.model.KalendarEvent
import com.himanshoe.kalendar.endlos.model.toKalendarDay
import kotlinx.datetime.Clock
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import kotlinx.datetime.Month
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDate
import kotlinx.datetime.todayIn

private const val DaysInWeek = 7
private val WeekDays = listOf("M", "T", "W", "T", "F", "S", "S")
Expand All @@ -38,6 +41,7 @@ internal fun KalendarMonth(
kalendarDayColors: KalendarDayColors,
kalendarThemeColors: KalendarThemeColor,
) {
val currentDay = Clock.System.todayIn(TimeZone.currentSystemDefault())

Column(
modifier = modifier
Expand Down Expand Up @@ -75,6 +79,7 @@ internal fun KalendarMonth(
Row(horizontalArrangement = Arrangement.spacedBy(0.dp)) {
weekDays.forEach { localDate ->
if (localDate is LocalDate) {
val isCurrentDay = localDate == currentDay
KalendarDay(
modifier = Modifier,
size = size,
Expand All @@ -83,6 +88,7 @@ internal fun KalendarMonth(
onCurrentDayClick = onCurrentDayClick,
kalendarDayColors = kalendarDayColors,
selectedKalendarDay = selectedDay,
isCurrentDay = isCurrentDay,
dotColor = kalendarThemeColors.headerTextColor,
dayBackgroundColor = kalendarThemeColors.dayBackgroundColor
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ fun KalendarDay(
.align(Alignment.CenterHorizontally),
horizontalArrangement = Arrangement.Center
) {
if (kalendarEvents.isNotEmpty()) {
kalendarEvents.take(3).forEachIndexed { index, _ ->
val kalendarEventForDay = kalendarEvents.filter { it.date == kalendarDay.localDate }
if (kalendarEventForDay.isNotEmpty()) {
val dayEvents = if (kalendarEventForDay.count() > 3) kalendarEventForDay.take(3) else kalendarEventForDay
dayEvents.forEachIndexed { index, _ ->
KalendarDots(
modifier = Modifier,
index = index,
size = size,
color = dotColor
modifier = Modifier, index = index, size = size, color = dotColor
)
}
}
Expand Down
6 changes: 0 additions & 6 deletions kalendar/src/main/java/com/himanshoe/kalendar/Kalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.himanshoe.kalendar
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.himanshoe.kalendar.color.KalendarColors
import com.himanshoe.kalendar.color.KalendarThemeColor
import com.himanshoe.kalendar.component.day.config.KalendarDayColors
Expand Down Expand Up @@ -80,8 +79,3 @@ fun Kalendar(
}
}
}

@Composable
@Preview
private fun KalendarPreview() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ fun KalendarDay(
.align(Alignment.CenterHorizontally),
horizontalArrangement = Arrangement.Center
) {
if (kalendarEvents.isNotEmpty()) {
kalendarEvents.take(3).forEachIndexed { index, _ ->
val kalendarEventForDay = kalendarEvents.filter { it.date == kalendarDay.localDate }
if (kalendarEventForDay.isNotEmpty()) {
val dayEvents = if (kalendarEventForDay.count() > 3) kalendarEventForDay.take(3) else kalendarEventForDay
dayEvents.forEachIndexed { index, _ ->
KalendarDots(
modifier = Modifier,
index = index,
size = size,
color = dotColor
modifier = Modifier, index = index, size = size, color = dotColor
)
}
}
Expand All @@ -106,8 +105,7 @@ fun KalendarDots(
.padding(horizontal = 1.dp)
.clip(shape = CircleShape)
.background(
color = color
.copy(alpha = index.plus(1) * 0.3F)
color = color.copy(alpha = index.plus(1) * 0.3F)
)
.size(size = size.div(12))
)
Expand All @@ -119,11 +117,10 @@ private fun getKalendarDayState(selectedDate: LocalDate, currentDay: LocalDate)
else -> KalendarDayState.KalendarDayDefault
}

private fun getBorder(isCurrentDay: Boolean) =
BorderStroke(
width = if (isCurrentDay) 1.dp else 0.dp,
color = if (isCurrentDay) Color.Black else Color.Transparent,
)
private fun getBorder(isCurrentDay: Boolean) = BorderStroke(
width = if (isCurrentDay) 1.dp else 0.dp,
color = if (isCurrentDay) Color.Black else Color.Transparent,
)

private fun getTextWeight(kalendarDayState: KalendarDayState) =
if (kalendarDayState is KalendarDayState.KalendarDaySelected) {
Expand All @@ -141,14 +138,6 @@ private fun getBackgroundColor(
Color.Transparent
}

private fun getTextSelectionShape(
kalendarDayState: KalendarDayState,
) = if (kalendarDayState is KalendarDayState.KalendarDaySelected) {
CircleShape
} else {
CircleShape
}

private fun getTextColor(
kalendarDayState: KalendarDayState,
kalendarDayColors: KalendarDayColors,
Expand Down
Loading