aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java')
-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
6 files changed, 37 insertions, 7 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)
}