kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor node list card layout
rodzic
74f463c09e
commit
a60013e2dd
|
@ -35,6 +35,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
// Provide a direct reference to each of the views within a data item
|
||||
// Used to cache the views within the item layout for fast access
|
||||
class ViewHolder(itemView: AdapterNodeLayoutBinding) : RecyclerView.ViewHolder(itemView.root) {
|
||||
val chipNode = itemView.chipNode
|
||||
val nodeNameView = itemView.nodeNameView
|
||||
val distanceView = itemView.distanceView
|
||||
val coordsView = itemView.coordsView
|
||||
|
@ -110,7 +111,9 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
*/
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val n = nodes[position]
|
||||
val name = n.user?.longName ?: n.user?.id ?: "Unknown node"
|
||||
val user = n.user
|
||||
holder.chipNode.text = user?.shortName ?: "UNK"
|
||||
val name = user?.longName ?: "Unknown node"
|
||||
holder.nodeNameView.text = name
|
||||
|
||||
val pos = n.validPosition
|
||||
|
@ -165,19 +168,21 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
holder.signalView.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
holder.itemView.setOnLongClickListener {
|
||||
val node = n.user
|
||||
if (position > 0 && node != null) {
|
||||
debug("calling MessagesFragment filter:${node.id}")
|
||||
holder.chipNode.setOnClickListener {
|
||||
if (position > 0 && user != null) {
|
||||
debug("calling MessagesFragment filter:${user.id}")
|
||||
setFragmentResult(
|
||||
"requestKey",
|
||||
bundleOf("contactKey" to "0${node.id}", "contactName" to name)
|
||||
bundleOf("contactKey" to "0${user.id}", "contactName" to name)
|
||||
)
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.mainActivityLayout, MessagesFragment())
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
holder.itemView.setOnLongClickListener {
|
||||
// do something else
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -210,10 +215,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
|
||||
holder.batteryPctView.text = text
|
||||
holder.powerIcon.setImageDrawable(context?.let {
|
||||
ContextCompat.getDrawable(
|
||||
it,
|
||||
image
|
||||
)
|
||||
ContextCompat.getDrawable(it, image)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,16c-2.69,0 -5.77,1.28 -6,2h12c-0.2,-0.71 -3.3,-2 -6,-2z"
|
||||
android:fillAlpha=".3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,8m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0"
|
||||
android:fillAlpha=".3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4zM6,18c0.22,-0.72 3.31,-2 6,-2 2.7,0 5.8,1.29 6,2L6,18zM12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,6c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2z"/>
|
||||
</vector>
|
|
@ -15,19 +15,15 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_node"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:contentDescription="@string/user_avatar"
|
||||
android:scaleType="center"
|
||||
android:scaleX="1.5"
|
||||
android:scaleY="1.5"
|
||||
app:layout_constraintEnd_toEndOf="@+id/distance_view"
|
||||
app:layout_constraintStart_toStartOf="@+id/distance_view"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_twotone_person_24" />
|
||||
android:layout_margin="8dp"
|
||||
android:text="@string/some_username"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nodeNameView"
|
||||
|
@ -35,32 +31,27 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/unknown_username"
|
||||
app:layout_constraintStart_toEndOf="@+id/distance_view"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView" />
|
||||
app:layout_constraintStart_toEndOf="@+id/chip_node"
|
||||
app:layout_constraintTop_toTopOf="@+id/chip_node" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/distance_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_margin="8dp"
|
||||
android:text="@string/sample_distance"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/chip_node"
|
||||
app:layout_constraintStart_toStartOf="@+id/chip_node"
|
||||
app:layout_constraintTop_toBottomOf="@+id/chip_node" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/coords_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_margin="8dp"
|
||||
android:text="@string/sample_coords"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
|
||||
app:layout_constraintStart_toEndOf="@+id/distance_view"
|
||||
app:layout_constraintStart_toEndOf="@+id/chip_node"
|
||||
app:layout_constraintTop_toBottomOf="@+id/nodeNameView"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
|
@ -68,10 +59,10 @@
|
|||
android:id="@+id/batteryIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_margin="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/batteryPercentageView"
|
||||
app:layout_constraintEnd_toStartOf="@+id/batteryPercentageView"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/batteryPercentageView"
|
||||
app:srcCompat="@drawable/ic_battery_full_24" />
|
||||
|
||||
<TextView
|
||||
|
@ -80,48 +71,46 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="100%"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/batteryIcon"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/nodeNameView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/batteryIcon" />
|
||||
app:layout_constraintTop_toTopOf="@+id/nodeNameView" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/lastCommIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintTop_toBottomOf="@id/batteryIcon"
|
||||
app:layout_constraintBottom_toTopOf="@id/signalView"
|
||||
android:layout_margin="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/lastConnectionView"
|
||||
app:layout_constraintEnd_toStartOf="@+id/lastConnectionView"
|
||||
app:layout_constraintTop_toTopOf="@+id/lastConnectionView"
|
||||
app:srcCompat="@drawable/ic_antenna_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lastConnectionView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_margin="8dp"
|
||||
android:text="11h01 PM"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/lastCommIcon"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/coords_view"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/lastCommIcon" />
|
||||
app:layout_constraintTop_toTopOf="@+id/coords_view" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/signalView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_margin="8dp"
|
||||
android:text="rssi:-40 snr:-8"
|
||||
app:layout_constraintBottom_toTopOf="@id/envMetrics"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/lastConnectionView"
|
||||
app:layout_constraintBottom_toTopOf="@id/envMetrics" />
|
||||
app:layout_constraintTop_toBottomOf="@id/lastConnectionView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/envMetrics"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
Ładowanie…
Reference in New Issue