mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-04-14 10:22:12 +02:00
Added SMS drafts support (#83)
This commit is contained in:
parent
72833f6f16
commit
7b84ec77fd
@ -108,11 +108,25 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
|
val smsDraft = getSmsDraft(threadId)
|
||||||
|
if (smsDraft != null) {
|
||||||
|
thread_type_message.setText(smsDraft)
|
||||||
|
}
|
||||||
isActivityVisible = true
|
isActivityVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.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
|
isActivityVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
|||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
import com.simplemobiletools.smsmessenger.extensions.deleteConversation
|
import com.simplemobiletools.smsmessenger.extensions.deleteConversation
|
||||||
|
import com.simplemobiletools.smsmessenger.extensions.getSmsDraft
|
||||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
import kotlinx.android.synthetic.main.item_conversation.view.*
|
import kotlinx.android.synthetic.main.item_conversation.view.*
|
||||||
@ -220,6 +221,8 @@ class ConversationsAdapter(
|
|||||||
|
|
||||||
private fun setupView(view: View, conversation: Conversation) {
|
private fun setupView(view: View, conversation: Conversation) {
|
||||||
view.apply {
|
view.apply {
|
||||||
|
val smsDraft = context.getSmsDraft(conversation.threadId)
|
||||||
|
|
||||||
conversation_frame.isSelected = selectedKeys.contains(conversation.hashCode())
|
conversation_frame.isSelected = selectedKeys.contains(conversation.hashCode())
|
||||||
|
|
||||||
conversation_address.apply {
|
conversation_address.apply {
|
||||||
@ -228,10 +231,14 @@ class ConversationsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
conversation_body_short.apply {
|
conversation_body_short.apply {
|
||||||
text = conversation.snippet
|
text = smsDraft ?: conversation.snippet
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.9f)
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.9f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draft_indicator.apply {
|
||||||
|
visibility = if (smsDraft != null) View.VISIBLE else View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
conversation_date.apply {
|
conversation_date.apply {
|
||||||
text = conversation.date.formatDateOrTime(context, true, false)
|
text = conversation.date.formatDateOrTime(context, true, false)
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f)
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f)
|
||||||
|
@ -764,3 +764,55 @@ fun Context.getLockScreenVisibilityText(type: Int) = getString(
|
|||||||
else -> R.string.nothing
|
else -> R.string.nothing
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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 lookupUri = Sms.Draft.CONTENT_URI
|
||||||
|
val lookupProjection = arrayOf(Sms._ID)
|
||||||
|
val lookupSelection = "${Sms.THREAD_ID} = ?"
|
||||||
|
val lookupSelectionArgs = arrayOf(threadId.toString())
|
||||||
|
try {
|
||||||
|
val cursor = contentResolver.query(lookupUri, lookupProjection, lookupSelection, lookupSelectionArgs, null)
|
||||||
|
cursor.use {
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
val draftId = cursor.getLong(0)
|
||||||
|
val uri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}")
|
||||||
|
contentResolver.delete(uri, null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -37,12 +37,26 @@
|
|||||||
android:textSize="@dimen/big_text_size"
|
android:textSize="@dimen/big_text_size"
|
||||||
tools:text="John" />
|
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
|
<TextView
|
||||||
android:id="@+id/conversation_body_short"
|
android:id="@+id/conversation_body_short"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/conversation_address"
|
android:layout_below="@+id/conversation_address"
|
||||||
android:layout_toEndOf="@+id/conversation_image"
|
android:layout_toEndOf="@+id/draft_indicator"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingEnd="@dimen/activity_margin"
|
android:paddingEnd="@dimen/activity_margin"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user