diff options
Diffstat (limited to 'androidApp/src/main')
6 files changed, 160 insertions, 11 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 new file mode 100644 index 0000000..72d61e3 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt @@ -0,0 +1,46 @@ +package mx.trackermap.TrackerMap.android.devices + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +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>() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val binding = UnitItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + + return ViewHolder(binding) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.toggleOptions(false) + + val unit = units[position] + holder.binding.apply { + unitName.text = unit.device.name + driverName.text = unit.device.contact + unitSpeed.text = "${unit.position?.speed ?: "--"} Km/h" + lastAddress.text = unit.position?.address ?: "Unknown location" + lastDate.text = "yyyy/mm/dd, hh:mm" + } + } + + override fun getItemCount(): Int = units.size + + inner class ViewHolder(val binding: UnitItemBinding) : RecyclerView.ViewHolder(binding.root) { + init { + binding.unitCard.setOnClickListener { + toggleOptions(binding.itemOptions.visibility == View.GONE) + } + } + + fun toggleOptions(shouldShow: Boolean) { + binding.itemOptions.visibility = if (shouldShow) View.VISIBLE else View.GONE + binding.unitCard.cardElevation = if (shouldShow) 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 98c98cc..4ac5d48 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,6 +6,7 @@ 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 import mx.trackermap.TrackerMap.android.units.UnitsViewModel @@ -34,13 +35,20 @@ class DevicesFragment: Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + setupList() setupObservers() } + private fun setupList() { + binding.devicesList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) + binding.devicesList.adapter = DevicesAdapter(emptyList()) + } + @DelicateCoroutinesApi private fun setupObservers() { unitsViewModel.units.observe(this) { units -> Log.d("DevicesFragment", "Success $units") + binding.devicesList.swapAdapter(DevicesAdapter(units), false) } } }
\ No newline at end of file diff --git a/androidApp/src/main/res/layout/devices_fragment.xml b/androidApp/src/main/res/layout/devices_fragment.xml index 579afc2..fd91db3 100644 --- a/androidApp/src/main/res/layout/devices_fragment.xml +++ b/androidApp/src/main/res/layout/devices_fragment.xml @@ -1,17 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent" - xmlns:app="http://schemas.android.com/apk/res-auto"> + android:layout_height="match_parent"> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="DEVICES LIST" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintStart_toStartOf="parent" + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/devicesList" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent"/> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> </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 new file mode 100644 index 0000000..4534339 --- /dev/null +++ b/androidApp/src/main/res/layout/unit_item.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.google.android.material.card.MaterialCardView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/unitCard" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:cardCornerRadius="20dp" + app:cardElevation="0dp" + app:cardUseCompatPadding="true" + app:contentPadding="16dp"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/unitName" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="26dp" + tools:text="1AAUTO" /> + + <TextView + android:id="@+id/driverName" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18dp" + tools:text="Javier Zavala" /> + + <TextView + android:id="@+id/unitSpeed" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18dp" + tools:text="0 Km/h - Stopped" /> + + <TextView + android:id="@+id/lastAddress" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18dp" + tools:text="404 Av. Arboledas, Celaya, Gto." /> + + <TextView + android:id="@+id/lastDate" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18dp" + tools:text="4 de Diciembre de 2021, 7:00 PM" /> + + <LinearLayout + android:id="@+id/itemOptions" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="horizontal" + android:visibility="gone"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/detailsButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="Details" + android:textColor="@color/colorPrimaryDark" + app:backgroundTint="@color/darkBackground" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/reportsButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" + android:layout_weight="1" + android:text="Reports" + android:textColor="@color/colorPrimaryDark" + app:backgroundTint="@color/darkBackground" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/commandsButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="Commands" + android:textColor="@color/colorPrimaryDark" + app:backgroundTint="@color/darkBackground" /> + + </LinearLayout> + + </LinearLayout> + +</com.google.android.material.card.MaterialCardView>
\ No newline at end of file diff --git a/androidApp/src/main/res/layout/units_activity.xml b/androidApp/src/main/res/layout/units_activity.xml index 750e00f..5bfb228 100644 --- a/androidApp/src/main/res/layout/units_activity.xml +++ b/androidApp/src/main/res/layout/units_activity.xml @@ -13,8 +13,7 @@ app:layout_constraintTop_toBottomOf="@id/displayModeToggle" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - android:background="@color/colorPrimary"/> + app:layout_constraintBottom_toBottomOf="parent"/> <com.google.android.material.card.MaterialCardView android:layout_width="0dp" diff --git a/androidApp/src/main/res/values/colors.xml b/androidApp/src/main/res/values/colors.xml index 8fb5f28..8f96260 100644 --- a/androidApp/src/main/res/values/colors.xml +++ b/androidApp/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ <color name="colorPrimary">#656A74</color> <color name="colorPrimaryDark">#43474E</color> <color name="colorAccent">#EB473E</color> + <color name="background">#FDFDFD</color> + <color name="darkBackground">#ECEFF3</color> </resources>
\ No newline at end of file |