aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-13 20:22:36 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-13 20:22:36 -0600
commit24bbcbb4a244f2e41c7ca3773ad1378ee422f55c (patch)
treefdf5444004231bf276054e9d513007d67f9ece77 /androidApp/src/main/java/mx
parent2417f926d9fb58bf99d5f4f7e6221390709e4899 (diff)
downloadetbsa-trackermap-mobile-24bbcbb4a244f2e41c7ca3773ad1378ee422f55c.tar.gz
etbsa-trackermap-mobile-24bbcbb4a244f2e41c7ca3773ad1378ee422f55c.tar.bz2
etbsa-trackermap-mobile-24bbcbb4a244f2e41c7ca3773ad1378ee422f55c.zip
Implemented base for exporting XLSX reports
Diffstat (limited to 'androidApp/src/main/java/mx')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt3
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt115
2 files changed, 76 insertions, 42 deletions
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 43f879d..2cb2d9a 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
@@ -78,6 +78,9 @@ class UnitReportsFragment : Fragment() {
binding.periodButton.setOnClickListener {
showPeriodPopUp(it)
}
+ binding.exportButton.setOnClickListener {
+ unitReportsViewModel.fetchReportXlsx()
+ }
unitReportsViewModel.setReportPeriod(UnitReportsViewModel.ReportPeriod.DAY)
unitReportsViewModel.setReportType(UnitReportsViewModel.ReportType.POSITIONS)
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
index 48486e1..851516e 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
@@ -112,7 +112,11 @@ class UnitReportsViewModel(
return Pair(currentDate, previousDate)
}
- private fun fetchReport() {
+ fun fetchReportXlsx() {
+ fetchReport(true)
+ }
+
+ private fun fetchReport(xlsx: Boolean = false) {
if (_reportType.value == null || _reportPeriod.value == null) {
return
}
@@ -126,64 +130,91 @@ class UnitReportsViewModel(
_report.postValue(Report.LoadingReport)
viewModelScope.launch {
when (_reportType.value!!) {
- ReportType.POSITIONS -> fetchPositions(previousDate, currentDate)
- ReportType.EVENTS -> fetchEvents(previousDate, currentDate)
- ReportType.STOPS -> fetchStops(previousDate, currentDate)
+ ReportType.POSITIONS -> fetchPositions(previousDate, currentDate, xlsx)
+ ReportType.EVENTS -> fetchEvents(previousDate, currentDate, xlsx)
+ ReportType.STOPS -> fetchStops(previousDate, currentDate, xlsx)
}
}
}
- private suspend fun fetchPositions(from: Date, to: Date) {
+ private suspend fun fetchPositions(from: Date, to: Date, xlsx: Boolean) {
Log.d("UnitReportsVM", "Fetching positions")
- val result = reportsApi.reportsRouteGet(
- dateFormat.format(from),
- dateFormat.format(to),
- _deviceId.value!!
- )
+ if (!xlsx) {
+ val result = reportsApi.reportsRouteGet(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+ Log.d("UnitReportsVM", "Positions report: $result")
+ _report.postValue(Report.PositionsReport(result))
+ } else {
+ val result = reportsApi.reportsRouteGetXlsx(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+ Log.d("UnitReportsVM", "Positions report: $result")
+ }
- Log.d("UnitReportsVM", "Positions report: $result")
- _report.postValue(Report.PositionsReport(result))
}
- private suspend fun fetchEvents(from: Date, to: Date) {
+ private suspend fun fetchEvents(from: Date, to: Date, xlsx: Boolean) {
Log.d("UnitReportsVM", "Fetching events")
- val positionsResult = reportsApi.reportsRouteGet(
- dateFormat.format(from),
- dateFormat.format(to),
- _deviceId.value!!
- )
-
- val eventsResult = reportsApi.reportsEventsGet(
- dateFormat.format(from),
- dateFormat.format(to),
- _deviceId.value!!
- )
-
- val result = mutableListOf<EventInformation>()
+ if (!xlsx) {
+ val positionsResult = reportsApi.reportsRouteGet(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+
+ val eventsResult = reportsApi.reportsEventsGet(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+
+ val result = mutableListOf<EventInformation>()
+
+ eventsResult.forEach { event ->
+ result.add(EventInformation(
+ event = event,
+ position = positionsResult.find { it.id == event.positionId }
+ ))
+ }
- eventsResult.forEach { event ->
- result.add(EventInformation(
- event = event,
- position = positionsResult.find { it.id == event.positionId }
- ))
+ Log.d("UnitReportsVM", "Events report: $result")
+ _report.postValue(Report.EventsReport(result.toTypedArray()))
+ } else {
+ val result = reportsApi.reportsEventsGetXlsx(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+ Log.d("UnitReportsVM", "Events report: $result")
}
-
- Log.d("UnitReportsVM", "Events report: $result")
- _report.postValue(Report.EventsReport(result.toTypedArray()))
}
- private suspend fun fetchStops(from: Date, to: Date) {
+ private suspend fun fetchStops(from: Date, to: Date, xlsx: Boolean) {
Log.d("UnitReportsVM", "Fetching stops")
- val result = reportsApi.reportsStopsGet(
- dateFormat.format(from),
- dateFormat.format(to),
- _deviceId.value!!
- )
+ if (!xlsx) {
+ val result = reportsApi.reportsStopsGet(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+ Log.d("UnitReportsVM", "Stops report: $result")
+ _report.postValue(Report.StopsReport(result))
+ } else {
+ val result = reportsApi.reportsStopsGetXlsx(
+ dateFormat.format(from),
+ dateFormat.format(to),
+ _deviceId.value!!
+ )
+ Log.d("UnitReportsVM", "Stops report: $result")
+ }
- Log.d("UnitReportsVM", "Stops report: $result")
- _report.postValue(Report.StopsReport(result))
}
} \ No newline at end of file