diff options
8 files changed, 63 insertions, 25 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt index 72d61e3..4aa210d 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt @@ -4,11 +4,20 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitItemBinding import mx.trackermap.TrackerMap.client.models.UnitInformation -class DevicesAdapter(private val units: List<UnitInformation>) : - RecyclerView.Adapter<DevicesAdapter.ViewHolder>() { +enum class Action { + DETAILS, REPORTS, COMMANDS +} + +typealias ActionCallback = (unit: UnitInformation, action: Action) -> Unit + +class DevicesAdapter( + private val units: List<UnitInformation>, + private val actionCallback: ActionCallback? +) : RecyclerView.Adapter<DevicesAdapter.ViewHolder>() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val binding = UnitItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) @@ -26,6 +35,11 @@ class DevicesAdapter(private val units: List<UnitInformation>) : unitSpeed.text = "${unit.position?.speed ?: "--"} Km/h" lastAddress.text = unit.position?.address ?: "Unknown location" lastDate.text = "yyyy/mm/dd, hh:mm" + actionCallback?.let { callback -> + detailsButton.setOnClickListener { callback(unit, Action.DETAILS) } + reportsButton.setOnClickListener { callback(unit, Action.REPORTS) } + commandsButton.setOnClickListener { callback(unit, Action.COMMANDS) } + } } } @@ -38,9 +52,15 @@ class DevicesAdapter(private val units: List<UnitInformation>) : } } - fun toggleOptions(shouldShow: Boolean) { - binding.itemOptions.visibility = if (shouldShow) View.VISIBLE else View.GONE - binding.unitCard.cardElevation = if (shouldShow) 5.0F else 0.0F + fun toggleOptions(shouldExpand: Boolean) { + val context = binding.root.context + binding.unitCard.setCardBackgroundColor( + context + .resources + .getColor(if (shouldExpand) R.color.background else R.color.darkBackground) + ) + binding.itemOptions.visibility = if (shouldExpand) View.VISIBLE else View.GONE + binding.unitCard.cardElevation = if (shouldExpand) 5.0F else 0.0F } } }
\ No newline at end of file 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 4ac5d48..a3ed7a8 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 @@ -10,9 +10,11 @@ import androidx.recyclerview.widget.LinearLayoutManager import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.databinding.DevicesFragmentBinding import mx.trackermap.TrackerMap.android.units.UnitsViewModel +import mx.trackermap.TrackerMap.client.models.UnitInformation import org.koin.androidx.viewmodel.ext.android.viewModel -class DevicesFragment: Fragment() { +class DevicesFragment : Fragment() { + private var _binding: DevicesFragmentBinding? = null private val binding get() = _binding!! @@ -40,15 +42,25 @@ class DevicesFragment: Fragment() { } private fun setupList() { - binding.devicesList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) - binding.devicesList.adapter = DevicesAdapter(emptyList()) + binding.devicesList.layoutManager = LinearLayoutManager( + context, LinearLayoutManager.VERTICAL, + false + ) + binding.devicesList.adapter = DevicesAdapter(emptyList(), null) } @DelicateCoroutinesApi private fun setupObservers() { unitsViewModel.units.observe(this) { units -> Log.d("DevicesFragment", "Success $units") - binding.devicesList.swapAdapter(DevicesAdapter(units), false) + binding.devicesList.swapAdapter( + DevicesAdapter(units, this::itemAction), + false + ) } } + + private fun itemAction(unit: UnitInformation, action: Action) { + Log.d("DevicesFragment", "Action: $action - Unit: $unit") + } }
\ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index 5d7d469..bcb0818 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -25,7 +25,7 @@ class UnitsViewModel( private val unitsController: UnitsController by inject() var searchQuery = savedStateHandle.getLiveData("searchQuery", "") - var unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) + var unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST) var units = MutableLiveData<List<UnitInformation>>() init { diff --git a/androidApp/src/main/res/layout/login.xml b/androidApp/src/main/res/layout/login.xml index 21c63b0..2512052 100644 --- a/androidApp/src/main/res/layout/login.xml +++ b/androidApp/src/main/res/layout/login.xml @@ -5,15 +5,15 @@ android:name="mx.trackermap.TrackerMap.android.session.LoginFragment" android:layout_width="match_parent" android:layout_height="wrap_content" - app:cardCornerRadius="@dimen/cardview_border_radius" - app:cardElevation="@dimen/cardview_elevation" + app:cardCornerRadius="@dimen/card_border_radius" + app:cardElevation="@dimen/card_elevation" app:cardUseCompatPadding="true"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingVertical="@dimen/cardview_padding_vertical" - android:paddingHorizontal="@dimen/cardview_padding_horizontal"> + android:paddingVertical="@dimen/card_large_padding" + android:paddingHorizontal="@dimen/card_padding"> <com.google.android.material.textfield.TextInputLayout android:id="@+id/usernameInputLayout" diff --git a/androidApp/src/main/res/layout/login_activity.xml b/androidApp/src/main/res/layout/login_activity.xml index 8021963..be143d9 100644 --- a/androidApp/src/main/res/layout/login_activity.xml +++ b/androidApp/src/main/res/layout/login_activity.xml @@ -24,7 +24,7 @@ app:layout_constraintTop_toBottomOf="@id/bannerImage" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" - android:layout_marginHorizontal="@dimen/cardview_margin_horizontal" + android:layout_marginHorizontal="@dimen/card_margin" android:layout_marginBottom="16dp"/> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/androidApp/src/main/res/layout/unit_item.xml b/androidApp/src/main/res/layout/unit_item.xml index 4534339..cdf0610 100644 --- a/androidApp/src/main/res/layout/unit_item.xml +++ b/androidApp/src/main/res/layout/unit_item.xml @@ -6,7 +6,7 @@ android:id="@+id/unitCard" android:layout_width="match_parent" android:layout_height="wrap_content" - app:cardCornerRadius="20dp" + app:cardCornerRadius="@dimen/card_border_radius" app:cardElevation="0dp" app:cardUseCompatPadding="true" app:contentPadding="16dp"> @@ -14,7 +14,8 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" + android:animateLayoutChanges="true"> <TextView android:id="@+id/unitName" @@ -64,7 +65,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:text="Details" + android:text="@string/unit_details" android:textColor="@color/colorPrimaryDark" app:backgroundTint="@color/darkBackground" /> @@ -74,7 +75,7 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="8dp" android:layout_weight="1" - android:text="Reports" + android:text="@string/unit_reports" android:textColor="@color/colorPrimaryDark" app:backgroundTint="@color/darkBackground" /> @@ -83,7 +84,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:text="Commands" + android:text="@string/unit_commands" android:textColor="@color/colorPrimaryDark" app:backgroundTint="@color/darkBackground" /> diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 6b5e340..c39d301 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <!-- CardView --> - <dimen name="cardview_border_radius">20dp</dimen> - <dimen name="cardview_elevation">5dp</dimen> - <dimen name="cardview_padding_vertical">32dp</dimen> - <dimen name="cardview_padding_horizontal">16dp</dimen> - <dimen name="cardview_margin_horizontal">7dp</dimen> + <dimen name="card_border_radius">20dp</dimen> + <dimen name="card_elevation">8dp</dimen> + <dimen name="card_large_padding">32dp</dimen> + <dimen name="card_padding">16dp</dimen> + <dimen name="card_margin">16dp</dimen> </resources>
\ No newline at end of file diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index db272e5..3919343 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -6,4 +6,9 @@ <string name="login_username">Username</string> <string name="login_password">Password</string> <string name="login_login">Login</string> + + <!-- Unit Item --> + <string name="unit_details">Details</string> + <string name="unit_reports">Reports</string> + <string name="unit_commands">Commands</string> </resources>
\ No newline at end of file |