aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt7
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt9
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt21
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt3
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt3
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt1
-rw-r--r--androidApp/src/main/res/layout/unit_details_commands.xml60
-rw-r--r--androidApp/src/main/res/values-es-rMX/strings.xml7
-rw-r--r--androidApp/src/main/res/values/strings.xml9
9 files changed, 95 insertions, 25 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
index 2c20c70..f66a760 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
@@ -9,19 +9,23 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
+import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding
import mx.trackermap.TrackerMap.android.devices.Action
+@DelicateCoroutinesApi
class DetailsActivity : AppCompatActivity() {
private var _binding: DetailsActivityBinding? = null
private val binding get() = _binding!!
private lateinit var adapter: UnitDetailsAdapter
private var deviceId: Int = 0
+ private var deviceName: String = ""
companion object {
const val DEVICE_ID_EXTRA = "device_id"
+ const val DEVICE_NAME_EXTRA = "device_name"
const val ACTION_EXTRA = "action"
}
@@ -42,11 +46,12 @@ class DetailsActivity : AppCompatActivity() {
private fun initialize() {
deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0)
+ deviceName = intent.getStringExtra(DEVICE_NAME_EXTRA) ?: ""
val initialSection = intent.getSerializableExtra(ACTION_EXTRA) as Action
Log.d("DetailsActivity", "Device ID - $deviceId")
Log.d("DetailsActivity", "Initial Section - $initialSection")
- adapter = UnitDetailsAdapter(this, deviceId)
+ adapter = UnitDetailsAdapter(this, deviceId, deviceName)
binding.detailsPager.adapter = adapter
TabLayoutMediator(binding.detailsTabs, binding.detailsPager) { tab, position ->
tab.text = when (position) {
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt
index df13b51..aed2bd5 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt
@@ -4,17 +4,21 @@ import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
+import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.details.commands.UnitCommandsFragment
import mx.trackermap.TrackerMap.android.details.information.UnitInformationFragment
import mx.trackermap.TrackerMap.android.details.reports.UnitReportsFragment
+@DelicateCoroutinesApi
class UnitDetailsAdapter(
activity: FragmentActivity,
- private val deviceId: Int
+ private val deviceId: Int,
+ private val deviceName: String,
) : FragmentStateAdapter(activity) {
companion object {
- val DEVICE_ID_ARG = "device_id"
+ const val DEVICE_ID_ARG = "device_id"
+ const val DEVICE_NAME_ARG = "device_name"
}
override fun getItemCount(): Int = 3
@@ -27,6 +31,7 @@ class UnitDetailsAdapter(
}
fragment.arguments = Bundle().apply {
putInt(DEVICE_ID_ARG, deviceId)
+ putString(DEVICE_NAME_ARG, deviceName)
}
return fragment
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt
index b0aab3e..90968e2 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
+import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
@@ -18,6 +19,8 @@ class UnitCommandsFragment: Fragment() {
private var _binding: UnitDetailsCommandsBinding? = null
private val binding get() = _binding!!
+ private var deviceName: String? = null
+
private val unitCommandsViewModel: UnitCommandsViewModel by viewModel()
override fun onCreateView(
@@ -51,16 +54,32 @@ class UnitCommandsFragment: Fragment() {
}
val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
+ deviceName = arguments?.getString(UnitDetailsAdapter.DEVICE_NAME_ARG)
+ binding.nameDetail.text = deviceName
unitCommandsViewModel.fetchCommands(id)
}
private fun setupEvents() {
binding.commandsList.setOnItemClickListener { _, _, index, _ ->
Log.d("UnitCommandsFragment", "Selected item at index - $index")
+ binding.sendCommandButton.isEnabled = true
unitCommandsViewModel.selectCommand(index)
}
binding.sendCommandButton.setOnClickListener {
- unitCommandsViewModel.sendCommand()
+ activity?.let {
+ val builder = AlertDialog.Builder(it)
+ builder.apply {
+ setMessage(getString(R.string.send_command_confirmation_text, deviceName))
+ setPositiveButton(R.string.shared_cancel) { dialogInterface, _ ->
+ dialogInterface.dismiss()
+ }
+ setNegativeButton(R.string.send_command) { dialogInterface, _ ->
+ unitCommandsViewModel.sendCommand()
+ dialogInterface.dismiss()
+ }
+ }
+ builder.create().show()
+ }
}
}
} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt
index dd8e202..232b6e9 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt
@@ -62,7 +62,9 @@ class UnitInformationFragment : Fragment() {
private fun fetchInformation() {
val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
+ val name = arguments?.getString(UnitDetailsAdapter.DEVICE_NAME_ARG)
unitInformationViewModel.fetchUnit(id ?: 0)
+ binding.nameDetail.text = name
binding.reportLoading.visibility = View.VISIBLE
}
@@ -96,7 +98,6 @@ class UnitInformationFragment : Fragment() {
details.add(getString(R.string.unit_info_protocol) to protocol)
}
- binding.nameDetail.text = unit.device.name
details.forEach { entry ->
val layout = LinearLayout(context)
layout.orientation = LinearLayout.VERTICAL
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
index 6bee413..3b44477 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
@@ -6,7 +6,6 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.DevicesFragmentBinding
@@ -14,7 +13,6 @@ import mx.trackermap.TrackerMap.android.details.DetailsActivity
import mx.trackermap.TrackerMap.android.units.UnitFragment
import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.models.UnitInformation
-import org.koin.androidx.viewmodel.ext.android.viewModel
@DelicateCoroutinesApi
class DevicesFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment(unitsViewModel) {
@@ -87,6 +85,7 @@ class DevicesFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
val activity = requireActivity()
val intent = Intent(activity.applicationContext, DetailsActivity::class.java)
intent.putExtra(DetailsActivity.DEVICE_ID_EXTRA, unit.device.id)
+ intent.putExtra(DetailsActivity.DEVICE_NAME_EXTRA, unit.device.name)
intent.putExtra(DetailsActivity.ACTION_EXTRA, action)
startActivity(intent)
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
index f79f8bd..09f41a8 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
@@ -119,6 +119,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
val activity = requireActivity()
val intent = Intent(activity.applicationContext, DetailsActivity::class.java)
intent.putExtra(DetailsActivity.DEVICE_ID_EXTRA, unit.device.id)
+ intent.putExtra(DetailsActivity.DEVICE_NAME_EXTRA, unit.device.name)
intent.putExtra(DetailsActivity.ACTION_EXTRA, action)
startActivity(intent)
}
diff --git a/androidApp/src/main/res/layout/unit_details_commands.xml b/androidApp/src/main/res/layout/unit_details_commands.xml
index 6e1d7b2..6b554cc 100644
--- a/androidApp/src/main/res/layout/unit_details_commands.xml
+++ b/androidApp/src/main/res/layout/unit_details_commands.xml
@@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -12,29 +13,56 @@
app:cardCornerRadius="@dimen/card_border_radius"
app:cardElevation="@dimen/card_elevation"
app:cardUseCompatPadding="true"
- app:layout_constraintBottom_toTopOf="@id/sendCommandButton"
+ app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
- <ListView
- android:id="@+id/commandsList"
+ <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:choiceMode="singleChoice"
- android:listSelector="@color/darkBackground" />
+ android:orientation="vertical">
- </com.google.android.material.card.MaterialCardView>
+ <TextView
+ android:id="@+id/nameDetail"
+ style="@style/TextAppearance.AppCompat.Headline"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:layout_margin="@dimen/card_padding"
+ android:layout_marginBottom="@dimen/margin"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toTopOf="@id/commandsList"
+ tools:text="1AAUTO" />
- <com.google.android.material.button.MaterialButton
- android:id="@+id/sendCommandButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/margin"
- android:text="@string/send_command"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@id/commandsCard" />
+ <ListView
+ android:id="@+id/commandsList"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:choiceMode="singleChoice"
+ android:listSelector="@color/darkBackground"
+ app:layout_constraintTop_toBottomOf="@id/nameDetail"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toTopOf="@id/sendCommandButton" />
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/sendCommandButton"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/margin"
+ android:text="@string/send_command"
+ android:enabled="false"
+ app:layout_constraintTop_toBottomOf="@id/commandsList"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ />
+
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
+ </com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml
index 0b4f4b3..1916f26 100644
--- a/androidApp/src/main/res/values-es-rMX/strings.xml
+++ b/androidApp/src/main/res/values-es-rMX/strings.xml
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">TrackerMap</string>
+ <!-- Shared strings -->
+ <string name="shared_ok">OK</string>
+ <string name="shared_cancel">Cancel</string>
<!-- LoginActivity -->
<string name="login_username">Nombre de usuario</string>
@@ -71,6 +73,9 @@
<!-- Commands -->
<string name="send_command">Enviar comando</string>
+ <string name="send_command_confirmation_text">
+ ¿Está seguro de que desea enviar el comando a la unidad %1$s?
+ </string>
<!-- Reports -->
<string name="positions">Posiciones</string>
diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml
index 268f5d5..e3a31e0 100644
--- a/androidApp/src/main/res/values/strings.xml
+++ b/androidApp/src/main/res/values/strings.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">TrackerMap</string>
+ <string name="app_name" translatable="false">TrackerMap</string>
<!-- Non translatable -->
<string name="app_website_url" translatable="false">https://trackermap.mx/</string>
@@ -23,6 +23,10 @@
<string name="notification_channel_id" translatable="false">default</string>
<string name="notification_channel" translatable="false">Default</string>
+ <!-- Shared strings -->
+ <string name="shared_ok">OK</string>
+ <string name="shared_cancel">Cancel</string>
+
<!-- LoginActivity -->
<string name="login_username">Username</string>
<string name="login_password">Password</string>
@@ -92,6 +96,9 @@
<!-- Commands -->
<string name="send_command">Send Command</string>
+ <string name="send_command_confirmation_text">
+ Are you sure you want to send the command to device %1$s?
+ </string>
<!-- Reports -->
<string name="positions">Positions</string>