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

Removed Oreo requirement for components #15

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
small changes
  • Loading branch information
Alessandro Sperotti committed Dec 15, 2022
commit 7231b9d9c251e4df6c2f398cf5732ac87975d0b5
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.commandiron.wheelpickercompose"
minSdk 21
minSdk 23
targetSdk 33
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion wheel-picker-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdk 33

defaultConfig {
minSdk 21
minSdk 23
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data class CompatTime(val hour: Int, val minute: Int) {
data class CompatDate(val dayOfMonth: Int, val month: Int, val year: Int) {
@RequiresApi(Build.VERSION_CODES.O)
fun toLocalDate(): LocalDate =
LocalDate.of(dayOfMonth, month, year)
LocalDate.of(year, month, dayOfMonth)

fun toCalendarDate(): Calendar =
Calendar.getInstance().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import java.text.DateFormatSymbols
import java.time.LocalDate
import java.util.Calendar
import java.util.GregorianCalendar

@Composable
internal fun DefaultWheelDatePicker(
Expand Down Expand Up @@ -237,10 +239,16 @@ private data class Year(
val index: Int
)

@RequiresApi(Build.VERSION_CODES.O)
internal fun calculateDayOfMonths(month: Int, year: Int): List<DayOfMonth> {

val isLeapYear = LocalDate.of(year, month, 1).isLeapYear
val isLeapYear = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LocalDate.of(year, month, 1).isLeapYear
} else {
//REMIND: Check if this makes sense. would casting to GregorianCalendar work anytime?
(Calendar.getInstance().apply {
set(year, month, 1)
} as? GregorianCalendar)?.isLeapYear(year) ?: false
}

val month31day = (1..31).map {
DayOfMonth(
Expand Down Expand Up @@ -272,44 +280,18 @@ internal fun calculateDayOfMonths(month: Int, year: Int): List<DayOfMonth> {
}

return when (month) {
1 -> {
month31day
}
2 -> {
if (isLeapYear) month29day else month28day
}
3 -> {
month31day
}
4 -> {
month30day
}
5 -> {
month31day
}
6 -> {
month30day
}
7 -> {
month31day
}
8 -> {
month31day
}
9 -> {
month30day
}
10 -> {
month31day
}
11 -> {
month30day
}
12 -> {
month31day
}
else -> {
emptyList()
}
1 -> { month31day }
2 -> { if (isLeapYear) month29day else month28day }
3 -> { month31day }
4 -> { month30day }
5 -> { month31day }
6 -> { month30day }
7 -> { month31day }
8 -> { month31day }
9 -> { month30day }
10 -> { month31day }
11 -> { month30day }
12 -> { month31day }
else -> { emptyList() }
}
}