aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt33
1 files changed, 33 insertions, 0 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 dfc0493..9131728 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
@@ -5,7 +5,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.PopupMenu
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 org.koin.androidx.viewmodel.ext.android.viewModel
@@ -48,6 +50,9 @@ class UnitReportsFragment : Fragment() {
else -> UnitReportsViewModel.ReportType.STOPS
}
}
+ binding.periodButton.setOnClickListener {
+ showPeriodPopUp(it)
+ }
unitReportsViewModel.reportPeriod.value = UnitReportsViewModel.ReportPeriod.DAY
unitReportsViewModel.reportType.value = UnitReportsViewModel.ReportType.POSITIONS
}
@@ -56,5 +61,33 @@ class UnitReportsFragment : Fragment() {
unitReportsViewModel.report.observe(this) { report ->
Log.d("UnitReportsFragment", "Report available: $report")
}
+ unitReportsViewModel.reportPeriod.observe(this) { period ->
+ Log.d("UnitReportsFragment", "Period changed: $period")
+ if (period == null) {
+ return@observe
+ }
+
+ binding.periodButton.text = context?.getString(
+ when (period) {
+ UnitReportsViewModel.ReportPeriod.DAY -> R.string.day_period
+ UnitReportsViewModel.ReportPeriod.WEEK -> R.string.week_period
+ UnitReportsViewModel.ReportPeriod.MONTH -> R.string.month_period
+ }
+ )
+ }
+ }
+
+ private fun showPeriodPopUp(view: View) {
+ val popOver = PopupMenu(context, view)
+ popOver.menuInflater.inflate(R.menu.report_period_options, popOver.menu)
+ popOver.setOnMenuItemClickListener { item ->
+ unitReportsViewModel.reportPeriod.value = when (item.itemId) {
+ R.id.dayOption -> UnitReportsViewModel.ReportPeriod.DAY
+ R.id.weekOption -> UnitReportsViewModel.ReportPeriod.WEEK
+ else -> UnitReportsViewModel.ReportPeriod.MONTH
+ }
+ true
+ }
+ popOver.show()
}
} \ No newline at end of file