forked from upstream-mirrors/quik
Add support for Android 5.0
This commit is contained in:
@@ -23,7 +23,7 @@ android {
|
|||||||
compileSdkVersion 25
|
compileSdkVersion 25
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 22
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.klinker.android.send_message
|
package com.klinker.android.send_message
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.telephony.SmsManager
|
import android.telephony.SmsManager
|
||||||
|
|
||||||
object SmsManagerFactory {
|
object SmsManagerFactory {
|
||||||
@@ -9,7 +10,7 @@ object SmsManagerFactory {
|
|||||||
fun createSmsManager(subscriptionId: Int): SmsManager {
|
fun createSmsManager(subscriptionId: Int): SmsManager {
|
||||||
var manager: SmsManager? = null
|
var manager: SmsManager? = null
|
||||||
|
|
||||||
if (subscriptionId != -1) {
|
if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 22) {
|
||||||
try {
|
try {
|
||||||
manager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId)
|
manager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ android {
|
|||||||
compileSdkVersion 27
|
compileSdkVersion 27
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 22
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 compat
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
|
import android.os.Build
|
||||||
|
import android.telephony.SubscriptionInfo
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||||
|
data class SubscriptionInfoCompat(private val subscriptionInfo: SubscriptionInfo) {
|
||||||
|
|
||||||
|
val subscriptionId get() = subscriptionInfo.subscriptionId
|
||||||
|
|
||||||
|
val simSlotIndex get() = subscriptionInfo.simSlotIndex
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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 compat
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import manager.PermissionManager
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SubscriptionManagerCompat @Inject constructor(context: Context, private val permissions: PermissionManager) {
|
||||||
|
|
||||||
|
private val subscriptionManager: SubscriptionManager?
|
||||||
|
get() = field?.takeIf { permissions.hasPhone() }
|
||||||
|
|
||||||
|
val activeSubscriptionInfoList: List<SubscriptionInfoCompat>
|
||||||
|
get() {
|
||||||
|
return if (Build.VERSION.SDK_INT >= 22) {
|
||||||
|
subscriptionManager?.activeSubscriptionInfoList?.map { SubscriptionInfoCompat(it) } ?: listOf()
|
||||||
|
} else listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
subscriptionManager = if (Build.VERSION.SDK_INT >= 22) SubscriptionManager.from(context) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addOnSubscriptionsChangedListener(listener: OnSubscriptionsChangedListener) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 22) {
|
||||||
|
subscriptionManager?.addOnSubscriptionsChangedListener(listener.listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeOnSubscriptionsChangedListener(listener: OnSubscriptionsChangedListener) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 22) {
|
||||||
|
subscriptionManager?.removeOnSubscriptionsChangedListener(listener.listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class OnSubscriptionsChangedListener {
|
||||||
|
|
||||||
|
val listener: SubscriptionManager.OnSubscriptionsChangedListener? = if (Build.VERSION.SDK_INT >= 22) {
|
||||||
|
object : SubscriptionManager.OnSubscriptionsChangedListener() {
|
||||||
|
override fun onSubscriptionsChanged() {
|
||||||
|
this@OnSubscriptionsChangedListener.onSubscriptionsChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
|
||||||
|
abstract fun onSubscriptionsChanged()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,11 +22,11 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.support.v4.app.RemoteInput
|
import android.support.v4.app.RemoteInput
|
||||||
|
import compat.SubscriptionManagerCompat
|
||||||
import dagger.android.AndroidInjection
|
import dagger.android.AndroidInjection
|
||||||
import interactor.MarkRead
|
import interactor.MarkRead
|
||||||
import interactor.SendMessage
|
import interactor.SendMessage
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
import util.SubscriptionUtils
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RemoteMessagingReceiver : BroadcastReceiver() {
|
class RemoteMessagingReceiver : BroadcastReceiver() {
|
||||||
@@ -34,7 +34,7 @@ class RemoteMessagingReceiver : BroadcastReceiver() {
|
|||||||
@Inject lateinit var markRead: MarkRead
|
@Inject lateinit var markRead: MarkRead
|
||||||
@Inject lateinit var messageRepo: MessageRepository
|
@Inject lateinit var messageRepo: MessageRepository
|
||||||
@Inject lateinit var sendMessage: SendMessage
|
@Inject lateinit var sendMessage: SendMessage
|
||||||
@Inject lateinit var subUtils: SubscriptionUtils
|
@Inject lateinit var subscriptionManager: SubscriptionManagerCompat
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
AndroidInjection.inject(this, context)
|
AndroidInjection.inject(this, context)
|
||||||
@@ -47,7 +47,7 @@ class RemoteMessagingReceiver : BroadcastReceiver() {
|
|||||||
markRead.execute(threadId)
|
markRead.execute(threadId)
|
||||||
|
|
||||||
val lastMessage = messageRepo.getMessages(threadId).lastOrNull()
|
val lastMessage = messageRepo.getMessages(threadId).lastOrNull()
|
||||||
val subId = subUtils.subscriptions.firstOrNull { it.subscriptionId == lastMessage?.subId }?.subscriptionId ?: -1
|
val subId = subscriptionManager.activeSubscriptionInfoList.firstOrNull { it.subscriptionId == lastMessage?.subId }?.subscriptionId ?: -1
|
||||||
val addresses = messageRepo.getConversation(threadId)?.recipients?.map { it.address } ?: return
|
val addresses = messageRepo.getConversation(threadId)?.recipients?.map { it.address } ?: return
|
||||||
|
|
||||||
val pendingRepository = goAsync()
|
val pendingRepository = goAsync()
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import compat.SubscriptionInfoCompat
|
||||||
|
import compat.SubscriptionManagerCompat
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.Observer
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
|
class ActiveSubscriptionObservable(
|
||||||
|
private val subscriptionManager: SubscriptionManagerCompat
|
||||||
|
) : Observable<List<SubscriptionInfoCompat>>() {
|
||||||
|
|
||||||
|
override fun subscribeActual(observer: Observer<in List<SubscriptionInfoCompat>>) {
|
||||||
|
observer.onNext(subscriptionManager.activeSubscriptionInfoList)
|
||||||
|
|
||||||
|
val listener = Listener(subscriptionManager, observer)
|
||||||
|
observer.onSubscribe(listener)
|
||||||
|
subscriptionManager.addOnSubscriptionsChangedListener(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Listener(
|
||||||
|
private val subscriptionManager: SubscriptionManagerCompat,
|
||||||
|
private val observer: Observer<in List<SubscriptionInfoCompat>>
|
||||||
|
) : Disposable, SubscriptionManagerCompat.OnSubscriptionsChangedListener() {
|
||||||
|
|
||||||
|
private var disposed: Boolean = false
|
||||||
|
|
||||||
|
override fun onSubscriptionsChanged() {
|
||||||
|
if (!isDisposed) {
|
||||||
|
observer.onNext(subscriptionManager.activeSubscriptionInfoList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isDisposed(): Boolean = disposed
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
disposed = true
|
||||||
|
subscriptionManager.removeOnSubscriptionsChangedListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+1
-1
@@ -7,7 +7,7 @@ android {
|
|||||||
compileSdkVersion 27
|
compileSdkVersion 27
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 22
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
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,7 +11,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.moez.QKSMS"
|
applicationId "com.moez.QKSMS"
|
||||||
minSdkVersion 22
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode 173
|
versionCode 173
|
||||||
versionName "3.3.2"
|
versionName "3.3.2"
|
||||||
|
|||||||
@@ -49,12 +49,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
|||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
field = value
|
field = value
|
||||||
|
applyTheme(value)
|
||||||
colors.theme(value).run {
|
|
||||||
setBackgroundTint(theme)
|
|
||||||
initial.setTextColor(textPrimary)
|
|
||||||
icon.setTint(textPrimary)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var lookupKey: String? = null
|
private var lookupKey: String? = null
|
||||||
@@ -106,16 +101,19 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
|||||||
super.onFinishInflate()
|
super.onFinishInflate()
|
||||||
|
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
colors.theme(threadId).run {
|
applyTheme(threadId)
|
||||||
setBackgroundTint(theme)
|
|
||||||
initial.setTextColor(textPrimary)
|
|
||||||
icon.setTint(textPrimary)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateView()
|
updateView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun applyTheme(threadId: Long) {
|
||||||
|
colors.theme(threadId).run {
|
||||||
|
setBackgroundTint(theme)
|
||||||
|
initial.setTextColor(textPrimary)
|
||||||
|
icon.setTint(textPrimary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateView() {
|
private fun updateView() {
|
||||||
if (name?.isNotEmpty() == true) {
|
if (name?.isNotEmpty() == true) {
|
||||||
initial.text = name?.substring(0, 1)
|
initial.text = name?.substring(0, 1)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package common.widget
|
package common.widget
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
import android.support.constraint.ConstraintLayout
|
import android.support.constraint.ConstraintLayout
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -47,6 +48,11 @@ class GroupAvatarView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
|
|
||||||
avatars.forEach { avatar ->
|
avatars.forEach { avatar ->
|
||||||
avatar.setBackgroundResource(R.drawable.rectangle)
|
avatar.setBackgroundResource(R.drawable.rectangle)
|
||||||
|
|
||||||
|
// If we're on API 21 we need to reapply the tint after changing the background
|
||||||
|
if (Build.VERSION.SDK_INT < 22) {
|
||||||
|
avatar.applyTheme(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.content.ContentValues
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
@@ -40,6 +41,7 @@ import com.uber.autodispose.android.lifecycle.scope
|
|||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.base.QkThemedActivity
|
import common.base.QkThemedActivity
|
||||||
import common.util.extensions.autoScrollToStart
|
import common.util.extensions.autoScrollToStart
|
||||||
|
import common.util.extensions.resolveThemeColor
|
||||||
import common.util.extensions.scrapViews
|
import common.util.extensions.scrapViews
|
||||||
import common.util.extensions.setBackgroundTint
|
import common.util.extensions.setBackgroundTint
|
||||||
import common.util.extensions.setTint
|
import common.util.extensions.setTint
|
||||||
@@ -134,6 +136,11 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
.subscribe { messageList.scrapViews() }
|
.subscribe { messageList.scrapViews() }
|
||||||
|
|
||||||
window.callback = ComposeWindowCallback(window.callback, this)
|
window.callback = ComposeWindowCallback(window.callback, this)
|
||||||
|
|
||||||
|
// These theme attributes don't apply themselves on API 21
|
||||||
|
if (Build.VERSION.SDK_INT <= 22) {
|
||||||
|
composeBackground.setBackgroundTint(resolveThemeColor(R.attr.composeBackground))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package feature.compose
|
package feature.compose
|
||||||
|
|
||||||
import android.telephony.SubscriptionInfo
|
import android.telephony.SubscriptionInfo
|
||||||
|
import compat.SubscriptionInfoCompat
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import model.Attachment
|
import model.Attachment
|
||||||
import model.Contact
|
import model.Contact
|
||||||
@@ -44,6 +45,6 @@ data class ComposeState(
|
|||||||
val attachments: List<Attachment> = ArrayList(),
|
val attachments: List<Attachment> = ArrayList(),
|
||||||
val attaching: Boolean = false,
|
val attaching: Boolean = false,
|
||||||
val remaining: String = "",
|
val remaining: String = "",
|
||||||
val subscription: SubscriptionInfo? = null,
|
val subscription: SubscriptionInfoCompat? = null,
|
||||||
val canSend: Boolean = false
|
val canSend: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -31,6 +31,7 @@ import common.Navigator
|
|||||||
import common.base.QkViewModel
|
import common.base.QkViewModel
|
||||||
import common.util.ClipboardUtils
|
import common.util.ClipboardUtils
|
||||||
import common.util.extensions.makeToast
|
import common.util.extensions.makeToast
|
||||||
|
import compat.SubscriptionManagerCompat
|
||||||
import filter.ContactFilter
|
import filter.ContactFilter
|
||||||
import interactor.CancelDelayedMessage
|
import interactor.CancelDelayedMessage
|
||||||
import interactor.ContactSync
|
import interactor.ContactSync
|
||||||
@@ -56,7 +57,7 @@ import model.Message
|
|||||||
import model.PhoneNumber
|
import model.PhoneNumber
|
||||||
import repository.ContactRepository
|
import repository.ContactRepository
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
import util.SubscriptionUtils
|
import util.ActiveSubscriptionObservable
|
||||||
import util.extensions.asObservable
|
import util.extensions.asObservable
|
||||||
import util.extensions.isImage
|
import util.extensions.isImage
|
||||||
import util.extensions.mapNotNull
|
import util.extensions.mapNotNull
|
||||||
@@ -80,7 +81,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
private val permissionManager: PermissionManager,
|
private val permissionManager: PermissionManager,
|
||||||
private val retrySending: RetrySending,
|
private val retrySending: RetrySending,
|
||||||
private val sendMessage: SendMessage,
|
private val sendMessage: SendMessage,
|
||||||
private val subUtils: SubscriptionUtils,
|
private val subscriptionManager: SubscriptionManagerCompat,
|
||||||
private val syncContacts: ContactSync
|
private val syncContacts: ContactSync
|
||||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(query = intent.extras?.getString("query") ?: "")) {
|
) : QkViewModel<ComposeView, ComposeState>(ComposeState(query = intent.extras?.getString("query") ?: "")) {
|
||||||
|
|
||||||
@@ -211,7 +212,8 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
val subscriptions = ActiveSubscriptionObservable(subscriptionManager)
|
||||||
|
disposables += Observables.combineLatest(latestSubId, subscriptions) { subId, subs ->
|
||||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||||
newState { copy(subscription = sub) }
|
newState { copy(subscription = sub) }
|
||||||
}.subscribe()
|
}.subscribe()
|
||||||
@@ -523,7 +525,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
// Toggle to the next sim slot
|
// Toggle to the next sim slot
|
||||||
view.changeSimIntent
|
view.changeSimIntent
|
||||||
.withLatestFrom(state) { _, state ->
|
.withLatestFrom(state) { _, state ->
|
||||||
val subs = subUtils.subscriptions
|
val subs = subscriptionManager.activeSubscriptionInfoList
|
||||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||||
val subscription = when {
|
val subscription = when {
|
||||||
subIndex == -1 -> null
|
subIndex == -1 -> null
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import common.util.extensions.setPadding
|
|||||||
import common.util.extensions.setTint
|
import common.util.extensions.setTint
|
||||||
import common.util.extensions.setVisible
|
import common.util.extensions.setVisible
|
||||||
import common.widget.BubbleImageView.Style.*
|
import common.widget.BubbleImageView.Style.*
|
||||||
|
import compat.SubscriptionManagerCompat
|
||||||
import ezvcard.Ezvcard
|
import ezvcard.Ezvcard
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
@@ -64,7 +65,6 @@ import model.Conversation
|
|||||||
import model.Message
|
import model.Message
|
||||||
import model.Recipient
|
import model.Recipient
|
||||||
import util.Preferences
|
import util.Preferences
|
||||||
import util.SubscriptionUtils
|
|
||||||
import util.extensions.isImage
|
import util.extensions.isImage
|
||||||
import util.extensions.isVCard
|
import util.extensions.isVCard
|
||||||
import util.extensions.isVideo
|
import util.extensions.isVideo
|
||||||
@@ -78,7 +78,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private val dateFormatter: DateFormatter,
|
private val dateFormatter: DateFormatter,
|
||||||
private val navigator: Navigator,
|
private val navigator: Navigator,
|
||||||
private val prefs: Preferences,
|
private val prefs: Preferences,
|
||||||
private val subUtils: SubscriptionUtils
|
private val subscriptionManager: SubscriptionManagerCompat
|
||||||
) : QkRealmAdapter<Message>() {
|
) : QkRealmAdapter<Message>() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -123,7 +123,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private val contactCache = ContactCache()
|
private val contactCache = ContactCache()
|
||||||
private val expanded = HashMap<Long, Boolean>()
|
private val expanded = HashMap<Long, Boolean>()
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
private val subs = subUtils.subscriptions
|
private val subs = subscriptionManager.activeSubscriptionInfoList
|
||||||
|
|
||||||
var theme: Colors.Theme = colors.theme()
|
var theme: Colors.Theme = colors.theme()
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package feature.qkreply
|
|||||||
|
|
||||||
import android.arch.lifecycle.ViewModelProvider
|
import android.arch.lifecycle.ViewModelProvider
|
||||||
import android.arch.lifecycle.ViewModelProviders
|
import android.arch.lifecycle.ViewModelProviders
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
@@ -34,6 +35,7 @@ import com.uber.autodispose.android.lifecycle.scope
|
|||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.base.QkThemedActivity
|
import common.base.QkThemedActivity
|
||||||
import common.util.extensions.autoScrollToStart
|
import common.util.extensions.autoScrollToStart
|
||||||
|
import common.util.extensions.resolveThemeColor
|
||||||
import common.util.extensions.setBackgroundTint
|
import common.util.extensions.setBackgroundTint
|
||||||
import common.util.extensions.setTint
|
import common.util.extensions.setTint
|
||||||
import common.util.extensions.setVisible
|
import common.util.extensions.setVisible
|
||||||
@@ -80,6 +82,14 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
|||||||
|
|
||||||
messages.layoutManager = LinearLayoutManager(this).apply { stackFromEnd = true }
|
messages.layoutManager = LinearLayoutManager(this).apply { stackFromEnd = true }
|
||||||
messages.adapter = adapter
|
messages.adapter = adapter
|
||||||
|
|
||||||
|
// These theme attributes don't apply themselves on API 21
|
||||||
|
if (Build.VERSION.SDK_INT <= 22) {
|
||||||
|
toolbar.setBackgroundTint(resolveThemeColor(R.attr.colorPrimary))
|
||||||
|
background.setBackgroundTint(resolveThemeColor(R.attr.composeBackground))
|
||||||
|
composeBackground.setBackgroundTint(resolveThemeColor(R.attr.composeBackground))
|
||||||
|
composeBackgroundGradient.setBackgroundTint(resolveThemeColor(R.attr.composeBackground))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: QkReplyState) {
|
override fun render(state: QkReplyState) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package feature.qkreply
|
package feature.qkreply
|
||||||
|
|
||||||
import android.telephony.SubscriptionInfo
|
import compat.SubscriptionInfoCompat
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import model.Conversation
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
@@ -29,6 +29,6 @@ data class QkReplyState(
|
|||||||
val expanded: Boolean = false,
|
val expanded: Boolean = false,
|
||||||
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
||||||
val remaining: String = "",
|
val remaining: String = "",
|
||||||
val subscription: SubscriptionInfo? = null,
|
val subscription: SubscriptionInfoCompat? = null,
|
||||||
val canSend: Boolean = false
|
val canSend: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -24,6 +24,7 @@ import com.uber.autodispose.android.lifecycle.scope
|
|||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.Navigator
|
import common.Navigator
|
||||||
import common.base.QkViewModel
|
import common.base.QkViewModel
|
||||||
|
import compat.SubscriptionManagerCompat
|
||||||
import interactor.MarkRead
|
import interactor.MarkRead
|
||||||
import interactor.SendMessage
|
import interactor.SendMessage
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
@@ -36,7 +37,7 @@ import io.realm.RealmResults
|
|||||||
import model.Conversation
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
import util.SubscriptionUtils
|
import util.ActiveSubscriptionObservable
|
||||||
import util.extensions.asObservable
|
import util.extensions.asObservable
|
||||||
import util.extensions.mapNotNull
|
import util.extensions.mapNotNull
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@@ -49,7 +50,7 @@ class QkReplyViewModel @Inject constructor(
|
|||||||
private val messageRepo: MessageRepository,
|
private val messageRepo: MessageRepository,
|
||||||
private val navigator: Navigator,
|
private val navigator: Navigator,
|
||||||
private val sendMessage: SendMessage,
|
private val sendMessage: SendMessage,
|
||||||
private val subUtils: SubscriptionUtils
|
private val subscriptionManager: SubscriptionManagerCompat
|
||||||
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
|
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
|
||||||
|
|
||||||
private val conversation by lazy {
|
private val conversation by lazy {
|
||||||
@@ -89,7 +90,8 @@ class QkReplyViewModel @Inject constructor(
|
|||||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
val subscriptions = ActiveSubscriptionObservable(subscriptionManager)
|
||||||
|
disposables += Observables.combineLatest(latestSubId, subscriptions) { subId, subs ->
|
||||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||||
newState { copy(subscription = sub) }
|
newState { copy(subscription = sub) }
|
||||||
}.subscribe()
|
}.subscribe()
|
||||||
@@ -189,7 +191,7 @@ class QkReplyViewModel @Inject constructor(
|
|||||||
// Toggle to the next sim slot
|
// Toggle to the next sim slot
|
||||||
view.changeSimIntent
|
view.changeSimIntent
|
||||||
.withLatestFrom(state) { _, state ->
|
.withLatestFrom(state) { _, state ->
|
||||||
val subs = subUtils.subscriptions
|
val subs = subscriptionManager.activeSubscriptionInfoList
|
||||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||||
val subscription = when {
|
val subscription = when {
|
||||||
subIndex == -1 -> null
|
subIndex == -1 -> null
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ import repository.MessageRepository
|
|||||||
import repository.MessageRepositoryImpl
|
import repository.MessageRepositoryImpl
|
||||||
import repository.SyncRepository
|
import repository.SyncRepository
|
||||||
import repository.SyncRepositoryImpl
|
import repository.SyncRepositoryImpl
|
||||||
import util.SubscriptionUtils
|
|
||||||
import util.SubscriptionUtilsImpl
|
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@@ -139,10 +137,4 @@ class AppModule(private var application: Application) {
|
|||||||
@Provides
|
@Provides
|
||||||
fun provideSyncRepository(repository: SyncRepositoryImpl): SyncRepository = repository
|
fun provideSyncRepository(repository: SyncRepositoryImpl): SyncRepository = repository
|
||||||
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
fun provideSubscriptionUtils(utils: SubscriptionUtilsImpl): SubscriptionUtils = utils
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user