The application I'm working on is related to the weekly calendar.
I want to fetch the days of the week. The code below for this is fully working. But I have to lower the API level of the project to 26 -> 24. Thus, some codes become inoperable at API 24 level.
How can I go about this in an alternative way?
My Code:
fun daysOfWeekFromLocale(): Array<DayOfWeek> {
val firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
var daysOfWeek = DayOfWeek.values()
if (firstDayOfWeek != DayOfWeek.MONDAY) {
val rhs = daysOfWeek.sliceArray(firstDayOfWeek.ordinal..daysOfWeek.indices.last)
val lhs = daysOfWeek.sliceArray(0 until firstDayOfWeek.ordinal)
daysOfWeek = rhs + lhs
}
return daysOfWeek
}
Android studio's Red Lines:
(In all cases this function should return the same value. -- Array< DayOfWeek > )