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