aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-12-26 22:44:08 -0600
committerIván Ávalos <avalos@disroot.org>2022-12-26 22:44:08 -0600
commited2b673141dc9983386b47cd0112c7a2f3493083 (patch)
tree7e570596e40cca0c263fd97ace3120820401c566 /androidApp
parent1c7fb261d89251340c0b2f44d85fea7180df7f05 (diff)
parent808fc8d4a121e7658821fc2956bf0c540cbc113f (diff)
downloadetbsa-trackermap-mobile-ed2b673141dc9983386b47cd0112c7a2f3493083.tar.gz
etbsa-trackermap-mobile-ed2b673141dc9983386b47cd0112c7a2f3493083.tar.bz2
etbsa-trackermap-mobile-ed2b673141dc9983386b47cd0112c7a2f3493083.zip
Merge branch 'main' of https://git.sr.ht/~avalos/trackermap-mobile
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/build.gradle.kts2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt22
2 files changed, 22 insertions, 2 deletions
diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts
index 655676e..efab132 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)