diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-16 18:56:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-16 18:56:00 -0600 |
commit | 62bd831586fee041a830366c97b07d2cdb52a1b6 (patch) | |
tree | a6a2fe6af07009dea1bc5f4b8351e696e719f208 /androidApp/src/main/java | |
parent | f133dc96d4072c3bf4f9794b000b1e0ab946f96b (diff) | |
download | etbsa-trackermap-mobile-62bd831586fee041a830366c97b07d2cdb52a1b6.tar.gz etbsa-trackermap-mobile-62bd831586fee041a830366c97b07d2cdb52a1b6.tar.bz2 etbsa-trackermap-mobile-62bd831586fee041a830366c97b07d2cdb52a1b6.zip |
Added device category icon to unit information and commands views
Diffstat (limited to 'androidApp/src/main/java')
6 files changed, 39 insertions, 1 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 c6d260b..7fd1203 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 @@ -22,10 +22,12 @@ class DetailsActivity : AppCompatActivity() { private lateinit var adapter: UnitDetailsAdapter private var deviceId: Int = 0 private var deviceName: String = "" + private var deviceCategory: String = "" companion object { const val DEVICE_ID_EXTRA = "device_id" const val DEVICE_NAME_EXTRA = "device_name" + const val DEVICE_CATEGORY_EXTRA = "device_category" const val ACTION_EXTRA = "action" } @@ -47,11 +49,12 @@ class DetailsActivity : AppCompatActivity() { private fun initialize() { deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0) deviceName = intent.getStringExtra(DEVICE_NAME_EXTRA) ?: "" + deviceCategory = intent.getStringExtra(DEVICE_CATEGORY_EXTRA) ?: "default" val initialSection = intent.getSerializableExtra(ACTION_EXTRA) as UnitRenderData.Action Log.d("DetailsActivity", "Device ID - $deviceId") Log.d("DetailsActivity", "Initial Section - $initialSection") - adapter = UnitDetailsAdapter(this, deviceId, deviceName) + adapter = UnitDetailsAdapter(this, deviceId, deviceName, deviceCategory) 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 aed2bd5..8987af1 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 @@ -14,11 +14,13 @@ class UnitDetailsAdapter( activity: FragmentActivity, private val deviceId: Int, private val deviceName: String, + private val deviceCategory: String ) : FragmentStateAdapter(activity) { companion object { const val DEVICE_ID_ARG = "device_id" const val DEVICE_NAME_ARG = "device_name" + const val DEVICE_CATEGORY_ARG = "device_category" } override fun getItemCount(): Int = 3 @@ -32,6 +34,7 @@ class UnitDetailsAdapter( fragment.arguments = Bundle().apply { putInt(DEVICE_ID_ARG, deviceId) putString(DEVICE_NAME_ARG, deviceName) + putString(DEVICE_CATEGORY_ARG, deviceCategory) } 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 822d351..5fc9d7c 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 @@ -7,11 +7,13 @@ import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import androidx.appcompat.app.AlertDialog +import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsCommandsBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter +import mx.trackermap.TrackerMap.android.shared.MarkerTransformations import org.koin.androidx.viewmodel.ext.android.viewModel @DelicateCoroutinesApi @@ -20,6 +22,7 @@ class UnitCommandsFragment: Fragment() { private val binding get() = _binding!! private var deviceName: String? = null + private var deviceCategory: String? = null private val unitCommandsViewModel: UnitCommandsViewModel by viewModel() @@ -57,7 +60,20 @@ class UnitCommandsFragment: Fragment() { val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) deviceName = arguments?.getString(UnitDetailsAdapter.DEVICE_NAME_ARG) + deviceCategory = arguments?.getString(UnitDetailsAdapter.DEVICE_CATEGORY_ARG) + binding.nameDetail.text = deviceName + context?.let { + binding.nameDetail.setCompoundDrawablesRelativeWithIntrinsicBounds( + ResourcesCompat.getDrawable( + it.resources, + MarkerTransformations.categoryToResourceId(deviceCategory), + it.theme + ), null, null, null + ) + } + binding.nameDetail.compoundDrawablePadding = + resources.getDimensionPixelSize(R.dimen.card_icon_margin) unitCommandsViewModel.fetchCommands(id) } 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 6c15ae4..e448b0b 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 @@ -9,6 +9,7 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView +import androidx.core.content.res.ResourcesCompat import androidx.core.widget.TextViewCompat import androidx.fragment.app.Fragment import com.google.android.material.button.MaterialButton @@ -17,6 +18,7 @@ import kotlinx.serialization.json.longOrNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter +import mx.trackermap.TrackerMap.android.shared.MarkerTransformations import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Formatter import mx.trackermap.TrackerMap.utils.SpeedUnit @@ -64,8 +66,20 @@ class UnitInformationFragment : Fragment() { private fun fetchInformation() { val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) val name = arguments?.getString(UnitDetailsAdapter.DEVICE_NAME_ARG) + val category = arguments?.getString(UnitDetailsAdapter.DEVICE_CATEGORY_ARG) unitInformationViewModel.fetchUnit(id ?: 0) binding.nameDetail.text = name + context?.let { + binding.nameDetail.setCompoundDrawablesRelativeWithIntrinsicBounds( + ResourcesCompat.getDrawable( + it.resources, + MarkerTransformations.categoryToResourceId(category), + it.theme + ), null, null, null + ) + } + binding.nameDetail.compoundDrawablePadding = + resources.getDimensionPixelSize(R.dimen.card_icon_margin) binding.reportLoading.root.visibility = View.VISIBLE } 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 b1a3663..923feab 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 @@ -91,6 +91,7 @@ class DevicesFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment 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.DEVICE_CATEGORY_EXTRA, unit.device.category) 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 6ea5f82..90ee36a 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 @@ -127,6 +127,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment 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.DEVICE_CATEGORY_EXTRA, unit.device.category) intent.putExtra(DetailsActivity.ACTION_EXTRA, action) startActivity(intent) } |