Split up app module into domain/data/presentation

This commit is contained in:
Moez Bhatti
2018-03-22 00:32:07 -04:00
parent 4ef97ab854
commit d7d202392c
282 changed files with 1153 additions and 482 deletions
+7
View File
@@ -3,12 +3,19 @@
buildscript {
ext.autodispose_version = '0.5.1'
ext.constraintlayout_version = '1.1.0-beta5'
ext.dagger_version = "2.11"
ext.kotlin_version = '1.2.20'
ext.ktx_version = "0.2"
ext.lifecycle_version = '1.1.0'
ext.realm_version = '4.3.1'
ext.realm_adapters_version = '2.1.0'
ext.rxandroid_version = '2.0.1'
ext.rxbinding_version = '2.0.0'
ext.rxjava_version = '2.1.4'
ext.rxkotlin_version = '2.1.0'
ext.rx_preferences_version = '2.0.0-RC3'
ext.support_version = '27.1.0'
ext.timber_version = '4.5.1'
repositories {
+38
View File
@@ -0,0 +1,38 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
}
dependencies {
// support
implementation "com.android.support:appcompat-v7:$support_version"
// dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
provided "javax.annotation:jsr250-api:1.0"
// rxjava
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
implementation "com.f2prateek.rx.preferences2:rx-preferences:$rx_preferences_version"
implementation "com.jakewharton.timber:timber:$timber_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "me.leolin:ShortcutBadger:1.1.21"
implementation project(":android-smsmms")
implementation project(':domain')
}
repositories {
mavenCentral()
}
+1
View File
@@ -0,0 +1 @@
<manifest package="com.moez.QKSMS.data" />
@@ -16,18 +16,15 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package manager
import data.model.Message
import io.realm.Realm
import model.Message
import javax.inject.Inject
import javax.inject.Singleton
/**
* Helper class for generating incrementing ids for messages
*/
@Singleton
class Keys @Inject constructor() {
class KeyManagerImpl @Inject constructor() : KeyManager {
private var maxValue: Long = 0L
@@ -40,16 +37,16 @@ class Keys @Inject constructor() {
/**
* Should be called when a new sync is being started
*/
fun reset() {
override fun reset() {
maxValue = 0L
}
/**
* Returns a valid ID that can be used to store a new message
*/
fun newId(): Long {
override fun newId(): Long {
maxValue++
return maxValue
}
}
}
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package manager
import android.Manifest
import android.content.Context
@@ -24,9 +24,11 @@ import android.content.pm.PackageManager
import android.support.v4.content.ContextCompat
import javax.inject.Inject
class Permissions @Inject constructor(private val context: Context) {
class PermissionManagerImpl @Inject constructor(private val context: Context) : PermissionManager {
fun hasSmsAndContacts() = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
override fun hasSmsAndContacts(): Boolean {
return ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
import android.content.Context
import me.leolin.shortcutbadger.ShortcutBadger
import javax.inject.Inject
class WidgetManagerImpl @Inject constructor(private val context: Context) : WidgetManager {
override fun updateUnreadCount(count: Int) {
ShortcutBadger.applyCount(context, count)
}
}
@@ -16,25 +16,25 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
import android.content.Context
import android.database.Cursor
import android.provider.ContactsContract.CommonDataKinds.Phone.*
import data.model.Contact
import data.model.PhoneNumber
import model.Contact
import model.PhoneNumber
import javax.inject.Inject
class CursorToContact @Inject constructor(private val context: Context) : Mapper<Cursor, Contact> {
class CursorToContactImpl @Inject constructor(private val context: Context) : CursorToContact {
companion object {
val URI = CONTENT_URI
val PROJECTION = arrayOf(LOOKUP_KEY, NUMBER, TYPE, DISPLAY_NAME)
val COLUMN_LOOKUP_KEY = 0
val COLUMN_NUMBER = 1
val COLUMN_TYPE = 2
val COLUMN_DISPLAY_NAME = 3
const val COLUMN_LOOKUP_KEY = 0
const val COLUMN_NUMBER = 1
const val COLUMN_TYPE = 2
const val COLUMN_DISPLAY_NAME = 3
}
override fun map(from: Cursor) = Contact().apply {
@@ -47,4 +47,8 @@ class CursorToContact @Inject constructor(private val context: Context) : Mapper
lastUpdate = System.currentTimeMillis()
}
override fun getContactsCursor(): Cursor {
return context.contentResolver.query(URI, PROJECTION, null, null, null)
}
}
@@ -16,16 +16,18 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.Telephony
import android.provider.Telephony.Threads
import data.model.Conversation
import data.model.Recipient
import model.Conversation
import model.Recipient
import javax.inject.Inject
class CursorToConversation @Inject constructor() : Mapper<Cursor, Conversation> {
class CursorToConversationImpl @Inject constructor(private val context: Context) : CursorToConversation {
companion object {
val URI: Uri = Uri.parse("content://mms-sms/conversations?simple=true")
@@ -48,4 +50,15 @@ class CursorToConversation @Inject constructor() : Mapper<Cursor, Conversation>
}
}
override fun getConversationsCursor(lastSync: Long): Cursor {
return context.contentResolver.query(URI, PROJECTION,
"date > $lastSync AND ${Telephony.Threads.MESSAGE_COUNT} > 0", null,
"date desc")
}
override fun getConversationCursor(threadId: Long): Cursor {
return context.contentResolver.query(URI, PROJECTION,
"_id = ?", arrayOf(threadId.toString()), null)
}
}
@@ -16,29 +16,54 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.Telephony
import android.provider.Telephony.*
import com.google.android.mms.pdu_alt.PduHeaders
import common.util.Keys
import common.util.extensions.map
import data.model.Message
import data.model.MmsPart
import timber.log.Timber
import java.util.*
import manager.KeyManager
import model.Message
import util.extensions.map
import javax.inject.Inject
class CursorToMessage @Inject constructor(
class CursorToMessageImpl @Inject constructor(
private val context: Context,
private val keys: Keys,
private val keys: KeyManager,
private val cursorToPart: CursorToPart
) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
) : CursorToMessage {
override fun map(from: Pair<Cursor, MessageColumns>): Message {
companion object {
val URI = Uri.parse("content://mms-sms/complete-conversations")
val PROJECTION = arrayOf(
MmsSms.TYPE_DISCRIMINATOR_COLUMN,
MmsSms._ID,
Mms.DATE,
Mms.DATE_SENT,
Mms.READ,
Mms.THREAD_ID,
Mms.LOCKED,
Sms.ADDRESS,
Sms.BODY,
Sms.SEEN,
Sms.TYPE,
Sms.STATUS,
Sms.ERROR_CODE,
Mms.SUBJECT,
Mms.SUBJECT_CHARSET,
Mms.SEEN,
Mms.MESSAGE_TYPE,
Mms.MESSAGE_BOX,
Mms.DELIVERY_REPORT,
Mms.READ_REPORT,
MmsSms.PendingMessages.ERROR_TYPE,
Mms.STATUS)
}
override fun map(from: Pair<Cursor, CursorToMessage.MessageColumns>): Message {
val cursor = from.first
val columnsMap = from.second
@@ -84,12 +109,19 @@ class CursorToMessage @Inject constructor(
textContentType = ""
attachmentType = Message.AttachmentType.NOT_LOADED
parts.addAll(getMmsParts(contentId))
parts.addAll(cursorToPart.getPartsCursor(contentId)?.map { cursorToPart.map(it) } ?: listOf())
}
}
}
}
override fun getMessagesCursor(): Cursor {
return context.contentResolver.query(URI, PROJECTION, null, null, "normalized_date desc")
}
override fun getMessageCursor(id: Long): Cursor {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun getMmsAddress(messageId: Long): String {
val uri = Mms.CONTENT_URI.buildUpon()
@@ -110,73 +142,4 @@ class CursorToMessage @Inject constructor(
return ""
}
private fun getMmsParts(contentId: Long): List<MmsPart> {
return context.contentResolver.query(CursorToPart.CONTENT_URI, null,
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(contentId.toString()), null)
?.map { cursorToPart.map(it) } ?: listOf()
}
companion object {
val URI = Uri.parse("content://mms-sms/complete-conversations")
val PROJECTION = arrayOf(
MmsSms.TYPE_DISCRIMINATOR_COLUMN,
MmsSms._ID,
Mms.DATE,
Mms.DATE_SENT,
Mms.READ,
Mms.THREAD_ID,
Mms.LOCKED,
Sms.ADDRESS,
Sms.BODY,
Sms.SEEN,
Sms.TYPE,
Sms.STATUS,
Sms.ERROR_CODE,
Mms.SUBJECT,
Mms.SUBJECT_CHARSET,
Mms.SEEN,
Mms.MESSAGE_TYPE,
Mms.MESSAGE_BOX,
Mms.DELIVERY_REPORT,
Mms.READ_REPORT,
MmsSms.PendingMessages.ERROR_TYPE,
Mms.STATUS)
}
class MessageColumns(private val cursor: Cursor) {
val msgType by lazy { getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) }
val msgId by lazy { getColumnIndex(MmsSms._ID) }
val date by lazy { getColumnIndex(Mms.DATE) }
val dateSent by lazy { getColumnIndex(Mms.DATE_SENT) }
val read by lazy { getColumnIndex(Mms.READ) }
val threadId by lazy { getColumnIndex(Mms.THREAD_ID) }
val locked by lazy { getColumnIndex(Mms.LOCKED) }
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
val smsBody by lazy { getColumnIndex(Sms.BODY) }
val smsSeen by lazy { getColumnIndex(Sms.SEEN) }
val smsType by lazy { getColumnIndex(Sms.TYPE) }
val smsStatus by lazy { getColumnIndex(Sms.STATUS) }
val smsErrorCode by lazy { getColumnIndex(Sms.ERROR_CODE) }
val mmsSubject by lazy { getColumnIndex(Mms.SUBJECT) }
val mmsSubjectCharset by lazy { getColumnIndex(Mms.SUBJECT_CHARSET) }
val mmsSeen by lazy { getColumnIndex(Mms.SEEN) }
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 mmsStatus by lazy { getColumnIndex(Mms.STATUS) }
private fun getColumnIndex(columnsName: String) = try {
cursor.getColumnIndexOrThrow(columnsName)
} catch (e: Exception) {
Timber.e("Couldn't find column \'$columnsName\' in ${Arrays.toString(cursor.columnNames)}")
-1
}
}
}
@@ -16,20 +16,23 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.Telephony
import data.model.MmsPart
import model.MmsPart
import timber.log.Timber
import util.extensions.isImage
import util.extensions.isSmil
import util.extensions.isText
import java.io.BufferedReader
import java.io.InputStreamReader
import javax.inject.Inject
class CursorToPart @Inject constructor(private val context: Context) : Mapper<Cursor, MmsPart> {
class CursorToPartImpl @Inject constructor(private val context: Context) : CursorToPart {
companion object {
val CONTENT_URI: Uri = Uri.parse("content://mms/part")
@@ -74,4 +77,9 @@ class CursorToPart @Inject constructor(private val context: Context) : Mapper<Cu
}
}
override fun getPartsCursor(messageId: Long): Cursor? {
return context.contentResolver.query(CONTENT_URI, null,
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(messageId.toString()), null)
}
}
@@ -16,20 +16,21 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
import android.content.Context
import android.database.Cursor
import android.net.Uri
import data.model.Recipient
import model.Recipient
import javax.inject.Inject
class CursorToRecipient @Inject constructor() : Mapper<Cursor, Recipient> {
class CursorToRecipienImpl @Inject constructor(private val context: Context) : CursorToRecipient {
companion object {
val URI = Uri.parse("content://mms-sms/canonical-addresses")
val COLUMN_ID = 0
val COLUMN_ADDRESS = 1
const val COLUMN_ID = 0
const val COLUMN_ADDRESS = 1
}
override fun map(from: Cursor) = Recipient().apply {
@@ -38,4 +39,12 @@ class CursorToRecipient @Inject constructor() : Mapper<Cursor, Recipient> {
lastUpdate = System.currentTimeMillis()
}
override fun getRecipientCursor(): Cursor {
return context.contentResolver.query(URI, null, null, null, null)
}
override fun getRecipientCursor(id: Long): Cursor {
return context.contentResolver.query(URI, null, "_id = ?", arrayOf(id.toString()), null)
}
}
@@ -16,25 +16,25 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.repository
package repository
import android.content.Context
import android.net.Uri
import android.provider.ContactsContract
import common.util.extensions.asFlowable
import data.model.Contact
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.realm.Realm
import model.Contact
import util.extensions.asFlowable
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class ContactRepository @Inject constructor(val context: Context) {
class ContactRepositoryImpl @Inject constructor(val context: Context) : ContactRepository {
fun findContactUri(address: String): Single<Uri> {
override fun findContactUri(address: String): Single<Uri> {
return Flowable.just(address)
.map { Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)) }
.flatMap { uri -> context.contentResolver.query(uri, arrayOf(ContactsContract.PhoneLookup._ID), null, null, null).asFlowable() }
@@ -43,7 +43,7 @@ class ContactRepository @Inject constructor(val context: Context) {
.map { id -> Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id) }
}
fun getUnmanagedContacts(): Flowable<List<Contact>> {
override fun getUnmanagedContacts(): Flowable<List<Contact>> {
val realm = Realm.getDefaultInstance()
return realm.where(Contact::class.java)
.sort("name")
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.repository
package repository
import android.app.PendingIntent
import android.content.ContentUris
@@ -26,17 +26,10 @@ import android.content.Intent
import android.net.Uri
import android.provider.BaseColumns
import android.provider.Telephony
import android.provider.Telephony.Sms
import android.telephony.PhoneNumberUtils
import android.telephony.SmsManager
import com.klinker.android.send_message.BroadcastUtils
import com.klinker.android.send_message.StripAccents
import common.util.Keys
import common.util.MessageUtils
import common.util.Preferences
import common.util.extensions.*
import data.mapper.CursorToConversation
import data.mapper.CursorToRecipient
import data.model.*
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
@@ -46,20 +39,32 @@ import io.reactivex.schedulers.Schedulers
import io.realm.Realm
import io.realm.RealmResults
import io.realm.Sort
import presentation.receiver.MessageDeliveredReceiver
import presentation.receiver.MessageSentReceiver
import manager.KeyManager
import mapper.CursorToConversation
import mapper.CursorToRecipient
import model.Contact
import model.Conversation
import model.Message
import model.MmsPart
import util.MessageUtils
import util.Preferences
import util.extensions.asFlowable
import util.extensions.asMaybe
import util.extensions.asObservable
import util.extensions.insertOrUpdate
import util.extensions.map
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class MessageRepository @Inject constructor(
class MessageRepositoryImpl @Inject constructor(
private val context: Context,
private val messageIds: Keys,
private val messageIds: KeyManager,
private val cursorToConversation: CursorToConversation,
private val cursorToRecipient: CursorToRecipient,
private val prefs: Preferences) {
private val prefs: Preferences) : MessageRepository {
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
override fun getConversations(archived: Boolean): Flowable<List<Pair<Conversation, Message>>> {
val realm = Realm.getDefaultInstance()
val conversationFlowable = realm.where(Conversation::class.java)
@@ -83,12 +88,12 @@ class MessageRepository @Inject constructor(
messages.mapNotNull { message ->
val conversation = conversationMap[message.threadId]
if (conversation == null) null else InboxItem(conversation, message)
if (conversation == null) null else Pair(conversation, message)
}
})
}
fun getBlockedConversations(): Flowable<List<Conversation>> {
override fun getBlockedConversations(): Flowable<List<Conversation>> {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.equalTo("blocked", true)
@@ -98,29 +103,29 @@ class MessageRepository @Inject constructor(
.map { it.toList() }
}
fun getConversationAsync(threadId: Long): Conversation {
override fun getConversationAsync(threadId: Long): Conversation {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.equalTo("id", threadId)
.findFirstAsync()
}
fun getConversation(threadId: Long): Conversation? {
override fun getConversation(threadId: Long): Conversation? {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.equalTo("id", threadId)
.findFirst()
}
fun getOrCreateConversation(threadId: Long): Conversation? {
override fun getOrCreateConversation(threadId: Long): Conversation? {
return getConversation(threadId) ?: getConversationFromCp(threadId)
}
fun getOrCreateConversation(address: String): Maybe<Conversation> {
override fun getOrCreateConversation(address: String): Maybe<Conversation> {
return getOrCreateConversation(listOf(address))
}
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
override fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
return Maybe.just(addresses)
.map { recipients ->
recipients.map { address ->
@@ -151,7 +156,7 @@ class MessageRepository @Inject constructor(
.observeOn(AndroidSchedulers.mainThread())
}
fun saveDraft(threadId: Long, draft: String) {
override fun saveDraft(threadId: Long, draft: String) {
Realm.getDefaultInstance().use { realm ->
val conversation = realm.where(Conversation::class.java)
.equalTo("id", threadId)
@@ -165,7 +170,7 @@ class MessageRepository @Inject constructor(
}
}
fun getMessages(threadId: Long): RealmResults<Message> {
override fun getMessages(threadId: Long): RealmResults<Message> {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("threadId", threadId)
@@ -173,35 +178,35 @@ class MessageRepository @Inject constructor(
.findAllAsync()
}
fun getMessage(id: Long): Message? {
override fun getMessage(id: Long): Message? {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("id", id)
.findFirst()
}
fun getMessageForPart(id: Long): Message? {
override fun getMessageForPart(id: Long): Message? {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("parts.id", id)
.findFirst()
}
fun getUnreadMessageCount(): Long {
override fun getUnreadMessageCount(): Long {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("read", false)
.count()
}
fun getPart(id: Long): MmsPart? {
override fun getPart(id: Long): MmsPart? {
return Realm.getDefaultInstance()
.where(MmsPart::class.java)
.equalTo("id", id)
.findFirst()
}
fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>> {
override fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>> {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("threadId", threadId)
@@ -216,7 +221,7 @@ class MessageRepository @Inject constructor(
* Retrieves the list of messages which should be shown in the notification
* for a given conversation
*/
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message> {
override fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message> {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("seen", false)
@@ -226,7 +231,7 @@ class MessageRepository @Inject constructor(
.findAll()
}
fun markArchived(threadId: Long) {
override fun markArchived(threadId: Long) {
val realm = Realm.getDefaultInstance()
val conversation = realm.where(Conversation::class.java)
.equalTo("id", threadId)
@@ -236,7 +241,7 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun markUnarchived(threadId: Long) {
override fun markUnarchived(threadId: Long) {
val realm = Realm.getDefaultInstance()
val conversation = realm.where(Conversation::class.java)
.equalTo("id", threadId)
@@ -246,7 +251,7 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun markBlocked(threadId: Long) {
override fun markBlocked(threadId: Long) {
val realm = Realm.getDefaultInstance()
val conversation = realm.where(Conversation::class.java)
.equalTo("id", threadId)
@@ -256,7 +261,7 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun markUnblocked(threadId: Long) {
override fun markUnblocked(threadId: Long) {
val realm = Realm.getDefaultInstance()
val conversation = realm.where(Conversation::class.java)
.equalTo("id", threadId)
@@ -266,14 +271,14 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun markAllSeen() {
override fun markAllSeen() {
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) {
override fun markSeen(threadId: Long) {
val realm = Realm.getDefaultInstance()
val messages = realm.where(Message::class.java)
.equalTo("threadId", threadId)
@@ -288,20 +293,20 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun markRead(threadId: Long) {
override fun markRead(threadId: Long) {
// 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)
}
@@ -325,29 +330,27 @@ class MessageRepository @Inject constructor(
realm.close()
}
/**
* Persists the SMS and attempts to send it
*/
fun sendSmsAndPersist(threadId: Long, address: String, body: String) {
override fun sendSmsAndPersist(threadId: Long, address: String, body: String) {
val message = insertSentSms(threadId, address, body)
sendSms(message)
}
/**
* Attempts to send the SMS message. This can be called if the message has already been persisted
*/
fun sendSms(message: Message) {
override fun sendSms(message: Message) {
val smsManager = SmsManager.getDefault()
val parts = smsManager.divideMessage(if (prefs.unicode.get()) StripAccents.stripAccents(message.body) else message.body)
val sentIntents = parts.map {
val intent = Intent(context, MessageSentReceiver::class.java).putExtra("id", message.id)
val action = "com.moez.QKSMS.SMS_SENT"
val intent = Intent(action).putExtra("id", message.id)
BroadcastUtils.addClassName(context, intent, action)
PendingIntent.getBroadcast(context, message.id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
val deliveredIntents = parts.map {
val intent = Intent(context, MessageDeliveredReceiver::class.java).putExtra("id", message.id)
val action = "com.moez.QKSMS.SMS_DELIVERED"
val intent = Intent(action).putExtra("id", message.id)
BroadcastUtils.addClassName(context, intent, action)
val pendingIntent = PendingIntent.getBroadcast(context, message.id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
if (prefs.delivery.get()) pendingIntent else null
}
@@ -355,7 +358,7 @@ class MessageRepository @Inject constructor(
smsManager.sendMultipartTextMessage(message.address, null, parts, ArrayList(sentIntents), ArrayList(deliveredIntents))
}
fun insertSentSms(threadId: Long, address: String, body: String): Message {
override fun insertSentSms(threadId: Long, address: String, body: String): Message {
// Insert the message to Realm
val message = Message().apply {
@@ -365,7 +368,7 @@ class MessageRepository @Inject constructor(
this.date = System.currentTimeMillis()
id = messageIds.newId()
boxId = Sms.MESSAGE_TYPE_OUTBOX
boxId = Telephony.Sms.MESSAGE_TYPE_OUTBOX
type = "sms"
read = true
seen = true
@@ -393,7 +396,7 @@ class MessageRepository @Inject constructor(
return message
}
fun insertReceivedSms(address: String, body: String, sentTime: Long): Message {
override fun insertReceivedSms(address: String, body: String, sentTime: Long): Message {
// Insert the message to Realm
val message = Message().apply {
@@ -404,7 +407,7 @@ class MessageRepository @Inject constructor(
id = messageIds.newId()
threadId = getOrCreateConversation(address).blockingGet().id
boxId = Sms.MESSAGE_TYPE_INBOX
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
type = "sms"
}
@@ -430,7 +433,7 @@ class MessageRepository @Inject constructor(
/**
* Marks the message as sending, in case we need to retry sending it
*/
fun markSending(id: Long) {
override fun markSending(id: Long) {
Realm.getDefaultInstance().use { realm ->
realm.refresh()
@@ -438,18 +441,18 @@ class MessageRepository @Inject constructor(
message?.let {
// Update the message in realm
realm.executeTransaction {
message.boxId = Sms.MESSAGE_TYPE_OUTBOX
message.boxId = Telephony.Sms.MESSAGE_TYPE_OUTBOX
}
// Update the message in the native ContentProvider
val values = ContentValues()
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_OUTBOX)
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_OUTBOX)
context.contentResolver.update(message.getUri(), values, null, null)
}
}
}
fun markSent(id: Long) {
override fun markSent(id: Long) {
Realm.getDefaultInstance().use { realm ->
realm.refresh()
@@ -457,18 +460,18 @@ class MessageRepository @Inject constructor(
message?.let {
// Update the message in realm
realm.executeTransaction {
message.boxId = Sms.MESSAGE_TYPE_SENT
message.boxId = Telephony.Sms.MESSAGE_TYPE_SENT
}
// Update the message in the native ContentProvider
val values = ContentValues()
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_SENT)
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_SENT)
context.contentResolver.update(message.getUri(), values, null, null)
}
}
}
fun markFailed(id: Long, resultCode: Int) {
override fun markFailed(id: Long, resultCode: Int) {
Realm.getDefaultInstance().use { realm ->
realm.refresh()
@@ -476,20 +479,20 @@ class MessageRepository @Inject constructor(
message?.let {
// Update the message in realm
realm.executeTransaction {
message.boxId = Sms.MESSAGE_TYPE_FAILED
message.boxId = Telephony.Sms.MESSAGE_TYPE_FAILED
message.errorCode = resultCode
}
// Update the message in the native ContentProvider
val values = ContentValues()
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_FAILED)
values.put(Sms.ERROR_CODE, resultCode)
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_FAILED)
values.put(Telephony.Sms.ERROR_CODE, resultCode)
context.contentResolver.update(message.getUri(), values, null, null)
}
}
}
fun markDelivered(id: Long) {
override fun markDelivered(id: Long) {
Realm.getDefaultInstance().use { realm ->
realm.refresh()
@@ -497,22 +500,22 @@ class MessageRepository @Inject constructor(
message?.let {
// Update the message in realm
realm.executeTransaction {
message.deliveryStatus = Sms.STATUS_COMPLETE
message.deliveryStatus = Telephony.Sms.STATUS_COMPLETE
message.dateSent = System.currentTimeMillis()
message.read = true
}
// Update the message in the native ContentProvider
val values = ContentValues()
values.put(Sms.STATUS, Sms.STATUS_COMPLETE)
values.put(Sms.DATE_SENT, System.currentTimeMillis())
values.put(Sms.READ, true)
values.put(Telephony.Sms.STATUS, Telephony.Sms.STATUS_COMPLETE)
values.put(Telephony.Sms.DATE_SENT, System.currentTimeMillis())
values.put(Telephony.Sms.READ, true)
context.contentResolver.update(message.getUri(), values, null, null)
}
}
}
fun markDeliveryFailed(id: Long, resultCode: Int) {
override fun markDeliveryFailed(id: Long, resultCode: Int) {
Realm.getDefaultInstance().use { realm ->
realm.refresh()
@@ -520,7 +523,7 @@ class MessageRepository @Inject constructor(
message?.let {
// Update the message in realm
realm.executeTransaction {
message.deliveryStatus = Sms.STATUS_FAILED
message.deliveryStatus = Telephony.Sms.STATUS_FAILED
message.dateSent = System.currentTimeMillis()
message.read = true
message.errorCode = resultCode
@@ -528,16 +531,16 @@ class MessageRepository @Inject constructor(
// Update the message in the native ContentProvider
val values = ContentValues()
values.put(Sms.STATUS, Sms.STATUS_FAILED)
values.put(Sms.DATE_SENT, System.currentTimeMillis())
values.put(Sms.READ, true)
values.put(Sms.ERROR_CODE, resultCode)
values.put(Telephony.Sms.STATUS, Telephony.Sms.STATUS_FAILED)
values.put(Telephony.Sms.DATE_SENT, System.currentTimeMillis())
values.put(Telephony.Sms.READ, true)
values.put(Telephony.Sms.ERROR_CODE, resultCode)
context.contentResolver.update(message.getUri(), values, null, null)
}
}
}
fun deleteMessage(messageId: Long) {
override fun deleteMessage(messageId: Long) {
val realm = Realm.getDefaultInstance()
realm.where(Message::class.java).equalTo("id", messageId).findFirst()?.let { message ->
val uri = message.getUri()
@@ -547,7 +550,7 @@ class MessageRepository @Inject constructor(
realm.close()
}
fun deleteConversation(threadId: Long) {
override fun deleteConversation(threadId: Long) {
Realm.getDefaultInstance().use { realm ->
val conversation = realm.where(Conversation::class.java).equalTo("id", threadId).findAll()
val messages = realm.where(Message::class.java).equalTo("threadId", threadId).findAll()
@@ -565,8 +568,7 @@ class MessageRepository @Inject constructor(
private fun getConversationFromCp(threadId: Long): Conversation? {
var conversation: Conversation? = null
val cursor = context.contentResolver.query(CursorToConversation.URI, CursorToConversation.PROJECTION,
"_id = ?", arrayOf(threadId.toString()), null)
val cursor = cursorToConversation.getConversationCursor(threadId)
if (cursor.moveToFirst()) {
conversation = cursorToConversation.map(cursor)
@@ -575,8 +577,8 @@ class MessageRepository @Inject constructor(
val contacts = realm.copyFromRealm(realm.where(Contact::class.java).findAll())
val recipients = conversation.recipients
.map { recipient -> recipient.id.toString() }
.map { id -> context.contentResolver.query(CursorToRecipient.URI, null, "_id = ?", arrayOf(id), null) }
.map { recipient -> recipient.id }
.map { id -> cursorToRecipient.getRecipientCursor(id) }
.map { recipientCursor -> recipientCursor.map { cursorToRecipient.map(recipientCursor) } }
.flatten()
.map { recipient ->
@@ -16,36 +16,41 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package repository
import android.content.ContentUris
import android.content.Context
import android.net.Uri
import android.provider.Telephony
import android.telephony.PhoneNumberUtils
import common.util.extensions.asFlowable
import common.util.extensions.insertOrUpdate
import common.util.extensions.map
import common.util.extensions.mapWhile
import data.mapper.CursorToContact
import data.mapper.CursorToConversation
import data.mapper.CursorToMessage
import data.mapper.CursorToRecipient
import data.model.*
import data.repository.MessageRepository
import io.reactivex.Flowable
import io.realm.Realm
import mapper.CursorToContact
import mapper.CursorToConversation
import mapper.CursorToMessage
import mapper.CursorToRecipient
import model.Contact
import model.Conversation
import model.Message
import model.MmsPart
import model.Recipient
import model.SyncLog
import util.extensions.asFlowable
import util.extensions.insertOrUpdate
import util.extensions.map
import util.extensions.mapWhile
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class SyncManager @Inject constructor(
class SyncRepositoryImpl @Inject constructor(
private val context: Context,
private val messageRepo: MessageRepository,
private val cursorToConversation: CursorToConversation,
private val cursorToMessage: CursorToMessage,
private val cursorToRecipient: CursorToRecipient,
private val cursorToContact: CursorToContact) {
private val cursorToContact: CursorToContact
) : SyncRepository {
sealed class Status {
class Idle : Status()
@@ -55,8 +60,7 @@ class SyncManager @Inject constructor(
private val contentResolver = context.contentResolver
private var status: Status = Status.Idle()
// TODO: This needs to be substantially faster
fun syncMessages(fullSync: Boolean = false) {
override fun syncMessages(fullSync: Boolean) {
// If the sync is already running, don't try to do another one
if (status is Status.Running) return
@@ -77,18 +81,14 @@ class SyncManager @Inject constructor(
realm.insert(SyncLog())
// Sync conversations
val conversationCursor = contentResolver.query(
CursorToConversation.URI,
CursorToConversation.PROJECTION,
"date > $lastSync AND ${Telephony.Threads.MESSAGE_COUNT} > 0", null,
"date desc")
val conversationCursor = cursorToConversation.getConversationsCursor()
val conversations = conversationCursor.map { cursor -> cursorToConversation.map(cursor) }
realm.insertOrUpdate(conversations)
conversationCursor.close()
// Sync messages
val messageCursor = contentResolver.query(CursorToMessage.URI, CursorToMessage.PROJECTION, null, null, "normalized_date desc")
val messageCursor = cursorToMessage.getMessagesCursor()
val messageColumns = CursorToMessage.MessageColumns(messageCursor)
val messages = messageCursor.mapWhile(
{ cursor -> cursorToMessage.map(Pair(cursor, messageColumns)) },
@@ -98,7 +98,7 @@ class SyncManager @Inject constructor(
// Sync recipients
val recipientCursor = contentResolver.query(CursorToRecipient.URI, null, null, null, null)
val recipientCursor = cursorToRecipient.getRecipientCursor()
val recipients = recipientCursor.map { cursor -> cursorToRecipient.map(cursor) }
realm.insertOrUpdate(recipients)
recipientCursor.close()
@@ -111,7 +111,7 @@ class SyncManager @Inject constructor(
status = Status.Idle()
}
fun syncMessage(uri: Uri): Flowable<Message> {
override fun syncMessage(uri: Uri): Flowable<Message> {
val id = ContentUris.parseId(uri)
val type = when {
uri.toString().contains("mms") -> "mms"
@@ -150,9 +150,9 @@ class SyncManager @Inject constructor(
.doOnNext { message -> message.insertOrUpdate() }
}
fun syncContacts() {
override fun syncContacts() {
// Load all the contacts
var contacts = context.contentResolver.query(CursorToContact.URI, CursorToContact.PROJECTION, null, null, null)
var contacts = cursorToContact.getContactsCursor()
.map { cursor -> cursorToContact.map(cursor) }
.groupBy { contact -> contact.lookupKey }
.map { contacts ->
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package util
import android.text.TextUtils
import android.util.Patterns
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package util
import android.provider.Settings
import com.f2prateek.rx.preferences2.Preference
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.extensions
package util.extensions
import android.database.Cursor
import io.reactivex.Flowable
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package util.extensions
import com.google.android.mms.ContentType
import model.MmsPart
fun MmsPart.isSmil() = ContentType.APP_SMIL == type
fun MmsPart.isImage() = ContentType.isImageType(type)
fun MmsPart.isText() = ContentType.isTextType(type)
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.extensions
package util.extensions
import io.reactivex.Observable
import io.realm.Realm
@@ -17,12 +17,15 @@
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util.extensions
package util.extensions
import common.util.Optional
import io.reactivex.Flowable
import io.reactivex.Observable
data class Optional<out T>(val value: T?) {
fun notNull() = value != null
}
fun <T, R> Flowable<T>.mapNotNull(mapper: (T) -> R?): Flowable<R>
= map { input -> Optional(mapper(input)) }
.filter { optional -> optional.notNull() }
+37
View File
@@ -0,0 +1,37 @@
apply plugin: 'com.android.library'
apply plugin: 'realm-android' // Realm needs to be before Kotlin or the build will fail
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
}
dependencies {
// dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
provided "javax.annotation:jsr250-api:1.0"
// realm
kapt "io.realm:realm-annotations:$realm_version"
kapt "io.realm:realm-annotations-processor:$realm_version"
// rxjava
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "com.jakewharton.timber:timber:$timber_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
mavenCentral()
}
+1
View File
@@ -0,0 +1 @@
<manifest package="com.moez.QKSMS.domain" />
@@ -18,13 +18,13 @@
*/
package interactor
import common.util.SyncManager
import io.reactivex.Flowable
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
open class ContactSync @Inject constructor(private val syncManager: SyncManager) : Interactor<Unit>() {
open class ContactSync @Inject constructor(private val syncManager: SyncRepository) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
return Flowable.just(System.currentTimeMillis())
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class DeleteConversation @Inject constructor(
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class DeleteMessage @Inject constructor(
@@ -18,16 +18,16 @@
*/
package interactor
import common.util.Keys
import common.util.SyncManager
import io.reactivex.Flowable
import manager.KeyManager
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class FullSync @Inject constructor(
private val syncManager: SyncManager,
private val keys: Keys
private val syncManager: SyncRepository,
private val keys: KeyManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkAllSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Unit>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkDelivered @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,13 +18,13 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkDeliveryFailed @Inject constructor(
private val messageRepo: MessageRepository)
: Interactor<MarkDeliveryFailed.Params>() {
private val messageRepo: MessageRepository
) : Interactor<MarkDeliveryFailed.Params>() {
data class Params(val id: Long, val resultCode: Int)
@@ -18,9 +18,9 @@
*/
package interactor
import common.util.NotificationManager
import data.repository.MessageRepository
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import javax.inject.Inject
class MarkFailed @Inject constructor(
@@ -18,9 +18,9 @@
*/
package interactor
import common.util.NotificationManager
import data.repository.MessageRepository
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import javax.inject.Inject
class MarkRead @Inject constructor(
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkSent @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,8 +18,8 @@
*/
package interactor
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
@@ -18,16 +18,16 @@
*/
package interactor
import common.util.Permissions
import common.util.SyncManager
import io.reactivex.Flowable
import manager.PermissionManager
import repository.SyncRepository
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
open class PartialSync @Inject constructor(
private val syncManager: SyncManager,
private val permissions: Permissions
private val syncManager: SyncRepository,
private val permissions: PermissionManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<Long> {
@@ -18,9 +18,9 @@
*/
package interactor
import data.model.Message
import data.repository.MessageRepository
import io.reactivex.Flowable
import model.Message
import repository.MessageRepository
import javax.inject.Inject
class RetrySending @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Message>() {
@@ -21,8 +21,8 @@ package interactor
import android.content.Context
import android.provider.MediaStore
import androidx.net.toUri
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import javax.inject.Inject
class SaveImage @Inject constructor(
@@ -19,12 +19,12 @@
package interactor
import android.net.Uri
import common.util.SyncManager
import data.model.Message
import io.reactivex.Flowable
import model.Message
import repository.SyncRepository
import javax.inject.Inject
class SyncMessage @Inject constructor(private val syncManager: SyncManager) : Interactor<Uri>() {
class SyncMessage @Inject constructor(private val syncManager: SyncRepository) : Interactor<Uri>() {
override fun buildObservable(params: Uri): Flowable<Message> {
return Flowable.just(params)
@@ -18,22 +18,21 @@
*/
package interactor
import android.content.Context
import data.repository.MessageRepository
import io.reactivex.Flowable
import me.leolin.shortcutbadger.ShortcutBadger
import manager.WidgetManager
import repository.MessageRepository
import javax.inject.Inject
class UpdateBadge @Inject constructor(
private val context: Context,
private val messageRepo: MessageRepository
private val messageRepo: MessageRepository,
private val widgetManager: WidgetManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<*> {
return Flowable.just(params)
.map { messageRepo.getUnreadMessageCount() }
.map { count -> count.toInt() }
.doOnNext { count -> ShortcutBadger.applyCount(context, count) }
.doOnNext { count -> widgetManager.updateUnreadCount(count) }
}
}
@@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.util
package manager
interface Analytics {
interface AnalyticsManager {
fun track(event: String)
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
/**
* Helper class for generating incrementing ids for messages
*/
interface KeyManager {
/**
* Should be called when a new sync is being started
*/
fun reset()
/**
* Returns a valid ID that can be used to store a new message
*/
fun newId(): Long
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
interface NotificationManager {
fun update(threadId: Long)
fun notifyFailed(threadId: Long)
fun createNotificationChannel(threadId: Long)
fun buildNotificationChannelId(threadId: Long): String
}
@@ -16,9 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package manager
package common.util
interface PermissionManager {
fun hasSmsAndContacts(): Boolean
data class Optional<out T>(val value: T?) {
fun notNull() = value != null
}
@@ -16,6 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package manager
data class MenuItem(val title: String, val actionId: Int)
interface WidgetManager {
fun updateUnreadCount(count: Int)
}
@@ -16,9 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package mapper
/**
* Groups a conversation with its latest message into a single model
*/
data class InboxItem(val conversation: Conversation, val message: Message)
import android.database.Cursor
import model.Contact
interface CursorToContact : Mapper<Cursor, Contact> {
fun getContactsCursor(): Cursor
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.Conversation
interface CursorToConversation : Mapper<Cursor, Conversation> {
fun getConversationsCursor(lastSync: Long = 0): Cursor
fun getConversationCursor(threadId: Long): Cursor
}
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import android.provider.Telephony.*
import model.Message
import timber.log.Timber
import java.util.*
interface CursorToMessage : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
fun getMessagesCursor(): Cursor
fun getMessageCursor(id: Long): Cursor
class MessageColumns(private val cursor: Cursor) {
val msgType by lazy { getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) }
val msgId by lazy { getColumnIndex(MmsSms._ID) }
val date by lazy { getColumnIndex(Mms.DATE) }
val dateSent by lazy { getColumnIndex(Mms.DATE_SENT) }
val read by lazy { getColumnIndex(Mms.READ) }
val threadId by lazy { getColumnIndex(Mms.THREAD_ID) }
val locked by lazy { getColumnIndex(Mms.LOCKED) }
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
val smsBody by lazy { getColumnIndex(Sms.BODY) }
val smsSeen by lazy { getColumnIndex(Sms.SEEN) }
val smsType by lazy { getColumnIndex(Sms.TYPE) }
val smsStatus by lazy { getColumnIndex(Sms.STATUS) }
val smsErrorCode by lazy { getColumnIndex(Sms.ERROR_CODE) }
val mmsSubject by lazy { getColumnIndex(Mms.SUBJECT) }
val mmsSubjectCharset by lazy { getColumnIndex(Mms.SUBJECT_CHARSET) }
val mmsSeen by lazy { getColumnIndex(Mms.SEEN) }
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 mmsStatus by lazy { getColumnIndex(Mms.STATUS) }
private fun getColumnIndex(columnsName: String) = try {
cursor.getColumnIndexOrThrow(columnsName)
} catch (e: Exception) {
Timber.e("Couldn't find column \'$columnsName\' in ${Arrays.toString(cursor.columnNames)}")
-1
}
}
}
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.MmsPart
interface CursorToPart : Mapper<Cursor, MmsPart> {
fun getPartsCursor(messageId: Long): Cursor?
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package mapper
import android.database.Cursor
import model.Recipient
interface CursorToRecipient : Mapper<Cursor, Recipient> {
fun getRecipientCursor(): Cursor
fun getRecipientCursor(id: Long): Cursor
}
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.mapper
package mapper
interface Mapper<in From, out To> {
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import io.realm.RealmList
import io.realm.RealmObject
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import android.telephony.PhoneNumberUtils
import io.realm.RealmList
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import android.content.ContentUris
import android.net.Uri
@@ -16,9 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import com.google.android.mms.ContentType
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
@@ -31,10 +30,4 @@ open class MmsPart : RealmObject() {
var text: String? = null
var image: String? = null
fun isSmil() = ContentType.APP_SMIL == type
fun isImage() = ContentType.isImageType(type)
fun isText() = ContentType.isTextType(type)
}
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import io.realm.RealmObject
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package data.model
package model
import io.realm.RealmObject
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import android.net.Uri
import io.reactivex.Flowable
import io.reactivex.Single
import model.Contact
interface ContactRepository {
fun findContactUri(address: String): Single<Uri>
fun getUnmanagedContacts(): Flowable<List<Contact>>
}
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.realm.RealmResults
import model.Conversation
import model.Message
import model.MmsPart
interface MessageRepository {
fun getConversations(archived: Boolean = false): Flowable<List<Pair<Conversation, Message>>>
fun getBlockedConversations(): Flowable<List<Conversation>>
fun getConversationAsync(threadId: Long): Conversation
fun getConversation(threadId: Long): Conversation?
fun getOrCreateConversation(threadId: Long): Conversation?
fun getOrCreateConversation(address: String): Maybe<Conversation>
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation>
fun saveDraft(threadId: Long, draft: String)
fun getMessages(threadId: Long): RealmResults<Message>
fun getMessage(id: Long): Message?
fun getMessageForPart(id: Long): Message?
fun getUnreadMessageCount(): Long
fun getPart(id: Long): MmsPart?
fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>>
/**
* Retrieves the list of messages which should be shown in the notification
* for a given conversation
*/
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message>
fun markArchived(threadId: Long)
fun markUnarchived(threadId: Long)
fun markBlocked(threadId: Long)
fun markUnblocked(threadId: Long)
fun markAllSeen()
fun markSeen(threadId: Long)
fun markRead(threadId: Long)
/**
* Persists the SMS and attempts to send it
*/
fun sendSmsAndPersist(threadId: Long, address: String, body: String)
/**
* Attempts to send the SMS message. This can be called if the message has already been persisted
*/
fun sendSms(message: Message)
fun insertSentSms(threadId: Long, address: String, body: String): Message
fun insertReceivedSms(address: String, body: String, sentTime: Long): Message
/**
* Marks the message as sending, in case we need to retry sending it
*/
fun markSending(id: Long)
fun markSent(id: Long)
fun markFailed(id: Long, resultCode: Int)
fun markDelivered(id: Long)
fun markDeliveryFailed(id: Long, resultCode: Int)
fun deleteMessage(messageId: Long)
fun deleteConversation(threadId: Long)
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package repository
import android.net.Uri
import io.reactivex.Flowable
import model.Message
interface SyncRepository {
fun syncMessages(fullSync: Boolean = false)
fun syncMessage(uri: Uri): Flowable<Message>
fun syncContacts()
}
@@ -87,36 +87,41 @@ dependencies {
implementation "com.uber.autodispose:autodispose-android-kotlin:$autodispose_version"
implementation "com.uber.autodispose:autodispose-kotlin:$autodispose_version"
// dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
provided "javax.annotation:jsr250-api:1.0"
// realm
implementation("io.realm:android-adapters:$realm_adapters_version") { transitive = false }
kapt "io.realm:realm-annotations:$realm_version"
kapt "io.realm:realm-annotations-processor:$realm_version"
// rxjava
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
implementation "androidx.core:core-ktx:0.2"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "com.android.billingclient:billing:1.0"
implementation "com.bugsnag:bugsnag-android:4.1.1"
implementation "com.github.chrisbanes:PhotoView:2.0.0"
implementation "com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC3"
implementation "com.f2prateek.rx.preferences2:rx-preferences:$rx_preferences_version"
implementation "com.github.bumptech.glide:glide:4.3.0"
implementation "com.google.android:flexbox:0.3.1"
implementation "com.google.dagger:dagger:2.11"
implementation "com.jakewharton.timber:timber:4.5.1"
implementation "com.jakewharton.timber:timber:$timber_version"
implementation "com.mlsdev.rximagepicker:library:2.0.2"
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
implementation "io.reactivex.rxjava2:rxjava:2.1.4"
implementation "io.reactivex.rxjava2:rxkotlin:2.1.0"
implementation "me.leolin:ShortcutBadger:1.1.21"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation project(":android-smsmms")
implementation project(':data')
implementation project(':domain')
kapt "com.github.bumptech.glide:compiler:4.3.0"
kapt "com.google.dagger:dagger-compiler:2.11"
testCompile "com.android.support.test:runner:1.0.1"
testCompile "junit:junit:4.12"
testCompile "org.mockito:mockito-core:1.10.19"
provided "javax.annotation:jsr250-api:1.0"
withAnalyticsCompile "com.amplitude:android-sdk:2.16.0"
withAnalyticsCompile "com.mixpanel.android:mixpanel-android:5.2.1"
}
@@ -97,8 +97,12 @@
<receiver
android:name="presentation.receiver.MmsReceivedReceiver"
android:taskAffinity="com.klinker.android.messaging.MMS_RECEIVED" />
<receiver android:name="presentation.receiver.MessageSentReceiver" />
<receiver android:name="presentation.receiver.MessageDeliveredReceiver" />
<receiver
android:name="presentation.receiver.SmsSentReceiver"
android:taskAffinity="com.moez.QKSMS.SMS_SENT" />
<receiver
android:name="presentation.receiver.SmsDeliveredReceiver"
android:taskAffinity="com.moez.QKSMS.SMS_DELIVERED" />
<receiver android:name="presentation.receiver.MarkSeenReceiver" />
<receiver android:name="presentation.receiver.MarkReadReceiver" />
<receiver android:name="presentation.receiver.RemoteMessagingReceiver" />
@@ -27,7 +27,7 @@ import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.R
import common.di.AppComponentManager
import common.di.appComponent
import common.util.Analytics
import manager.AnalyticsManager
import io.realm.Realm
import io.realm.RealmConfiguration
import timber.log.Timber
@@ -40,7 +40,7 @@ class QKApplication : Application() {
* Inject this so that it is forced to initialize
*/
@Suppress("unused")
@Inject lateinit var analytics: Analytics
@Inject lateinit var analyticsManager: AnalyticsManager
override fun onCreate() {
super.onCreate()
@@ -21,7 +21,14 @@ package common.di
import common.QKApplication
import common.util.ContactImageLoader
import dagger.Component
import presentation.common.widget.*
import presentation.common.widget.AvatarView
import presentation.common.widget.MmsPreviewView
import presentation.common.widget.PagerTitleView
import presentation.common.widget.PreferenceView
import presentation.common.widget.QkEditText
import presentation.common.widget.QkSwitch
import presentation.common.widget.QkTextView
import presentation.common.widget.Separator
import presentation.feature.blocked.BlockedActivity
import presentation.feature.blocked.BlockedViewModel
import presentation.feature.compose.ComposeActivity
@@ -43,7 +50,18 @@ import presentation.feature.setup.SetupActivity
import presentation.feature.setup.SetupViewModel
import presentation.feature.themepicker.ThemePickerActivity
import presentation.feature.themepicker.ThemePickerViewModel
import presentation.receiver.*
import presentation.receiver.DefaultSmsChangedReceiver
import presentation.receiver.MarkReadReceiver
import presentation.receiver.MarkSeenReceiver
import presentation.receiver.MmsReceivedReceiver
import presentation.receiver.MmsSentReceiver
import presentation.receiver.MmsUpdatedReceiver
import presentation.receiver.NightModeReceiver
import presentation.receiver.RemoteMessagingReceiver
import presentation.receiver.SmsDeliveredReceiver
import presentation.receiver.SmsProviderChangedReceiver
import presentation.receiver.SmsReceiver
import presentation.receiver.SmsSentReceiver
import javax.inject.Singleton
@Singleton
@@ -64,8 +82,8 @@ interface AppComponent {
fun inject(activity: ThemePickerActivity)
fun inject(receiver: DefaultSmsChangedReceiver)
fun inject(receiver: MessageDeliveredReceiver)
fun inject(receiver: MessageSentReceiver)
fun inject(receiver: SmsDeliveredReceiver)
fun inject(receiver: SmsSentReceiver)
fun inject(receiver: MarkSeenReceiver)
fun inject(receiver: MarkReadReceiver)
fun inject(receiver: MmsReceivedReceiver)
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package common.di
import android.app.Application
import android.content.Context
import android.preference.PreferenceManager
import com.f2prateek.rx.preferences2.RxSharedPreferences
import common.util.AnalyticsManagerImpl
import common.util.NotificationManagerImpl
import dagger.Module
import dagger.Provides
import manager.AnalyticsManager
import manager.KeyManager
import manager.KeyManagerImpl
import manager.NotificationManager
import manager.PermissionManager
import manager.PermissionManagerImpl
import manager.WidgetManager
import manager.WidgetManagerImpl
import mapper.CursorToContact
import mapper.CursorToContactImpl
import mapper.CursorToConversation
import mapper.CursorToConversationImpl
import mapper.CursorToMessage
import mapper.CursorToMessageImpl
import mapper.CursorToPart
import mapper.CursorToPartImpl
import mapper.CursorToRecipienImpl
import mapper.CursorToRecipient
import repository.ContactRepository
import repository.ContactRepositoryImpl
import repository.MessageRepository
import repository.MessageRepositoryImpl
import repository.SyncRepository
import repository.SyncRepositoryImpl
import javax.inject.Singleton
@Module
class AppModule(private var application: Application) {
@Provides
@Singleton
fun provideContext(): Context {
return application
}
@Provides
@Singleton
fun provideRxPreferences(context: Context): RxSharedPreferences {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return RxSharedPreferences.create(preferences)
}
// Manager
@Provides
fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager
@Provides
fun provideKeyManager(manager: KeyManagerImpl): KeyManager = manager
@Provides
fun provideNotificationsManager(manager: NotificationManagerImpl): NotificationManager = manager
@Provides
fun providePermissionsManager(manager: PermissionManagerImpl): PermissionManager = manager
@Provides
fun provideWidgetManager(manager: WidgetManagerImpl): WidgetManager = manager
// Mapper
@Provides
fun provideCursorToContact(mapper: CursorToContactImpl): CursorToContact = mapper
@Provides
fun provideCursorToConversation(mapper: CursorToConversationImpl): CursorToConversation = mapper
@Provides
fun provideCursorToMessage(mapper: CursorToMessageImpl): CursorToMessage = mapper
@Provides
fun provideCursorToPart(mapper: CursorToPartImpl): CursorToPart = mapper
@Provides
fun provideCursorToRecipient(mapper: CursorToRecipienImpl): CursorToRecipient = mapper
// Repository
@Provides
fun provideContactRepository(repository: ContactRepositoryImpl): ContactRepository = repository
@Provides
fun provideMessageRepository(repository: MessageRepositoryImpl): MessageRepository = repository
@Provides
fun provideSyncRepository(repository: SyncRepositoryImpl): SyncRepository = repository
}
@@ -20,9 +20,15 @@ package common.util
import android.app.Activity
import android.content.Context
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingClient.BillingResponse
import com.android.billingclient.api.BillingClient.SkuType
import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.BillingFlowParams
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.PurchasesUpdatedListener
import com.android.billingclient.api.SkuDetails
import com.android.billingclient.api.SkuDetailsParams
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
@@ -27,6 +27,7 @@ import android.view.View
import com.moez.QKSMS.R
import io.reactivex.Observable
import io.reactivex.rxkotlin.Observables
import util.Preferences
import javax.inject.Inject
import javax.inject.Singleton
@@ -30,9 +30,9 @@ import com.bumptech.glide.load.model.ModelLoader
import com.bumptech.glide.load.model.ModelLoaderFactory
import com.bumptech.glide.load.model.MultiModelLoaderFactory
import common.di.appComponent
import data.repository.ContactRepository
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import repository.ContactRepository
import java.io.InputStream
import java.security.MessageDigest
import javax.inject.Inject
@@ -60,6 +60,7 @@ class ContactImageLoader(val context: Context) : ModelLoader<String, InputStream
class ContactImageFetcher(private val context: Context, private val address: String) : DataFetcher<InputStream> {
@Inject lateinit var contactRepo: ContactRepository
private var loadPhotoDisposable: Disposable? = null
init {
@@ -23,6 +23,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import presentation.receiver.NightModeReceiver
import util.Preferences
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -32,21 +32,22 @@ import android.support.v4.app.NotificationManagerCompat
import android.support.v4.app.RemoteInput
import android.support.v4.app.TaskStackBuilder
import com.moez.QKSMS.R
import data.repository.MessageRepository
import presentation.feature.compose.ComposeActivity
import presentation.receiver.MarkReadReceiver
import presentation.receiver.MarkSeenReceiver
import presentation.receiver.RemoteMessagingReceiver
import repository.MessageRepository
import util.Preferences
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class NotificationManager @Inject constructor(
class NotificationManagerImpl @Inject constructor(
private val context: Context,
private val prefs: Preferences,
private val colors: Colors,
private val messageRepo: MessageRepository
) {
): manager.NotificationManager {
companion object {
const val DEFAULT_CHANNEL_ID = "notifications_default"
@@ -74,7 +75,7 @@ class NotificationManager @Inject constructor(
/**
* Updates the notification for a particular conversation
*/
fun update(threadId: Long) {
override fun update(threadId: Long) {
// If notifications are disabled, don't do anything
if (!prefs.notifications(threadId).get()) {
return
@@ -130,7 +131,7 @@ class NotificationManager @Inject constructor(
notificationManager.notify(threadId.toInt(), notification.build())
}
fun notifyFailed(msgId: Long) {
override fun notifyFailed(msgId: Long) {
val message = messageRepo.getMessage(msgId)
if (message == null || !message.isFailedMessage()) {
@@ -183,7 +184,7 @@ class NotificationManager @Inject constructor(
/**
* Creates a notification channel for the given conversation
*/
fun createNotificationChannel(threadId: Long) {
override fun createNotificationChannel(threadId: Long) {
// Only proceed if the android version supports notification channels
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
@@ -241,7 +242,7 @@ class NotificationManager @Inject constructor(
/**
* Formats a notification channel id for a given thread id, whether the channel exists or not
*/
fun buildNotificationChannelId(threadId: Long): String {
override fun buildNotificationChannelId(threadId: Long): String {
return when (threadId) {
0L -> DEFAULT_CHANNEL_ID
else -> "notifications_$threadId"
@@ -18,7 +18,7 @@
*/
package common.util.filter
import data.model.Contact
import model.Contact
import javax.inject.Inject
class ContactFilter @Inject constructor(private val phoneNumberFilter: PhoneNumberFilter) : Filter<Contact>() {
@@ -18,7 +18,7 @@
*/
package common.util.filter
import data.model.Conversation
import model.Conversation
import javax.inject.Inject
class ConversationFilter @Inject constructor(private val recipientFilter: RecipientFilter) : Filter<Conversation>() {
@@ -18,7 +18,7 @@
*/
package common.util.filter
import data.model.Recipient
import model.Recipient
import javax.inject.Inject
class RecipientFilter @Inject constructor(
@@ -20,7 +20,7 @@ package interactor
import com.f2prateek.rx.preferences2.RxSharedPreferences
import common.util.NightModeManager
import common.util.Preferences
import util.Preferences
import io.reactivex.Flowable
import javax.inject.Inject
@@ -19,15 +19,15 @@
package interactor
import android.net.Uri
import common.util.NotificationManager
import common.util.SyncManager
import common.util.extensions.mapNotNull
import data.repository.MessageRepository
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import repository.SyncRepository
import util.extensions.mapNotNull
import javax.inject.Inject
class ReceiveMms @Inject constructor(
private val syncManager: SyncManager,
private val syncManager: SyncRepository,
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge
@@ -19,10 +19,10 @@
package interactor
import android.telephony.SmsMessage
import common.util.NotificationManager
import common.util.extensions.mapNotNull
import data.repository.MessageRepository
import io.reactivex.Flowable
import manager.NotificationManager
import repository.MessageRepository
import util.extensions.mapNotNull
import javax.inject.Inject
class ReceiveSms @Inject constructor(
@@ -25,9 +25,9 @@ import com.klinker.android.send_message.Message
import com.klinker.android.send_message.Settings
import com.klinker.android.send_message.Transaction
import com.mlsdev.rximagepicker.RxImageConverters
import common.util.Preferences
import data.repository.MessageRepository
import io.reactivex.Flowable
import repository.MessageRepository
import util.Preferences
import java.io.ByteArrayOutputStream
import javax.inject.Inject
@@ -28,7 +28,6 @@ import com.moez.QKSMS.R
import common.util.Colors
import common.util.extensions.setTint
import common.util.extensions.setVisible
import data.model.MenuItem
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.subjects.PublishSubject
@@ -38,6 +37,8 @@ import presentation.common.base.QkAdapter
import presentation.common.base.QkViewHolder
import javax.inject.Inject
data class MenuItem(val title: String, val actionId: Int)
class MenuItemAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter<MenuItem>() {
val menuItemClicks: Subject<Int> = PublishSubject.create()
@@ -30,7 +30,7 @@ import android.provider.ContactsContract
import android.provider.Settings
import android.provider.Telephony
import android.view.View
import common.util.NotificationManager
import manager.NotificationManager
import presentation.feature.blocked.BlockedActivity
import presentation.feature.blocked.BlockedViewModel
import presentation.feature.compose.ComposeActivity

Some files were not shown because too many files have changed in this diff Show More