Merge branch 'master' into feature/compress-images

# Conflicts:
#	app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
This commit is contained in:
Paul Akhamiogu 2021-09-08 22:07:52 +01:00
commit b52aeda83b
4 changed files with 87 additions and 2 deletions

View file

@ -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