aboutsummaryrefslogtreecommitdiff
path: root/androidApp
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
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')
-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
-rw-r--r--androidApp/src/main/res/layout/unit_details_reports.xml7
-rw-r--r--androidApp/src/main/res/values-es-rMX/strings.xml1
-rw-r--r--androidApp/src/main/res/values/strings.xml1
5 files changed, 85 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
diff --git a/androidApp/src/main/res/layout/unit_details_reports.xml b/androidApp/src/main/res/layout/unit_details_reports.xml
index dc649e4..0a8e23d 100644
--- a/androidApp/src/main/res/layout/unit_details_reports.xml
+++ b/androidApp/src/main/res/layout/unit_details_reports.xml
@@ -102,10 +102,17 @@
android:id="@+id/periodButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_marginEnd="@dimen/fields_spacing"
android:text="@string/select_period"
android:textColor="@color/colorPrimaryDark"
app:backgroundTint="@color/darkBackground" />
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/exportButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/export_report" />
+
</LinearLayout>
<com.addisonelliott.segmentedbutton.SegmentedButtonGroup
diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml
index 6aee861..0b4f4b3 100644
--- a/androidApp/src/main/res/values-es-rMX/strings.xml
+++ b/androidApp/src/main/res/values-es-rMX/strings.xml
@@ -81,6 +81,7 @@
<string name="month_period">Mes</string>
<string name="period">Periodo</string>
<string name="select_period">Seleccionar</string>
+ <string name="export_report">Exportar</string>
<string name="table_event">Evento</string>
<string name="table_datetime">Fecha y hora</string>
diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml
index 5f39ce1..268f5d5 100644
--- a/androidApp/src/main/res/values/strings.xml
+++ b/androidApp/src/main/res/values/strings.xml
@@ -102,6 +102,7 @@
<string name="month_period">Month</string>
<string name="period">Period</string>
<string name="select_period">Select</string>
+ <string name="export_report">Export</string>
<string name="table_event">Event</string>
<string name="table_datetime">Datetime</string>