aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-12-26 22:30:23 -0600
committerIván Ávalos <avalos@disroot.org>2022-12-26 22:30:23 -0600
commit808fc8d4a121e7658821fc2956bf0c540cbc113f (patch)
treefa7f449790763b980fe5820ea56b234ba1da5ce9 /androidApp
parent3c9c065f8f8a9076230e203c8ffa4c8793844b6d (diff)
downloadetbsa-trackermap-mobile-808fc8d4a121e7658821fc2956bf0c540cbc113f.tar.gz
etbsa-trackermap-mobile-808fc8d4a121e7658821fc2956bf0c540cbc113f.tar.bz2
etbsa-trackermap-mobile-808fc8d4a121e7658821fc2956bf0c540cbc113f.zip
[android] Added LeakCanary as debug dependency and limit reports to one month to avoid crashes.
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 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)