show an error at messages that havent been sent

This commit is contained in:
tibbi 2020-04-04 19:41:48 +02:00
parent 35a2023866
commit 3eb1127c74
6 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.smsmessenger.activities
import android.os.Bundle
import android.provider.Telephony
import android.telephony.SmsManager
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.onTextChangeListener
@ -13,6 +14,7 @@ import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadError
import com.simplemobiletools.smsmessenger.models.ThreadItem
import kotlinx.android.synthetic.main.activity_thread.*
@ -67,6 +69,10 @@ class ThreadActivity : SimpleActivity() {
prevDateTime = it.date
}
items.add(it)
if (it.type == Telephony.Sms.MESSAGE_TYPE_FAILED) {
items.add(ThreadError(it.id))
}
}
return items

View File

@ -12,8 +12,10 @@ import com.simplemobiletools.smsmessenger.activities.SimpleActivity
import com.simplemobiletools.smsmessenger.helpers.THREAD_DATE_TIME
import com.simplemobiletools.smsmessenger.helpers.THREAD_RECEIVED_MESSAGE
import com.simplemobiletools.smsmessenger.helpers.THREAD_SENT_MESSAGE
import com.simplemobiletools.smsmessenger.helpers.THREAD_SENT_MESSAGE_ERROR
import com.simplemobiletools.smsmessenger.models.Message
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadError
import com.simplemobiletools.smsmessenger.models.ThreadItem
import kotlinx.android.synthetic.main.item_received_message.view.*
import kotlinx.android.synthetic.main.item_thread_date_time.view.*
@ -59,6 +61,7 @@ class ThreadAdapter(
val layout = when (viewType) {
THREAD_DATE_TIME -> R.layout.item_thread_date_time
THREAD_RECEIVED_MESSAGE -> R.layout.item_received_message
THREAD_SENT_MESSAGE_ERROR -> R.layout.item_thread_error
else -> R.layout.item_sent_message
}
return createViewHolder(layout, parent)
@ -69,7 +72,7 @@ class ThreadAdapter(
holder.bindView(item, true, item is Message) { itemView, layoutPosition ->
if (item is ThreadDateTime) {
setupDateTime(itemView, item)
} else {
} else if (item !is ThreadError) {
setupView(itemView, item as Message)
}
}
@ -83,6 +86,7 @@ class ThreadAdapter(
return when {
item is ThreadDateTime -> THREAD_DATE_TIME
(messages[position] as? Message)?.isReceivedMessage() == true -> THREAD_RECEIVED_MESSAGE
item is ThreadError -> THREAD_SENT_MESSAGE_ERROR
else -> THREAD_SENT_MESSAGE
}
}

View File

@ -8,3 +8,4 @@ const val THREAD_NUMBER = "thread_number"
const val THREAD_DATE_TIME = 1
const val THREAD_RECEIVED_MESSAGE = 2
const val THREAD_SENT_MESSAGE = 3
const val THREAD_SENT_MESSAGE_ERROR = 4

View File

@ -0,0 +1,3 @@
package com.simplemobiletools.smsmessenger.models
data class ThreadError(val messageID: Int) : ThreadItem()

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/thread_date_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/message_not_sent"
android:textColor="@color/theme_dark_red_primary_color"
android:textSize="@dimen/normal_text_size" />

View File

@ -2,4 +2,5 @@
<string name="app_name">Simple SMS Messenger</string>
<string name="app_launcher_name">SMS Messenger</string>
<string name="type_a_message">Type a message…</string>
<string name="message_not_sent">Message has not been sent.</string>
</resources>