diff options
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/details')
5 files changed, 165 insertions, 2 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 c9769e4..3e8f00b 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 @@ -3,11 +3,16 @@ package mx.trackermap.TrackerMap.android.details import android.os.Bundle import android.util.Log import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.tabs.TabLayoutMediator import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding +import mx.trackermap.TrackerMap.android.devices.Action class DetailsActivity: AppCompatActivity() { private var _binding: DetailsActivityBinding? = null private val binding get() = _binding!! + private lateinit var adapter: UnitDetailsAdapter + private var deviceId: Int = 0 + private lateinit var initialSection: Action companion object { val DEVICE_ID_EXTRA = "device_id" @@ -20,8 +25,7 @@ class DetailsActivity: AppCompatActivity() { _binding = DetailsActivityBinding.inflate(layoutInflater) setContentView(binding.root) - Log.d("DetailsActivity", "Device ID - ${intent.getIntExtra(DEVICE_ID_EXTRA, 0)}") - Log.d("DetailsActivity", "Device ID - ${intent.getSerializableExtra(ACTION_EXTRA)}") + initialize() } override fun onDestroy() { @@ -29,4 +33,26 @@ class DetailsActivity: AppCompatActivity() { _binding = null } + + private fun initialize() { + deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0) + initialSection = intent.getSerializableExtra(ACTION_EXTRA) as Action + Log.d("DetailsActivity", "Device ID - $deviceId") + Log.d("DetailsActivity", "Initial Section - $initialSection") + + adapter = UnitDetailsAdapter(this, deviceId) + binding.detailsPager.adapter = adapter + TabLayoutMediator(binding.detailsTabs, binding.detailsPager) { tab, position -> + tab.text = when(position) { + 0 -> "Details" + 1 -> "Reports" + else -> "Commands" + } + }.attach() + binding.detailsPager.setCurrentItem(when(initialSection) { + Action.DETAILS -> 0 + Action.REPORTS -> 1 + else -> 2 + }, false) + } }
\ No newline at end of file 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 new file mode 100644 index 0000000..df13b51 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt @@ -0,0 +1,34 @@ +package mx.trackermap.TrackerMap.android.details + +import android.os.Bundle +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.viewpager2.adapter.FragmentStateAdapter +import mx.trackermap.TrackerMap.android.details.commands.UnitCommandsFragment +import mx.trackermap.TrackerMap.android.details.information.UnitInformationFragment +import mx.trackermap.TrackerMap.android.details.reports.UnitReportsFragment + +class UnitDetailsAdapter( + activity: FragmentActivity, + private val deviceId: Int +) : FragmentStateAdapter(activity) { + + companion object { + val DEVICE_ID_ARG = "device_id" + } + + override fun getItemCount(): Int = 3 + + override fun createFragment(position: Int): Fragment { + val fragment = when (position) { + 0 -> UnitInformationFragment() + 1 -> UnitReportsFragment() + else -> UnitCommandsFragment() + } + fragment.arguments = Bundle().apply { + putInt(DEVICE_ID_ARG, deviceId) + } + return fragment + } + +}
\ No newline at end of file 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 new file mode 100644 index 0000000..0391c16 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt @@ -0,0 +1,34 @@ +package mx.trackermap.TrackerMap.android.details.commands + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import mx.trackermap.TrackerMap.android.databinding.UnitDetailsCommandsBinding +import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter + +class UnitCommandsFragment: Fragment() { + private var _binding: UnitDetailsCommandsBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = UnitDetailsCommandsBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) + binding.unitCommandsText.text = "COMMANDS for ID - $id" + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +}
\ 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 new file mode 100644 index 0000000..3b8e7d5 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -0,0 +1,35 @@ +package mx.trackermap.TrackerMap.android.details.information + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding +import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter + +class UnitInformationFragment : Fragment() { + + private var _binding: UnitDetailsInformationBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = UnitDetailsInformationBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) + binding.unitInformationText.text = "INFORMATION for ID - $id" + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000..a2faec8 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -0,0 +1,34 @@ +package mx.trackermap.TrackerMap.android.details.reports + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding +import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter + +class UnitReportsFragment: Fragment() { + private var _binding: UnitDetailsReportsBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = UnitDetailsReportsBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) + binding.unitReportsText.text = "COMMANDS for ID - $id" + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +}
\ No newline at end of file |