aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-14 03:02:41 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-14 03:02:41 -0600
commit81a0b6689e94b8a10ebf68dccbb94a1f11507487 (patch)
tree211a24d64df149a1bc1587b19f2d65dedba012b5 /androidApp/src/main/java/mx/trackermap/TrackerMap/android/details
parent3692d0de20a85ef7e22a31aa9f842078fb774bbe (diff)
downloadetbsa-trackermap-mobile-81a0b6689e94b8a10ebf68dccbb94a1f11507487.tar.gz
etbsa-trackermap-mobile-81a0b6689e94b8a10ebf68dccbb94a1f11507487.tar.bz2
etbsa-trackermap-mobile-81a0b6689e94b8a10ebf68dccbb94a1f11507487.zip
Pass device name to details activity and redesigned commands fragment
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/details')
-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
4 files changed, 35 insertions, 5 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