Merge branch 'master' into feature/compress-images
# Conflicts: # app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
This commit is contained in:
commit
b52aeda83b
4 changed files with 87 additions and 2 deletions
|
|
@ -768,6 +768,58 @@ fun Context.getLockScreenVisibilityText(type: Int) = getString(
|
|||
}
|
||||
)
|
||||
|
||||
fun Context.getSmsDraft(threadId: Long): String? {
|
||||
val uri = Sms.Draft.CONTENT_URI
|
||||
val projection = arrayOf(Sms.BODY)
|
||||
val selection = "${Sms.THREAD_ID} = ?"
|
||||
val selectionArgs = arrayOf(threadId.toString())
|
||||
|
||||
try {
|
||||
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
cursor.use {
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
return cursor.getString(0)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun Context.saveSmsDraft(body: String, threadId: Long) {
|
||||
val uri = Sms.Draft.CONTENT_URI
|
||||
val contentValues = ContentValues().apply {
|
||||
put(Sms.BODY, body)
|
||||
put(Sms.DATE, System.currentTimeMillis().toString())
|
||||
put(Sms.TYPE, Sms.MESSAGE_TYPE_DRAFT)
|
||||
put(Sms.THREAD_ID, threadId)
|
||||
}
|
||||
|
||||
try {
|
||||
contentResolver.insert(uri, contentValues)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.deleteSmsDraft(threadId: Long) {
|
||||
val uri = Sms.Draft.CONTENT_URI
|
||||
val projection = arrayOf(Sms._ID)
|
||||
val selection = "${Sms.THREAD_ID} = ?"
|
||||
val selectionArgs = arrayOf(threadId.toString())
|
||||
try {
|
||||
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
cursor.use {
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
val draftId = cursor.getLong(0)
|
||||
val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}")
|
||||
contentResolver.delete(draftUri, null, null)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getMMSFileLimitText(size: Long) = getString(
|
||||
when (size) {
|
||||
FILE_SIZE_100_KB -> R.string.mms_file_size_limit_100kb
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue