Skip to content

Commit

Permalink
simplify WidgetCalendar setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mvmike committed Sep 29, 2023
1 parent e9c80a8 commit ca65332
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import cat.mvmike.minimalcalendarwidget.domain.configuration.item.SymbolSet
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.TextSize
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Theme
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Transparency
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.getAvailableCalendars
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.getAvailableColors
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.getCalendarDisplayValues
import cat.mvmike.minimalcalendarwidget.domain.configuration.item.getColourDisplayValues
Expand Down Expand Up @@ -100,10 +99,8 @@ sealed class EnumConfigurationItem<E : Enum<E>>(
data object WidgetCalendar : EnumConfigurationItem<Calendar>(
key = "WIDGET_CALENDAR",
enumClass = Calendar::class.java,
defaultValue = getAvailableCalendars().first()
defaultValue = Calendar.GREGORIAN
) {
override fun getEnumConstants() = getAvailableCalendars()

override fun getDisplayValues(context: Context) = getCalendarDisplayValues(context)

override fun getCurrentDisplayValue(context: Context) = get(context).getDisplayValue(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ enum class Calendar(
.format(instant)
}

fun getAvailableCalendars() =
Calendar.values()

fun Calendar.getDisplayValue(context: Context) =
context.getString(displayString).replaceFirstChar { it.uppercase() }

fun getCalendarDisplayValues(context: Context) =
getAvailableCalendars()
Calendar.values()
.map { it.getDisplayValue(context) }
.toTypedArray()

0 comments on commit ca65332

Please sign in to comment.