aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt48
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt6
-rw-r--r--androidApp/src/main/res/layout/unit_details_reports.xml56
-rw-r--r--androidApp/src/main/res/values/strings.xml2
4 files changed, 105 insertions, 7 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 9131728..9874a03 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
@@ -6,10 +6,15 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
+import android.widget.TableRow
+import android.widget.TextView
import androidx.fragment.app.Fragment
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding
import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
+import mx.trackermap.TrackerMap.client.models.Event
+import mx.trackermap.TrackerMap.client.models.Position
+import mx.trackermap.TrackerMap.client.models.Stop
import org.koin.androidx.viewmodel.ext.android.viewModel
class UnitReportsFragment : Fragment() {
@@ -60,7 +65,14 @@ class UnitReportsFragment : Fragment() {
private fun setupObservers() {
unitReportsViewModel.report.observe(this) { report ->
Log.d("UnitReportsFragment", "Report available: $report")
+
+ when (report) {
+ is UnitReportsViewModel.Report.PositionsReport -> display(report.positions)
+ is UnitReportsViewModel.Report.EventsReport -> display(report.events)
+ is UnitReportsViewModel.Report.StopsReport -> display(report.stops)
+ }
}
+
unitReportsViewModel.reportPeriod.observe(this) { period ->
Log.d("UnitReportsFragment", "Period changed: $period")
if (period == null) {
@@ -90,4 +102,40 @@ class UnitReportsFragment : Fragment() {
}
popOver.show()
}
+
+ private fun display(positions: Array<Position>) {
+ Log.d("UnitReportsFragment", "Displaying positions: $positions")
+
+ binding.eventsScroll.visibility = View.GONE
+ binding.reportMap.visibility = View.VISIBLE
+ }
+
+ private fun display(events: Array<Event>) {
+ Log.d("UnitReportsFragment", "Displaying events: $events")
+
+ binding.eventsScroll.visibility = View.VISIBLE
+ binding.reportMap.visibility = View.GONE
+ binding.eventsTable.removeViews(1, Math.max(0, binding.eventsTable.childCount - 1))
+
+ val context = context!!
+ events.forEach { event ->
+ val row = TableRow(context)
+ val eventText = TextView(context)
+ val datetimeText = TextView(context)
+
+ row.addView(eventText)
+ row.addView(datetimeText)
+ binding.eventsTable.addView(row)
+
+ eventText.text = event.type
+ datetimeText.text = event.eventTime
+ }
+ }
+
+ private fun display(stops: Array<Stop>) {
+ Log.d("UnitReportsFragment", "Displaying stops: $stops")
+
+ binding.eventsScroll.visibility = View.GONE
+ binding.reportMap.visibility = View.VISIBLE
+ }
} \ No newline at end of file
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 808bdda..35ef343 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
@@ -23,9 +23,9 @@ class UnitReportsViewModel(
) : ViewModel(), KoinComponent {
sealed class Report {
- class PositionsReport(positions: Array<Position>) : Report()
- class EventsReport(events: Array<Event>) : Report()
- class StopsReport(stops: Array<Stop>) : Report()
+ class PositionsReport(val positions: Array<Position>) : Report()
+ class EventsReport(val events: Array<Event>) : Report()
+ class StopsReport(val stops: Array<Stop>) : Report()
}
enum class ReportType {
diff --git a/androidApp/src/main/res/layout/unit_details_reports.xml b/androidApp/src/main/res/layout/unit_details_reports.xml
index d0c50e5..e39f279 100644
--- a/androidApp/src/main/res/layout/unit_details_reports.xml
+++ b/androidApp/src/main/res/layout/unit_details_reports.xml
@@ -5,14 +5,62 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+ <View
+ android:id="@+id/reportMap"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintBottom_toTopOf="@id/periodSection"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ android:layout_margin="@dimen/margin"
+ android:visibility="gone"
+ android:background="@color/darkBackground"/>
+
+ <ScrollView
+ android:id="@+id/eventsScroll"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintBottom_toTopOf="@id/periodSection"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ android:layout_margin="@dimen/margin"
+ android:visibility="gone">
+ <TableLayout
+ android:id="@+id/eventsTable"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:stretchColumns="*"
+ android:scrollbars="vertical"
+ android:isScrollContainer="true">
+
+ <TableRow android:background="@color/colorPrimary">
+
+ <TextView
+ android:paddingHorizontal="@dimen/padding"
+ android:text="@string/table_event"
+ android:textColor="@color/background" />
+
+ <TextView
+ android:paddingHorizontal="@dimen/padding"
+ android:text="@string/table_datetime"
+ android:textColor="@color/background" />
+
+ </TableRow>
+
+ </TableLayout>
+ </ScrollView>
+
<LinearLayout
+ android:id="@+id/periodSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_margin="@dimen/margin"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- android:layout_margin="@dimen/margin">
+ app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="match_parent"
@@ -23,10 +71,10 @@
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
+ android:gravity="center_vertical"
android:text="@string/period"
android:textColor="@color/colorPrimaryDark"
- android:textSize="22sp"
- android:gravity="center_vertical"/>
+ android:textSize="22sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/periodButton"
diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml
index 77a3048..7333a1e 100644
--- a/androidApp/src/main/res/values/strings.xml
+++ b/androidApp/src/main/res/values/strings.xml
@@ -39,4 +39,6 @@
<string name="month_period">Month</string>
<string name="period">Period</string>
<string name="select_period">Select</string>
+ <string name="table_event">Event</string>
+ <string name="table_datetime">Datetime</string>
</resources> \ No newline at end of file