52 lines
1.9 KiB
Kotlin
52 lines
1.9 KiB
Kotlin
package com.simplemobiletools.smsmessenger.receivers
|
|
|
|
import android.app.Activity
|
|
import android.content.ContentValues
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.database.sqlite.SQLiteException
|
|
import android.net.Uri
|
|
import android.provider.Telephony
|
|
import android.widget.Toast
|
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
|
import com.simplemobiletools.commons.extensions.toast
|
|
import com.simplemobiletools.smsmessenger.R
|
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
|
import java.io.File
|
|
|
|
/** Handles updating databases and states when a MMS message is sent. */
|
|
class MmsSentReceiver : SendStatusReceiver() {
|
|
|
|
override fun updateAndroidDatabase(context: Context, intent: Intent, receiverResultCode: Int) {
|
|
val uri = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI))
|
|
val messageBox = if (receiverResultCode == Activity.RESULT_OK) {
|
|
Telephony.Mms.MESSAGE_BOX_SENT
|
|
} else {
|
|
val msg = context.getString(R.string.unknown_error_occurred_sending_message, receiverResultCode)
|
|
context.toast(msg = msg, length = Toast.LENGTH_LONG)
|
|
Telephony.Mms.MESSAGE_BOX_FAILED
|
|
}
|
|
val values = ContentValues(1).apply {
|
|
put(Telephony.Mms.MESSAGE_BOX, messageBox)
|
|
}
|
|
try {
|
|
context.contentResolver.update(uri, values, null, null)
|
|
} catch (e: SQLiteException) {
|
|
context.showErrorToast(e)
|
|
}
|
|
|
|
val filePath = intent.getStringExtra(EXTRA_FILE_PATH)
|
|
if (filePath != null) {
|
|
File(filePath).delete()
|
|
}
|
|
}
|
|
|
|
override fun updateAppDatabase(context: Context, intent: Intent, receiverResultCode: Int) {
|
|
refreshMessages()
|
|
}
|
|
|
|
companion object {
|
|
private const val EXTRA_CONTENT_URI = "content_uri"
|
|
private const val EXTRA_FILE_PATH = "file_path"
|
|
}
|
|
}
|