mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Merge branch 'master' into add-simple-characters
This commit is contained in:
@@ -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,10 +23,11 @@ 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.extensions.markThreadMessagesRead
|
||||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesUnread
|
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesUnread
|
||||||
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 com.simplemobiletools.smsmessenger.models.Events
|
|
||||||
import kotlinx.android.synthetic.main.item_conversation.view.*
|
import kotlinx.android.synthetic.main.item_conversation.view.*
|
||||||
|
|
||||||
class ConversationsAdapter(
|
class ConversationsAdapter(
|
||||||
@@ -61,8 +62,9 @@ class ConversationsAdapter(
|
|||||||
R.id.cab_dial_number -> dialNumber()
|
R.id.cab_dial_number -> dialNumber()
|
||||||
R.id.cab_copy_number -> copyNumberToClipboard()
|
R.id.cab_copy_number -> copyNumberToClipboard()
|
||||||
R.id.cab_delete -> askConfirmDelete()
|
R.id.cab_delete -> askConfirmDelete()
|
||||||
R.id.cab_select_all -> selectAll()
|
R.id.cab_mark_as_read -> markAsRead()
|
||||||
R.id.cab_mark_as_unread -> markAsUnread()
|
R.id.cab_mark_as_unread -> markAsUnread()
|
||||||
|
R.id.cab_select_all -> selectAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,14 +189,15 @@ class ConversationsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun markAsUnread() {
|
private fun markAsRead() {
|
||||||
if (selectedKeys.isEmpty()) {
|
if (selectedKeys.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val conversationsMarkedAsUnread = conversations.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
|
|
||||||
|
val conversationsMarkedAsRead = conversations.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
conversationsMarkedAsUnread.filter { conversation -> conversation.read }.forEach {
|
conversationsMarkedAsRead.filter { conversation -> !conversation.read }.forEach {
|
||||||
activity.markThreadMessagesUnread(it.threadId)
|
activity.markThreadMessagesRead(it.threadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
@@ -204,6 +207,19 @@ class ConversationsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun markAsUnread() {
|
||||||
|
if (selectedKeys.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val conversationsMarkedAsUnread = conversations.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversationsMarkedAsUnread.filter { conversation -> conversation.read }.forEach {
|
||||||
|
activity.markThreadMessagesUnread(it.threadId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun addNumberToContact() {
|
private fun addNumberToContact() {
|
||||||
val conversation = getSelectedItems().firstOrNull() ?: return
|
val conversation = getSelectedItems().firstOrNull() ?: return
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
@@ -240,6 +256,10 @@ 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)
|
||||||
|
draft_indicator.beVisibleIf(smsDraft != null)
|
||||||
|
draft_indicator.setTextColor(adjustedPrimaryColor)
|
||||||
|
|
||||||
conversation_frame.isSelected = selectedKeys.contains(conversation.hashCode())
|
conversation_frame.isSelected = selectedKeys.contains(conversation.hashCode())
|
||||||
|
|
||||||
conversation_address.apply {
|
conversation_address.apply {
|
||||||
@@ -248,7 +268,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,9 +35,9 @@ import com.simplemobiletools.smsmessenger.interfaces.MessagesDao
|
|||||||
import com.simplemobiletools.smsmessenger.models.*
|
import com.simplemobiletools.smsmessenger.models.*
|
||||||
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
|
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
|
||||||
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
||||||
|
import me.leolin.shortcutbadger.ShortcutBadger
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import me.leolin.shortcutbadger.ShortcutBadger
|
|
||||||
import java.text.Normalizer
|
import java.text.Normalizer
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
@@ -776,6 +776,58 @@ fun Context.removeDiacriticsIfNeeded(text: String): String {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.updateLastConversationMessage(threadId: Long) {
|
fun Context.updateLastConversationMessage(threadId: Long) {
|
||||||
val uri = Threads.CONTENT_URI
|
val uri = Threads.CONTENT_URI
|
||||||
val selection = "${Threads._ID} = ?"
|
val selection = "${Threads._ID} = ?"
|
||||||
|
@@ -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"
|
||||||
|
@@ -25,6 +25,10 @@
|
|||||||
android:id="@+id/cab_copy_number"
|
android:id="@+id/cab_copy_number"
|
||||||
android:title="@string/copy_number_to_clipboard"
|
android:title="@string/copy_number_to_clipboard"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_mark_as_read"
|
||||||
|
android:title="@string/mark_as_read"
|
||||||
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_mark_as_unread"
|
android:id="@+id/cab_mark_as_unread"
|
||||||
android:title="@string/mark_as_unread"
|
android:title="@string/mark_as_unread"
|
||||||
|
Reference in New Issue
Block a user