mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Merge pull request #3 from moezbhatti/revise-architecture
Revise architecture
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.1.4-3'
|
||||
ext.kotlin_version = '1.1.50'
|
||||
repositories {
|
||||
maven { url 'https://maven.google.com' }
|
||||
jcenter()
|
||||
|
||||
+1
-5
@@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
|
||||
apply plugin: 'realm-android' // Realm needs to be before Kotlin or the build will fail
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
@@ -30,7 +31,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
@@ -55,7 +55,3 @@ dependencies {
|
||||
kapt 'io.realm:realm-annotations-processor:3.7.0'
|
||||
provided 'javax.annotation:jsr250-api:1.0'
|
||||
}
|
||||
|
||||
kapt {
|
||||
generateStubs = true
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_SMS" />
|
||||
|
||||
<application
|
||||
android:name=".QKApplication"
|
||||
android:name=".common.QKApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
@@ -21,7 +21,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".ui.conversations.ConversationListActivity"
|
||||
android:name="com.moez.QKSMS.presentation.conversations.ConversationListActivity"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -44,7 +44,7 @@
|
||||
<data android:scheme="sms_body" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ui.messages.MessageListActivity" />
|
||||
<activity android:name="com.moez.QKSMS.presentation.messages.MessageListActivity" />
|
||||
|
||||
<receiver
|
||||
android:name=".receiver.SmsReceiver"
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.moez.QKSMS
|
||||
package com.moez.QKSMS.common
|
||||
|
||||
import android.app.Application
|
||||
import com.bugsnag.android.Bugsnag
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import timber.log.Timber
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
package com.moez.QKSMS.dagger
|
||||
package com.moez.QKSMS.common.di
|
||||
|
||||
import com.moez.QKSMS.common.util.NotificationManager
|
||||
import com.moez.QKSMS.presentation.conversations.ConversationAdapter
|
||||
import com.moez.QKSMS.presentation.conversations.ConversationListViewModel
|
||||
import com.moez.QKSMS.presentation.messages.MessageAdapter
|
||||
import com.moez.QKSMS.presentation.messages.MessageListActivity
|
||||
import com.moez.QKSMS.presentation.messages.MessageListViewModel
|
||||
import com.moez.QKSMS.presentation.view.AvatarView
|
||||
import com.moez.QKSMS.receiver.*
|
||||
import com.moez.QKSMS.ui.conversations.ConversationAdapter
|
||||
import com.moez.QKSMS.ui.conversations.ConversationListViewModel
|
||||
import com.moez.QKSMS.ui.messages.MessageAdapter
|
||||
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||
import com.moez.QKSMS.ui.messages.MessageListViewModel
|
||||
import com.moez.QKSMS.ui.view.AvatarView
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import dagger.Component
|
||||
import javax.inject.Singleton
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.moez.QKSMS.dagger
|
||||
package com.moez.QKSMS.common.di
|
||||
|
||||
import com.moez.QKSMS.QKApplication
|
||||
import com.moez.QKSMS.common.QKApplication
|
||||
|
||||
internal object AppComponentManager {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.moez.QKSMS.common.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class AppModule(private var application: Application) {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContext(): Context {
|
||||
return application
|
||||
}
|
||||
|
||||
}
|
||||
+8
-5
@@ -1,14 +1,17 @@
|
||||
package com.moez.QKSMS.util
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import com.moez.QKSMS.util.extensions.isSameDay
|
||||
import com.moez.QKSMS.util.extensions.isSameWeek
|
||||
import com.moez.QKSMS.util.extensions.isSameYear
|
||||
import com.moez.QKSMS.common.util.extensions.isSameDay
|
||||
import com.moez.QKSMS.common.util.extensions.isSameWeek
|
||||
import com.moez.QKSMS.common.util.extensions.isSameYear
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class DateFormatter(val context: Context) {
|
||||
@Singleton
|
||||
class DateFormatter @Inject constructor(val context: Context) {
|
||||
|
||||
/**
|
||||
* Replace 12 hour format with 24 hour format if necessary
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.arch.lifecycle.LiveData
|
||||
import io.realm.RealmChangeListener
|
||||
+8
-4
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
@@ -15,10 +15,14 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.receiver.MarkReadReceiver
|
||||
import com.moez.QKSMS.receiver.MarkSeenReceiver
|
||||
import com.moez.QKSMS.receiver.RemoteMessagingReceiver
|
||||
import com.moez.QKSMS.ui.conversations.ConversationListActivity
|
||||
import com.moez.QKSMS.presentation.conversations.ConversationListActivity
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
class NotificationManager(private val context: Context, private val themeManager: ThemeManager) {
|
||||
@Singleton
|
||||
class NotificationManager @Inject constructor(
|
||||
private val context: Context,
|
||||
private val themeManager: ThemeManager) {
|
||||
|
||||
private val notificationManager = NotificationManagerCompat.from(context)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ThemeManager @Inject constructor() {
|
||||
|
||||
val color = 0xFF008389.toInt()
|
||||
val bubbleColor = 0xFFF4F4F4.toInt()
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import java.util.*
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.ContextCompat
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.database.Cursor
|
||||
import io.reactivex.Flowable
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmObject
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.moez.QKSMS.dagger
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
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.NotificationManager
|
||||
import com.moez.QKSMS.util.ThemeManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class AppModule(var application: Application) {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContext(): Context {
|
||||
return application
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideDateFormatter(context: Context): DateFormatter {
|
||||
return DateFormatter(context)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSyncManager(context: Context, contacts: ContactRepository): SyncManager {
|
||||
return SyncManager(context, contacts)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideThemeMaager(): ThemeManager {
|
||||
return ThemeManager()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideNotificationHelper(context: Context, themeManager: ThemeManager): NotificationManager {
|
||||
return NotificationManager(context, themeManager)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideMessageRepository(context: Context, notificationManager: NotificationManager): MessageRepository {
|
||||
return MessageRepository(context, notificationManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContactRepository(context: Context): ContactRepository {
|
||||
return ContactRepository(context)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.moez.QKSMS.data.mapper
|
||||
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony.Threads
|
||||
import com.moez.QKSMS.common.util.extensions.asFlowable
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToConversationFlowable @Inject constructor(val contactsRepo: ContactRepository) : Mapper<Cursor, Flowable<Conversation>> {
|
||||
|
||||
override fun map(from: Cursor): Flowable<Conversation> {
|
||||
return from.asFlowable().map { cursor ->
|
||||
Conversation().apply {
|
||||
id = cursor.getLong(ID)
|
||||
|
||||
cursor.getString(RECIPIENT_IDS).split(" ")
|
||||
.map { id -> id.toLong() }
|
||||
.map { id -> contactsRepo.getContactBlocking(id) }
|
||||
.filter { contact -> contact.recipientId != 0L }
|
||||
.forEach { contact -> contacts.add(contact) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val URI: Uri = Uri.parse("content://mms-sms/conversations?simple=true")
|
||||
val PROJECTION = arrayOf(
|
||||
Threads._ID,
|
||||
Threads.RECIPIENT_IDS)
|
||||
|
||||
val ID = 0
|
||||
val RECIPIENT_IDS = 1
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.moez.QKSMS.data.mapper
|
||||
|
||||
import android.database.Cursor
|
||||
import android.provider.Telephony.*
|
||||
import com.moez.QKSMS.common.util.extensions.asFlowable
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.reactivex.Flowable
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToMessageFlowable @Inject constructor() : Mapper<Cursor, Flowable<Message>> {
|
||||
|
||||
override fun map(from: Cursor): Flowable<Message> {
|
||||
val columnsMap = MessageColumns(from)
|
||||
return from.asFlowable().map { cursor ->
|
||||
Message().apply {
|
||||
type = when (cursor.getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN)) {
|
||||
-1 -> "sms"
|
||||
else -> cursor.getString(columnsMap.msgType)
|
||||
}
|
||||
|
||||
id = cursor.getLong(columnsMap.msgId)
|
||||
body = cursor.getString(columnsMap.smsBody) ?: ""
|
||||
|
||||
when (type) {
|
||||
"sms" -> {
|
||||
threadId = cursor.getLong(columnsMap.smsThreadId)
|
||||
address = cursor.getString(columnsMap.smsAddress)
|
||||
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
|
||||
}
|
||||
|
||||
"mms" -> {
|
||||
threadId = cursor.getLong(columnsMap.mmsThreadId)
|
||||
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
|
||||
errorType = cursor.getInt(columnsMap.mmsErrorType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val CURSOR_PROJECTION = arrayOf(
|
||||
MmsSms.TYPE_DISCRIMINATOR_COLUMN,
|
||||
MmsSms._ID,
|
||||
|
||||
Sms.THREAD_ID,
|
||||
Sms.ADDRESS,
|
||||
Sms.BODY,
|
||||
Sms.DATE,
|
||||
Sms.DATE_SENT,
|
||||
Sms.SEEN,
|
||||
Sms.READ,
|
||||
Sms.TYPE,
|
||||
Sms.STATUS,
|
||||
Sms.LOCKED,
|
||||
Sms.ERROR_CODE,
|
||||
|
||||
Mms.THREAD_ID,
|
||||
Mms.SUBJECT,
|
||||
Mms.SUBJECT_CHARSET,
|
||||
Mms.DATE,
|
||||
Mms.DATE_SENT,
|
||||
Mms.SEEN,
|
||||
Mms.READ,
|
||||
Mms.MESSAGE_TYPE,
|
||||
Mms.MESSAGE_BOX,
|
||||
Mms.DELIVERY_REPORT,
|
||||
Mms.READ_REPORT,
|
||||
MmsSms.PendingMessages.ERROR_TYPE,
|
||||
Mms.LOCKED,
|
||||
Mms.STATUS,
|
||||
Mms.TEXT_ONLY)
|
||||
}
|
||||
|
||||
private class MessageColumns(val cursor: Cursor) {
|
||||
|
||||
val msgType by lazy { getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) }
|
||||
val msgId by lazy { getColumnIndex(MmsSms._ID) }
|
||||
|
||||
val smsThreadId by lazy { getColumnIndex(Sms.THREAD_ID) }
|
||||
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
|
||||
val smsBody by lazy { getColumnIndex(Sms.BODY) }
|
||||
val smsDate by lazy { getColumnIndex(Sms.DATE) }
|
||||
val smsDateSent by lazy { getColumnIndex(Sms.DATE_SENT) }
|
||||
val smsSeen by lazy { getColumnIndex(Sms.SEEN) }
|
||||
val smsRead by lazy { getColumnIndex(Sms.READ) }
|
||||
val smsType by lazy { getColumnIndex(Sms.TYPE) }
|
||||
val smsStatus by lazy { getColumnIndex(Sms.STATUS) }
|
||||
val smsLocked by lazy { getColumnIndex(Sms.LOCKED) }
|
||||
val smsErrorCode by lazy { getColumnIndex(Sms.ERROR_CODE) }
|
||||
|
||||
val mmsThreadId by lazy { getColumnIndex(Mms.THREAD_ID) }
|
||||
val mmsSubject by lazy { getColumnIndex(Mms.SUBJECT) }
|
||||
val mmsSubjectCharset by lazy { getColumnIndex(Mms.SUBJECT_CHARSET) }
|
||||
val mmsDate by lazy { getColumnIndex(Mms.DATE) }
|
||||
val mmsDateSent by lazy { getColumnIndex(Mms.DATE_SENT) }
|
||||
val mmsSeen by lazy { getColumnIndex(Mms.SEEN) }
|
||||
val mmsRead by lazy { getColumnIndex(Mms.READ) }
|
||||
val mmsMessageType by lazy { getColumnIndex(Mms.MESSAGE_TYPE) }
|
||||
val mmsMessageBox by lazy { getColumnIndex(Mms.MESSAGE_BOX) }
|
||||
val mmsDeliveryReport by lazy { getColumnIndex(Mms.DELIVERY_REPORT) }
|
||||
val mmsReadReport by lazy { getColumnIndex(Mms.READ_REPORT) }
|
||||
val mmsErrorType by lazy { getColumnIndex(MmsSms.PendingMessages.ERROR_TYPE) }
|
||||
val mmsLocked by lazy { getColumnIndex(Mms.LOCKED) }
|
||||
val mmsStatus by lazy { getColumnIndex(Mms.STATUS) }
|
||||
val mmsTextOnly by lazy { getColumnIndex(Mms.TEXT_ONLY) }
|
||||
|
||||
private fun getColumnIndex(columnsName: String): Int {
|
||||
return try {
|
||||
cursor.getColumnIndexOrThrow(columnsName)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
-1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.moez.QKSMS.data.mapper
|
||||
|
||||
interface Mapper<in From, out To> {
|
||||
|
||||
fun map(from: From): To
|
||||
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import io.reactivex.Maybe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
class ContactRepository(val context: Context) {
|
||||
@Singleton
|
||||
class ContactRepository @Inject constructor(val context: Context) {
|
||||
|
||||
/**
|
||||
* Uri for the MMS-SMS recipients table, where there exists only one column (address)
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
package com.moez.QKSMS.data.repository
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.BaseColumns
|
||||
import android.provider.Telephony.Sms
|
||||
import android.telephony.SmsManager
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.common.util.extensions.asFlowable
|
||||
import com.moez.QKSMS.common.util.extensions.insertOrUpdate
|
||||
import com.moez.QKSMS.data.mapper.CursorToMessageFlowable
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.sync.MessageColumns
|
||||
import com.moez.QKSMS.data.sync.SyncManager
|
||||
import com.moez.QKSMS.receiver.MessageDeliveredReceiver
|
||||
import com.moez.QKSMS.receiver.MessageSentReceiver
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import com.moez.QKSMS.util.extensions.asFlowable
|
||||
import com.moez.QKSMS.util.extensions.insertOrUpdate
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
import io.realm.Sort
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class MessageRepository(val context: Context, val notificationManager: NotificationManager) {
|
||||
@Singleton
|
||||
class MessageRepository @Inject constructor(private val context: Context) {
|
||||
|
||||
fun getConversationMessagesAsync(): RealmResults<Message> {
|
||||
return Realm.getDefaultInstance()
|
||||
@@ -61,181 +57,77 @@ class MessageRepository(val context: Context, val notificationManager: Notificat
|
||||
.findAllSorted("date")
|
||||
}
|
||||
|
||||
fun insertReceivedMessage(address: String, body: String, time: Long) {
|
||||
val values = ContentValues()
|
||||
values.put(Sms.ADDRESS, address)
|
||||
values.put(Sms.BODY, body)
|
||||
values.put(Sms.DATE_SENT, time)
|
||||
|
||||
val contentResolver = context.contentResolver
|
||||
Flowable.just(values)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { contentResolver.insert(Sms.Inbox.CONTENT_URI, values) }
|
||||
.subscribe { uri ->
|
||||
copyMessageToRealm(uri)
|
||||
notificationManager.update(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun markAllSeen() {
|
||||
// Messages in SMS ContentProvider
|
||||
val projection = arrayOf(BaseColumns._ID)
|
||||
val selection = "${Sms.SEEN} = 0"
|
||||
val contentResolver = context.contentResolver
|
||||
contentResolver.query(Sms.Inbox.CONTENT_URI, projection, selection, null, null)
|
||||
.asFlowable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { cursor -> cursor.getLong(0) }
|
||||
.map { id -> Uri.withAppendedPath(Sms.CONTENT_URI, id.toString()) }
|
||||
.subscribe { uri ->
|
||||
val values = ContentValues()
|
||||
values.put(Sms.SEEN, true)
|
||||
contentResolver.update(uri, values, null, null)
|
||||
}
|
||||
|
||||
// TODO also need to mark MMS in ContentProvider as Seen
|
||||
|
||||
// Messages in Realm
|
||||
Schedulers.io().scheduleDirect {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java).equalTo("seen", false).findAll()
|
||||
realm.executeTransaction { messages.forEach { message -> message.seen = true } }
|
||||
realm.close()
|
||||
}
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java).equalTo("seen", false).findAll()
|
||||
realm.executeTransaction { messages.forEach { message -> message.seen = true } }
|
||||
realm.close()
|
||||
}
|
||||
|
||||
fun markSeen(threadId: Long) {
|
||||
// Messages in SMS ContentProvider
|
||||
val projection = arrayOf(BaseColumns._ID)
|
||||
val selection = "${Sms.THREAD_ID} = $threadId AND ${Sms.SEEN} = 0"
|
||||
val contentResolver = context.contentResolver
|
||||
contentResolver.query(Sms.Inbox.CONTENT_URI, projection, selection, null, null)
|
||||
.asFlowable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { cursor -> cursor.getLong(0) }
|
||||
.map { id -> Uri.withAppendedPath(Sms.CONTENT_URI, id.toString()) }
|
||||
.subscribe { uri ->
|
||||
val values = ContentValues()
|
||||
values.put(Sms.SEEN, true)
|
||||
contentResolver.update(uri, values, null, null)
|
||||
}
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.equalTo("seen", false)
|
||||
.findAll()
|
||||
|
||||
// TODO also need to mark MMS in ContentProvider as Seen
|
||||
|
||||
// Messages in Realm
|
||||
Schedulers.io().scheduleDirect {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.equalTo("seen", false)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
messages.forEach { message ->
|
||||
message.seen = true
|
||||
}
|
||||
realm.executeTransaction {
|
||||
messages.forEach { message ->
|
||||
message.seen = true
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
|
||||
fun markRead(threadId: Long) {
|
||||
// Messages in SMS ContentProvider
|
||||
// TODO also need to mark MMS in ContentProvider as Read
|
||||
val projection = arrayOf(BaseColumns._ID)
|
||||
val selection = "${Sms.THREAD_ID} = $threadId AND (${Sms.SEEN} = 0 OR ${Sms.READ} = 0)"
|
||||
val selection = "${Telephony.Sms.THREAD_ID} = $threadId AND (${Telephony.Sms.SEEN} = 0 OR ${Telephony.Sms.READ} = 0)"
|
||||
val contentResolver = context.contentResolver
|
||||
contentResolver.query(Sms.Inbox.CONTENT_URI, projection, selection, null, null)
|
||||
contentResolver.query(Telephony.Sms.Inbox.CONTENT_URI, projection, selection, null, null)
|
||||
.asFlowable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { cursor -> cursor.getLong(0) }
|
||||
.map { id -> Uri.withAppendedPath(Sms.CONTENT_URI, id.toString()) }
|
||||
.map { id -> Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, id.toString()) }
|
||||
.subscribe { uri ->
|
||||
val values = ContentValues()
|
||||
values.put(Sms.SEEN, true)
|
||||
values.put(Sms.READ, true)
|
||||
values.put(Telephony.Sms.SEEN, true)
|
||||
values.put(Telephony.Sms.READ, true)
|
||||
contentResolver.update(uri, values, null, null)
|
||||
}
|
||||
|
||||
// TODO also need to mark MMS in ContentProvider as Read
|
||||
|
||||
// Messages in Realm
|
||||
Schedulers.io().scheduleDirect {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.beginGroup()
|
||||
.equalTo("read", false)
|
||||
.or()
|
||||
.equalTo("seen", false)
|
||||
.endGroup()
|
||||
.findAll()
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val messages = realm.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.beginGroup()
|
||||
.equalTo("read", false)
|
||||
.or()
|
||||
.equalTo("seen", false)
|
||||
.endGroup()
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
messages.forEach { message ->
|
||||
message.seen = true
|
||||
message.read = true
|
||||
}
|
||||
realm.executeTransaction {
|
||||
messages.forEach { message ->
|
||||
message.seen = true
|
||||
message.read = true
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
|
||||
fun markSent(uri: Uri) {
|
||||
val values = ContentValues()
|
||||
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_SENT)
|
||||
updateMessage(values, uri)
|
||||
}
|
||||
|
||||
fun markFailed(uri: Uri, resultCode: Int) {
|
||||
val values = ContentValues()
|
||||
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_FAILED)
|
||||
values.put(Sms.ERROR_CODE, resultCode)
|
||||
updateMessage(values, uri)
|
||||
}
|
||||
|
||||
fun sendMessage(threadId: Long, address: String, body: String) {
|
||||
val values = ContentValues()
|
||||
values.put(Sms.ADDRESS, address)
|
||||
values.put(Sms.BODY, body)
|
||||
values.put(Sms.DATE, System.currentTimeMillis())
|
||||
values.put(Sms.READ, true)
|
||||
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_OUTBOX)
|
||||
values.put(Sms.THREAD_ID, threadId)
|
||||
|
||||
val contentResolver = context.contentResolver
|
||||
Flowable.just(values)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { contentResolver.insert(Sms.CONTENT_URI, values) }
|
||||
.subscribe { uri ->
|
||||
copyMessageToRealm(uri)
|
||||
|
||||
val sentIntent = Intent(context, MessageSentReceiver::class.java).putExtra("uri", uri.toString())
|
||||
val sentPI = PendingIntent.getBroadcast(context, uri.lastPathSegment.toInt(), sentIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val deliveredIntent = Intent(context, MessageDeliveredReceiver::class.java).putExtra("uri", uri.toString())
|
||||
val deliveredPI = PendingIntent.getBroadcast(context, uri.lastPathSegment.toInt(), deliveredIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val smsManager = SmsManager.getDefault()
|
||||
smsManager.sendTextMessage(address, null, body, sentPI, deliveredPI)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMessage(values: ContentValues, uri: Uri) {
|
||||
fun updateMessageFromUri(values: ContentValues, uri: Uri) {
|
||||
val contentResolver = context.contentResolver
|
||||
Flowable.just(values)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { contentResolver.update(uri, values, null, null) }
|
||||
.subscribe { copyMessageToRealm(uri) }
|
||||
.subscribe { addMessageFromUri(uri) }
|
||||
}
|
||||
|
||||
private fun copyMessageToRealm(uri: Uri) {
|
||||
fun addMessageFromUri(uri: Uri) {
|
||||
val cursor = context.contentResolver.query(uri, null, null, null, "date DESC")
|
||||
if (cursor.moveToFirst()) {
|
||||
val columns = MessageColumns(cursor)
|
||||
val message = SyncManager.messageFromCursor(cursor, columns)
|
||||
message.insertOrUpdate()
|
||||
}
|
||||
cursor.close()
|
||||
CursorToMessageFlowable().map(cursor)
|
||||
.subscribe { message -> message.insertOrUpdate() }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.moez.QKSMS.data.sync
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
internal object ConversationColumns {
|
||||
|
||||
val URI: Uri = Uri.parse("content://mms-sms/conversations?simple=true")
|
||||
val PROJECTION = arrayOf(
|
||||
android.provider.Telephony.Threads._ID,
|
||||
android.provider.Telephony.Threads.RECIPIENT_IDS)
|
||||
|
||||
val ID = 0
|
||||
val RECIPIENT_IDS = 1
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package com.moez.QKSMS.data.sync
|
||||
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony.*
|
||||
import timber.log.Timber
|
||||
|
||||
@Suppress("unused")
|
||||
class MessageColumns(val cursor: Cursor) {
|
||||
private val TAG = "ColumnsMap"
|
||||
private val DEBUG = false
|
||||
|
||||
companion object {
|
||||
val URI: Uri = Uri.parse("content://mms-sms/conversations/")
|
||||
val PROJECTION = arrayOf(
|
||||
MmsSms.TYPE_DISCRIMINATOR_COLUMN,
|
||||
MmsSms._ID,
|
||||
|
||||
Sms.THREAD_ID,
|
||||
Sms.ADDRESS,
|
||||
Sms.BODY,
|
||||
Sms.DATE,
|
||||
Sms.DATE_SENT,
|
||||
Sms.SEEN,
|
||||
Sms.READ,
|
||||
Sms.TYPE,
|
||||
Sms.STATUS,
|
||||
Sms.LOCKED,
|
||||
Sms.ERROR_CODE,
|
||||
|
||||
Mms.THREAD_ID,
|
||||
Mms.SUBJECT,
|
||||
Mms.SUBJECT_CHARSET,
|
||||
Mms.DATE,
|
||||
Mms.DATE_SENT,
|
||||
Mms.SEEN,
|
||||
Mms.READ,
|
||||
Mms.MESSAGE_TYPE,
|
||||
Mms.MESSAGE_BOX,
|
||||
Mms.DELIVERY_REPORT,
|
||||
Mms.READ_REPORT,
|
||||
MmsSms.PendingMessages.ERROR_TYPE,
|
||||
Mms.LOCKED,
|
||||
Mms.STATUS,
|
||||
Mms.TEXT_ONLY)
|
||||
}
|
||||
|
||||
val msgType by lazy { getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) }
|
||||
val msgId by lazy { getColumnIndex(MmsSms._ID) }
|
||||
|
||||
val smsThreadId by lazy { getColumnIndex(Sms.THREAD_ID) }
|
||||
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
|
||||
val smsBody by lazy { getColumnIndex(Sms.BODY) }
|
||||
val smsDate by lazy { getColumnIndex(Sms.DATE) }
|
||||
val smsDateSent by lazy { getColumnIndex(Sms.DATE_SENT) }
|
||||
val smsSeen by lazy { getColumnIndex(Sms.SEEN) }
|
||||
val smsRead by lazy { getColumnIndex(Sms.READ) }
|
||||
val smsType by lazy { getColumnIndex(Sms.TYPE) }
|
||||
val smsStatus by lazy { getColumnIndex(Sms.STATUS) }
|
||||
val smsLocked by lazy { getColumnIndex(Sms.LOCKED) }
|
||||
val smsErrorCode by lazy { getColumnIndex(Sms.ERROR_CODE) }
|
||||
|
||||
val mmsThreadId by lazy { getColumnIndex(Mms.THREAD_ID) }
|
||||
val mmsSubject by lazy { getColumnIndex(Mms.SUBJECT) }
|
||||
val mmsSubjectCharset by lazy { getColumnIndex(Mms.SUBJECT_CHARSET) }
|
||||
val mmsDate by lazy { getColumnIndex(Mms.DATE) }
|
||||
val mmsDateSent by lazy { getColumnIndex(Mms.DATE_SENT) }
|
||||
val mmsSeen by lazy { getColumnIndex(Mms.SEEN) }
|
||||
val mmsRead by lazy { getColumnIndex(Mms.READ) }
|
||||
val mmsMessageType by lazy { getColumnIndex(Mms.MESSAGE_TYPE) }
|
||||
val mmsMessageBox by lazy { getColumnIndex(Mms.MESSAGE_BOX) }
|
||||
val mmsDeliveryReport by lazy { getColumnIndex(Mms.DELIVERY_REPORT) }
|
||||
val mmsReadReport by lazy { getColumnIndex(Mms.READ_REPORT) }
|
||||
val mmsErrorType by lazy { getColumnIndex(MmsSms.PendingMessages.ERROR_TYPE) }
|
||||
val mmsLocked by lazy { getColumnIndex(Mms.LOCKED) }
|
||||
val mmsStatus by lazy { getColumnIndex(Mms.STATUS) }
|
||||
val mmsTextOnly by lazy { getColumnIndex(Mms.TEXT_ONLY) }
|
||||
|
||||
private fun getColumnIndex(columnsName: String): Int {
|
||||
return try {
|
||||
cursor.getColumnIndexOrThrow(columnsName)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.moez.QKSMS.data.sync
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
class RecipientColumns {
|
||||
|
||||
companion object {
|
||||
val URI = Uri.parse("content://mms-sms/canonical-address/")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.moez.QKSMS.data.sync
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
import com.moez.QKSMS.util.extensions.asFlowable
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
|
||||
class SyncManager(val context: Context, private val contactsRepo: ContactRepository) {
|
||||
|
||||
fun copyToRealm(completionListener: () -> Unit) {
|
||||
|
||||
val contentResolver = context.contentResolver
|
||||
val conversationsCursor = contentResolver.query(ConversationColumns.URI, ConversationColumns.PROJECTION, null, null, "date desc")
|
||||
|
||||
var realm: Realm? = null
|
||||
|
||||
Flowable.just(conversationsCursor)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.doOnNext {
|
||||
// We need to set up realm on the io thread, and doOnSubscribe doesn't support setting a custom Scheduler
|
||||
realm = Realm.getDefaultInstance()
|
||||
realm?.beginTransaction()
|
||||
realm?.deleteAll()
|
||||
}
|
||||
.flatMap { cursor -> cursor.asFlowable() }
|
||||
.map { cursor -> conversationFromCursor(cursor) }
|
||||
.distinct { conversation -> conversation.id }
|
||||
.doOnNext { conversation -> realm?.insertOrUpdate(conversation) }
|
||||
.map { conversation -> conversation.id }
|
||||
.flatMap { threadId ->
|
||||
val uri = Uri.withAppendedPath(MessageColumns.URI, threadId.toString())
|
||||
val messagesCursor = contentResolver.query(uri, MessageColumns.PROJECTION, null, null, "date desc")
|
||||
val columnsMap = MessageColumns(messagesCursor)
|
||||
messagesCursor.asFlowable().map { cursor -> messageFromCursor(cursor, columnsMap) }
|
||||
}
|
||||
.filter { message -> message.type == "sms" || message.type == "mms" }
|
||||
.distinct { message -> message.id }
|
||||
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
||||
.count()
|
||||
.toFlowable()
|
||||
.doOnNext {
|
||||
realm?.commitTransaction()
|
||||
realm?.close()
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { completionListener.invoke() }
|
||||
}
|
||||
|
||||
private fun conversationFromCursor(cursor: Cursor): Conversation {
|
||||
return Conversation().apply {
|
||||
id = cursor.getLong(ConversationColumns.ID)
|
||||
|
||||
cursor.getString(ConversationColumns.RECIPIENT_IDS).split(" ")
|
||||
.map { id -> id.toLong() }
|
||||
.map { id -> contactsRepo.getContactBlocking(id) }
|
||||
.filter { contact -> contact.recipientId != 0L }
|
||||
.forEach { contact -> contacts.add(contact) }
|
||||
}
|
||||
}
|
||||
|
||||
// TODO take this out of the companion object
|
||||
companion object {
|
||||
fun messageFromCursor(cursor: Cursor, columnsMap: MessageColumns): Message {
|
||||
return Message().apply {
|
||||
type = when (cursor.getColumnIndex(Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN)) {
|
||||
-1 -> "sms"
|
||||
else -> cursor.getString(columnsMap.msgType)
|
||||
}
|
||||
|
||||
id = cursor.getLong(columnsMap.msgId)
|
||||
body = cursor.getString(columnsMap.smsBody) ?: ""
|
||||
|
||||
when (type) {
|
||||
"sms" -> {
|
||||
threadId = cursor.getLong(columnsMap.smsThreadId)
|
||||
address = cursor.getString(columnsMap.smsAddress)
|
||||
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
|
||||
}
|
||||
|
||||
"mms" -> {
|
||||
threadId = cursor.getLong(columnsMap.mmsThreadId)
|
||||
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
|
||||
errorType = cursor.getInt(columnsMap.mmsErrorType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
abstract class Interactor<T, in Params> {
|
||||
|
||||
private val disposables: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
abstract fun buildObservable(params: Params): Flowable<T>
|
||||
|
||||
fun execute(observer: ((T) -> Unit), params: Params) {
|
||||
disposables.add(buildObservable(params)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(observer))
|
||||
}
|
||||
|
||||
fun dispose() = disposables.dispose()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkAllSeen @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Unit>() {
|
||||
|
||||
override fun buildObservable(params: Unit): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markAllSeen() }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkFailed @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, MarkFailed.Params>() {
|
||||
|
||||
data class Params(val uri: Uri, val resultCode: Int)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext {
|
||||
val values = ContentValues()
|
||||
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_FAILED)
|
||||
values.put(Telephony.Sms.ERROR_CODE, params.resultCode)
|
||||
messageRepo.updateMessageFromUri(values, params.uri)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkRead @Inject constructor(val messageRepo: MessageRepository): Interactor<Unit, Long>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markRead(params) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkSeen @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Long>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markSeen(params) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkSent @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Uri>() {
|
||||
|
||||
override fun buildObservable(params: Uri): Flowable<Unit> {
|
||||
return Flowable.just(params)
|
||||
.doOnNext {
|
||||
val values = ContentValues()
|
||||
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_SENT)
|
||||
messageRepo.updateMessageFromUri(values, params)
|
||||
}
|
||||
.map { Unit }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.common.util.NotificationManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class ReceiveMessage @Inject constructor(
|
||||
val context: Context,
|
||||
val messageRepo: MessageRepository,
|
||||
val notificationManager: NotificationManager) : Interactor<Unit, ReceiveMessage.Params>() {
|
||||
|
||||
data class Params(val address: String, val body: String, val sentTime: Long)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<Unit> {
|
||||
val values = ContentValues()
|
||||
values.put(Telephony.Sms.ADDRESS, params.address)
|
||||
values.put(Telephony.Sms.BODY, params.body)
|
||||
values.put(Telephony.Sms.DATE_SENT, params.sentTime)
|
||||
values.put(Telephony.Sms.READ, false)
|
||||
values.put(Telephony.Sms.SEEN, false)
|
||||
|
||||
val contentResolver = context.contentResolver
|
||||
return Flowable.just(values)
|
||||
.map { contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values) }
|
||||
.doOnNext { uri -> messageRepo.addMessageFromUri(uri) }
|
||||
.doOnNext { notificationManager.update(messageRepo) }
|
||||
.map { Unit }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Telephony
|
||||
import android.telephony.SmsManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.receiver.MessageDeliveredReceiver
|
||||
import com.moez.QKSMS.receiver.MessageSentReceiver
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendMessage @Inject constructor(
|
||||
val context: Context,
|
||||
val messageRepo: MessageRepository) : Interactor<Unit, SendMessage.Params>() {
|
||||
|
||||
data class Params(val threadId: Long, val address: String, val body: String)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<Unit> {
|
||||
val values = ContentValues()
|
||||
values.put(Telephony.Sms.ADDRESS, params.address)
|
||||
values.put(Telephony.Sms.BODY, params.body)
|
||||
values.put(Telephony.Sms.DATE, System.currentTimeMillis())
|
||||
values.put(Telephony.Sms.READ, true)
|
||||
values.put(Telephony.Sms.SEEN, true)
|
||||
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_OUTBOX)
|
||||
values.put(Telephony.Sms.THREAD_ID, params.threadId)
|
||||
|
||||
val contentResolver = context.contentResolver
|
||||
return Flowable.just(values)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { contentResolver.insert(Telephony.Sms.CONTENT_URI, values) }
|
||||
.doOnNext { uri ->
|
||||
messageRepo.addMessageFromUri(uri)
|
||||
|
||||
val sentIntent = Intent(context, MessageSentReceiver::class.java).putExtra("uri", uri.toString())
|
||||
val sentPI = PendingIntent.getBroadcast(context, uri.lastPathSegment.toInt(), sentIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val deliveredIntent = Intent(context, MessageDeliveredReceiver::class.java).putExtra("uri", uri.toString())
|
||||
val deliveredPI = PendingIntent.getBroadcast(context, uri.lastPathSegment.toInt(), deliveredIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val smsManager = SmsManager.getDefault()
|
||||
smsManager.sendTextMessage(params.address, null, params.body, sentPI, deliveredPI)
|
||||
}
|
||||
.map { Unit }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.moez.QKSMS.domain.interactor
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import com.moez.QKSMS.data.mapper.CursorToConversationFlowable
|
||||
import com.moez.QKSMS.data.mapper.CursorToMessageFlowable
|
||||
import io.reactivex.Flowable
|
||||
import io.realm.Realm
|
||||
import javax.inject.Inject
|
||||
|
||||
class SyncConversations @Inject constructor(
|
||||
private val context: Context,
|
||||
private val cursorToConversationFlowable: CursorToConversationFlowable,
|
||||
private val cursorToMessageFlowable: CursorToMessageFlowable) : Interactor<Long, Unit>() {
|
||||
|
||||
override fun buildObservable(params: Unit): Flowable<Long> {
|
||||
val contentResolver = context.contentResolver
|
||||
val conversationsCursor = contentResolver.query(CursorToConversationFlowable.URI, CursorToConversationFlowable.PROJECTION, null, null, "date desc")
|
||||
|
||||
var realm: Realm? = null
|
||||
|
||||
return Flowable.just(conversationsCursor)
|
||||
.doOnNext {
|
||||
// We need to set up realm on the io thread, and doOnSubscribe doesn't support setting a custom Scheduler
|
||||
realm = Realm.getDefaultInstance()
|
||||
realm?.beginTransaction()
|
||||
realm?.deleteAll()
|
||||
}
|
||||
.flatMap { cursor -> cursorToConversationFlowable.map(cursor) }
|
||||
.distinct { conversation -> conversation.id }
|
||||
.doOnNext { conversation -> realm?.insertOrUpdate(conversation) }
|
||||
.map { conversation -> conversation.id }
|
||||
.map { threadId -> Uri.withAppendedPath(Telephony.MmsSms.CONTENT_CONVERSATIONS_URI, threadId.toString()) }
|
||||
.map { threadUri -> contentResolver.query(threadUri, CursorToMessageFlowable.CURSOR_PROJECTION, null, null, "date desc") }
|
||||
.flatMap { threadCursor -> cursorToMessageFlowable.map(threadCursor) }
|
||||
.filter { message -> message.type == "sms" || message.type == "mms" }
|
||||
.distinct { message -> message.id }
|
||||
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
||||
.count()
|
||||
.toFlowable()
|
||||
.doOnNext {
|
||||
realm?.commitTransaction()
|
||||
realm?.close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.base
|
||||
package com.moez.QKSMS.presentation.base
|
||||
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.MenuItem
|
||||
+6
-6
@@ -1,17 +1,17 @@
|
||||
package com.moez.QKSMS.ui.conversations
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||
import com.moez.QKSMS.util.DateFormatter
|
||||
import com.moez.QKSMS.util.ThemeManager
|
||||
import com.moez.QKSMS.util.extensions.getColorCompat
|
||||
import com.moez.QKSMS.presentation.messages.MessageListActivity
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.common.util.ThemeManager
|
||||
import com.moez.QKSMS.common.util.extensions.getColorCompat
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.conversations
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import android.Manifest
|
||||
import android.arch.lifecycle.Observer
|
||||
@@ -13,8 +13,8 @@ import com.karumi.dexter.PermissionToken
|
||||
import com.karumi.dexter.listener.PermissionRequest
|
||||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.ui.base.QkActivity
|
||||
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||
import com.moez.QKSMS.presentation.base.QkActivity
|
||||
import com.moez.QKSMS.presentation.messages.MessageListActivity
|
||||
import kotlinx.android.synthetic.main.conversation_list_activity.*
|
||||
import timber.log.Timber
|
||||
|
||||
@@ -41,7 +41,7 @@ class ConversationListActivity : QkActivity(), Observer<ConversationListViewStat
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
intent?.getLongExtra("threadId", -1)?.takeIf { threadId -> threadId != -1L }.let { threadId ->
|
||||
intent?.getLongExtra("threadId", 0)?.takeIf { threadId -> threadId > 0 }?.let { threadId ->
|
||||
startActivity(Intent(this, MessageListActivity::class.java).putExtra("threadId", threadId))
|
||||
}
|
||||
}
|
||||
+14
-7
@@ -1,21 +1,22 @@
|
||||
package com.moez.QKSMS.ui.conversations
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.data.sync.SyncManager
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import com.moez.QKSMS.domain.interactor.MarkAllSeen
|
||||
import com.moez.QKSMS.domain.interactor.SyncConversations
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.realm.RealmResults
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationListViewModel : ViewModel() {
|
||||
|
||||
@Inject lateinit var syncManager: SyncManager
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var syncConversations: SyncConversations
|
||||
@Inject lateinit var markAllSeen: MarkAllSeen
|
||||
|
||||
val state: MutableLiveData<ConversationListViewState> = MutableLiveData()
|
||||
|
||||
@@ -32,12 +33,18 @@ class ConversationListViewModel : ViewModel() {
|
||||
conversations = messageRepo.getConversationMessagesAsync()
|
||||
partialStates.onNext(PartialState.ConversationsLoaded(conversations))
|
||||
|
||||
messageRepo.markAllSeen()
|
||||
markAllSeen.execute({}, Unit)
|
||||
}
|
||||
|
||||
fun onRefresh() {
|
||||
partialStates.onNext(PartialState.Refreshing(true))
|
||||
syncManager.copyToRealm { partialStates.onNext(PartialState.Refreshing(false)) }
|
||||
syncConversations.execute({ partialStates.onNext(PartialState.Refreshing(false)) }, Unit)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
syncConversations.dispose()
|
||||
markAllSeen.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.conversations
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.realm.OrderedRealmCollection
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.moez.QKSMS.ui.conversations
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.ui.view.GroupAvatarView
|
||||
import com.moez.QKSMS.presentation.view.GroupAvatarView
|
||||
|
||||
class ConversationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
+7
-7
@@ -1,18 +1,18 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
package com.moez.QKSMS.presentation.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.common.util.ThemeManager
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setPadding
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
import com.moez.QKSMS.util.DateFormatter
|
||||
import com.moez.QKSMS.util.ThemeManager
|
||||
import com.moez.QKSMS.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.util.extensions.setPadding
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
import timber.log.Timber
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
package com.moez.QKSMS.presentation.messages
|
||||
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
@@ -8,11 +8,11 @@ import android.support.v7.widget.RecyclerView
|
||||
import com.jakewharton.rxbinding2.view.RxView
|
||||
import com.jakewharton.rxbinding2.widget.RxTextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.ui.base.QkActivity
|
||||
import com.moez.QKSMS.util.ThemeManager
|
||||
import com.moez.QKSMS.util.extensions.setTint
|
||||
import com.moez.QKSMS.presentation.base.QkActivity
|
||||
import com.moez.QKSMS.common.util.ThemeManager
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_activity.*
|
||||
import javax.inject.Inject
|
||||
+11
-4
@@ -1,16 +1,20 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
package com.moez.QKSMS.presentation.messages
|
||||
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.domain.interactor.MarkRead
|
||||
import com.moez.QKSMS.domain.interactor.SendMessage
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import javax.inject.Inject
|
||||
|
||||
class MessageListViewModel : ViewModel() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
|
||||
val state: MutableLiveData<MessageListViewState> = MutableLiveData()
|
||||
var threadId: Long = 0
|
||||
@@ -31,6 +35,7 @@ class MessageListViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
private fun newThreadId() {
|
||||
dataChanged()
|
||||
conversation?.removeAllChangeListeners()
|
||||
conversation = messageRepo.getConversationAsync(threadId)
|
||||
conversation?.addChangeListener { conversation: Conversation ->
|
||||
@@ -47,13 +52,13 @@ class MessageListViewModel : ViewModel() {
|
||||
|
||||
fun sendMessage(body: String) {
|
||||
conversation?.takeIf { conversation -> conversation.isValid }?.let { conversation ->
|
||||
messageRepo.sendMessage(threadId, conversation.contacts[0].address, body)
|
||||
sendMessage.execute({}, SendMessage.Params(threadId, conversation.contacts[0].address, body))
|
||||
partialStates.onNext(PartialState.TextChanged(""))
|
||||
}
|
||||
}
|
||||
|
||||
fun dataChanged() {
|
||||
messageRepo.markRead(threadId)
|
||||
markRead.execute({}, threadId)
|
||||
}
|
||||
|
||||
fun textChanged(text: String) {
|
||||
@@ -62,6 +67,8 @@ class MessageListViewModel : ViewModel() {
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
sendMessage.dispose()
|
||||
markRead.dispose()
|
||||
conversation?.removeAllChangeListeners()
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
package com.moez.QKSMS.presentation.messages
|
||||
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.realm.RealmResults
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
package com.moez.QKSMS.presentation.messages
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.ui.view.AvatarView
|
||||
import com.moez.QKSMS.presentation.view.AvatarView
|
||||
|
||||
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.view
|
||||
package com.moez.QKSMS.presentation.view
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
@@ -6,10 +6,10 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
import com.moez.QKSMS.util.extensions.getColorCompat
|
||||
import com.moez.QKSMS.common.util.extensions.getColorCompat
|
||||
import io.reactivex.disposables.Disposable
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.moez.QKSMS.ui.view
|
||||
package com.moez.QKSMS.presentation.view
|
||||
|
||||
import android.content.Context
|
||||
import android.support.constraint.ConstraintLayout
|
||||
@@ -3,19 +3,19 @@ package com.moez.QKSMS.receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.MarkRead
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkReadReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
messageRepo.markRead(threadId)
|
||||
markRead.execute({}, threadId)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,19 +3,19 @@ package com.moez.QKSMS.receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.MarkSeen
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkSeenReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markSeen: MarkSeen
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
messageRepo.markSeen(threadId)
|
||||
markSeen.execute({}, threadId)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,13 +6,15 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.telephony.SmsManager
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.MarkFailed
|
||||
import com.moez.QKSMS.domain.interactor.MarkSent
|
||||
import javax.inject.Inject
|
||||
|
||||
class MessageSentReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markSent: MarkSent
|
||||
@Inject lateinit var markFailed: MarkFailed
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
@@ -20,12 +22,12 @@ class MessageSentReceiver : BroadcastReceiver() {
|
||||
val uri = Uri.parse(intent.getStringExtra("uri"))
|
||||
|
||||
when (resultCode) {
|
||||
Activity.RESULT_OK -> messageRepo.markSent(uri)
|
||||
Activity.RESULT_OK -> markSent.execute({}, uri)
|
||||
|
||||
SmsManager.RESULT_ERROR_GENERIC_FAILURE,
|
||||
SmsManager.RESULT_ERROR_NO_SERVICE,
|
||||
SmsManager.RESULT_ERROR_NULL_PDU,
|
||||
SmsManager.RESULT_ERROR_RADIO_OFF -> messageRepo.markFailed(uri, resultCode)
|
||||
SmsManager.RESULT_ERROR_RADIO_OFF -> markFailed.execute({}, MarkFailed.Params(uri, resultCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,15 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v4.app.RemoteInput
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.util.NotificationManager
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.MarkRead
|
||||
import com.moez.QKSMS.domain.interactor.SendMessage
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemoteMessagingReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
@@ -23,8 +23,8 @@ class RemoteMessagingReceiver : BroadcastReceiver() {
|
||||
val address = bundle.getString("address")
|
||||
val threadId = bundle.getLong("threadId")
|
||||
val body = remoteInput.getCharSequence("body").toString()
|
||||
messageRepo.markRead(threadId)
|
||||
messageRepo.sendMessage(threadId, address, body)
|
||||
markRead.execute({}, threadId)
|
||||
sendMessage.execute({}, SendMessage.Params(threadId, address, body))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Telephony.Sms
|
||||
import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.ReceiveMessage
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class SmsReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var receiveMessage: ReceiveMessage
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Timber.v("Received SMS: $intent")
|
||||
@@ -25,7 +25,8 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
.map { message -> message.displayMessageBody }
|
||||
.reduce { body, new -> body + new }
|
||||
|
||||
messageRepo.insertReceivedMessage(address, body, time)
|
||||
val pendingResult = goAsync()
|
||||
receiveMessage.execute({ pendingResult.finish() }, ReceiveMessage.Params(address, body, time))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.moez.QKSMS.util
|
||||
|
||||
class ThemeManager {
|
||||
|
||||
val color = 0xFF008389.toInt()
|
||||
val bubbleColor = 0xFFF4F4F4.toInt()
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:background="@color/list_separator"
|
||||
tools:parentTag="com.moez.QKSMS.ui.view.AvatarView">
|
||||
tools:parentTag="com.moez.QKSMS.presentation.view.AvatarView">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/initial"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<com.moez.QKSMS.ui.view.GroupAvatarView
|
||||
<com.moez.QKSMS.presentation.view.GroupAvatarView
|
||||
android:id="@+id/avatars"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<com.moez.QKSMS.ui.view.GroupAvatarView
|
||||
<com.moez.QKSMS.presentation.view.GroupAvatarView
|
||||
android:id="@+id/avatars"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
tools:parentTag="com.moez.QKSMS.ui.view.GroupAvatarView">
|
||||
tools:parentTag="com.moez.QKSMS.presentation.view.GroupAvatarView">
|
||||
|
||||
<com.moez.QKSMS.ui.view.AvatarView
|
||||
<com.moez.QKSMS.presentation.view.AvatarView
|
||||
android:id="@+id/avatar1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.moez.QKSMS.ui.view.AvatarView
|
||||
<com.moez.QKSMS.presentation.view.AvatarView
|
||||
android:id="@+id/avatar2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
@@ -25,7 +25,7 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar1"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.moez.QKSMS.ui.view.AvatarView
|
||||
<com.moez.QKSMS.presentation.view.AvatarView
|
||||
android:id="@+id/avatar3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
android:paddingEnd="60dp"
|
||||
android:paddingStart="12dp">
|
||||
|
||||
<com.moez.QKSMS.ui.view.AvatarView
|
||||
<com.moez.QKSMS.presentation.view.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
|
||||
Reference in New Issue
Block a user