diff options
-rw-r--r-- | androidApp/build.gradle.kts | 2 | ||||
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt | 22 |
2 files changed, 22 insertions, 2 deletions
diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index a0a5abb..099d4a3 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -65,6 +65,8 @@ dependencies { implementation(group = "", name = "WhirlyGlobeMaply", ext = "aar") implementation("androidx.legacy:legacy-support-v4:1.0.0") + debugImplementation("com.squareup.leakcanary:leakcanary-android:2.10") + googleImplementation(platform("com.google.firebase:firebase-bom:29.0.3")) googleImplementation("com.google.firebase:firebase-messaging") } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index 6cc36bd..aab3cfa 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -38,7 +38,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.card.MaterialCardView import io.ktor.utils.io.* import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.* +import kotlinx.datetime.TimeZone import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter @@ -53,7 +54,9 @@ import org.koin.androidx.viewmodel.ext.android.viewModel import java.io.* import java.util.* import kotlin.math.max +import kotlin.time.DurationUnit import kotlin.time.ExperimentalTime +import kotlin.time.toDuration @DelicateCoroutinesApi @ExperimentalTime @@ -271,7 +274,22 @@ class UnitReportsFragment : Fragment() { p1, p2 ) (period as? ReportDates.ReportPeriod.Custom)?.let { - unitReportsViewModel.setReportPeriod(it.withFrom(fromPickedDatetime)) + val fromInstant = fromPickedDatetime.toInstant(TimeZone.currentSystemDefault()) + val toInstant = Calendar.getInstance().toInstant().toKotlinInstant() + val plusMonth = fromInstant.plus(31.toDuration(DurationUnit.DAYS)) + + /* Make ultra sure that user can't select a period longer than a month */ + unitReportsViewModel.setReportPeriod( + if (fromInstant.daysUntil(toInstant, TimeZone.currentSystemDefault()) > 31) { + it.withFrom(fromPickedDatetime).withTo( + plusMonth.toLocalDateTime(TimeZone.currentSystemDefault())) + } else { + it.withFrom(fromPickedDatetime) + } + ) + + toDatePicker.datePicker.minDate = fromInstant.toEpochMilliseconds() + toDatePicker.datePicker.maxDate = plusMonth.toEpochMilliseconds() } }, from.hour, from.minute, false) |