Show last message in contacts list.

This commit is contained in:
Felix Ableitner 2015-06-24 11:08:29 +02:00
parent a06884f204
commit da7fd6e5f7
2 changed files with 47 additions and 5 deletions

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:orientation="vertical" >
<TextView android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textStyle="bold" />
<TextView android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
android:layout_alignStart="@android:id/text1"
android:textAppearance="?android:attr/textAppearanceListItemSecondary" />
</LinearLayout>

View file

@ -1,21 +1,38 @@
package com.nutomic.ensichat.util
import android.content.Context
import android.view.{View, ViewGroup}
import android.view.{LayoutInflater, View, ViewGroup}
import android.widget.{ArrayAdapter, TextView}
import com.nutomic.ensichat.bluetooth.Device
import com.nutomic.ensichat.protocol.User
import com.nutomic.ensichat.protocol.body.Text
import com.nutomic.ensichat.R
/**
* Displays [[Device]]s in ListView.
*/
class UsersAdapter(context: Context) extends
ArrayAdapter[User](context, android.R.layout.simple_list_item_1) {
ArrayAdapter[User](context, 0) {
private lazy val database = new Database(context)
override def getView(position: Int, convertView: View, parent: ViewGroup): View = {
val view = super.getView(position, convertView, parent)
val title: TextView = view.findViewById(android.R.id.text1).asInstanceOf[TextView]
title.setText(getItem(position).name)
val view =
if (convertView == null) {
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)
.asInstanceOf[LayoutInflater]
.inflate(R.layout.item_user, parent, false)
} else
convertView
val title = view.findViewById(android.R.id.text1).asInstanceOf[TextView]
val summary = view.findViewById(android.R.id.text2).asInstanceOf[TextView]
val item = getItem(position)
title.setText(item.name)
database.getMessages(item.address, 1)
.map(_.body)
.foreach {
case m: Text => summary.setText(m.text)
}
view
}