Import SMS
This commit is contained in:
parent
7f32115afe
commit
9656207135
14 changed files with 310 additions and 28 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.simplemobiletools.smsmessenger.extensions
|
||||
|
||||
import android.content.ContentValues
|
||||
|
||||
inline fun <T> List<T>.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? {
|
||||
var index = 0
|
||||
for (item in this) {
|
||||
|
|
@ -9,3 +11,22 @@ inline fun <T> List<T>.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun Map<String, Any>.toContentValues(): ContentValues {
|
||||
val contentValues = ContentValues()
|
||||
for (item in entries) {
|
||||
when (val value = item.value) {
|
||||
is String -> contentValues.put(item.key, value)
|
||||
is Byte -> contentValues.put(item.key, value)
|
||||
is Short -> contentValues.put(item.key, value)
|
||||
is Int -> contentValues.put(item.key, value)
|
||||
is Long -> contentValues.put(item.key, value)
|
||||
is Float -> contentValues.put(item.key, value)
|
||||
is Double -> contentValues.put(item.key, value)
|
||||
is Boolean -> contentValues.put(item.key, value)
|
||||
is ByteArray -> contentValues.put(item.key, value)
|
||||
}
|
||||
}
|
||||
|
||||
return contentValues
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,11 @@ fun Context.getMessages(threadId: Long): ArrayList<Message> {
|
|||
val blockedNumbers = getBlockedNumbers()
|
||||
var messages = ArrayList<Message>()
|
||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor ->
|
||||
val senderNumber = cursor.getStringValue(Sms.ADDRESS) ?: return@queryCursor
|
||||
val senderNumber = cursor.getStringValue(Sms.ADDRESS)
|
||||
|
||||
if(senderNumber == null){
|
||||
return@queryCursor
|
||||
}
|
||||
|
||||
val isNumberBlocked = if (blockStatus.containsKey(senderNumber)) {
|
||||
blockStatus[senderNumber]!!
|
||||
|
|
@ -251,6 +255,32 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<
|
|||
return conversations
|
||||
}
|
||||
|
||||
fun Context.getAllMessages(): List<SmsBackup> {
|
||||
val uri = Sms.CONTENT_URI
|
||||
val sortOrder = "${Sms._ID}"
|
||||
|
||||
val messages= mutableListOf<SmsBackup>()
|
||||
queryCursor(uri, null, null, null, sortOrder, showErrors = true) { cursor ->
|
||||
val senderNumber = cursor.getStringValue(Sms.ADDRESS)
|
||||
val id = cursor.getLongValue(Sms._ID)
|
||||
val body = cursor.getStringValue(Sms.BODY)
|
||||
val person = cursor.getStringValue(Sms.PERSON)
|
||||
val protocol = cursor.getStringValue(Sms.PROTOCOL)
|
||||
val type = cursor.getIntValue(Sms.TYPE)
|
||||
val date = (cursor.getLongValue(Sms.DATE) / 1000)
|
||||
val read = cursor.getIntValue(Sms.READ)
|
||||
val thread = cursor.getLongValue(Sms.THREAD_ID)
|
||||
val subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID)
|
||||
val status = cursor.getIntValue(Sms.STATUS)
|
||||
|
||||
messages.add(SmsBackup(id, senderNumber, body, "", date,
|
||||
0, 0,0 , person, protocol, read, Any(), 0, 0, status, subscriptionId, Any(), thread, type))
|
||||
}
|
||||
|
||||
return messages
|
||||
}
|
||||
|
||||
|
||||
fun Context.getConversationIds(): List<Long> {
|
||||
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
|
||||
val projection = arrayOf(Threads._ID)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import android.database.Cursor
|
|||
import com.google.gson.JsonNull
|
||||
import com.google.gson.JsonObject
|
||||
|
||||
fun Cursor.
|
||||
rowsToJson(): JsonObject {
|
||||
fun Cursor.rowsToJson(): JsonObject {
|
||||
val obj = JsonObject()
|
||||
for (i in 0 until columnCount) {
|
||||
val key = getColumnName(i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue