Remvoed count parameter from getMessagesCursor.

This commit is contained in:
Felix Ableitner 2015-09-19 13:42:57 +02:00
parent 1c48484358
commit cdcf0ace01
3 changed files with 11 additions and 18 deletions

View file

@ -55,8 +55,8 @@ class DatabaseTest extends AndroidTestCase {
/**
* Calls [[Database.getMessagesCursor]] with parameters and converts the result to sorted set.
*/
private def getMessages(address: Address, count: Int): SortedSet[Message] = {
val c = database.getMessagesCursor(address, Option(count))
private def getMessages(address: Address): SortedSet[Message] = {
val c = database.getMessagesCursor(address)
var messages = new TreeSet[Message]()(Message.Ordering)
while (c.moveToNext()) {
messages += Database.messageFromCursor(c)
@ -65,27 +65,20 @@ class DatabaseTest extends AndroidTestCase {
messages
}
def testMessageCount(): Unit = {
val msg1 = getMessages(m1.header.origin, 1)
assertEquals(1, msg1.size)
val msg2 = getMessages(m1.header.origin, 3)
assertEquals(2, msg2.size)
}
def testMessageOrder(): Unit = {
val msg = getMessages(m1.header.target, 1)
assertTrue(msg.contains(m1))
val msg = getMessages(m1.header.target).firstKey
assertEquals(m1.body, msg.body)
}
def testMessageSelect(): Unit = {
val msg = getMessages(m1.header.target, 2)
val msg = getMessages(m1.header.target)
assertTrue(msg.contains(m1))
assertFalse(msg.contains(m2))
assertTrue(msg.contains(m3))
}
def testMessageFields(): Unit = {
val msg = getMessages(m2.header.target, 1).firstKey
val msg = getMessages(m2.header.target).firstKey
val header = msg.header.asInstanceOf[ContentHeader]
assertEquals(h2.origin, header.origin)

View file

@ -53,7 +53,7 @@ class ChatFragment extends ListFragment with OnClickListener {
database.getContact(address).foreach(c => getActivity.setTitle(c.name))
adapter = new DatesAdapter(getActivity,
new MessagesAdapter(getActivity, database.getMessagesCursor(address, None), address))
new MessagesAdapter(getActivity, database.getMessagesCursor(address), address))
if (listView != null) {
listView.setAdapter(adapter)
@ -125,7 +125,7 @@ class ChatFragment extends ListFragment with OnClickListener {
msg.body match {
case _: Text =>
adapter.changeCursor(database.getMessagesCursor(address, None))
adapter.changeCursor(database.getMessagesCursor(address))
case _ =>
}
}

View file

@ -63,11 +63,11 @@ class Database(context: Context)
db.execSQL(Database.CreateMessagesTable)
}
def getMessagesCursor(address: Address, count: Option[Int]): Cursor = {
def getMessagesCursor(address: Address): Cursor = {
getReadableDatabase.query(true,
"messages", Array("_id", "origin", "target", "message_id", "text", "date"),
"origin = ? OR target = ?", Array(address.toString, address.toString),
null, null, "date ASC", count.map(_.toString).orNull)
null, null, "date ASC", null)
}
/**