forked from upstream-mirrors/quik
Only display notifications for messages that are unread and unseen
This commit is contained in:
@@ -7,7 +7,7 @@ import com.moez.QKSMS.data.repository.ConversationRepository
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.data.sync.SyncManager
|
||||
import com.moez.QKSMS.util.DateFormatter
|
||||
import com.moez.QKSMS.util.NotificationHelper
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
@@ -35,8 +35,8 @@ class AppModule(var application: Application) {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideNotificationHelper(context: Context): NotificationHelper {
|
||||
return NotificationHelper(context)
|
||||
fun provideNotificationHelper(context: Context): NotificationManager {
|
||||
return NotificationManager(context)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -36,7 +36,7 @@ open class Conversation() : RealmObject() {
|
||||
|
||||
snippet = cursor.getString(ConversationColumns.SNIPPET) ?: ""
|
||||
snippetCs = cursor.getString(ConversationColumns.SNIPPET_CS) ?: ""
|
||||
read = cursor.getInt(ConversationColumns.READ) == 1
|
||||
read = cursor.getInt(ConversationColumns.READ) != 0
|
||||
error = cursor.getInt(ConversationColumns.ERROR)
|
||||
hasAttachment = cursor.getInt(ConversationColumns.HAS_ATTACHMENT)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ open class Message() : RealmObject() {
|
||||
var body: String = ""
|
||||
var date: Long = 0
|
||||
var dateSent: Long = 0
|
||||
var seen: Boolean = false
|
||||
var read: Boolean = false
|
||||
var errorType: Int = 0
|
||||
|
||||
constructor(threadId: Long, cursor: Cursor, columnsMap: MessageColumns) : this() {
|
||||
@@ -33,10 +35,14 @@ open class Message() : RealmObject() {
|
||||
boxId = cursor.getInt(columnsMap.mmsMessageBox)
|
||||
date = cursor.getLong(columnsMap.smsDate)
|
||||
dateSent = cursor.getLong(columnsMap.smsDateSent)
|
||||
seen = cursor.getInt(columnsMap.smsSeen) != 0
|
||||
read = cursor.getInt(columnsMap.smsRead) != 0
|
||||
} else {
|
||||
boxId = cursor.getInt(columnsMap.smsType)
|
||||
date = cursor.getLong(columnsMap.mmsDate)
|
||||
dateSent = cursor.getLong(columnsMap.mmsDateSent)
|
||||
seen = cursor.getInt(columnsMap.mmsSeen) != 0
|
||||
read = cursor.getInt(columnsMap.mmsRead) != 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class MessageColumns(val cursor: Cursor) {
|
||||
Telephony.Sms.BODY,
|
||||
Telephony.Sms.DATE,
|
||||
Telephony.Sms.DATE_SENT,
|
||||
Telephony.Sms.SEEN,
|
||||
Telephony.Sms.READ,
|
||||
Telephony.Sms.TYPE,
|
||||
Telephony.Sms.STATUS,
|
||||
@@ -32,6 +33,7 @@ class MessageColumns(val cursor: Cursor) {
|
||||
Telephony.Mms.SUBJECT_CHARSET,
|
||||
Telephony.Mms.DATE,
|
||||
Telephony.Mms.DATE_SENT,
|
||||
Telephony.Mms.SEEN,
|
||||
Telephony.Mms.READ,
|
||||
Telephony.Mms.MESSAGE_TYPE,
|
||||
Telephony.Mms.MESSAGE_BOX,
|
||||
@@ -51,25 +53,27 @@ class MessageColumns(val cursor: Cursor) {
|
||||
val smsBody = getColumnIndex(4)
|
||||
val smsDate = getColumnIndex(5)
|
||||
val smsDateSent = getColumnIndex(6)
|
||||
val smsRead = getColumnIndex(7)
|
||||
val smsType = getColumnIndex(8)
|
||||
val smsStatus = getColumnIndex(9)
|
||||
val smsLocked = getColumnIndex(10)
|
||||
val smsErrorCode = getColumnIndex(11)
|
||||
val smsSeen = getColumnIndex(7)
|
||||
val smsRead = getColumnIndex(8)
|
||||
val smsType = getColumnIndex(9)
|
||||
val smsStatus = getColumnIndex(10)
|
||||
val smsLocked = getColumnIndex(11)
|
||||
val smsErrorCode = getColumnIndex(12)
|
||||
|
||||
val mmsSubject = getColumnIndex(12)
|
||||
val mmsSubjectCharset = getColumnIndex(13)
|
||||
val mmsDate = getColumnIndex(14)
|
||||
val mmsDateSent = getColumnIndex(15)
|
||||
val mmsRead = getColumnIndex(16)
|
||||
val mmsMessageType = getColumnIndex(17)
|
||||
val mmsMessageBox = getColumnIndex(18)
|
||||
val mmsDeliveryReport = getColumnIndex(19)
|
||||
val mmsReadReport = getColumnIndex(20)
|
||||
val mmsErrorType = getColumnIndex(21)
|
||||
val mmsLocked = getColumnIndex(22)
|
||||
val mmsStatus = getColumnIndex(23)
|
||||
val mmsTextOnly = getColumnIndex(24)
|
||||
val mmsSubject = getColumnIndex(13)
|
||||
val mmsSubjectCharset = getColumnIndex(14)
|
||||
val mmsDate = getColumnIndex(15)
|
||||
val mmsDateSent = getColumnIndex(16)
|
||||
val mmsSeen = getColumnIndex(17)
|
||||
val mmsRead = getColumnIndex(18)
|
||||
val mmsMessageType = getColumnIndex(19)
|
||||
val mmsMessageBox = getColumnIndex(20)
|
||||
val mmsDeliveryReport = getColumnIndex(21)
|
||||
val mmsReadReport = getColumnIndex(22)
|
||||
val mmsErrorType = getColumnIndex(23)
|
||||
val mmsLocked = getColumnIndex(24)
|
||||
val mmsStatus = getColumnIndex(25)
|
||||
val mmsTextOnly = getColumnIndex(26)
|
||||
|
||||
private fun getColumnIndex(index: Int): Int {
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.repository.ConversationRepository
|
||||
import com.moez.QKSMS.data.sync.SyncManager
|
||||
import com.moez.QKSMS.util.NotificationHelper
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.realm.RealmResults
|
||||
import javax.inject.Inject
|
||||
@@ -14,7 +14,7 @@ import javax.inject.Inject
|
||||
class ConversationListViewModel : ViewModel() {
|
||||
|
||||
@Inject lateinit var syncManager: SyncManager
|
||||
@Inject lateinit var notificationManager: NotificationHelper
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
|
||||
val state: MutableLiveData<ConversationListViewState> = MutableLiveData()
|
||||
|
||||
+4
-5
@@ -11,10 +11,9 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.realm.Realm
|
||||
import io.realm.Sort
|
||||
|
||||
|
||||
class NotificationHelper(val context: Context) {
|
||||
class NotificationManager(val context: Context) {
|
||||
|
||||
private val notificationManager = NotificationManagerCompat.from(context)
|
||||
|
||||
@@ -46,9 +45,9 @@ class NotificationHelper(val context: Context) {
|
||||
val style = NotificationCompat.MessagingStyle("Me")
|
||||
realm.where(Message::class.java)
|
||||
.equalTo("threadId", conversation.id)
|
||||
.findAllSorted("date", Sort.DESCENDING)
|
||||
.take(2)
|
||||
.reversed()
|
||||
.equalTo("seen", false)
|
||||
.equalTo("read", false)
|
||||
.findAllSorted("date")
|
||||
.forEach { message ->
|
||||
val name = if (message.isMe()) null else conversation.getTitle()
|
||||
style.addMessage(message.body, message.date, name)
|
||||
Reference in New Issue
Block a user