mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-19 11:51:40 +01:00
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
@ -109,11 +109,25 @@ class ThreadActivity : SimpleActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val smsDraft = getSmsDraft(threadId)
|
||||
if (smsDraft != null) {
|
||||
thread_type_message.setText(smsDraft)
|
||||
}
|
||||
isActivityVisible = true
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
if (thread_type_message.value != "" && attachmentUris.isEmpty()) {
|
||||
saveSmsDraft(thread_type_message.value, threadId)
|
||||
} else {
|
||||
deleteSmsDraft(threadId)
|
||||
}
|
||||
|
||||
bus?.post(Events.RefreshMessages())
|
||||
|
||||
isActivityVisible = false
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteConversation
|
||||
import com.simplemobiletools.smsmessenger.extensions.getSmsDraft
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesRead
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesUnread
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
@ -255,6 +256,10 @@ class ConversationsAdapter(
|
||||
|
||||
private fun setupView(view: View, conversation: Conversation) {
|
||||
view.apply {
|
||||
val smsDraft = context.getSmsDraft(conversation.threadId)
|
||||
draft_indicator.beVisibleIf(smsDraft != null)
|
||||
draft_indicator.setTextColor(adjustedPrimaryColor)
|
||||
|
||||
conversation_frame.isSelected = selectedKeys.contains(conversation.hashCode())
|
||||
|
||||
conversation_address.apply {
|
||||
@ -263,7 +268,7 @@ class ConversationsAdapter(
|
||||
}
|
||||
|
||||
conversation_body_short.apply {
|
||||
text = conversation.snippet
|
||||
text = smsDraft ?: conversation.snippet
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.9f)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -37,12 +37,26 @@
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="John" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/draft_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/conversation_address"
|
||||
android:layout_toEndOf="@+id/conversation_image"
|
||||
android:textColor="@color/color_primary"
|
||||
android:textStyle="italic"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
android:text="@string/draft" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/conversation_body_short"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/conversation_address"
|
||||
android:layout_toEndOf="@+id/conversation_image"
|
||||
android:layout_toEndOf="@+id/draft_indicator"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
|
Loading…
Reference in New Issue
Block a user