sforkowany z mirror/meshtastic-android
message fragment kinda works
rodzic
e157bb0140
commit
29f0435f18
|
@ -12,6 +12,7 @@ import com.geeksville.android.Logging
|
|||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.TextMessage
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import kotlinx.android.synthetic.main.adapter_message_layout.view.*
|
||||
import kotlinx.android.synthetic.main.messages_fragment.*
|
||||
|
||||
|
||||
|
@ -22,6 +23,8 @@ class MessagesFragment : ScreenFragment("Messages"), 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: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val username = itemView.username
|
||||
val messageText = itemView.messageText
|
||||
}
|
||||
|
||||
private val messagesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
|
||||
|
@ -55,7 +58,7 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
// Inflate the custom layout
|
||||
|
||||
// Inflate the custom layout
|
||||
val contactView: View = inflater.inflate(R.layout.adapter_node_layout, parent, false)
|
||||
val contactView: View = inflater.inflate(R.layout.adapter_message_layout, parent, false)
|
||||
|
||||
// Return a new holder instance
|
||||
return ViewHolder(contactView)
|
||||
|
@ -90,7 +93,21 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
* @param position The position of the item within the adapter's data set.
|
||||
*/
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val n = messages[position]
|
||||
val msg = messages[position]
|
||||
|
||||
val nodes = model.nodeDB.nodes.value!!
|
||||
|
||||
// If we can't find the sender, just use the ID
|
||||
val node = nodes.get(msg.from)
|
||||
val user = node?.user
|
||||
holder.username.text = user?.shortName ?: msg.from
|
||||
|
||||
if (msg.errorMessage != null) {
|
||||
// FIXME, set the style to show a red error message
|
||||
holder.messageText.text = msg.errorMessage
|
||||
} else {
|
||||
holder.messageText.text = msg.text
|
||||
}
|
||||
}
|
||||
|
||||
private var messages = arrayOf<TextMessage>()
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/some_username"
|
||||
app:chipIcon="@drawable/ic_twotone_person_24"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/messageText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/sample_message"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/username"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -11,4 +11,6 @@
|
|||
<string name="unknown_username">Unknown Username</string>
|
||||
<string name="user_avatar">User avatar</string>
|
||||
<string name="sample_distance">2.13 km</string>
|
||||
<string name="sample_message">hey I found the cache, it is over here next to the big tiger. I\'m kinda scared.</string>
|
||||
<string name="some_username">Some Username</string>
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue