mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Use int instead of enum to store SMS delivery status
This commit is contained in:
@@ -24,7 +24,6 @@ import android.net.Uri
|
||||
import android.provider.Telephony.*
|
||||
import common.util.Keys
|
||||
import data.model.Message
|
||||
import data.model.Message.DeliveryStatus
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -60,14 +59,7 @@ class CursorToMessage @Inject constructor(
|
||||
seen = cursor.getInt(columnsMap.smsSeen) != 0
|
||||
body = cursor.getString(columnsMap.smsBody) ?: ""
|
||||
errorCode = cursor.getInt(columnsMap.smsErrorCode)
|
||||
|
||||
val status = cursor.getLong(columnsMap.smsStatus)
|
||||
deliveryStatus = when {
|
||||
status == Sms.STATUS_NONE.toLong() -> DeliveryStatus.NONE
|
||||
status >= Sms.STATUS_FAILED -> DeliveryStatus.FAILED
|
||||
status >= Sms.STATUS_PENDING -> DeliveryStatus.PENDING
|
||||
else -> DeliveryStatus.RECEIVED
|
||||
}
|
||||
deliveryStatus = cursor.getInt(columnsMap.smsStatus)
|
||||
}
|
||||
|
||||
"mms" -> {
|
||||
|
||||
@@ -41,22 +41,16 @@ open class Message : RealmObject() {
|
||||
var address: String = ""
|
||||
var boxId: Int = 0
|
||||
var type: String = ""
|
||||
var body: String = ""
|
||||
var date: Long = 0
|
||||
var dateSent: Long = 0
|
||||
var seen: Boolean = false
|
||||
var read: Boolean = false
|
||||
var locked: Boolean = false
|
||||
|
||||
var deliveryStatusString: String = DeliveryStatus.NONE.toString()
|
||||
var deliveryStatus: DeliveryStatus
|
||||
get() = DeliveryStatus.valueOf(deliveryStatusString)
|
||||
set(value) {
|
||||
deliveryStatusString = value.toString()
|
||||
}
|
||||
|
||||
// SMS only
|
||||
var body: String = ""
|
||||
var errorCode: Int = 0
|
||||
var deliveryStatus: Int = Sms.STATUS_NONE
|
||||
|
||||
// MMS only
|
||||
var attachmentTypeString: String = AttachmentType.NOT_LOADED.toString()
|
||||
@@ -114,7 +108,7 @@ open class Message : RealmObject() {
|
||||
|
||||
fun isDelivered(): Boolean {
|
||||
val isDeliveredMms = false // TODO
|
||||
val isDeliveredSms = deliveryStatus == DeliveryStatus.RECEIVED
|
||||
val isDeliveredSms = deliveryStatus == Sms.STATUS_COMPLETE
|
||||
return isDeliveredMms || isDeliveredSms
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.net.Uri
|
||||
import android.provider.BaseColumns
|
||||
import android.provider.Telephony
|
||||
import android.provider.Telephony.Sms
|
||||
import android.provider.Telephony.TextBasedSmsColumns
|
||||
import common.util.Keys
|
||||
import common.util.MessageUtils
|
||||
import common.util.extensions.*
|
||||
@@ -389,7 +388,7 @@ class MessageRepository @Inject constructor(
|
||||
.doOnNext { message ->
|
||||
// Update the message in realm
|
||||
realm.executeTransaction {
|
||||
message.deliveryStatus = Message.DeliveryStatus.RECEIVED
|
||||
message.deliveryStatus = Sms.STATUS_COMPLETE
|
||||
message.dateSent = System.currentTimeMillis()
|
||||
message.read = true
|
||||
}
|
||||
@@ -399,7 +398,7 @@ class MessageRepository @Inject constructor(
|
||||
.doOnNext { uri ->
|
||||
// Update the message in the native ContentProvider
|
||||
val values = ContentValues()
|
||||
values.put(Sms.STATUS, TextBasedSmsColumns.STATUS_COMPLETE)
|
||||
values.put(Sms.STATUS, Sms.STATUS_COMPLETE)
|
||||
values.put(Sms.DATE_SENT, System.currentTimeMillis())
|
||||
values.put(Sms.READ, true)
|
||||
context.contentResolver.update(uri, values, null, null)
|
||||
@@ -418,7 +417,7 @@ class MessageRepository @Inject constructor(
|
||||
.doOnNext { message ->
|
||||
// Update the message in realm
|
||||
realm.executeTransaction {
|
||||
message.deliveryStatus = Message.DeliveryStatus.FAILED
|
||||
message.deliveryStatus = Sms.STATUS_FAILED
|
||||
message.dateSent = System.currentTimeMillis()
|
||||
message.read = true
|
||||
message.errorCode = resultCode
|
||||
@@ -429,7 +428,7 @@ class MessageRepository @Inject constructor(
|
||||
.doOnNext { uri ->
|
||||
// Update the message in the native ContentProvider
|
||||
val values = ContentValues()
|
||||
values.put(Sms.STATUS, TextBasedSmsColumns.STATUS_FAILED)
|
||||
values.put(Sms.STATUS, Sms.STATUS_FAILED)
|
||||
values.put(Sms.DATE_SENT, System.currentTimeMillis())
|
||||
values.put(Sms.READ, true)
|
||||
values.put(Sms.ERROR_CODE, resultCode)
|
||||
|
||||
Reference in New Issue
Block a user