Skip to content

Commit 4f30f14

Browse files
committed
(Calendar] Improve design when timeline is disabled #18
1 parent 293b321 commit 4f30f14

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

calendar/src/main/java/com/maxkeppeler/sheets/calendar/models/CalendarDateData.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.time.LocalDate
2121
* Defines all calculated information for a specific date.
2222
* @param date The current date that the view represents.
2323
* @param disabled Whenever the date is disabled.
24+
* @param disabledTimeline Whenever the date is falling into a disabled time line.
2425
* @param selected Whenever the date is selected in a single or multiple date selection.
2526
* @param selectedBetween Whenever the date is within a range selection.
2627
* @param selectedStart Whenever the date is the start of a range selection.
@@ -30,6 +31,7 @@ import java.time.LocalDate
3031
internal data class CalendarDateData(
3132
val date: LocalDate? = null,
3233
val disabled: Boolean = false,
34+
val disabledTimeline: Boolean = false,
3335
val selected: Boolean = false,
3436
val selectedBetween: Boolean = false,
3537
val selectedStart: Boolean = false,

calendar/src/main/java/com/maxkeppeler/sheets/calendar/utils/Constants.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ internal object Constants {
4040

4141
internal const val YEAR_GRID_COLUMNS = 1
4242
internal const val MONTH_GRID_COLUMNS = 4
43+
44+
internal const val DATE_ITEM_DISABLED_TIMELINE_OPACITY = 0.3f
45+
internal const val DATE_ITEM_OPACITY = 1f
4346
}

calendar/src/main/java/com/maxkeppeler/sheets/calendar/utils/Utils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ internal fun calcCalendarDateData(
255255
}
256256
}
257257

258-
val otherMonth = config.disabledTimeline?.let { timeline ->
258+
val disabledTimeline = config.disabledTimeline?.let { timeline ->
259259
when (timeline) {
260260
CalendarTimeline.PAST -> date.isBefore(today)
261261
CalendarTimeline.FUTURE -> date.isAfter(today)
@@ -266,11 +266,11 @@ internal fun calcCalendarDateData(
266266
return CalendarDateData(
267267
date = date,
268268
disabled = disabled,
269+
disabledTimeline = disabledTimeline,
269270
selected = selected,
270271
selectedBetween = selectedBetween,
271272
selectedStart = selectedStartInit,
272273
selectedEnd = selectedEnd,
273-
otherMonth = otherMonth
274274
)
275275
}
276276

calendar/src/main/java/com/maxkeppeler/sheets/calendar/views/CalendarDateItemComponent.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import androidx.compose.material3.Text
2525
import androidx.compose.runtime.Composable
2626
import androidx.compose.ui.Alignment
2727
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.draw.alpha
2829
import androidx.compose.ui.draw.clip
2930
import androidx.compose.ui.res.dimensionResource
3031
import androidx.compose.ui.text.style.TextAlign
3132
import androidx.compose.ui.unit.dp
3233
import com.maxkeppeler.sheets.calendar.models.CalendarDateData
3334
import com.maxkeppeler.sheets.calendar.models.CalendarSelection
35+
import com.maxkeppeler.sheets.calendar.utils.Constants
3436
import java.time.LocalDate
3537
import java.time.format.DateTimeFormatter
3638
import com.maxkeppeler.sheets.core.R as RC
@@ -104,20 +106,27 @@ internal fun CalendarDateItemComponent(
104106
}
105107

106108
val cellModifier = when {
107-
data.otherMonth -> otherMonthModifier
109+
data.otherMonth || data.disabledTimeline -> otherMonthModifier
108110
data.disabled -> disabledModifier
109111
data.selected -> selectedModifier
110112
else -> normalModifier
111113
}
112114

115+
val textAlpha = when {
116+
data.disabledTimeline -> Constants.DATE_ITEM_DISABLED_TIMELINE_OPACITY
117+
else -> Constants.DATE_ITEM_OPACITY
118+
}
119+
113120
Column(modifier = parentModifier) {
114121
Row(
115122
modifier = cellModifier,
116123
verticalAlignment = Alignment.CenterVertically,
117124
horizontalArrangement = Arrangement.Center
118125
) {
119126
Text(
120-
modifier = Modifier.weight(1f),
127+
modifier = Modifier
128+
.weight(1f)
129+
.alpha(textAlpha),
121130
text = data.date?.format(DateTimeFormatter.ofPattern("d"))
122131
?.takeUnless { data.otherMonth } ?: "",
123132
style = textStyle,

0 commit comments

Comments
 (0)