forked from upstream-mirrors/quik
Drastic cleanup of ColumnsMap.kt
This commit is contained in:
@@ -1,202 +1,47 @@
|
|||||||
package com.moez.QKSMS.data.sync
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
|
import android.database.Cursor
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_ID
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_DELIVERY_REPORT
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_ERROR_TYPE
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_LOCKED
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_MESSAGE_BOX
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_MESSAGE_TYPE
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_READ_REPORT
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_STATUS
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_SUBJECT
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_SUBJECT_CHARSET
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_TEXT_ONLY
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MSG_TYPE
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_ADDRESS
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_BODY
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_DATE
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_DATE_SENT
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_ERROR_CODE
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_LOCKED
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_STATUS
|
|
||||||
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_TYPE
|
|
||||||
|
|
||||||
class ColumnsMap {
|
@Suppress("unused")
|
||||||
|
class ColumnsMap(val cursor: Cursor) {
|
||||||
private val TAG = "ColumnsMap"
|
private val TAG = "ColumnsMap"
|
||||||
private val DEBUG = false
|
private val DEBUG = false
|
||||||
|
|
||||||
var mColumnMsgType: Int = 0
|
var msgType = getColumnIndex(MessageSyncManager.COLUMN_MSG_TYPE)
|
||||||
var mColumnMsgId: Int = 0
|
var msgId = getColumnIndex(MessageSyncManager.COLUMN_ID)
|
||||||
var mColumnSmsAddress: Int = 0
|
var threadId = getColumnIndex(MessageSyncManager.COLUMN_THREAD_ID)
|
||||||
var mColumnSmsBody: Int = 0
|
var smsAddress = getColumnIndex(MessageSyncManager.COLUMN_SMS_ADDRESS)
|
||||||
var mColumnSmsDate: Int = 0
|
var smsBody = getColumnIndex(MessageSyncManager.COLUMN_SMS_BODY)
|
||||||
var mColumnSmsDateSent: Int = 0
|
var smsDate = getColumnIndex(MessageSyncManager.COLUMN_SMS_DATE)
|
||||||
var mColumnSmsRead: Int = 0
|
var smsDateSent = getColumnIndex(MessageSyncManager.COLUMN_SMS_DATE_SENT)
|
||||||
var mColumnSmsType: Int = 0
|
var smsRead = getColumnIndex(MessageSyncManager.COLUMN_SMS_READ)
|
||||||
var mColumnSmsStatus: Int = 0
|
var smsType = getColumnIndex(MessageSyncManager.COLUMN_SMS_TYPE)
|
||||||
var mColumnSmsLocked: Int = 0
|
var smsStatus = getColumnIndex(MessageSyncManager.COLUMN_SMS_STATUS)
|
||||||
var mColumnSmsErrorCode: Int = 0
|
var smsLocked = getColumnIndex(MessageSyncManager.COLUMN_SMS_LOCKED)
|
||||||
var mColumnMmsSubject: Int = 0
|
var smsErrorCode = getColumnIndex(MessageSyncManager.COLUMN_SMS_ERROR_CODE)
|
||||||
var mColumnMmsSubjectCharset: Int = 0
|
var mmsSubject = getColumnIndex(MessageSyncManager.COLUMN_MMS_SUBJECT)
|
||||||
var mColumnMmsDate: Int = 0
|
var mmsSubjectCharset = getColumnIndex(MessageSyncManager.COLUMN_MMS_SUBJECT_CHARSET)
|
||||||
var mColumnMmsDateSent: Int = 0
|
var mmsDate = getColumnIndex(MessageSyncManager.COLUMN_MMS_DATE)
|
||||||
var mColumnMmsRead: Int = 0
|
var mmsDateSent = getColumnIndex(MessageSyncManager.COLUMN_MMS_DATE_SENT)
|
||||||
var mColumnMmsMessageType: Int = 0
|
var mmsRead = getColumnIndex(MessageSyncManager.COLUMN_MMS_READ)
|
||||||
var mColumnMmsMessageBox: Int = 0
|
var mmsMessageType = getColumnIndex(MessageSyncManager.COLUMN_MMS_MESSAGE_TYPE)
|
||||||
var mColumnMmsDeliveryReport: Int = 0
|
var mmsMessageBox = getColumnIndex(MessageSyncManager.COLUMN_MMS_MESSAGE_BOX)
|
||||||
var mColumnMmsReadReport: Int = 0
|
var mmsDeliveryReport = getColumnIndex(MessageSyncManager.COLUMN_MMS_DELIVERY_REPORT)
|
||||||
var mColumnMmsErrorType: Int = 0
|
var mmsReadReport = getColumnIndex(MessageSyncManager.COLUMN_MMS_READ_REPORT)
|
||||||
var mColumnMmsLocked: Int = 0
|
var mmsErrorType = getColumnIndex(MessageSyncManager.COLUMN_MMS_ERROR_TYPE)
|
||||||
var mColumnMmsStatus: Int = 0
|
var mmsLocked = getColumnIndex(MessageSyncManager.COLUMN_MMS_LOCKED)
|
||||||
var mColumnMmsTextOnly: Int = 0
|
var mmsStatus = getColumnIndex(MessageSyncManager.COLUMN_MMS_STATUS)
|
||||||
|
var mmsTextOnly = getColumnIndex(MessageSyncManager.COLUMN_MMS_TEXT_ONLY)
|
||||||
|
|
||||||
constructor() {
|
private fun getColumnIndex(index: Int): Int {
|
||||||
mColumnMsgType = COLUMN_MSG_TYPE
|
try {
|
||||||
mColumnMsgId = COLUMN_ID
|
return cursor.getColumnIndexOrThrow(MessageSyncManager.PROJECTION[index])
|
||||||
mColumnSmsAddress = COLUMN_SMS_ADDRESS
|
} catch (e: IllegalArgumentException) {
|
||||||
mColumnSmsBody = COLUMN_SMS_BODY
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
mColumnSmsDate = COLUMN_SMS_DATE
|
}
|
||||||
mColumnSmsDateSent = COLUMN_SMS_DATE_SENT
|
|
||||||
mColumnSmsType = COLUMN_SMS_TYPE
|
return index
|
||||||
mColumnSmsStatus = COLUMN_SMS_STATUS
|
|
||||||
mColumnSmsLocked = COLUMN_SMS_LOCKED
|
|
||||||
mColumnSmsErrorCode = COLUMN_SMS_ERROR_CODE
|
|
||||||
mColumnMmsSubject = COLUMN_MMS_SUBJECT
|
|
||||||
mColumnMmsSubjectCharset = COLUMN_MMS_SUBJECT_CHARSET
|
|
||||||
mColumnMmsMessageType = COLUMN_MMS_MESSAGE_TYPE
|
|
||||||
mColumnMmsMessageBox = COLUMN_MMS_MESSAGE_BOX
|
|
||||||
mColumnMmsDeliveryReport = COLUMN_MMS_DELIVERY_REPORT
|
|
||||||
mColumnMmsReadReport = COLUMN_MMS_READ_REPORT
|
|
||||||
mColumnMmsErrorType = COLUMN_MMS_ERROR_TYPE
|
|
||||||
mColumnMmsLocked = COLUMN_MMS_LOCKED
|
|
||||||
mColumnMmsStatus = COLUMN_MMS_STATUS
|
|
||||||
mColumnMmsTextOnly = COLUMN_MMS_TEXT_ONLY
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@android.annotation.SuppressLint("InlinedApi")
|
|
||||||
constructor(cursor: android.database.Cursor) {
|
|
||||||
// Ignore all 'not found' exceptions since the custom columns
|
|
||||||
// may be just a subset of the default columns.
|
|
||||||
try {
|
|
||||||
mColumnMsgType = cursor.getColumnIndexOrThrow(android.provider.Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMsgId = cursor.getColumnIndexOrThrow(android.provider.BaseColumns._ID)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsAddress = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.ADDRESS)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsBody = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.BODY)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsDate = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.DATE)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsDateSent = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.DATE_SENT)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsType = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.TYPE)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsStatus = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.STATUS)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsLocked = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.LOCKED)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnSmsErrorCode = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.ERROR_CODE)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsSubject = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.SUBJECT)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsSubjectCharset = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.SUBJECT_CHARSET)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsMessageType = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.MESSAGE_TYPE)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsMessageBox = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.MESSAGE_BOX)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsDeliveryReport = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.DELIVERY_REPORT)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsReadReport = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.READ_REPORT)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsErrorType = cursor.getColumnIndexOrThrow(android.provider.Telephony.MmsSms.PendingMessages.ERROR_TYPE)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsLocked = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.LOCKED)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsStatus = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.STATUS)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mColumnMmsTextOnly = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.TEXT_ONLY)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
if (DEBUG) Log.w(TAG, e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.moez.QKSMS.data.sync
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.BaseColumns
|
import android.provider.BaseColumns
|
||||||
@@ -39,23 +38,21 @@ internal object MessageSyncManager {
|
|||||||
|
|
||||||
val MMS_SMS_CONTENT_PROVIDER = Uri.parse("content://mms-sms/conversations/")
|
val MMS_SMS_CONTENT_PROVIDER = Uri.parse("content://mms-sms/conversations/")
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
val PROJECTION = arrayOf(
|
val PROJECTION = arrayOf(
|
||||||
Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN,
|
Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN,
|
||||||
BaseColumns._ID,
|
BaseColumns._ID,
|
||||||
Telephony.Sms.Conversations.THREAD_ID,
|
Telephony.Sms.Conversations.THREAD_ID,
|
||||||
|
|
||||||
// For SMS
|
|
||||||
Telephony.Sms.ADDRESS,
|
Telephony.Sms.ADDRESS,
|
||||||
Telephony.Sms.BODY,
|
Telephony.Sms.BODY,
|
||||||
Telephony.Sms.DATE,
|
Telephony.Sms.DATE,
|
||||||
Telephony.Sms.DATE_SENT,
|
Telephony.Sms.DATE_SENT,
|
||||||
Telephony.Sms.READ, Telephony.Sms.TYPE,
|
Telephony.Sms.READ,
|
||||||
|
Telephony.Sms.TYPE,
|
||||||
Telephony.Sms.STATUS,
|
Telephony.Sms.STATUS,
|
||||||
Telephony.Sms.LOCKED,
|
Telephony.Sms.LOCKED,
|
||||||
Telephony.Sms.ERROR_CODE,
|
Telephony.Sms.ERROR_CODE,
|
||||||
|
|
||||||
// For MMS
|
|
||||||
Telephony.Mms.SUBJECT,
|
Telephony.Mms.SUBJECT,
|
||||||
Telephony.Mms.SUBJECT_CHARSET,
|
Telephony.Mms.SUBJECT_CHARSET,
|
||||||
Telephony.Mms.DATE,
|
Telephony.Mms.DATE,
|
||||||
@@ -77,23 +74,22 @@ internal object MessageSyncManager {
|
|||||||
Realm.getDefaultInstance().executeTransaction {
|
Realm.getDefaultInstance().executeTransaction {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
|
|
||||||
val type = cursor.getString(columnsMap.mColumnMsgType)
|
val type = cursor.getString(columnsMap.msgType)
|
||||||
if (type != "sms" && type != "mms") continue // If we can't read the type, don't use this message
|
if (type != "sms" && type != "mms") continue // If we can't read the type, don't use this message
|
||||||
|
|
||||||
val isMms = type == "mms"
|
val isMms = type == "mms"
|
||||||
val body = cursor.getString(columnsMap.mColumnSmsBody) ?: ""
|
val body = cursor.getString(columnsMap.smsBody) ?: ""
|
||||||
val errorType = cursor.getInt(columnsMap.mColumnMmsErrorType)
|
val errorType = cursor.getInt(columnsMap.mmsErrorType)
|
||||||
|
|
||||||
val boxId: Int
|
val boxId: Int
|
||||||
|
|
||||||
if (isMms) {
|
if (isMms) {
|
||||||
boxId = cursor.getInt(columnsMap.mColumnMmsMessageBox)
|
boxId = cursor.getInt(columnsMap.mmsMessageBox)
|
||||||
} else {
|
} else {
|
||||||
boxId = cursor.getInt(columnsMap.mColumnSmsType)
|
boxId = cursor.getInt(columnsMap.smsType)
|
||||||
}
|
}
|
||||||
|
|
||||||
it.insertOrUpdate(
|
it.insertOrUpdate(Message(cursor.getLong(columnsMap.msgId), threadId, boxId, type, body, errorType))
|
||||||
Message(cursor.getLong(columnsMap.mColumnMsgId), threadId, boxId, type, body, errorType))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user