Merge pull request #150 from tom93/refactor-extensions-Context
Refactor extensions/Context.kt slightly
This commit is contained in:
commit
bfa1f879a2
1 changed files with 8 additions and 16 deletions
|
|
@ -278,11 +278,11 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<
|
||||||
projection += Threads.ARCHIVED
|
projection += Threads.ARCHIVED
|
||||||
}
|
}
|
||||||
|
|
||||||
var selection = "${Threads.MESSAGE_COUNT} > ?"
|
var selection = "${Threads.MESSAGE_COUNT} > 0"
|
||||||
var selectionArgs = arrayOf("0")
|
var selectionArgs = arrayOf<String>()
|
||||||
if (threadId != null) {
|
if (threadId != null) {
|
||||||
selection += " AND ${Threads._ID} = ?"
|
selection += " AND ${Threads._ID} = ?"
|
||||||
selectionArgs = arrayOf("0", threadId.toString())
|
selectionArgs += threadId.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val sortOrder = "${Threads.DATE} DESC"
|
val sortOrder = "${Threads.DATE} DESC"
|
||||||
|
|
@ -355,11 +355,10 @@ private fun Context.queryCursorUnsafe(
|
||||||
fun Context.getConversationIds(): List<Long> {
|
fun Context.getConversationIds(): List<Long> {
|
||||||
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
|
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
|
||||||
val projection = arrayOf(Threads._ID)
|
val projection = arrayOf(Threads._ID)
|
||||||
val selection = "${Threads.MESSAGE_COUNT} > ?"
|
val selection = "${Threads.MESSAGE_COUNT} > 0"
|
||||||
val selectionArgs = arrayOf("0")
|
|
||||||
val sortOrder = "${Threads.DATE} ASC"
|
val sortOrder = "${Threads.DATE} ASC"
|
||||||
val conversationIds = mutableListOf<Long>()
|
val conversationIds = mutableListOf<Long>()
|
||||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor ->
|
queryCursor(uri, projection, selection, null, sortOrder, true) { cursor ->
|
||||||
val id = cursor.getLongValue(Threads._ID)
|
val id = cursor.getLongValue(Threads._ID)
|
||||||
conversationIds.add(id)
|
conversationIds.add(id)
|
||||||
}
|
}
|
||||||
|
|
@ -1058,16 +1057,9 @@ fun Context.insertOrUpdateConversation(
|
||||||
conversation: Conversation,
|
conversation: Conversation,
|
||||||
cachedConv: Conversation? = conversationsDB.getConversationWithThreadId(conversation.threadId)
|
cachedConv: Conversation? = conversationsDB.getConversationWithThreadId(conversation.threadId)
|
||||||
) {
|
) {
|
||||||
val updatedConv = if (cachedConv != null) {
|
var updatedConv = conversation
|
||||||
val usesCustomTitle = cachedConv.usesCustomTitle
|
if (cachedConv != null && cachedConv.usesCustomTitle) {
|
||||||
val title = if (usesCustomTitle) {
|
updatedConv = updatedConv.copy(title = cachedConv.title, usesCustomTitle = cachedConv.usesCustomTitle)
|
||||||
cachedConv.title
|
|
||||||
} else {
|
|
||||||
conversation.title
|
|
||||||
}
|
|
||||||
conversation.copy(title = title, usesCustomTitle = usesCustomTitle)
|
|
||||||
} else {
|
|
||||||
conversation
|
|
||||||
}
|
}
|
||||||
conversationsDB.insertOrUpdate(updatedConv)
|
conversationsDB.insertOrUpdate(updatedConv)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue