forked from upstream-mirrors/quik
Merge commit '82332207d23d9be47a3cd2b251a953e64ad84453'
This commit is contained in:
@@ -23,7 +23,7 @@ android {
|
||||
compileSdkVersion 25
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
import com.klinker.android.logger.Log;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
@@ -52,6 +53,7 @@ public final class SqliteWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Cursor query(Context context, ContentResolver resolver, Uri uri,
|
||||
String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
try {
|
||||
@@ -63,17 +65,6 @@ public final class SqliteWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean requery(Context context, Cursor cursor) {
|
||||
try {
|
||||
return cursor.requery();
|
||||
} catch (SQLiteException e) {
|
||||
Log.e(TAG, "Catch a SQLiteException when requery: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int update(Context context, ContentResolver resolver, Uri uri,
|
||||
ContentValues values, String where, String[] selectionArgs) {
|
||||
try {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.klinker.android.send_message
|
||||
|
||||
import android.os.Build
|
||||
|
||||
/**
|
||||
* Class to house all of the settings that can be used to send a message
|
||||
*/
|
||||
@@ -39,20 +37,4 @@ class Settings @JvmOverloads constructor(
|
||||
var preText: String? = null,
|
||||
var sendLongAsMms: Boolean = true,
|
||||
var sendLongAsMmsAfter: Int = 3,
|
||||
subscriptionId: Int = DEFAULT_SUBSCRIPTION_ID) {
|
||||
|
||||
// SIM options
|
||||
var subscriptionId: Int = subscriptionId
|
||||
set(value) {
|
||||
// we won't allow you to go away from the default if your device doesn't support it
|
||||
field = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || false) {
|
||||
DEFAULT_SUBSCRIPTION_ID
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_SUBSCRIPTION_ID = -1
|
||||
}
|
||||
}
|
||||
var subscriptionId: Int = -1)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.klinker.android.send_message
|
||||
|
||||
import android.os.Build
|
||||
import android.telephony.SmsManager
|
||||
|
||||
object SmsManagerFactory {
|
||||
@@ -10,7 +9,7 @@ object SmsManagerFactory {
|
||||
fun createSmsManager(subscriptionId: Int): SmsManager {
|
||||
var manager: SmsManager? = null
|
||||
|
||||
if (subscriptionId != Settings.DEFAULT_SUBSCRIPTION_ID && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
if (subscriptionId != -1) {
|
||||
try {
|
||||
manager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId)
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -4,6 +4,7 @@ buildscript {
|
||||
ext.autodispose_version = '0.5.1'
|
||||
ext.constraintlayout_version = '1.1.0-beta5'
|
||||
ext.dagger_version = "2.16"
|
||||
ext.exoplayer_version = "2.8.1"
|
||||
ext.glide_version = "4.3.0"
|
||||
ext.kotlin_version = '1.2.31'
|
||||
ext.ktx_version = "0.2"
|
||||
@@ -36,6 +37,7 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url 'https://maven.google.com' }
|
||||
|
||||
+2
-1
@@ -6,7 +6,7 @@ android {
|
||||
compileSdkVersion 27
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 27
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ dependencies {
|
||||
|
||||
// dagger
|
||||
implementation "com.google.dagger:dagger:$dagger_version"
|
||||
implementation "com.google.dagger:dagger-android-support:$dagger_version"
|
||||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
compileOnly "javax.annotation:jsr250-api:1.0"
|
||||
|
||||
|
||||
@@ -26,18 +26,14 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class KeyManagerImpl @Inject constructor() : KeyManager {
|
||||
|
||||
private var maxValue: Long = 0L
|
||||
|
||||
init {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
maxValue = realm.where(Message::class.java).max("id")?.toLong() ?: 0L
|
||||
realm.close()
|
||||
}
|
||||
private var initialized = false
|
||||
private var maxValue: Long = 0
|
||||
|
||||
/**
|
||||
* Should be called when a new sync is being started
|
||||
*/
|
||||
override fun reset() {
|
||||
initialized = true
|
||||
maxValue = 0L
|
||||
}
|
||||
|
||||
@@ -45,6 +41,13 @@ class KeyManagerImpl @Inject constructor() : KeyManager {
|
||||
* Returns a valid ID that can be used to store a new message
|
||||
*/
|
||||
override fun newId(): Long {
|
||||
if (!initialized) {
|
||||
maxValue = Realm.getDefaultInstance().use { realm ->
|
||||
realm.where(Message::class.java).max("id")?.toLong() ?: 0L
|
||||
}
|
||||
initialized = true
|
||||
}
|
||||
|
||||
maxValue++
|
||||
return maxValue
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ class PermissionManagerImpl @Inject constructor(private val context: Context) :
|
||||
|
||||
override fun hasContacts(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PERMISSION_GRANTED
|
||||
|
||||
override fun hasPhone(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PERMISSION_GRANTED
|
||||
|
||||
override fun hasStorage(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PERMISSION_GRANTED
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ class CursorToMessageImpl @Inject constructor(
|
||||
Mms.READ,
|
||||
Mms.THREAD_ID,
|
||||
Mms.LOCKED,
|
||||
Mms.SUBSCRIPTION_ID,
|
||||
|
||||
Sms.ADDRESS,
|
||||
Sms.BODY,
|
||||
@@ -84,6 +85,7 @@ class CursorToMessageImpl @Inject constructor(
|
||||
dateSent = cursor.getLong(columnsMap.dateSent)
|
||||
read = cursor.getInt(columnsMap.read) != 0
|
||||
locked = cursor.getInt(columnsMap.locked) != 0
|
||||
subId = if (columnsMap.subId != -1) cursor.getInt(columnsMap.subId) else -1
|
||||
|
||||
when (type) {
|
||||
"sms" -> {
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
package migration
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.FieldAttribute
|
||||
import io.realm.RealmMigration
|
||||
|
||||
|
||||
class QkRealmMigration : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SCHEMA_VERSION: Long = 3
|
||||
}
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
var version = oldVersion
|
||||
|
||||
@@ -34,6 +39,20 @@ class QkRealmMigration : RealmMigration {
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 1L) {
|
||||
realm.schema.get("Message")
|
||||
?.addField("subId", Int::class.java)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 2L) {
|
||||
realm.schema.get("Conversation")
|
||||
?.addField("name", String::class.java, FieldAttribute.REQUIRED)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version < newVersion) {
|
||||
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.Telephony
|
||||
import android.support.annotation.RequiresApi
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.SyncMessages
|
||||
import util.Preferences
|
||||
import javax.inject.Inject
|
||||
@@ -36,7 +36,7 @@ class DefaultSmsChangedReceiver : BroadcastReceiver() {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
if (intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)) {
|
||||
val pendingResult = goAsync()
|
||||
+2
-2
@@ -21,7 +21,7 @@ package receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkRead
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -30,7 +30,7 @@ class MarkReadReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
markRead.execute(threadId)
|
||||
+2
-2
@@ -21,7 +21,7 @@ package receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkSeen
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -30,7 +30,7 @@ class MarkSeenReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var markSeen: MarkSeen
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
markSeen.execute(threadId)
|
||||
+8
-3
@@ -18,9 +18,11 @@
|
||||
*/
|
||||
package receiver
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.klinker.android.send_message.MmsReceivedReceiver
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.ReceiveMms
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -28,9 +30,12 @@ class MmsReceivedReceiver : MmsReceivedReceiver() {
|
||||
|
||||
@Inject lateinit var receiveMms: ReceiveMms
|
||||
|
||||
override fun onMessageReceived(messageUri: Uri?) {
|
||||
appComponent.inject(this)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
AndroidInjection.inject(this, context)
|
||||
super.onReceive(context, intent)
|
||||
}
|
||||
|
||||
override fun onMessageReceived(messageUri: Uri?) {
|
||||
messageUri?.let { uri ->
|
||||
val pendingResult = goAsync()
|
||||
receiveMms.execute(uri) { pendingResult.finish() }
|
||||
+2
-2
@@ -29,7 +29,7 @@ import android.provider.Telephony
|
||||
import com.google.android.mms.MmsException
|
||||
import com.google.android.mms.util_alt.SqliteWrapper
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.SyncMessage
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
@@ -40,7 +40,7 @@ class MmsSentReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var syncMessage: SyncMessage
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
Timber.v("MMS sending result: $resultCode")
|
||||
val uri = Uri.parse(intent.getStringExtra(Transaction.EXTRA_CONTENT_URI))
|
||||
+3
-2
@@ -22,7 +22,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.SyncMessage
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -35,7 +35,8 @@ class MmsUpdatedReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var syncMessage: SyncMessage
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
intent.getStringExtra(URI)?.let { uriString ->
|
||||
val pendingResult = goAsync()
|
||||
syncMessage.execute(Uri.parse(uriString)) { pendingResult.finish() }
|
||||
+4
-6
@@ -21,19 +21,17 @@ package receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import common.util.NightModeManager
|
||||
import dagger.android.AndroidInjection
|
||||
import util.NightModeManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class NightModeReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var nightModeManager: NightModeManager
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
nightModeManager.updateCurrentTheme()
|
||||
}
|
||||
}
|
||||
+20
-12
@@ -22,27 +22,35 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v4.app.RemoteInput
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkRead
|
||||
import interactor.SendMessage
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemoteMessagingReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var subUtils: SubscriptionUtils
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val remoteInput = RemoteInput.getResultsFromIntent(intent)
|
||||
val bundle = intent.extras
|
||||
if (remoteInput != null && bundle != null) {
|
||||
val address = bundle.getString("address")
|
||||
val threadId = bundle.getLong("threadId")
|
||||
val body = remoteInput.getCharSequence("body").toString()
|
||||
markRead.execute(threadId)
|
||||
sendMessage.execute(SendMessage.Params(threadId, listOf(address), body))
|
||||
}
|
||||
val remoteInput = RemoteInput.getResultsFromIntent(intent) ?: return
|
||||
val bundle = intent.extras ?: return
|
||||
|
||||
val threadId = bundle.getLong("threadId")
|
||||
val body = remoteInput.getCharSequence("body").toString()
|
||||
markRead.execute(threadId)
|
||||
|
||||
val lastMessage = messageRepo.getMessages(threadId).lastOrNull()
|
||||
val subId = subUtils.subscriptions.firstOrNull { it.subscriptionId == lastMessage?.subId }?.subscriptionId ?: -1
|
||||
val addresses = messageRepo.getConversation(threadId)?.recipients?.map { it.address } ?: return
|
||||
|
||||
val pendingRepository = goAsync()
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body)) { pendingRepository.finish() }
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -21,7 +21,7 @@ package receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.RetrySending
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
@@ -32,7 +32,7 @@ class SendSmsReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var retrySending: RetrySending
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val id = intent.getLongExtra("id", 0L)
|
||||
messageRepo.getMessage(id)?.let { message ->
|
||||
+3
-5
@@ -22,7 +22,7 @@ import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkDelivered
|
||||
import interactor.MarkDeliveryFailed
|
||||
import javax.inject.Inject
|
||||
@@ -32,11 +32,9 @@ class SmsDeliveredReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var markDelivered: MarkDelivered
|
||||
@Inject lateinit var markDeliveryFailed: MarkDeliveryFailed
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val id = intent.getLongExtra("id", 0L)
|
||||
|
||||
when (resultCode) {
|
||||
+2
-2
@@ -21,7 +21,7 @@ package receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.SyncMessage
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -41,7 +41,7 @@ class SmsProviderChangedReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var syncMessage: SyncMessage
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
// Obtain the uri for the changed data
|
||||
// If the value is null, don't continue
|
||||
+5
-3
@@ -22,7 +22,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Telephony.Sms
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.ReceiveSms
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -31,11 +31,13 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var receiveMessage: ReceiveSms
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
Sms.Intents.getMessagesFromIntent(intent)?.let { messages ->
|
||||
val subId = intent.extras?.getInt("subscription", -1) ?: -1
|
||||
|
||||
val pendingResult = goAsync()
|
||||
receiveMessage.execute(messages, { pendingResult.finish() })
|
||||
receiveMessage.execute(ReceiveSms.Params(subId, messages), { pendingResult.finish() })
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.telephony.SmsManager
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkFailed
|
||||
import interactor.MarkSent
|
||||
import javax.inject.Inject
|
||||
@@ -34,7 +34,7 @@ class SmsSentReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var markFailed: MarkFailed
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val id = intent.getLongExtra("id", 0L)
|
||||
|
||||
@@ -24,18 +24,20 @@ import android.content.ContentUris
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.sqlite.SqliteWrapper
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.BaseColumns
|
||||
import android.provider.Telephony
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SmsManager
|
||||
import com.google.android.mms.ContentType
|
||||
import com.klinker.android.send_message.BroadcastUtils
|
||||
import com.klinker.android.send_message.Settings
|
||||
import com.klinker.android.send_message.StripAccents
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import filter.ConversationFilter
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Case
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
@@ -43,6 +45,7 @@ import io.realm.Sort
|
||||
import manager.KeyManager
|
||||
import mapper.CursorToConversation
|
||||
import mapper.CursorToRecipient
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
@@ -51,9 +54,8 @@ import model.SearchResult
|
||||
import util.MessageUtils
|
||||
import util.Preferences
|
||||
import util.extensions.anyOf
|
||||
import util.extensions.asMaybe
|
||||
import util.extensions.insertOrUpdate
|
||||
import util.extensions.map
|
||||
import java.io.ByteArrayOutputStream
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -64,6 +66,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
private val conversationFilter: ConversationFilter,
|
||||
private val cursorToConversation: CursorToConversation,
|
||||
private val cursorToRecipient: CursorToRecipient,
|
||||
private val imageRepository: ImageRepository,
|
||||
private val prefs: Preferences) : MessageRepository {
|
||||
|
||||
override fun getConversations(archived: Boolean): RealmResults<Conversation> {
|
||||
@@ -90,6 +93,17 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.findAll())
|
||||
}
|
||||
|
||||
override fun setConversationName(id: Long, name: String) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
realm.executeTransaction {
|
||||
realm.where(Conversation::class.java)
|
||||
.equalTo("id", id)
|
||||
.findFirst()
|
||||
?.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun searchConversations(query: String): List<SearchResult> {
|
||||
val conversations = getConversationsSnapshot()
|
||||
|
||||
@@ -104,7 +118,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.sortedByDescending { result -> result.messages }
|
||||
|
||||
return conversations
|
||||
.filter { conversation -> conversationFilter.filter(conversation, query) }
|
||||
.filter { conversation -> conversationFilter.filter(conversation, query) }
|
||||
.map { conversation -> SearchResult(query, conversation, 0) }
|
||||
.plus(messagesByConversation)
|
||||
}
|
||||
@@ -134,39 +148,32 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return getConversation(threadId) ?: getConversationFromCp(threadId)
|
||||
}
|
||||
|
||||
override fun getOrCreateConversation(address: String): Maybe<Conversation> {
|
||||
override fun getOrCreateConversation(address: String): Conversation? {
|
||||
return getOrCreateConversation(listOf(address))
|
||||
}
|
||||
|
||||
override fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
|
||||
return Maybe.just(addresses)
|
||||
.map { recipients ->
|
||||
recipients.map { address ->
|
||||
when (MessageUtils.isEmailAddress(address)) {
|
||||
true -> MessageUtils.extractAddrSpec(address)
|
||||
false -> address
|
||||
}
|
||||
override fun getOrCreateConversation(addresses: List<String>): Conversation? {
|
||||
return addresses
|
||||
.map { address ->
|
||||
when (MessageUtils.isEmailAddress(address)) {
|
||||
true -> MessageUtils.extractAddrSpec(address)
|
||||
false -> address
|
||||
}
|
||||
}
|
||||
.map { recipients ->
|
||||
.let { recipients ->
|
||||
Uri.parse("content://mms-sms/threadID").buildUpon().apply {
|
||||
recipients.forEach { recipient -> appendQueryParameter("recipient", recipient) }
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
.flatMap { uriBuilder ->
|
||||
context.contentResolver.query(uriBuilder.build(), arrayOf(BaseColumns._ID), null, null, null).asMaybe()
|
||||
}
|
||||
.map { cursor -> cursor.getLong(0) }
|
||||
.filter { threadId -> threadId != 0L }
|
||||
.map { threadId ->
|
||||
.let { uri -> SqliteWrapper.query(context, context.contentResolver, uri, arrayOf(BaseColumns._ID), null, null, null) }
|
||||
?.use { cursor -> if (cursor.moveToFirst()) cursor.getLong(0) else null }
|
||||
?.takeIf { threadId -> threadId != 0L }
|
||||
?.let { threadId ->
|
||||
var conversation = getConversation(threadId)
|
||||
if (conversation != null) conversation = Realm.getDefaultInstance().copyFromRealm(conversation)
|
||||
|
||||
conversation ?: getConversationFromCp(threadId)?.apply { insertOrUpdate() } ?: Conversation()
|
||||
conversation ?: getConversationFromCp(threadId)
|
||||
}
|
||||
.onErrorReturn { Conversation() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
override fun saveDraft(threadId: Long, draft: String) {
|
||||
@@ -226,7 +233,11 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return Realm.getDefaultInstance()
|
||||
.where(MmsPart::class.java)
|
||||
.equalTo("messages.threadId", threadId)
|
||||
.beginGroup()
|
||||
.contains("type", "image/")
|
||||
.or()
|
||||
.contains("type", "video/")
|
||||
.endGroup()
|
||||
.sort("id", Sort.DESCENDING)
|
||||
.findAllAsync()
|
||||
}
|
||||
@@ -386,7 +397,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendSmsAndPersist(threadId: Long, address: String, body: String) {
|
||||
override fun sendSmsAndPersist(subId: Int, threadId: Long, address: String, body: String) {
|
||||
if (prefs.sendDelay.get() != Preferences.SEND_DELAY_NONE) {
|
||||
val delay = when (prefs.sendDelay.get()) {
|
||||
Preferences.SEND_DELAY_SHORT -> 3000
|
||||
@@ -396,7 +407,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
|
||||
val sendTime = System.currentTimeMillis() + delay
|
||||
val message = insertSentSms(threadId, address, body, sendTime)
|
||||
val message = insertSentSms(subId, threadId, address, body, sendTime)
|
||||
|
||||
val intent = getIntentForDelayedSms(message.id)
|
||||
|
||||
@@ -407,13 +418,15 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, sendTime, intent)
|
||||
}
|
||||
} else {
|
||||
val message = insertSentSms(threadId, address, body, System.currentTimeMillis())
|
||||
val message = insertSentSms(subId, threadId, address, body, System.currentTimeMillis())
|
||||
sendSms(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendSms(message: Message) {
|
||||
val smsManager = SmsManager.getDefault()
|
||||
val smsManager = message.subId.takeIf { it != -1 }
|
||||
?.let(SmsManager::getSmsManagerForSubscriptionId)
|
||||
?: SmsManager.getDefault()
|
||||
|
||||
val parts = smsManager.divideMessage(if (prefs.unicode.get()) StripAccents.stripAccents(message.body) else message.body)
|
||||
?: arrayListOf()
|
||||
@@ -436,6 +449,60 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
smsManager.sendMultipartTextMessage(message.address, null, parts, ArrayList(sentIntents), ArrayList(deliveredIntents))
|
||||
}
|
||||
|
||||
override fun sendMms(subId: Int, threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>) {
|
||||
val settings = Settings().apply { subscriptionId = subId }
|
||||
val message = com.klinker.android.send_message.Message(body, addresses.toTypedArray())
|
||||
|
||||
// Add the GIFs as attachments. The app currently can't compress them, which may result
|
||||
// in a lot of these messages failing to send
|
||||
// TODO Add support for GIF compression
|
||||
attachments
|
||||
.filter { attachment -> attachment.isGif(context) }
|
||||
.map { attachment -> attachment.getUri() }
|
||||
.map { uri -> context.contentResolver.openInputStream(uri) }
|
||||
.map { inputStream -> inputStream.readBytes() }
|
||||
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_GIF) }
|
||||
|
||||
// Compress the images and add them as attachments
|
||||
var totalImageBytes = 0
|
||||
attachments
|
||||
.filter { attachment -> !attachment.isGif(context) }
|
||||
.mapNotNull { attachment -> attachment.getUri() }
|
||||
.mapNotNull { uri -> imageRepository.loadImage(uri) }
|
||||
.also { totalImageBytes = it.sumBy { it.allocationByteCount } }
|
||||
.map { bitmap ->
|
||||
val byteRatio = bitmap.allocationByteCount / totalImageBytes.toFloat()
|
||||
shrink(bitmap, (prefs.mmsSize.get() * 1024 * byteRatio).toInt())
|
||||
}
|
||||
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_JPEG) }
|
||||
|
||||
val transaction = Transaction(context, settings)
|
||||
transaction.sendNewMessage(message, threadId)
|
||||
}
|
||||
|
||||
private fun shrink(src: Bitmap, maxBytes: Int): ByteArray {
|
||||
var step = 0.0
|
||||
val factor = 0.5
|
||||
val quality = 60
|
||||
|
||||
val height = src.height
|
||||
val width = src.width
|
||||
|
||||
val stream = ByteArrayOutputStream()
|
||||
src.compress(Bitmap.CompressFormat.JPEG, 100, stream)
|
||||
|
||||
while (maxBytes > 0 && stream.size() > maxBytes) {
|
||||
step++
|
||||
val scale = Math.pow(factor, step)
|
||||
|
||||
stream.reset()
|
||||
Bitmap.createScaledBitmap(src, (width * scale).toInt(), (height * scale).toInt(), false)
|
||||
.compress(Bitmap.CompressFormat.JPEG, quality, stream)
|
||||
}
|
||||
|
||||
return stream.toByteArray()
|
||||
}
|
||||
|
||||
override fun cancelDelayedSms(id: Long) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
alarmManager.cancel(getIntentForDelayedSms(id))
|
||||
@@ -448,7 +515,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return PendingIntent.getBroadcast(context, id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
override fun insertSentSms(threadId: Long, address: String, body: String, date: Long): Message {
|
||||
override fun insertSentSms(subId: Int, threadId: Long, address: String, body: String, date: Long): Message {
|
||||
|
||||
// Insert the message to Realm
|
||||
val message = Message().apply {
|
||||
@@ -456,6 +523,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
this.address = address
|
||||
this.body = body
|
||||
this.date = date
|
||||
this.subId = subId
|
||||
|
||||
id = messageIds.newId()
|
||||
boxId = Telephony.Sms.MESSAGE_TYPE_OUTBOX
|
||||
@@ -476,6 +544,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
put(Telephony.Sms.SEEN, true)
|
||||
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_OUTBOX)
|
||||
put(Telephony.Sms.THREAD_ID, threadId)
|
||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
||||
}
|
||||
val uri = context.contentResolver.insert(Telephony.Sms.CONTENT_URI, values)
|
||||
|
||||
@@ -487,7 +556,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return message
|
||||
}
|
||||
|
||||
override fun insertReceivedSms(address: String, body: String, sentTime: Long): Message {
|
||||
override fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message {
|
||||
|
||||
// Insert the message to Realm
|
||||
val message = Message().apply {
|
||||
@@ -495,9 +564,10 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
this.body = body
|
||||
this.dateSent = sentTime
|
||||
this.date = System.currentTimeMillis()
|
||||
this.subId = subId
|
||||
|
||||
id = messageIds.newId()
|
||||
threadId = getOrCreateConversation(address).blockingGet().id
|
||||
threadId = getOrCreateConversation(address)?.id ?: 0L
|
||||
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
|
||||
type = "sms"
|
||||
}
|
||||
@@ -510,6 +580,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
put(Telephony.Sms.ADDRESS, address)
|
||||
put(Telephony.Sms.BODY, body)
|
||||
put(Telephony.Sms.DATE_SENT, sentTime)
|
||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
||||
}
|
||||
val uri = context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)
|
||||
|
||||
@@ -690,7 +761,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
|
||||
conversation.recipients.clear()
|
||||
conversation.recipients.addAll(recipients)
|
||||
conversation.insertOrUpdate()
|
||||
realm.executeTransaction { it.insertOrUpdate(conversation) }
|
||||
realm.close()
|
||||
|
||||
conversation
|
||||
|
||||
@@ -59,7 +59,11 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
/**
|
||||
* Holds data that should be persisted across full syncs
|
||||
*/
|
||||
private data class PersistedData(val id: Long, val archived: Boolean, val blocked: Boolean)
|
||||
private data class PersistedData(
|
||||
val id: Long,
|
||||
val archived: Boolean,
|
||||
val blocked: Boolean,
|
||||
val name: String)
|
||||
|
||||
override val syncProgress: Subject<SyncRepository.SyncProgress> = BehaviorSubject.createDefault(SyncRepository.SyncProgress.Idle())
|
||||
|
||||
@@ -77,9 +81,11 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
.equalTo("archived", true)
|
||||
.or()
|
||||
.equalTo("blocked", true)
|
||||
.or()
|
||||
.isNotEmpty("name")
|
||||
.endGroup()
|
||||
.findAll()
|
||||
.map { PersistedData(it.id, it.archived, it.blocked) }
|
||||
.map { PersistedData(it.id, it.archived, it.blocked, it.name) }
|
||||
|
||||
realm.delete(Contact::class.java)
|
||||
realm.delete(Conversation::class.java)
|
||||
@@ -102,7 +108,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
persistedData += oldBlockedSenders.get()
|
||||
.map { threadIdString -> threadIdString.toLong() }
|
||||
.filter { threadId -> persistedData.none { it.id == threadId } }
|
||||
.map { threadId -> PersistedData(threadId, false, true) }
|
||||
.map { threadId -> PersistedData(threadId, false, true, "") }
|
||||
|
||||
// Sync conversations
|
||||
cursorToConversation.getConversationsCursor()?.use { conversationCursor ->
|
||||
@@ -113,6 +119,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
val conversation = conversations.firstOrNull { conversation -> conversation.id == data.id }
|
||||
conversation?.archived = data.archived
|
||||
conversation?.blocked = data.blocked
|
||||
conversation?.name = data.name
|
||||
}
|
||||
|
||||
realm.insertOrUpdate(conversations)
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import android.app.IntentService
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.telephony.TelephonyManager
|
||||
import injection.appComponent
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.SendMessage
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
@@ -35,12 +35,12 @@ class HeadlessSmsSendService : IntentService("HeadlessSmsSendService") {
|
||||
override fun onHandleIntent(intent: Intent?) {
|
||||
if (intent?.action != TelephonyManager.ACTION_RESPOND_VIA_MESSAGE) return
|
||||
|
||||
appComponent.inject(this)
|
||||
AndroidInjection.inject(this)
|
||||
intent.extras?.getString(Intent.EXTRA_TEXT)?.takeIf { it.isNotBlank() }?.let { body ->
|
||||
val intentUri = intent.data
|
||||
val recipients = getRecipients(intentUri).split(";")
|
||||
val threadId = messageRepo.getOrCreateConversation(recipients).blockingGet()?.id ?: 0L
|
||||
sendMessage.execute(SendMessage.Params(threadId, recipients, body))
|
||||
val threadId = messageRepo.getOrCreateConversation(recipients)?.id ?: 0L
|
||||
sendMessage.execute(SendMessage.Params(-1, threadId, recipients, body))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -16,15 +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 common.util
|
||||
package util
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import receiver.NightModeReceiver
|
||||
import util.Preferences
|
||||
import util.tryOrNull
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -0,0 +1,69 @@
|
||||
package util
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.disposables.Disposable
|
||||
import manager.PermissionManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class SubscriptionUtilsImpl @Inject constructor(
|
||||
context: Context,
|
||||
private val permissions: PermissionManager
|
||||
) : SubscriptionUtils {
|
||||
|
||||
/**
|
||||
* If we don't have the phone permission, then return a null [SubscriptionManager]
|
||||
*/
|
||||
private val subscriptionManager: SubscriptionManager? = SubscriptionManager.from(context)
|
||||
get() = field?.takeIf { permissions.hasPhone() }
|
||||
|
||||
override val subscriptions: List<SubscriptionInfo>
|
||||
get() = subscriptionManager?.activeSubscriptionInfoList ?: listOf()
|
||||
|
||||
override val subscriptionsObservable: Observable<List<SubscriptionInfo>> = ActiveSubscriptionObservable(subscriptionManager)
|
||||
|
||||
override fun getSubIdForAddress(address: String): Int {
|
||||
return subscriptions.firstOrNull { PhoneNumberUtils.compare(it.number, address) }?.subscriptionId ?: -1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ActiveSubscriptionObservable(
|
||||
private val subscriptionManager: SubscriptionManager?
|
||||
) : Observable<List<SubscriptionInfo>>() {
|
||||
|
||||
override fun subscribeActual(observer: Observer<in List<SubscriptionInfo>>) {
|
||||
observer.onNext(subscriptionManager?.activeSubscriptionInfoList ?: listOf())
|
||||
|
||||
val listener = Listener(subscriptionManager, observer)
|
||||
observer.onSubscribe(listener)
|
||||
subscriptionManager?.addOnSubscriptionsChangedListener(listener)
|
||||
}
|
||||
|
||||
internal class Listener(
|
||||
private val subscriptionManager: SubscriptionManager?,
|
||||
private val observer: Observer<in List<SubscriptionInfo>>
|
||||
) : Disposable, SubscriptionManager.OnSubscriptionsChangedListener() {
|
||||
|
||||
private var disposed: Boolean = false
|
||||
|
||||
override fun onSubscriptionsChanged() {
|
||||
if (!isDisposed) {
|
||||
observer.onNext(subscriptionManager?.activeSubscriptionInfoList ?: listOf())
|
||||
}
|
||||
}
|
||||
|
||||
override fun isDisposed(): Boolean = disposed
|
||||
|
||||
override fun dispose() {
|
||||
disposed = true
|
||||
subscriptionManager?.removeOnSubscriptionsChangedListener(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,4 +29,4 @@ fun MmsPart.isVideo() = ContentType.isVideoType(type)
|
||||
|
||||
fun MmsPart.isText() = ContentType.isTextType(type)
|
||||
|
||||
fun MmsPart.hasThumbnails() = isImage() || isVideo()
|
||||
fun MmsPart.isVCard() = ContentType.TEXT_VCARD == type
|
||||
+1
-1
@@ -7,7 +7,7 @@ android {
|
||||
compileSdkVersion 27
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 27
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class Interactor<in Params>: Disposable {
|
||||
abstract class Interactor<in Params> : Disposable {
|
||||
|
||||
private val disposables: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@@ -36,7 +37,7 @@ abstract class Interactor<in Params>: Disposable {
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnComplete(onComplete)
|
||||
.subscribe()
|
||||
.subscribe({}, Timber::w)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
@@ -32,23 +32,26 @@ class ReceiveSms @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
private val updateBadge: UpdateBadge
|
||||
) : Interactor<Array<SmsMessage>>() {
|
||||
) : Interactor<ReceiveSms.Params>() {
|
||||
|
||||
override fun buildObservable(params: Array<SmsMessage>): Flowable<*> {
|
||||
class Params(val subId: Int, val messages: Array<SmsMessage>)
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.filter { it.isNotEmpty() }
|
||||
.filter { messages -> // Don't continue if the sender is blocked
|
||||
val address = messages[0].displayOriginatingAddress
|
||||
.filter { it.messages.isNotEmpty() }
|
||||
.filter { // Don't continue if the sender is blocked
|
||||
val address = it.messages[0].displayOriginatingAddress
|
||||
!externalBlockingManager.shouldBlock(address).blockingGet()
|
||||
}
|
||||
.map { messages ->
|
||||
.map {
|
||||
val messages = it.messages
|
||||
val address = messages[0].displayOriginatingAddress
|
||||
val time = messages[0].timestampMillis
|
||||
val body: String = messages
|
||||
.map { message -> message.displayMessageBody }
|
||||
.reduce { body, new -> body + new }
|
||||
|
||||
messageRepo.insertReceivedSms(address, body, time) // Add the message to the db
|
||||
messageRepo.insertReceivedSms(it.subId, address, body, time) // Add the message to the db
|
||||
}
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
|
||||
@@ -34,6 +34,7 @@ class RetrySending @Inject constructor(private val messageRepo: MessageRepositor
|
||||
type = params.type
|
||||
address = params.address
|
||||
body = params.body
|
||||
subId = params.subId
|
||||
}
|
||||
|
||||
return Flowable.just(message)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import model.Attachment
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendMessage @Inject constructor(
|
||||
private val messageRepo: MessageRepository
|
||||
) : Interactor<SendMessage.Params>() {
|
||||
|
||||
data class Params(val subId: Int, val threadId: Long, val addresses: List<String>, val body: String, val attachments: List<Attachment> = listOf())
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.filter { params.addresses.isNotEmpty() }
|
||||
.doOnNext {
|
||||
if (params.addresses.size == 1 && params.attachments.isEmpty()) {
|
||||
messageRepo.sendSmsAndPersist(params.subId, params.threadId, params.addresses.first(), params.body)
|
||||
} else {
|
||||
messageRepo.sendMms(params.subId, params.threadId, params.addresses, params.body, params.attachments)
|
||||
}
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversations(params.threadId) }
|
||||
.doOnNext { messageRepo.markUnarchived(params.threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,8 @@ interface PermissionManager {
|
||||
|
||||
fun hasContacts(): Boolean
|
||||
|
||||
fun hasPhone(): Boolean
|
||||
|
||||
fun hasStorage(): Boolean
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@ interface CursorToMessage : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>,
|
||||
val read by lazy { getColumnIndex(Mms.READ) }
|
||||
val threadId by lazy { getColumnIndex(Mms.THREAD_ID) }
|
||||
val locked by lazy { getColumnIndex(Mms.LOCKED) }
|
||||
val subId by lazy { getColumnIndex(Mms.SUBSCRIPTION_ID) }
|
||||
|
||||
val smsAddress by lazy { getColumnIndex(Sms.ADDRESS) }
|
||||
val smsBody by lazy { getColumnIndex(Sms.BODY) }
|
||||
|
||||
+3
-4
@@ -16,13 +16,12 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package feature.compose
|
||||
package model
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.support.v13.view.inputmethod.InputContentInfoCompat
|
||||
import com.google.android.mms.ContentType
|
||||
|
||||
data class Attachment(private val uri: Uri? = null, private val inputContent: InputContentInfoCompat? = null) {
|
||||
|
||||
@@ -36,9 +35,9 @@ data class Attachment(private val uri: Uri? = null, private val inputContent: In
|
||||
|
||||
fun isGif(context: Context): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && inputContent != null) {
|
||||
inputContent.description.hasMimeType(ContentType.IMAGE_GIF)
|
||||
inputContent.description.hasMimeType("image/gif")
|
||||
} else {
|
||||
context.contentResolver.getType(uri) == ContentType.IMAGE_GIF
|
||||
context.contentResolver.getType(uri) == "image/gif"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,5 +36,10 @@ open class Conversation : RealmObject() {
|
||||
var me: Boolean = false
|
||||
var draft: String = ""
|
||||
|
||||
fun getTitle() = recipients.joinToString { recipient -> recipient.getDisplayName() }
|
||||
// For group chats, the user is allowed to set a custom title for the conversation
|
||||
var name: String = ""
|
||||
|
||||
fun getTitle(): String {
|
||||
return name.takeIf { it.isNotBlank() } ?: recipients.joinToString { recipient -> recipient.getDisplayName() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ open class Message : RealmObject() {
|
||||
var seen: Boolean = false
|
||||
var read: Boolean = false
|
||||
var locked: Boolean = false
|
||||
var subId: Int = -1
|
||||
|
||||
// SMS only
|
||||
var body: String = ""
|
||||
@@ -132,7 +133,7 @@ open class Message : RealmObject() {
|
||||
* Cleanses the subject in case it's useless, so that the UI doesn't have to show it
|
||||
*/
|
||||
fun getCleansedSubject(): String {
|
||||
val uselessSubjects = listOf("no subject", "NoSubject")
|
||||
val uselessSubjects = listOf("no subject", "NoSubject", "<not present>")
|
||||
|
||||
return if (uselessSubjects.contains(subject)) "" else subject
|
||||
}
|
||||
@@ -153,7 +154,9 @@ open class Message : RealmObject() {
|
||||
return isFailedMms || isFailedSms
|
||||
}
|
||||
|
||||
fun compareSender(other: Message): Boolean {
|
||||
return isMe() && other.isMe() || (!isMe() && !other.isMe() && address == other.address)
|
||||
fun compareSender(other: Message): Boolean = when {
|
||||
isMe() && other.isMe() -> subId == other.subId
|
||||
!isMe() && !other.isMe() -> subId == other.subId && address == other.address
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
package repository
|
||||
|
||||
import io.reactivex.Maybe
|
||||
import io.realm.RealmResults
|
||||
import model.Attachment
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.MmsPart
|
||||
@@ -31,6 +31,8 @@ interface MessageRepository {
|
||||
|
||||
fun getConversationsSnapshot(): List<Conversation>
|
||||
|
||||
fun setConversationName(id: Long, name: String)
|
||||
|
||||
fun searchConversations(query: String): List<SearchResult>
|
||||
|
||||
fun getBlockedConversations(): RealmResults<Conversation>
|
||||
@@ -41,9 +43,9 @@ interface MessageRepository {
|
||||
|
||||
fun getOrCreateConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(address: String): Maybe<Conversation>
|
||||
fun getOrCreateConversation(address: String): Conversation?
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation>
|
||||
fun getOrCreateConversation(addresses: List<String>): Conversation?
|
||||
|
||||
fun saveDraft(threadId: Long, draft: String)
|
||||
|
||||
@@ -93,21 +95,23 @@ interface MessageRepository {
|
||||
/**
|
||||
* Persists the SMS and attempts to send it
|
||||
*/
|
||||
fun sendSmsAndPersist(threadId: Long, address: String, body: String)
|
||||
fun sendSmsAndPersist(subId: Int, 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 sendMms(subId: Int, threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>)
|
||||
|
||||
/**
|
||||
* Attempts to cancel sending the message with the given id
|
||||
*/
|
||||
fun cancelDelayedSms(id: Long)
|
||||
|
||||
fun insertSentSms(threadId: Long, address: String, body: String, date: Long): Message
|
||||
fun insertSentSms(subId: Int, threadId: Long, address: String, body: String, date: Long): Message
|
||||
|
||||
fun insertReceivedSms(address: String, body: String, sentTime: Long): Message
|
||||
fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message
|
||||
|
||||
/**
|
||||
* Marks the message as sending, in case we need to retry sending it
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package util
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface SubscriptionUtils {
|
||||
|
||||
val subscriptions: List<SubscriptionInfo>
|
||||
|
||||
val subscriptionsObservable: Observable<List<SubscriptionInfo>>
|
||||
|
||||
fun getSubIdForAddress(address: String): Int
|
||||
|
||||
}
|
||||
@@ -11,10 +11,10 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.moez.QKSMS"
|
||||
minSdkVersion 21
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 27
|
||||
versionCode 170
|
||||
versionName "3.2.2"
|
||||
versionCode 173
|
||||
versionName "3.3.2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
buildConfigField "String", "AMPLITUDE_API_KEY", "\"${System.getenv("AMPLITUDE_API_KEY")}\""
|
||||
@@ -92,6 +92,10 @@ dependencies {
|
||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||
kapt "com.github.bumptech.glide:compiler:$glide_version"
|
||||
|
||||
// exoplayer
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
|
||||
implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
|
||||
|
||||
// rxbinding
|
||||
implementation "com.jakewharton.rxbinding2:rxbinding-kotlin:$rxbinding_version"
|
||||
implementation "com.jakewharton.rxbinding2:rxbinding-support-v4-kotlin:$rxbinding_version"
|
||||
@@ -109,6 +113,13 @@ dependencies {
|
||||
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
|
||||
compileOnly "javax.annotation:jsr250-api:1.0"
|
||||
|
||||
// ezvcard
|
||||
implementation('com.googlecode.ez-vcard:ez-vcard:0.10.4', {
|
||||
exclude group: "org.jsoup", module: "jsoup"
|
||||
exclude group: "org.freemarker", module: "freemarker"
|
||||
exclude group: "com.fasterxml.jackson.core", module: "jackson-core"
|
||||
})
|
||||
|
||||
// realm
|
||||
implementation("io.realm:android-adapters:$realm_adapters_version") { transitive = false }
|
||||
kapt "io.realm:realm-annotations:$realm_version"
|
||||
|
||||
Vendored
+6
@@ -5,5 +5,11 @@
|
||||
-dontwarn android.net.ConnectivityManager
|
||||
-dontwarn android.net.LinkProperties
|
||||
|
||||
# ez-vcard
|
||||
-dontwarn ezvcard.**
|
||||
-dontwarn org.apache.log.**
|
||||
-dontwarn org.apache.log4j.**
|
||||
-dontwarn org.python.core.**
|
||||
|
||||
# okio
|
||||
-dontwarn okio.**
|
||||
@@ -97,19 +97,12 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showImage(partId: Long) {
|
||||
fun showMedia(partId: Long) {
|
||||
val intent = Intent(context, GalleryActivity::class.java)
|
||||
intent.putExtra("partId", partId)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showVideo(uri: Uri, type: String) {
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
.setDataAndType(uri, type)
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the attachment full-screen
|
||||
* The transitionName for the view should be the id of the image being displayed
|
||||
@@ -211,8 +204,16 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
||||
}
|
||||
|
||||
fun addContact(address: String) {
|
||||
val uri = Uri.parse("tel: $address")
|
||||
val intent = Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, uri)
|
||||
val intent = Intent(Intent.ACTION_INSERT)
|
||||
.setType(ContactsContract.Contacts.CONTENT_TYPE)
|
||||
.putExtra(ContactsContract.Intents.Insert.PHONE, address)
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun saveVcard(uri: Uri) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, "text/x-vcard")
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ package common
|
||||
*/
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.app.Service
|
||||
import android.content.BroadcastReceiver
|
||||
import android.support.text.emoji.EmojiCompat
|
||||
import android.support.text.emoji.FontRequestEmojiCompatConfig
|
||||
import android.support.v4.provider.FontRequest
|
||||
@@ -27,10 +29,12 @@ import com.bugsnag.android.Bugsnag
|
||||
import com.bugsnag.android.Configuration
|
||||
import com.moez.QKSMS.BuildConfig
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.NightModeManager
|
||||
import common.util.BugsnagTree
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.DispatchingAndroidInjector
|
||||
import dagger.android.HasActivityInjector
|
||||
import dagger.android.HasBroadcastReceiverInjector
|
||||
import dagger.android.HasServiceInjector
|
||||
import injection.AppComponentManager
|
||||
import injection.appComponent
|
||||
import io.realm.Realm
|
||||
@@ -38,9 +42,10 @@ import io.realm.RealmConfiguration
|
||||
import manager.AnalyticsManager
|
||||
import migration.QkRealmMigration
|
||||
import timber.log.Timber
|
||||
import util.NightModeManager
|
||||
import javax.inject.Inject
|
||||
|
||||
class QKApplication : Application(), HasActivityInjector {
|
||||
class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverInjector, HasServiceInjector {
|
||||
|
||||
/**
|
||||
* Inject this so that it is forced to initialize
|
||||
@@ -48,7 +53,9 @@ class QKApplication : Application(), HasActivityInjector {
|
||||
@Suppress("unused")
|
||||
@Inject lateinit var analyticsManager: AnalyticsManager
|
||||
|
||||
@Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
|
||||
@Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity>
|
||||
@Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver>
|
||||
@Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service>
|
||||
@Inject lateinit var nightModeManager: NightModeManager
|
||||
|
||||
private val packages = arrayOf("common", "feature", "injection", "filter", "interactor", "manager", "mapper",
|
||||
@@ -68,7 +75,7 @@ class QKApplication : Application(), HasActivityInjector {
|
||||
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
||||
.compactOnLaunch()
|
||||
.migration(QkRealmMigration())
|
||||
.schemaVersion(1)
|
||||
.schemaVersion(QkRealmMigration.SCHEMA_VERSION)
|
||||
.build())
|
||||
|
||||
AppComponentManager.init(this)
|
||||
@@ -84,11 +91,19 @@ class QKApplication : Application(), HasActivityInjector {
|
||||
|
||||
EmojiCompat.init(FontRequestEmojiCompatConfig(this, fontRequest))
|
||||
|
||||
Timber.plant(Timber.DebugTree())
|
||||
Timber.plant(Timber.DebugTree(), BugsnagTree())
|
||||
}
|
||||
|
||||
override fun activityInjector(): AndroidInjector<Activity> {
|
||||
return dispatchingAndroidInjector
|
||||
return dispatchingActivityInjector
|
||||
}
|
||||
|
||||
override fun broadcastReceiverInjector(): AndroidInjector<BroadcastReceiver> {
|
||||
return dispatchingBroadcastReceiverInjector
|
||||
}
|
||||
|
||||
override fun serviceInjector(): AndroidInjector<Service> {
|
||||
return dispatchingServiceInjector
|
||||
}
|
||||
|
||||
}
|
||||
@@ -88,6 +88,9 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
else -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
|
||||
// Some devices don't let you modify android.R.attr.navigationBarColor
|
||||
if (Build.VERSION.SDK_INT >= 27) window.navigationBarColor = resolveThemeColor(android.R.attr.windowBackground)
|
||||
|
||||
// Set the color for the overflow and navigation icon
|
||||
val textTertiary = resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(textTertiary) }
|
||||
|
||||
@@ -40,7 +40,7 @@ abstract class QkViewModel<in View : QkView<State>, State>(initialState: State)
|
||||
.subscribe { view.render(it) }
|
||||
}
|
||||
|
||||
protected fun newState(reducer: (State) -> State) {
|
||||
protected fun newState(reducer: State.() -> State) {
|
||||
state.value?.let { state.onNext(reducer(it)) }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package common.util
|
||||
|
||||
import android.util.Log
|
||||
import com.bugsnag.android.Bugsnag
|
||||
import com.bugsnag.android.Severity
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* If an exception is logged with the [Log.WARN] or [Log.ERROR] priority, the exception will be
|
||||
* sent to Bugsnag
|
||||
*/
|
||||
class BugsnagTree : Timber.Tree() {
|
||||
|
||||
override fun isLoggable(tag: String?, priority: Int): Boolean {
|
||||
return priority == Log.WARN || priority == Log.ERROR
|
||||
}
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String?, throwable: Throwable?) {
|
||||
val severity = if (priority == Log.ERROR) Severity.ERROR else Severity.WARNING
|
||||
throwable?.run { Bugsnag.notify(this, severity) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
@@ -36,11 +37,13 @@ import com.moez.QKSMS.R
|
||||
import common.util.extensions.dpToPx
|
||||
import feature.compose.ComposeActivity
|
||||
import feature.qkreply.QkReplyActivity
|
||||
import mapper.CursorToPartImpl
|
||||
import receiver.MarkReadReceiver
|
||||
import receiver.MarkSeenReceiver
|
||||
import receiver.RemoteMessagingReceiver
|
||||
import repository.MessageRepository
|
||||
import util.Preferences
|
||||
import util.extensions.isImage
|
||||
import util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -128,9 +131,26 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
|
||||
val messagingStyle = NotificationCompat.MessagingStyle("Me")
|
||||
if (conversation.recipients.size >= 2) {
|
||||
messagingStyle.conversationTitle = conversation.getTitle()
|
||||
}
|
||||
|
||||
messages.forEach { message ->
|
||||
val name = if (message.isMe()) null else conversation.getTitle()
|
||||
messagingStyle.addMessage(message.getSummary(), message.date, name)
|
||||
val name = when {
|
||||
message.isMe() -> null
|
||||
conversation.recipients.size < 2 -> conversation.getTitle()
|
||||
else -> conversation.recipients
|
||||
.firstOrNull { PhoneNumberUtils.compare(it.address, message.address) }
|
||||
?.getDisplayName()
|
||||
?: message.address
|
||||
}
|
||||
|
||||
NotificationCompat.MessagingStyle.Message(message.getSummary(), message.date, name).apply {
|
||||
message.parts.firstOrNull { it.isImage() }?.let { part ->
|
||||
setData(part.type, ContentUris.withAppendedId(CursorToPartImpl.CONTENT_URI, part.id))
|
||||
}
|
||||
messagingStyle.addMessage(this)
|
||||
}
|
||||
}
|
||||
|
||||
val avatar = conversation.recipients.takeIf { it.size == 1 }
|
||||
@@ -172,7 +192,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.forEach { uri -> notification.addPerson(uri) }
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
notification.addAction(getReplyAction(conversation.recipients[0]?.address.orEmpty(), threadId))
|
||||
notification.addAction(getReplyAction(threadId))
|
||||
} else {
|
||||
val replyIntent = Intent(context, QkReplyActivity::class.java).putExtra("threadId", threadId)
|
||||
val replyPI = PendingIntent.getActivity(context, threadId.toInt() + 40000, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
@@ -224,10 +244,8 @@ class NotificationManagerImpl @Inject constructor(
|
||||
notificationManager.notify(threadId.toInt() + 50000, notification.build())
|
||||
}
|
||||
|
||||
private fun getReplyAction(address: String, threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java)
|
||||
.putExtra("address", address)
|
||||
.putExtra("threadId", threadId)
|
||||
private fun getReplyAction(threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java).putExtra("threadId", threadId)
|
||||
val replyPI = PendingIntent.getBroadcast(context, threadId.toInt() + 40000, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val responseSet = context.resources.getStringArray(R.array.qk_responses)
|
||||
|
||||
@@ -22,6 +22,10 @@ import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.TextViewStyler.Companion.SIZE_PRIMARY
|
||||
import common.util.TextViewStyler.Companion.SIZE_SECONDARY
|
||||
import common.util.TextViewStyler.Companion.SIZE_TERTIARY
|
||||
import common.util.TextViewStyler.Companion.SIZE_TOOLBAR
|
||||
import common.util.extensions.getColorCompat
|
||||
import common.util.extensions.resolveThemeColor
|
||||
import common.widget.QkEditText
|
||||
@@ -48,72 +52,91 @@ class TextViewStyler @Inject constructor(
|
||||
const val SIZE_SECONDARY = 1
|
||||
const val SIZE_TERTIARY = 2
|
||||
const val SIZE_TOOLBAR = 3
|
||||
}
|
||||
|
||||
fun applyAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||
textView.run {
|
||||
when (this) {
|
||||
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
val colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
val textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
applyAttributes(textView, colorAttr, textSizeAttr)
|
||||
recycle()
|
||||
fun applyEditModeAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||
textView.run {
|
||||
var colorAttr = 0
|
||||
var textSizeAttr = 0
|
||||
|
||||
when (this) {
|
||||
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
else -> return
|
||||
}
|
||||
|
||||
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
val colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||
val textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||
applyAttributes(textView, colorAttr, textSizeAttr)
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
setTypeface(lato, typeface?.style ?: Typeface.NORMAL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyAttributes(textView: TextView, colorAttr: Int, textSizeAttr: Int) {
|
||||
textView.run {
|
||||
if (isInEditMode) {
|
||||
setTextColor(context.getColorCompat(when (colorAttr) {
|
||||
COLOR_PRIMARY -> R.color.textPrimary
|
||||
COLOR_SECONDARY -> R.color.textSecondary
|
||||
COLOR_TERTIARY -> R.color.textTertiary
|
||||
COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark
|
||||
COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark
|
||||
COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark
|
||||
COLOR_THEME -> R.color.tools_theme
|
||||
else -> R.color.textPrimary
|
||||
}))
|
||||
setTextColor(when (colorAttr) {
|
||||
COLOR_PRIMARY -> context.getColorCompat(R.color.textPrimary)
|
||||
COLOR_SECONDARY -> context.getColorCompat(R.color.textSecondary)
|
||||
COLOR_TERTIARY -> context.getColorCompat(R.color.textTertiary)
|
||||
COLOR_PRIMARY_ON_THEME -> context.getColorCompat(R.color.textPrimaryDark)
|
||||
COLOR_SECONDARY_ON_THEME -> context.getColorCompat(R.color.textSecondaryDark)
|
||||
COLOR_TERTIARY_ON_THEME -> context.getColorCompat(R.color.textTertiaryDark)
|
||||
COLOR_THEME -> context.getColorCompat(R.color.tools_theme)
|
||||
else -> currentTextColor
|
||||
})
|
||||
|
||||
textSize = when (textSizeAttr) {
|
||||
SIZE_PRIMARY -> 16f
|
||||
SIZE_SECONDARY -> 14f
|
||||
SIZE_TERTIARY -> 12f
|
||||
SIZE_TOOLBAR -> 20f
|
||||
else -> textSize
|
||||
else -> textSize / paint.density
|
||||
}
|
||||
} else {
|
||||
setTextColor(when (colorAttr) {
|
||||
COLOR_PRIMARY -> context.resolveThemeColor(android.R.attr.textColorPrimary)
|
||||
COLOR_SECONDARY -> context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
COLOR_TERTIARY -> context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
COLOR_PRIMARY_ON_THEME -> colors.theme().textPrimary
|
||||
COLOR_SECONDARY_ON_THEME -> colors.theme().textSecondary
|
||||
COLOR_TERTIARY_ON_THEME -> colors.theme().textTertiary
|
||||
COLOR_THEME -> colors.theme().theme
|
||||
else -> currentTextColor
|
||||
})
|
||||
|
||||
setTextSize(textView, textSizeAttr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun applyAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||
textView.run {
|
||||
var colorAttr = 0
|
||||
var textSizeAttr = 0
|
||||
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
setTypeface(lato, typeface?.style ?: Typeface.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
when (this) {
|
||||
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
else -> return
|
||||
}
|
||||
|
||||
setTextColor(when (colorAttr) {
|
||||
COLOR_PRIMARY -> context.resolveThemeColor(android.R.attr.textColorPrimary)
|
||||
COLOR_SECONDARY -> context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
COLOR_TERTIARY -> context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||
COLOR_PRIMARY_ON_THEME -> colors.theme().textPrimary
|
||||
COLOR_SECONDARY_ON_THEME -> colors.theme().textSecondary
|
||||
COLOR_TERTIARY_ON_THEME -> colors.theme().textTertiary
|
||||
COLOR_THEME -> colors.theme().theme
|
||||
else -> currentTextColor
|
||||
})
|
||||
|
||||
setTextSize(textView, textSizeAttr)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SIZE_PRIMARY
|
||||
* @see SIZE_SECONDARY
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package common.util.extensions
|
||||
|
||||
import android.animation.LayoutTransition
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
@@ -25,11 +26,19 @@ import android.os.Build
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
|
||||
var ViewGroup.animateLayoutChanges: Boolean
|
||||
get() = layoutTransition != null
|
||||
set(value) {
|
||||
layoutTransition = if (value) LayoutTransition() else null
|
||||
}
|
||||
|
||||
|
||||
fun EditText.showKeyboard() {
|
||||
requestFocus()
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
@@ -41,6 +50,7 @@ fun ImageView.setTint(color: Int) {
|
||||
}
|
||||
|
||||
fun ProgressBar.setTint(color: Int) {
|
||||
indeterminateTintList = ColorStateList.valueOf(color)
|
||||
progressTintList = ColorStateList.valueOf(color)
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
textViewStyler.applyAttributes(this, attrs)
|
||||
} else {
|
||||
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
textViewStyler.applyAttributes(this, attrs)
|
||||
} else {
|
||||
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ class BlockedViewModel @Inject constructor(
|
||||
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
|
||||
init {
|
||||
newState { it.copy(data = messageRepo.getBlockedConversations()) }
|
||||
newState { copy(data = messageRepo.getBlockedConversations()) }
|
||||
|
||||
disposables += prefs.sia.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(siaEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(siaEnabled = enabled) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: BlockedView) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.attachment_list_item.view.*
|
||||
import model.Attachment
|
||||
import javax.inject.Inject
|
||||
|
||||
class AttachmentAdapter @Inject constructor(
|
||||
|
||||
@@ -50,6 +50,7 @@ import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.compose_activity.*
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
import model.Message
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -78,6 +79,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
|
||||
override val messageClickIntent: Subject<Message> by lazy { messageAdapter.clicks }
|
||||
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
|
||||
override val cancelSendingIntent: Subject<Message> by lazy { messageAdapter.cancelSending }
|
||||
@@ -88,12 +90,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val galleryIntent by lazy { gallery.clicks() }
|
||||
override val attachmentSelectedIntent: Subject<Uri> = PublishSubject.create()
|
||||
override val inputContentIntent by lazy { message.inputContentSelected }
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
|
||||
|
||||
var cameraDestination: Uri? = null
|
||||
private var cameraDestination: Uri? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
@@ -123,6 +126,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
message.supportsInputContent = true
|
||||
|
||||
theme
|
||||
.doOnNext { loading.setTint(it.theme) }
|
||||
.doOnNext { send.setBackgroundTint(it.theme) }
|
||||
.doOnNext { send.setTint(it.textPrimary) }
|
||||
.doOnNext { messageAdapter.theme = it }
|
||||
@@ -162,7 +166,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
toolbarTitle.setVisible(!state.editingMode)
|
||||
chips.setVisible(state.editingMode)
|
||||
contacts.setVisible(state.contactsVisible)
|
||||
composeBar.setVisible(!state.contactsVisible)
|
||||
composeBar.setVisible(!state.contactsVisible && !state.loading)
|
||||
|
||||
// Don't set the adapters unless needed
|
||||
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
||||
@@ -183,6 +187,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
chipsAdapter.data = state.selectedContacts
|
||||
contactsAdapter.data = state.contacts
|
||||
|
||||
loading.setVisible(state.loading)
|
||||
|
||||
sendAsGroup.setVisible(state.editingMode && state.selectedContacts.size >= 2)
|
||||
sendAsGroupSwitch.isChecked = state.sendAsGroup
|
||||
|
||||
messageList.setVisible(state.sendAsGroup)
|
||||
messageAdapter.data = state.messages
|
||||
messageAdapter.highlight = state.searchSelectionId
|
||||
|
||||
@@ -196,6 +207,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
sim.setVisible(state.subscription != null)
|
||||
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
*/
|
||||
package feature.compose
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import io.realm.RealmResults
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
@@ -30,7 +32,9 @@ data class ComposeState(
|
||||
val contactsVisible: Boolean = false,
|
||||
val selectedConversation: Long = 0,
|
||||
val selectedContacts: List<Contact> = ArrayList(),
|
||||
val sendAsGroup: Boolean = true,
|
||||
val conversationtitle: String = "",
|
||||
val loading: Boolean = false,
|
||||
val query: String = "",
|
||||
val searchSelectionId: Long = -1,
|
||||
val searchSelectionPosition: Int = 0,
|
||||
@@ -40,5 +44,6 @@ data class ComposeState(
|
||||
val attachments: List<Attachment> = ArrayList(),
|
||||
val attaching: Boolean = false,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfo? = null,
|
||||
val canSend: Boolean = false
|
||||
)
|
||||
@@ -23,6 +23,7 @@ import android.support.v13.view.inputmethod.InputContentInfoCompat
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.Subject
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
import model.Message
|
||||
|
||||
@@ -36,6 +37,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val chipDeletedIntent: Subject<Contact>
|
||||
val menuReadyIntent: Observable<Unit>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val sendAsGroupIntent: Observable<*>
|
||||
val messageClickIntent: Subject<Message>
|
||||
val messagesSelectedIntent: Observable<List<Long>>
|
||||
val cancelSendingIntent: Subject<Message>
|
||||
@@ -46,6 +48,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val galleryIntent: Observable<*>
|
||||
val attachmentSelectedIntent: Observable<Uri>
|
||||
val inputContentIntent: Observable<InputContentInfoCompat>
|
||||
val changeSimIntent: Observable<*>
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
fun clearSelection()
|
||||
|
||||
@@ -49,12 +49,14 @@ import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmList
|
||||
import manager.PermissionManager
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.PhoneNumber
|
||||
import repository.ContactRepository
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.asObservable
|
||||
import util.extensions.isImage
|
||||
import util.extensions.mapNotNull
|
||||
@@ -78,6 +80,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val permissionManager: PermissionManager,
|
||||
private val retrySending: RetrySending,
|
||||
private val sendMessage: SendMessage,
|
||||
private val subUtils: SubscriptionUtils,
|
||||
private val syncContacts: ContactSync
|
||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(query = intent.extras?.getString("query") ?: "")) {
|
||||
|
||||
@@ -118,24 +121,27 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
val initialConversation: Observable<Conversation> = when {
|
||||
threadId != 0L -> {
|
||||
newState { it.copy(selectedConversation = threadId, editingMode = false) }
|
||||
newState { copy(selectedConversation = threadId, editingMode = false) }
|
||||
messageRepo.getConversationAsync(threadId).asObservable()
|
||||
}
|
||||
|
||||
address.isNotBlank() -> {
|
||||
newState { it.copy(editingMode = false) }
|
||||
messageRepo.getOrCreateConversation(address).toObservable()
|
||||
newState { copy(editingMode = false) }
|
||||
Observable.just(address)
|
||||
.mapNotNull { messageRepo.getOrCreateConversation(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
else -> {
|
||||
newState { it.copy(editingMode = true) }
|
||||
newState { copy(editingMode = true) }
|
||||
Observable.empty()
|
||||
}
|
||||
}
|
||||
|
||||
selectedContacts = contactsReducer
|
||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||
.doOnNext { contacts -> newState { copy(selectedContacts = contacts) } }
|
||||
|
||||
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||
@@ -143,18 +149,24 @@ class ComposeViewModel @Inject constructor(
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
||||
.flatMapMaybe { addresses -> messageRepo.getOrCreateConversation(addresses) }
|
||||
.observeOn(Schedulers.computation())
|
||||
.doOnNext { newState { copy(loading = true) } }
|
||||
.mapNotNull { addresses ->
|
||||
val conversation = messageRepo.getOrCreateConversation(addresses)
|
||||
newState { copy(loading = false) }
|
||||
conversation
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.mergeWith(initialConversation)
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { conversation.onNext(it) }
|
||||
.subscribe(conversation::onNext)
|
||||
|
||||
// When the conversation changes, update the threadId and the messages for the adapter
|
||||
disposables += conversation
|
||||
@@ -162,7 +174,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { conversation ->
|
||||
val messages = messageRepo.getMessages(conversation.id)
|
||||
newState { it.copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
newState { copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
@@ -171,10 +183,10 @@ class ComposeViewModel @Inject constructor(
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { it.copy(conversationtitle = title) } }
|
||||
.subscribe { title -> newState { copy(conversationtitle = title) } }
|
||||
|
||||
disposables += attachments
|
||||
.subscribe { attachments -> newState { it.copy(attachments = attachments) } }
|
||||
.subscribe { attachments -> newState { copy(attachments = attachments) } }
|
||||
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.id }
|
||||
@@ -191,10 +203,19 @@ class ComposeViewModel @Inject constructor(
|
||||
messages.lastOrNull()?.let { message -> searchSelection.onNext(message.id) }
|
||||
} else {
|
||||
val position = messages.indexOfFirst { it.id == selected } + 1
|
||||
newState { it.copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
newState { copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
}
|
||||
}.subscribe()
|
||||
|
||||
val latestSubId = messages
|
||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||
.distinctUntilChanged()
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
|
||||
if (threadId == 0L) {
|
||||
syncContacts.execute(Unit)
|
||||
}
|
||||
@@ -213,7 +234,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
||||
.subscribe { contactsVisible -> newState { copy(contactsVisible = contactsVisible && editingMode) } }
|
||||
|
||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||
// that have already been selected
|
||||
@@ -242,7 +263,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
|
||||
.subscribe { contacts -> newState { copy(contacts = contacts) } }
|
||||
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
@@ -282,7 +303,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// When the menu is loaded, trigger a new state so that the menu options can be rendered correctly
|
||||
view.menuReadyIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy() } }
|
||||
.subscribe { newState { copy() } }
|
||||
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
@@ -364,13 +385,19 @@ class ComposeViewModel @Inject constructor(
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.clear }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(query = "", searchSelectionId = -1) } }
|
||||
.subscribe { newState { copy(query = "", searchSelectionId = -1) } }
|
||||
|
||||
|
||||
// Toggle the group sending mode
|
||||
view.sendAsGroupIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(sendAsGroup = !sendAsGroup) } }
|
||||
|
||||
|
||||
// Scroll to search position
|
||||
searchSelection
|
||||
.filter { id -> id != -1L }
|
||||
.doOnNext { id -> newState { it.copy(searchSelectionId = id) } }
|
||||
.doOnNext { id -> newState { copy(searchSelectionId = id) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::scrollToMessage)
|
||||
|
||||
@@ -386,7 +413,7 @@ class ComposeViewModel @Inject constructor(
|
||||
view.messagesSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { messages -> newState { it.copy(selectedMessages = messages, editingMode = false) } }
|
||||
.subscribe { messages -> newState { copy(selectedMessages = messages, editingMode = false) } }
|
||||
|
||||
// Cancel sending a message
|
||||
view.cancelSendingIntent
|
||||
@@ -417,7 +444,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Open the attachment options
|
||||
view.attachIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = !it.attaching) } }
|
||||
.subscribe { newState { copy(attaching = !attaching) } }
|
||||
|
||||
// Attach a photo from camera
|
||||
view.cameraIntent
|
||||
@@ -441,7 +468,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
|
||||
.doOnNext { attachments.onNext(it) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = false) } }
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
|
||||
// Detach a photo
|
||||
view.attachmentDeletedIntent
|
||||
@@ -473,7 +500,7 @@ class ComposeViewModel @Inject constructor(
|
||||
text.isNotBlank() || attachments.isNotEmpty()
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -491,22 +518,52 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
.withLatestFrom(state) { _, state ->
|
||||
val subs = subUtils.subscriptions
|
||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||
val subscription = when {
|
||||
subIndex == -1 -> null
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(attachments, conversation, { body, attachments, conversation ->
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(threadId, addresses, body, attachments))
|
||||
.withLatestFrom(state, attachments, conversation, selectedContacts, { body, state, attachments, conversation, contacts ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
|
||||
if (state.sendAsGroup) {
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body, attachments))
|
||||
} else {
|
||||
contacts
|
||||
.map { contact -> contact.numbers }
|
||||
.mapNotNull { numbers -> numbers.firstOrNull() }
|
||||
.map { number -> number.address }
|
||||
.mapNotNull { address -> messageRepo.getOrCreateConversation(address) }
|
||||
.filter { it.recipients.isNotEmpty() }
|
||||
.forEach {
|
||||
val address = it.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(subId, it.id, address, body, attachments))
|
||||
}
|
||||
}
|
||||
|
||||
view.setDraft("")
|
||||
this.attachments.onNext(ArrayList())
|
||||
})
|
||||
.withLatestFrom(state, { _, state ->
|
||||
|
||||
if (state.editingMode) {
|
||||
newState { it.copy(editingMode = false) }
|
||||
newState { copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -520,7 +577,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.selectedMessages > 0 -> view.clearSelection()
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package feature.compose
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.text.Spannable
|
||||
@@ -43,25 +43,32 @@ import common.util.DateFormatter
|
||||
import common.util.GlideApp
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.forwardTouches
|
||||
import common.util.extensions.resolveThemeColor
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setPadding
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.BubbleImageView.Style.*
|
||||
import ezvcard.Ezvcard
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.mms_vcard_list_item.view.*
|
||||
import mapper.CursorToPartImpl
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.Recipient
|
||||
import util.Preferences
|
||||
import util.extensions.hasThumbnails
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.isImage
|
||||
import util.extensions.isVCard
|
||||
import util.extensions.isVideo
|
||||
import util.extensions.mapNotNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -70,7 +77,8 @@ class MessagesAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
private val prefs: Preferences,
|
||||
private val subUtils: SubscriptionUtils
|
||||
) : QkRealmAdapter<Message>() {
|
||||
|
||||
companion object {
|
||||
@@ -112,10 +120,10 @@ class MessagesAdapter @Inject constructor(
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private val layoutInflater = LayoutInflater.from(context)
|
||||
private val contactCache = ContactCache()
|
||||
private val expanded = HashMap<Long, Boolean>()
|
||||
private val disposables = CompositeDisposable()
|
||||
private val subs = subUtils.subscriptions
|
||||
|
||||
var theme: Colors.Theme = colors.theme()
|
||||
|
||||
@@ -206,12 +214,18 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
// Bind the timestamp
|
||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
||||
val simIndex = subs.takeIf { it.size > 1 }?.indexOfFirst { it.subscriptionId == message.subId } ?: -1
|
||||
|
||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
view.timestamp.visibility = if (timeSincePrevious < TIMESTAMP_THRESHOLD) View.GONE else View.VISIBLE
|
||||
view.simIndex.text = "${simIndex + 1}"
|
||||
|
||||
view.timestamp.setVisible(timeSincePrevious >= TIMESTAMP_THRESHOLD || message.subId != previous?.subId && simIndex != -1)
|
||||
view.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
view.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
|
||||
|
||||
// Bind the grouping
|
||||
val media = message.parts.filter { it.hasThumbnails() }
|
||||
val media = message.parts.filter { it.isImage() || it.isVideo() || it.isVCard() }
|
||||
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||
|
||||
|
||||
@@ -231,9 +245,10 @@ class MessagesAdapter @Inject constructor(
|
||||
subject.setSpan(StyleSpan(Typeface.BOLD), 0, subject.length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||
|
||||
val body = message.parts
|
||||
.mapNotNull { it.text }
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString("\n") { text -> text }
|
||||
.filter { part -> !part.isVCard() }
|
||||
.mapNotNull { part -> part.text }
|
||||
.filter { part -> part.isNotBlank() }
|
||||
.joinToString("\n")
|
||||
|
||||
when {
|
||||
subject.isNotBlank() && body.isNotBlank() -> subject.append("\n$body")
|
||||
@@ -243,15 +258,10 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
view.body.setVisible(message.isSms() || view.body.text.isNotBlank())
|
||||
|
||||
val canBodyGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty()
|
||||
val canBodyGroupWithNext = canGroup(message, next)
|
||||
view.body.setBackgroundResource(when {
|
||||
!canBodyGroupWithPrevious && canBodyGroupWithNext -> if (message.isMe()) R.drawable.message_out_first else R.drawable.message_in_first
|
||||
canBodyGroupWithPrevious && canBodyGroupWithNext -> if (message.isMe()) R.drawable.message_out_middle else R.drawable.message_in_middle
|
||||
canBodyGroupWithPrevious && !canBodyGroupWithNext -> if (message.isMe()) R.drawable.message_out_last else R.drawable.message_in_last
|
||||
else -> R.drawable.message_only
|
||||
})
|
||||
view.body.setBackgroundResource(getBubble(
|
||||
canGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty(),
|
||||
canGroupWithNext = canGroup(message, next),
|
||||
isMe = message.isMe()))
|
||||
|
||||
|
||||
// Bind the attachments
|
||||
@@ -261,36 +271,49 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
media.forEachIndexed { index, part ->
|
||||
val mediaView = layoutInflater.inflate(R.layout.mms_preview_list_item, view.attachments, false)
|
||||
mediaView.video.setVisible(part.isVideo())
|
||||
mediaView.forwardTouches(view)
|
||||
mediaView.clicks().subscribe {
|
||||
when {
|
||||
part.isImage() -> navigator.showImage(part.id)
|
||||
part.isVideo() -> navigator.showVideo(part.getUri(), part.type)
|
||||
}
|
||||
}
|
||||
|
||||
val canMediaGroupWithPrevious = canGroup(message, previous) || index > 0
|
||||
val canMediaGroupWithNext = canGroup(message, next) || index < media.size && view.body.visibility == View.VISIBLE
|
||||
mediaView.thumbnail.bubbleStyle = when {
|
||||
!canMediaGroupWithPrevious && canMediaGroupWithNext -> if (message.isMe()) OUT_FIRST else IN_FIRST
|
||||
canMediaGroupWithPrevious && canMediaGroupWithNext -> if (message.isMe()) OUT_MIDDLE else IN_MIDDLE
|
||||
canMediaGroupWithPrevious && !canMediaGroupWithNext -> if (message.isMe()) OUT_LAST else IN_LAST
|
||||
else -> ONLY
|
||||
|
||||
when {
|
||||
part.isImage() || part.isVideo() -> {
|
||||
val mediaView = View.inflate(view.context, R.layout.mms_preview_list_item, view.attachments)
|
||||
mediaView.video.setVisible(part.isVideo())
|
||||
mediaView.forwardTouches(view)
|
||||
mediaView.setOnClickListener { navigator.showMedia(part.id) }
|
||||
|
||||
mediaView.thumbnail.bubbleStyle = when {
|
||||
!canMediaGroupWithPrevious && canMediaGroupWithNext -> if (message.isMe()) OUT_FIRST else IN_FIRST
|
||||
canMediaGroupWithPrevious && canMediaGroupWithNext -> if (message.isMe()) OUT_MIDDLE else IN_MIDDLE
|
||||
canMediaGroupWithPrevious && !canMediaGroupWithNext -> if (message.isMe()) OUT_LAST else IN_LAST
|
||||
else -> ONLY
|
||||
}
|
||||
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(mediaView.thumbnail)
|
||||
}
|
||||
|
||||
part.isVCard() -> {
|
||||
val uri = ContentUris.withAppendedId(CursorToPartImpl.CONTENT_URI, part.id)
|
||||
|
||||
val mediaView = View.inflate(view.context, R.layout.mms_vcard_list_item, view.attachments)
|
||||
mediaView.forwardTouches(view)
|
||||
mediaView.setOnClickListener { navigator.saveVcard(uri) }
|
||||
mediaView.vCardBackground.setBackgroundResource(getBubble(canMediaGroupWithPrevious, canMediaGroupWithNext, message.isMe()))
|
||||
|
||||
Observable.just(uri)
|
||||
.map(context.contentResolver::openInputStream)
|
||||
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> mediaView?.name?.text = vcard.formattedName.value }
|
||||
|
||||
if (!message.isMe()) {
|
||||
mediaView.vCardBackground.setBackgroundTint(theme.theme)
|
||||
mediaView.vCardAvatar.setTint(theme.textPrimary)
|
||||
mediaView.name.setTextColor(theme.textPrimary)
|
||||
mediaView.label.setTextColor(theme.textTertiary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(mediaView.thumbnail)
|
||||
view.attachments.addView(mediaView)
|
||||
}
|
||||
|
||||
|
||||
// If we're on API 21, we need to re-tint the background
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
view.body.setBackgroundTint(when (message.isMe()) {
|
||||
true -> context.resolveThemeColor(R.attr.bubbleColor)
|
||||
false -> theme.theme
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +342,15 @@ class MessagesAdapter @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
private fun getBubble(canGroupWithPrevious: Boolean, canGroupWithNext: Boolean, isMe: Boolean): Int {
|
||||
return when {
|
||||
!canGroupWithPrevious && canGroupWithNext -> if (isMe) R.drawable.message_out_first else R.drawable.message_in_first
|
||||
canGroupWithPrevious && canGroupWithNext -> if (isMe) R.drawable.message_out_middle else R.drawable.message_in_middle
|
||||
canGroupWithPrevious && !canGroupWithNext -> if (isMe) R.drawable.message_out_last else R.drawable.message_in_last
|
||||
else -> R.drawable.message_only
|
||||
}
|
||||
}
|
||||
|
||||
private fun canGroup(message: Message, other: Message?): Boolean {
|
||||
if (other == null) return false
|
||||
val diff = TimeUnit.MILLISECONDS.toMinutes(Math.abs(message.date - other.date))
|
||||
|
||||
@@ -22,16 +22,22 @@ import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.text.InputFilter
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.animateLayoutChanges
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.resolveThemeColor
|
||||
import common.util.extensions.scrapViews
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.QkEditText
|
||||
import dagger.android.AndroidInjection
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_info_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -43,6 +49,8 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
override val nameIntent by lazy { name.clicks() }
|
||||
override val nameChangedIntent: Subject<String> = PublishSubject.create()
|
||||
override val notificationsIntent by lazy { notifications.clicks() }
|
||||
override val themeIntent by lazy { themePrefs.clicks() }
|
||||
override val archiveIntent by lazy { archive.clicks() }
|
||||
@@ -60,6 +68,8 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
viewModel.bindView(this)
|
||||
setTitle(R.string.info_title)
|
||||
|
||||
items.postDelayed({ items.animateLayoutChanges = true }, 100)
|
||||
|
||||
mediaAdapter.thumbnailClicks
|
||||
.autoDisposable(scope())
|
||||
.subscribe { view -> navigator.showImageAnimated(this, view) }
|
||||
@@ -84,6 +94,9 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
recipientAdapter.threadId = state.threadId
|
||||
recipientAdapter.updateData(state.recipients)
|
||||
|
||||
name.setVisible(state.recipients?.size ?: 0 >= 2)
|
||||
name.summary = state.name
|
||||
|
||||
notifications.setVisible(!state.blocked)
|
||||
|
||||
archive.setVisible(!state.blocked)
|
||||
@@ -100,6 +113,27 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
mediaAdapter.updateData(state.media)
|
||||
}
|
||||
|
||||
override fun showNameDialog(name: String) {
|
||||
val editText = QkEditText(this).apply {
|
||||
val padding = 8.dpToPx(this@ConversationInfoActivity)
|
||||
setPadding(padding * 3, padding, padding * 3, padding)
|
||||
setSingleLine(true)
|
||||
setHint(R.string.info_name_hint)
|
||||
setText(name)
|
||||
setHintTextColor(context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
setTextColor(context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
filters = arrayOf(InputFilter.LengthFilter(30))
|
||||
background = null
|
||||
}
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.info_name)
|
||||
.setView(editText)
|
||||
.setPositiveButton(R.string.button_save, { _, _ -> nameChangedIntent.onNext(editText.text.toString()) })
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun showDeleteDialog() {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
|
||||
@@ -24,6 +24,7 @@ import model.MmsPart
|
||||
import model.Recipient
|
||||
|
||||
data class ConversationInfoState(
|
||||
val name: String = "",
|
||||
val recipients: RealmList<Recipient>? = null,
|
||||
val threadId: Long = 0,
|
||||
val archived: Boolean = false,
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
*/
|
||||
package feature.conversationinfo
|
||||
|
||||
import io.reactivex.Observable
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||
|
||||
val nameIntent: Observable<*>
|
||||
val nameChangedIntent: Observable<String>
|
||||
val notificationsIntent: Observable<Unit>
|
||||
val themeIntent: Observable<Unit>
|
||||
val archiveIntent: Observable<Unit>
|
||||
@@ -30,6 +32,7 @@ interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||
val deleteIntent: Observable<Unit>
|
||||
val confirmDeleteIntent: Observable<Unit>
|
||||
|
||||
fun showNameDialog(name: String)
|
||||
fun showDeleteDialog()
|
||||
|
||||
}
|
||||
@@ -27,9 +27,10 @@ import interactor.MarkArchived
|
||||
import interactor.MarkBlocked
|
||||
import interactor.MarkUnarchived
|
||||
import interactor.MarkUnblocked
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import model.Conversation
|
||||
import repository.MessageRepository
|
||||
import util.extensions.asObservable
|
||||
@@ -38,30 +39,31 @@ import javax.inject.Named
|
||||
|
||||
class ConversationInfoViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
messageRepo: MessageRepository,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
private val markUnblocked: MarkUnblocked,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val deleteConversations: DeleteConversations
|
||||
) : QkViewModel<ConversationInfoView, ConversationInfoState>(
|
||||
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
|
||||
) {
|
||||
|
||||
private val conversation: Observable<Conversation>
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
|
||||
init {
|
||||
conversation = messageRepo.getConversationAsync(threadId)
|
||||
disposables += messageRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.subscribe(conversation::onNext)
|
||||
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
@@ -73,24 +75,45 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.recipients }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { recipients -> newState { it.copy(recipients = recipients) } }
|
||||
.subscribe { recipients -> newState { copy(recipients = recipients) } }
|
||||
|
||||
// Update conversation title whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.name }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { name -> newState { copy(name = name) } }
|
||||
|
||||
// Update the view's archived state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.archived }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { archived -> newState { it.copy(archived = archived) } }
|
||||
.subscribe { archived -> newState { copy(archived = archived) } }
|
||||
|
||||
// Update the view's blocked state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.blocked }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { blocked -> newState { it.copy(blocked = blocked) } }
|
||||
.subscribe { blocked -> newState { copy(blocked = blocked) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: ConversationInfoView) {
|
||||
super.bindView(view)
|
||||
|
||||
// Show the conversation title dialog
|
||||
view.nameIntent
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> conversation.name }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::showNameDialog)
|
||||
|
||||
// Set the conversation title
|
||||
view.nameChangedIntent
|
||||
.withLatestFrom(conversation) { name, conversation ->
|
||||
messageRepo.setConversationName(conversation.id, name)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Show the notifications settings for the conversation
|
||||
view.notificationsIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
|
||||
@@ -24,17 +24,22 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import common.Navigator
|
||||
import common.base.QkRealmAdapter
|
||||
import common.base.QkViewHolder
|
||||
import common.util.GlideApp
|
||||
import common.util.extensions.setVisible
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.conversation_media_list_item.view.*
|
||||
import model.MmsPart
|
||||
import util.extensions.isImage
|
||||
import util.extensions.isVideo
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationMediaAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
private val context: Context,
|
||||
private val navigator: Navigator
|
||||
) : QkRealmAdapter<MmsPart>() {
|
||||
|
||||
val thumbnailClicks: PublishSubject<View> = PublishSubject.create()
|
||||
@@ -55,8 +60,11 @@ class ConversationMediaAdapter @Inject constructor(
|
||||
.fitCenter()
|
||||
.into(view.thumbnail)
|
||||
|
||||
view.video.setVisible(part.isVideo())
|
||||
view.thumbnail.transitionName = part.id.toString()
|
||||
view.thumbnail.setOnClickListener { thumbnailClicks.onNext(it) }
|
||||
view.thumbnail.setOnClickListener {
|
||||
if (part.isImage()) thumbnailClicks.onNext(it) else navigator.showMedia(part.id)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
|
||||
@@ -20,12 +20,21 @@ package feature.gallery
|
||||
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.transition.ChangeBounds
|
||||
import android.transition.ChangeImageTransform
|
||||
import android.transition.TransitionSet
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.android.exoplayer2.ExoPlayerFactory
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||
import com.google.android.exoplayer2.source.ExtractorMediaSource
|
||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
|
||||
import com.google.android.exoplayer2.util.Util
|
||||
import com.google.android.mms.ContentType
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.GlideCompletionListener
|
||||
@@ -38,6 +47,7 @@ import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.gallery_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class GalleryActivity : QkActivity(), GalleryView {
|
||||
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
@@ -47,6 +57,8 @@ class GalleryActivity : QkActivity(), GalleryView {
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[GalleryViewModel::class.java] }
|
||||
|
||||
private var exoPlayer: SimpleExoPlayer? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -91,9 +103,19 @@ class GalleryActivity : QkActivity(), GalleryView {
|
||||
|
||||
title = state.title
|
||||
|
||||
when {
|
||||
ContentType.isImageType(state.type) -> showImage(state.uri)
|
||||
ContentType.isVideoType(state.type) -> showVideo(state.uri)
|
||||
else -> hideMedia()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showImage(uri: Uri?) {
|
||||
image.setVisible(true)
|
||||
video.setVisible(false)
|
||||
if (image.drawable == null) {
|
||||
GlideApp.with(this)
|
||||
.load(state.imageUri)
|
||||
.load(uri)
|
||||
.dontAnimate()
|
||||
.listener(GlideCompletionListener {
|
||||
startPostponedEnterTransition()
|
||||
@@ -102,6 +124,27 @@ class GalleryActivity : QkActivity(), GalleryView {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showVideo(uri: Uri?) {
|
||||
image.setVisible(false)
|
||||
video.setVisible(true)
|
||||
|
||||
if (video.player == null) {
|
||||
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(null)
|
||||
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
|
||||
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
|
||||
video.player = exoPlayer
|
||||
|
||||
val dataSourceFactory = DefaultDataSourceFactory(this, Util.getUserAgent(this, "QKSMS"))
|
||||
val videoSource = ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri)
|
||||
exoPlayer?.prepare(videoSource)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideMedia() {
|
||||
image.setVisible(false)
|
||||
video.setVisible(false)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.gallery, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
@@ -115,4 +158,9 @@ class GalleryActivity : QkActivity(), GalleryView {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
exoPlayer?.release()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,5 +23,6 @@ import android.net.Uri
|
||||
data class GalleryState(
|
||||
val navigationVisible: Boolean = true,
|
||||
val title: String = "",
|
||||
val imageUri: Uri? = null
|
||||
val uri: Uri? = null,
|
||||
val type: String = ""
|
||||
)
|
||||
@@ -47,13 +47,12 @@ class GalleryViewModel @Inject constructor(
|
||||
init {
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getPart(partId) }
|
||||
.mapNotNull { part -> part.getUri() }
|
||||
.subscribe { uri -> newState { it.copy(imageUri = uri) } }
|
||||
.subscribe { part -> newState { copy(uri = part.getUri(), type = part.type) } }
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||
.mapNotNull { message -> messageRepo.getConversation(message.threadId) }
|
||||
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||
.subscribe { conversation -> newState { copy(title = conversation.getTitle()) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: GalleryView) {
|
||||
@@ -64,7 +63,7 @@ class GalleryViewModel @Inject constructor(
|
||||
.withLatestFrom(state, { _, state -> state.navigationVisible })
|
||||
.map { navigationVisible -> !navigationVisible }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigationVisible -> newState { it.copy(navigationVisible = navigationVisible) } }
|
||||
.subscribe { navigationVisible -> newState { copy(navigationVisible = navigationVisible) } }
|
||||
|
||||
// Save image to device
|
||||
view.optionsItemSelectedIntent
|
||||
|
||||
@@ -72,12 +72,12 @@ class MainViewModel @Inject constructor(
|
||||
// Show the syncing UI
|
||||
disposables += syncRepository.syncProgress
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
||||
.subscribe { syncing -> newState { copy(syncing = syncing) } }
|
||||
|
||||
|
||||
// Show the rating UI
|
||||
disposables += ratingManager.shouldShowRating
|
||||
.subscribe { show -> newState { it.copy(showRating = show) } }
|
||||
.subscribe { show -> newState { copy(showRating = show) } }
|
||||
|
||||
|
||||
// Migrate the preferences from 2.7.3
|
||||
@@ -108,7 +108,7 @@ class MainViewModel @Inject constructor(
|
||||
view.activityResumedIntent.map { permissionManager.hasSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged(),
|
||||
{ defaultSms, smsPermission, contactPermission ->
|
||||
newState { it.copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -134,21 +134,21 @@ class MainViewModel @Inject constructor(
|
||||
.map { query -> query.removeAccents() }
|
||||
.withLatestFrom(state, { query, state ->
|
||||
if (query.isEmpty() && state.page is Searching) {
|
||||
newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
}
|
||||
query
|
||||
})
|
||||
.filter { query -> query.length >= 2 }
|
||||
.doOnNext {
|
||||
newState { state ->
|
||||
val page = (state.page as? Searching) ?: Searching()
|
||||
state.copy(page = page.copy(loading = true))
|
||||
newState {
|
||||
val page = (page as? Searching) ?: Searching()
|
||||
copy(page = page.copy(loading = true))
|
||||
}
|
||||
}
|
||||
.observeOn(Schedulers.io())
|
||||
.switchMap { query -> Observable.just(query).map { messageRepo.searchConversations(it) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { data -> newState { it.copy(page = Searching(loading = false, data = data)) } }
|
||||
.subscribe { data -> newState { copy(page = Searching(loading = false, data = data)) } }
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
@@ -164,7 +164,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
else -> newState { it.copy(drawerOpen = true) }
|
||||
else -> newState { copy(drawerOpen = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -172,19 +172,19 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
view.drawerOpenIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { open -> newState { it.copy(drawerOpen = open) } }
|
||||
.subscribe { open -> newState { copy(drawerOpen = open) } }
|
||||
|
||||
view.drawerItemIntent
|
||||
.doOnNext { newState { it.copy(drawerOpen = false) } }
|
||||
.doOnNext { newState { copy(drawerOpen = false) } }
|
||||
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
|
||||
.doOnNext { if (it == DrawerItem.PLUS) navigator.showQksmsPlusActivity() }
|
||||
.doOnNext { if (it == DrawerItem.HELP) navigator.showSupport() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
DrawerItem.INBOX -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { copy(page = Scheduled()) }
|
||||
else -> {
|
||||
} // Do nothing
|
||||
}
|
||||
@@ -233,12 +233,12 @@ class MainViewModel @Inject constructor(
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -259,7 +259,7 @@ class MainViewModel @Inject constructor(
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = true)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -268,7 +268,7 @@ class MainViewModel @Inject constructor(
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = false)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -294,7 +294,7 @@ class MainViewModel @Inject constructor(
|
||||
view.backPressedIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.drawerOpen -> newState { it.copy(drawerOpen = false) }
|
||||
state.drawerOpen -> newState { copy(drawerOpen = false) }
|
||||
|
||||
state.page is Searching -> view.clearSearch()
|
||||
|
||||
@@ -303,9 +303,9 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
state.page !is Inbox -> newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
state.page !is Inbox -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.QkDialog
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.animateLayoutChanges
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.PreferenceView
|
||||
import dagger.android.AndroidInjection
|
||||
@@ -58,6 +59,8 @@ class NotificationPrefsActivity : QkThemedActivity(), NotificationPrefsView {
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
|
||||
|
||||
val hasOreo = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
|
||||
notificationsO.setVisible(hasOreo)
|
||||
|
||||
@@ -61,19 +61,19 @@ class NotificationPrefsViewModel @Inject constructor(
|
||||
.mapNotNull { threadId -> messageRepo.getConversation(threadId) }
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { title -> newState { it.copy(conversationTitle = title) } }
|
||||
.subscribe { title -> newState { copy(conversationTitle = title) } }
|
||||
|
||||
disposables += notifications.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||
|
||||
val previewLabels = context.resources.getStringArray(R.array.notification_preview_options)
|
||||
disposables += previews.asObservable()
|
||||
.subscribe { previewId ->
|
||||
newState { it.copy(previewSummary = previewLabels[previewId], previewId = previewId) }
|
||||
newState { copy(previewSummary = previewLabels[previewId], previewId = previewId) }
|
||||
}
|
||||
|
||||
disposables += vibration.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(vibrationEnabled = enabled) } }
|
||||
|
||||
disposables += ringtone.asObservable()
|
||||
.map { uriString ->
|
||||
@@ -82,13 +82,13 @@ class NotificationPrefsViewModel @Inject constructor(
|
||||
?.let { uri -> RingtoneManager.getRingtone(context, uri) }?.getTitle(context)
|
||||
?: context.getString(R.string.settings_ringtone_none)
|
||||
}
|
||||
.subscribe { title -> newState { it.copy(ringtoneName = title) } }
|
||||
.subscribe { title -> newState { copy(ringtoneName = title) } }
|
||||
|
||||
disposables += prefs.qkreply.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(qkReplyEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(qkReplyEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.qkreplyTapDismiss.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(qkReplyTapDismiss = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(qkReplyTapDismiss = enabled) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: NotificationPrefsView) {
|
||||
|
||||
@@ -38,14 +38,14 @@ class PlusViewModel @Inject constructor(
|
||||
analyticsManager.track("Viewed QKSMS+")
|
||||
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { it.copy(upgraded = upgraded) } }
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
|
||||
disposables += billingManager.products
|
||||
.subscribe { products ->
|
||||
newState {
|
||||
val upgrade = products.firstOrNull { it.sku == BillingManager.SKU_PLUS }
|
||||
val upgradeDonate = products.firstOrNull { it.sku == BillingManager.SKU_PLUS_DONATE }
|
||||
it.copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
|
||||
copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
|
||||
currency = upgrade?.priceCurrencyCode ?: upgradeDonate?.priceCurrencyCode ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import android.view.WindowManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.R.id.*
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.base.QkThemedActivity
|
||||
@@ -52,6 +51,7 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
||||
|
||||
override val menuItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[QkReplyViewModel::class.java] }
|
||||
@@ -99,6 +99,9 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
sim.setVisible(state.subscription != null)
|
||||
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package feature.qkreply
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.content.Intent
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import injection.ViewModelKey
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
class QkReplyActivityModule {
|
||||
|
||||
@Provides
|
||||
fun provideIntent(activity: QkReplyActivity): Intent = activity.intent
|
||||
@Named("threadId")
|
||||
fun provideThreadId(activity: QkReplyActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L
|
||||
|
||||
@Provides
|
||||
@IntoMap
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package feature.qkreply
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
@@ -28,5 +29,6 @@ data class QkReplyState(
|
||||
val expanded: Boolean = false,
|
||||
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfo? = null,
|
||||
val canSend: Boolean = false
|
||||
)
|
||||
@@ -25,6 +25,7 @@ interface QkReplyView : QkView<QkReplyState> {
|
||||
|
||||
val menuItemIntent: Observable<Int>
|
||||
val textChangedIntent: Observable<CharSequence>
|
||||
val changeSimIntent: Observable<*>
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
fun setDraft(draft: String)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package feature.qkreply
|
||||
|
||||
import android.content.Intent
|
||||
import android.telephony.SmsMessage
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -27,37 +26,42 @@ import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import interactor.MarkRead
|
||||
import interactor.SendMessage
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.asObservable
|
||||
import util.extensions.mapNotNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class QkReplyViewModel @Inject constructor(
|
||||
private val intent: Intent,
|
||||
@Named("threadId") threadId: Long,
|
||||
private val markRead: MarkRead,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val sendMessage: SendMessage
|
||||
private val sendMessage: SendMessage,
|
||||
private val subUtils: SubscriptionUtils
|
||||
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
|
||||
|
||||
private val conversation by lazy {
|
||||
messageRepo.getConversationAsync(intent.getLongExtra("threadId", -1))
|
||||
messageRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
|
||||
private val messages: Subject<RealmResults<Message>> = PublishSubject.create()
|
||||
private val messages: Subject<RealmResults<Message>> =
|
||||
BehaviorSubject.createDefault(messageRepo.getUnreadMessages(threadId))
|
||||
|
||||
init {
|
||||
disposables += markRead
|
||||
@@ -65,21 +69,30 @@ class QkReplyViewModel @Inject constructor(
|
||||
|
||||
// When the set of messages changes, update the state
|
||||
// If we're ever showing an empty set of messages, then it's time to shut down to activity
|
||||
disposables += messages
|
||||
.withLatestFrom(conversation, { messages, conversation -> Pair(conversation, messages) })
|
||||
.doOnNext { data -> newState { it.copy(data = data) } }
|
||||
.map { data -> data.second }
|
||||
disposables += Observables
|
||||
.combineLatest(messages, conversation) { messages, conversation ->
|
||||
newState { copy(data = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
.filter { it.isEmpty() }
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
disposables += conversation
|
||||
.doOnNext { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||
.distinctUntilChanged { conversation -> conversation.id } // We only need to set the messages once
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.subscribe { messages.onNext(it) }
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { copy(title = title) } }
|
||||
|
||||
val latestSubId = messages
|
||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||
.distinctUntilChanged()
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
}
|
||||
|
||||
override fun bindView(view: QkReplyView) {
|
||||
@@ -98,7 +111,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> conversation.id }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId ->
|
||||
markRead.execute(threadId) { newState { it.copy(hasError = true) } }
|
||||
markRead.execute(threadId) { newState { copy(hasError = true) } }
|
||||
}
|
||||
|
||||
// Call
|
||||
@@ -108,25 +121,25 @@ class QkReplyViewModel @Inject constructor(
|
||||
.mapNotNull { conversation -> conversation.recipients.first()?.address }
|
||||
.doOnNext { address -> navigator.makePhoneCall(address) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
// Show all messages
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.expand }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.map { conversation -> messageRepo.getMessages(conversation.id) }
|
||||
.doOnNext { messages.onNext(it) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = true) } }
|
||||
.subscribe { newState { copy(expanded = true) } }
|
||||
|
||||
// Show unread messages only
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.collapse }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.doOnNext { messages.onNext(it) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = false) } }
|
||||
.subscribe { newState { copy(expanded = false) } }
|
||||
|
||||
// View conversation
|
||||
view.menuItemIntent
|
||||
@@ -135,14 +148,14 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> conversation.id }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
// Enable the send button when there is text input into the new message body or there's
|
||||
// an attachment, disable otherwise
|
||||
view.textChangedIntent
|
||||
.map { text -> text.isNotBlank() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -160,7 +173,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
||||
|
||||
// Update the draft whenever the text is changed
|
||||
view.textChangedIntent
|
||||
@@ -173,23 +186,36 @@ class QkReplyViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
.withLatestFrom(state) { _, state ->
|
||||
val subs = subUtils.subscriptions
|
||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||
val subscription = when {
|
||||
subIndex == -1 -> null
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(conversation, { body, conversation ->
|
||||
.withLatestFrom(state, conversation, { body, state, conversation ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body))
|
||||
view.setDraft("")
|
||||
sendMessage.execute(SendMessage.Params(threadId, addresses, body, listOf())) {
|
||||
}
|
||||
|
||||
threadId
|
||||
})
|
||||
.doOnNext { threadId ->
|
||||
markRead.execute(threadId) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package feature.settings
|
||||
|
||||
import android.animation.LayoutTransition
|
||||
import android.app.ProgressDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
@@ -33,6 +34,7 @@ import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.QkDialog
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.animateLayoutChanges
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.PreferenceView
|
||||
@@ -81,6 +83,8 @@ class SettingsActivity : QkThemedActivity(), SettingsView {
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
|
||||
|
||||
nightModeDialog.adapter.setData(R.array.night_modes)
|
||||
textSizeDialog.adapter.setData(R.array.text_sizes)
|
||||
sendDelayDialog.adapter.setData(R.array.delayed_sending_labels)
|
||||
|
||||
@@ -27,11 +27,11 @@ import common.base.QkViewModel
|
||||
import common.util.BillingManager
|
||||
import common.util.Colors
|
||||
import common.util.DateFormatter
|
||||
import common.util.NightModeManager
|
||||
import interactor.SyncMessages
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import timber.log.Timber
|
||||
import util.NightModeManager
|
||||
import util.Preferences
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -49,60 +49,60 @@ class SettingsViewModel @Inject constructor(
|
||||
|
||||
|
||||
init {
|
||||
newState { it.copy(theme = colors.theme().theme) }
|
||||
newState { copy(theme = colors.theme().theme) }
|
||||
|
||||
val nightModeLabels = context.resources.getStringArray(R.array.night_modes)
|
||||
disposables += prefs.nightMode.asObservable()
|
||||
.subscribe { nightMode ->
|
||||
newState { it.copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||
newState { copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||
}
|
||||
|
||||
disposables += prefs.nightStart.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightStart -> newState { it.copy(nightStart = nightStart) } }
|
||||
.subscribe { nightStart -> newState { copy(nightStart = nightStart) } }
|
||||
|
||||
disposables += prefs.nightEnd.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightEnd -> newState { it.copy(nightEnd = nightEnd) } }
|
||||
.subscribe { nightEnd -> newState { copy(nightEnd = nightEnd) } }
|
||||
|
||||
disposables += prefs.black.asObservable()
|
||||
.subscribe { black -> newState { it.copy(black = black) } }
|
||||
.subscribe { black -> newState { copy(black = black) } }
|
||||
|
||||
disposables += prefs.notifications().asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.autoEmoji.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(autoEmojiEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(autoEmojiEnabled = enabled) } }
|
||||
|
||||
val delayedSendingLabels = context.resources.getStringArray(R.array.delayed_sending_labels)
|
||||
disposables += prefs.sendDelay.asObservable()
|
||||
.subscribe { id -> newState { it.copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
|
||||
disposables += prefs.delivery.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||
|
||||
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
|
||||
disposables += prefs.textSize.asObservable()
|
||||
.subscribe { textSize ->
|
||||
newState { it.copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
}
|
||||
|
||||
disposables += prefs.systemFont.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(systemFontEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.unicode.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(stripUnicodeEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
||||
|
||||
val mmsSizeLabels = context.resources.getStringArray(R.array.mms_sizes)
|
||||
val mmsSizeIds = context.resources.getIntArray(R.array.mms_sizes_ids)
|
||||
disposables += prefs.mmsSize.asObservable()
|
||||
.subscribe { maxMmsSize ->
|
||||
val index = mmsSizeIds.indexOf(maxMmsSize)
|
||||
newState { it.copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
}
|
||||
|
||||
disposables += syncMessages
|
||||
@@ -152,9 +152,9 @@ class SettingsViewModel @Inject constructor(
|
||||
R.id.mmsSize -> view.showMmsSizePicker()
|
||||
|
||||
R.id.sync -> {
|
||||
newState { it.copy(syncing = true) }
|
||||
newState { copy(syncing = true) }
|
||||
syncMessages.execute(Unit, {
|
||||
newState { it.copy(syncing = false) }
|
||||
newState { copy(syncing = false) }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -55,16 +55,16 @@ class ThemePickerViewModel @Inject constructor(
|
||||
|
||||
// Update the color of the apply button
|
||||
view.hsvThemeSelectedIntent
|
||||
.doOnNext { color -> newState { it.copy(newColor = color) } }
|
||||
.doOnNext { color -> newState { copy(newColor = color) } }
|
||||
.map { color -> colors.textPrimaryOnThemeForColor(color) }
|
||||
.doOnNext { color -> newState { it.copy(newTextColor = color) } }
|
||||
.doOnNext { color -> newState { copy(newTextColor = color) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Toggle the visibility of the apply group
|
||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent, { old, new -> old != new })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { themeChanged -> newState { it.copy(applyThemeVisible = themeChanged) } }
|
||||
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
||||
|
||||
// Update the theme, when apply is clicked
|
||||
view.hsvThemeAppliedIntent
|
||||
|
||||
@@ -31,9 +31,9 @@ import android.widget.RemoteViews
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.Colors
|
||||
import common.util.extensions.getColorCompat
|
||||
import dagger.android.AndroidInjection
|
||||
import feature.compose.ComposeActivity
|
||||
import feature.main.MainActivity
|
||||
import injection.appComponent
|
||||
import manager.WidgetManager
|
||||
import timber.log.Timber
|
||||
import util.Preferences
|
||||
@@ -44,11 +44,9 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
when (intent.action) {
|
||||
WidgetManager.ACTION_NOTIFY_DATASET_CHANGED -> updateData(context)
|
||||
else -> super.onReceive(context, intent)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import feature.themepicker.ThemePickerActivity
|
||||
import feature.themepicker.ThemePickerActivityModule
|
||||
|
||||
@Module
|
||||
abstract class BuildersModule {
|
||||
abstract class ActivityBuilderModule {
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector(modules = [MainActivityModule::class])
|
||||
@@ -31,25 +31,15 @@ import dagger.Component
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
import feature.compose.DetailedChipView
|
||||
import feature.widget.WidgetAdapter
|
||||
import feature.widget.WidgetProvider
|
||||
import receiver.DefaultSmsChangedReceiver
|
||||
import receiver.MarkReadReceiver
|
||||
import receiver.MarkSeenReceiver
|
||||
import receiver.MmsReceivedReceiver
|
||||
import receiver.MmsSentReceiver
|
||||
import receiver.MmsUpdatedReceiver
|
||||
import receiver.NightModeReceiver
|
||||
import receiver.RemoteMessagingReceiver
|
||||
import receiver.SendSmsReceiver
|
||||
import receiver.SmsDeliveredReceiver
|
||||
import receiver.SmsProviderChangedReceiver
|
||||
import receiver.SmsReceiver
|
||||
import receiver.SmsSentReceiver
|
||||
import service.HeadlessSmsSendService
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Component(modules = [AndroidSupportInjectionModule::class, AppModule::class, BuildersModule::class])
|
||||
@Component(modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
AppModule::class,
|
||||
ActivityBuilderModule::class,
|
||||
BroadcastReceiverBuilderModule::class,
|
||||
ServiceBuilderModule::class])
|
||||
interface AppComponent {
|
||||
|
||||
fun inject(application: QKApplication)
|
||||
@@ -58,22 +48,6 @@ interface AppComponent {
|
||||
|
||||
fun inject(fetcher: ContactImageLoader.ContactImageFetcher)
|
||||
|
||||
fun inject(receiver: DefaultSmsChangedReceiver)
|
||||
fun inject(receiver: SmsDeliveredReceiver)
|
||||
fun inject(receiver: SmsSentReceiver)
|
||||
fun inject(receiver: MarkSeenReceiver)
|
||||
fun inject(receiver: MarkReadReceiver)
|
||||
fun inject(receiver: MmsReceivedReceiver)
|
||||
fun inject(receiver: MmsSentReceiver)
|
||||
fun inject(receiver: MmsUpdatedReceiver)
|
||||
fun inject(receiver: NightModeReceiver)
|
||||
fun inject(receiver: RemoteMessagingReceiver)
|
||||
fun inject(receiver: SendSmsReceiver)
|
||||
fun inject(receiver: SmsProviderChangedReceiver)
|
||||
fun inject(receiver: SmsReceiver)
|
||||
fun inject(receiver: WidgetProvider)
|
||||
|
||||
fun inject(service: HeadlessSmsSendService)
|
||||
fun inject(service: WidgetAdapter)
|
||||
|
||||
fun inject(view: AvatarView)
|
||||
|
||||
@@ -59,6 +59,8 @@ import repository.MessageRepository
|
||||
import repository.MessageRepositoryImpl
|
||||
import repository.SyncRepository
|
||||
import repository.SyncRepositoryImpl
|
||||
import util.SubscriptionUtils
|
||||
import util.SubscriptionUtilsImpl
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@@ -137,4 +139,10 @@ class AppModule(private var application: Application) {
|
||||
@Provides
|
||||
fun provideSyncRepository(repository: SyncRepositoryImpl): SyncRepository = repository
|
||||
|
||||
|
||||
// Utils
|
||||
|
||||
@Provides
|
||||
fun provideSubscriptionUtils(utils: SubscriptionUtilsImpl): SubscriptionUtils = utils
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 injection
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import feature.widget.WidgetProvider
|
||||
import receiver.DefaultSmsChangedReceiver
|
||||
import receiver.MarkReadReceiver
|
||||
import receiver.MarkSeenReceiver
|
||||
import receiver.MmsReceivedReceiver
|
||||
import receiver.MmsReceiver
|
||||
import receiver.MmsSentReceiver
|
||||
import receiver.MmsUpdatedReceiver
|
||||
import receiver.NightModeReceiver
|
||||
import receiver.RemoteMessagingReceiver
|
||||
import receiver.SendSmsReceiver
|
||||
import receiver.SmsDeliveredReceiver
|
||||
import receiver.SmsProviderChangedReceiver
|
||||
import receiver.SmsReceiver
|
||||
import receiver.SmsSentReceiver
|
||||
|
||||
@Module
|
||||
abstract class BroadcastReceiverBuilderModule {
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindDefaultSmsChangedReceiver(): DefaultSmsChangedReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMarkReadReceiver(): MarkReadReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMarkSeenReceiver(): MarkSeenReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMmsReceivedReceiver(): MmsReceivedReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMmsReceiver(): MmsReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMmsSentReceiver(): MmsSentReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMmsUpdatedReceiver(): MmsUpdatedReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindNightModeReceiver(): NightModeReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindRemoteMessagingReceiver(): RemoteMessagingReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindSendSmsReceiver(): SendSmsReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindSmsDeliveredReceiver(): SmsDeliveredReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindSmsProviderChangedReceiver(): SmsProviderChangedReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindSmsReceiver(): SmsReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindSmsSentReceiver(): SmsSentReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindWidgetProvider(): WidgetProvider
|
||||
|
||||
}
|
||||
@@ -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 injection
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import service.HeadlessSmsSendService
|
||||
|
||||
@Module
|
||||
abstract class ServiceBuilderModule {
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindHeadlessSmsSendService(): HeadlessSmsSendService
|
||||
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
package interactor
|
||||
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import common.util.NightModeManager
|
||||
import io.reactivex.Flowable
|
||||
import util.NightModeManager
|
||||
import util.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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 interactor
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import com.google.android.mms.ContentType
|
||||
import com.klinker.android.send_message.Message
|
||||
import com.klinker.android.send_message.Settings
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import feature.compose.Attachment
|
||||
import io.reactivex.Flowable
|
||||
import repository.ImageRepository
|
||||
import repository.MessageRepository
|
||||
import util.Preferences
|
||||
import java.io.ByteArrayOutputStream
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendMessage @Inject constructor(
|
||||
private val context: Context,
|
||||
private val imageRepository: ImageRepository,
|
||||
private val prefs: Preferences,
|
||||
private val messageRepo: MessageRepository
|
||||
) : Interactor<SendMessage.Params>() {
|
||||
|
||||
data class Params(val threadId: Long, val addresses: List<String>, val body: String, val attachments: List<Attachment> = listOf())
|
||||
|
||||
override fun buildObservable(params: Params): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.filter { params.addresses.isNotEmpty() }
|
||||
.doOnNext {
|
||||
if (params.addresses.size == 1 && params.attachments.isEmpty()) {
|
||||
messageRepo.sendSmsAndPersist(params.threadId, params.addresses.first(), params.body)
|
||||
} else {
|
||||
sendMms(params.threadId, params.addresses, params.body, params.attachments)
|
||||
}
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversations(params.threadId) }
|
||||
.doOnNext { messageRepo.markUnarchived(params.threadId) }
|
||||
}
|
||||
|
||||
private fun sendMms(threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>) {
|
||||
val settings = Settings()
|
||||
val message = Message(body, addresses.toTypedArray())
|
||||
|
||||
// Add the GIFs as attachments. The app currently can't compress them, which may result
|
||||
// in a lot of these messages failing to send
|
||||
// TODO Add support for GIF compression
|
||||
attachments
|
||||
.filter { attachment -> attachment.isGif(context) }
|
||||
.map { attachment -> attachment.getUri() }
|
||||
.map { uri -> context.contentResolver.openInputStream(uri) }
|
||||
.map { inputStream -> inputStream.readBytes() }
|
||||
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_GIF) }
|
||||
|
||||
// Compress the images and add them as attachments
|
||||
var totalImageBytes = 0
|
||||
attachments
|
||||
.filter { attachment -> !attachment.isGif(context) }
|
||||
.mapNotNull { attachment -> attachment.getUri() }
|
||||
.mapNotNull { uri -> imageRepository.loadImage(uri) }
|
||||
.also { totalImageBytes = it.sumBy { it.allocationByteCount } }
|
||||
.map { bitmap ->
|
||||
val byteRatio = bitmap.allocationByteCount / totalImageBytes.toFloat()
|
||||
shrink(bitmap, (prefs.mmsSize.get() * 1024 * byteRatio).toInt())
|
||||
}
|
||||
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_JPEG) }
|
||||
|
||||
val transaction = Transaction(context, settings)
|
||||
transaction.sendNewMessage(message, threadId)
|
||||
}
|
||||
|
||||
private fun shrink(src: Bitmap, maxBytes: Int): ByteArray {
|
||||
var step = 0.0
|
||||
val factor = 0.5
|
||||
val quality = 60
|
||||
|
||||
val height = src.height
|
||||
val width = src.width
|
||||
|
||||
val stream = ByteArrayOutputStream()
|
||||
src.compress(Bitmap.CompressFormat.JPEG, 100, stream)
|
||||
|
||||
while (maxBytes > 0 && stream.size() > maxBytes) {
|
||||
step++
|
||||
val scale = Math.pow(factor, step)
|
||||
|
||||
stream.reset()
|
||||
Bitmap.createScaledBitmap(src, (width * scale).toInt(), (height * scale).toInt(), false)
|
||||
.compress(Bitmap.CompressFormat.JPEG, quality, stream)
|
||||
}
|
||||
|
||||
return stream.toByteArray()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,2h-8L4.02,8 4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,4c0,-1.1 -0.9,-2 -2,-2zM14,8h"/>
|
||||
</vector>
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
~
|
||||
~ This file is part of QKSMS.
|
||||
@@ -53,6 +54,19 @@
|
||||
app:textColor="tertiary"
|
||||
app:textSize="secondary" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar"
|
||||
tools:progress="45"
|
||||
tools:progressTint="@color/tools_theme" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/contacts"
|
||||
android:layout_width="0dp"
|
||||
@@ -184,9 +198,37 @@
|
||||
android:padding="12dp"
|
||||
android:textColorHint="?android:attr/textColorTertiary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/messageBackground"
|
||||
app:layout_constraintEnd_toEndOf="@id/messageBackground"
|
||||
app:layout_constraintEnd_toStartOf="@id/sim"
|
||||
app:layout_constraintStart_toEndOf="@id/attachSeparator" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sim"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:contentDescription="@string/compose_attach_cd"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/ic_sim_card_black_24dp"
|
||||
android:tint="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message"
|
||||
app:layout_constraintEnd_toEndOf="@id/messageBackground" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/simIndex"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="center"
|
||||
android:textColor="?android:attr/textColorPrimaryInverse"
|
||||
android:textSize="14dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@id/sim"
|
||||
app:layout_constraintEnd_toEndOf="@id/sim"
|
||||
app:layout_constraintStart_toStartOf="@id/sim"
|
||||
app:layout_constraintTop_toTopOf="@id/sim"
|
||||
tools:ignore="SpUsage"
|
||||
tools:text="1" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/counter"
|
||||
android:layout_width="0dp"
|
||||
@@ -258,12 +300,71 @@
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<android.support.constraint.Group
|
||||
android:id="@+id/sendAsGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:constraint_referenced_ids="sendAsGroupBackground, sendAsGroupTitle, sendAsGroupSummary, sendAsGroupSwitch, sendAsGroupShadow"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<View
|
||||
android:id="@+id/sendAsGroupBackground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/sendAsGroupSummary"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/sendAsGroupTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/compose_send_group_title"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/sendAsGroupSwitch"
|
||||
app:layout_constraintStart_toStartOf="@id/sendAsGroupBackground"
|
||||
app:layout_constraintTop_toTopOf="@id/sendAsGroupBackground"
|
||||
app:textSize="primary" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/sendAsGroupSummary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:text="@string/compose_send_group_summary"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
app:layout_constraintEnd_toEndOf="@id/sendAsGroupTitle"
|
||||
app:layout_constraintStart_toStartOf="@id/sendAsGroupTitle"
|
||||
app:layout_constraintTop_toBottomOf="@id/sendAsGroupTitle"
|
||||
app:textSize="secondary" />
|
||||
|
||||
<common.widget.QkSwitch
|
||||
android:id="@+id/sendAsGroupSwitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:checked="true"
|
||||
android:clickable="false"
|
||||
app:layout_constraintBottom_toBottomOf="@id/sendAsGroupBackground"
|
||||
app:layout_constraintEnd_toEndOf="@id/sendAsGroupBackground"
|
||||
app:layout_constraintTop_toTopOf="@id/sendAsGroupBackground" />
|
||||
|
||||
<View
|
||||
android:id="@+id/sendAsGroupShadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:background="@drawable/ab_shadow"
|
||||
app:layout_constraintTop_toBottomOf="@id/sendAsGroupBackground" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:background="@drawable/ab_shadow"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||
|
||||
<View
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/items"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
@@ -61,6 +61,14 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="?android:attr/divider" />
|
||||
|
||||
<common.widget.PreferenceView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_people_black_24dp"
|
||||
app:title="@string/info_name" />
|
||||
|
||||
<common.widget.PreferenceView
|
||||
android:id="@+id/notifications"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -17,11 +17,27 @@
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<common.widget.SquareImageView android:id="@+id/thumbnail"
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/divider"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<common.widget.SquareImageView android:id="@+id/thumbnail"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/divider"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/video"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="top|end"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_play_circle_filled_white_24dp" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -30,6 +30,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<com.google.android.exoplayer2.ui.PlayerView
|
||||
android:id="@+id/video"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -31,11 +31,36 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/sim"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Tue at 11:39pm" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sim"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:src="@drawable/ic_sim_card_black_24dp"
|
||||
android:tint="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/timestamp"
|
||||
app:layout_constraintEnd_toStartOf="@id/simIndex"
|
||||
app:layout_constraintStart_toEndOf="@id/timestamp"
|
||||
app:layout_constraintTop_toTopOf="@id/timestamp" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/simIndex"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/timestamp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/sim"
|
||||
app:layout_constraintTop_toTopOf="@id/timestamp"
|
||||
app:textSize="tertiary"
|
||||
tools:text="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/attachments"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -31,11 +31,36 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/sim"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Tue at 11:39pm" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sim"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:src="@drawable/ic_sim_card_black_24dp"
|
||||
android:tint="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/timestamp"
|
||||
app:layout_constraintEnd_toStartOf="@id/simIndex"
|
||||
app:layout_constraintStart_toEndOf="@id/timestamp"
|
||||
app:layout_constraintTop_toTopOf="@id/timestamp" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/simIndex"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/timestamp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/sim"
|
||||
app:layout_constraintTop_toTopOf="@id/timestamp"
|
||||
app:textSize="tertiary"
|
||||
tools:text="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/attachments"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -19,18 +19,16 @@
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="2dp">
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="280dp"
|
||||
android:layout_marginTop="2dp">
|
||||
|
||||
<common.widget.BubbleImageView
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:adjustViewBounds="true"
|
||||
android:maxHeight="320dp"
|
||||
android:maxWidth="280dp"
|
||||
android:scaleType="fitStart"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp">
|
||||
|
||||
<View
|
||||
android:id="@+id/vCardBackground"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/label"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/name" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/vCardAvatar"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:src="@drawable/ic_person_black_24dp"
|
||||
android:tint="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="@id/vCardBackground"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/vCardBackground" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingTop="8dp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintStart_toEndOf="@id/vCardAvatar"
|
||||
app:textSize="primary"
|
||||
tools:text="@tools:sample/full_names" />
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingStart="12dp"
|
||||
android:text="@string/compose_vcard_label"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
app:layout_constraintStart_toStartOf="@id/name"
|
||||
app:layout_constraintTop_toBottomOf="@id/name"
|
||||
app:textSize="secondary" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -45,7 +45,6 @@
|
||||
android:id="@+id/preferences"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user