mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.migration
|
package com.moez.QKSMS.migration
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
import com.moez.QKSMS.extensions.map
|
import com.moez.QKSMS.extensions.map
|
||||||
import com.moez.QKSMS.mapper.CursorToContactImpl
|
import com.moez.QKSMS.mapper.CursorToContactImpl
|
||||||
import io.realm.DynamicRealm
|
import io.realm.DynamicRealm
|
||||||
@@ -29,13 +31,15 @@ import io.realm.Sort
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class QkRealmMigration @Inject constructor(
|
class QkRealmMigration @Inject constructor(
|
||||||
private val cursorToContact: CursorToContactImpl
|
private val cursorToContact: CursorToContactImpl,
|
||||||
|
private val prefs: RxSharedPreferences
|
||||||
) : RealmMigration {
|
) : RealmMigration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SchemaVersion: Long = 9
|
const val SchemaVersion: Long = 9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||||
var version = oldVersion
|
var version = oldVersion
|
||||||
|
|
||||||
@@ -169,6 +173,23 @@ class QkRealmMigration @Inject constructor(
|
|||||||
realmContact.setString("photoUri", photoUri)
|
realmContact.setString("photoUri", photoUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate conversation themes
|
||||||
|
val recipients = mutableMapOf<Long, Int>() // Map of recipientId:theme
|
||||||
|
realm.where("Conversation").findAll().forEach { conversation ->
|
||||||
|
val pref = prefs.getInteger("theme_${conversation.getLong("id")}")
|
||||||
|
if (pref.isSet) {
|
||||||
|
conversation.getList("Recipient").forEach { recipient ->
|
||||||
|
recipients[recipient.getLong("id")] = pref.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pref.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recipients.forEach { (recipientId, theme) ->
|
||||||
|
prefs.getInteger("theme_$recipientId").set(theme)
|
||||||
|
}
|
||||||
|
|
||||||
version++
|
version++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import android.media.MediaScannerConnection
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
|
import android.provider.Telephony.Mms
|
||||||
|
import android.provider.Telephony.Sms
|
||||||
import android.telephony.SmsManager
|
import android.telephony.SmsManager
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.core.content.contentValuesOf
|
import androidx.core.content.contentValuesOf
|
||||||
@@ -110,6 +112,25 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getLastIncomingMessage(threadId: Long): RealmResults<Message> {
|
||||||
|
return Realm.getDefaultInstance()
|
||||||
|
.where(Message::class.java)
|
||||||
|
.equalTo("threadId", threadId)
|
||||||
|
.beginGroup()
|
||||||
|
.beginGroup()
|
||||||
|
.equalTo("type", "sms")
|
||||||
|
.`in`("boxId", arrayOf(Sms.MESSAGE_TYPE_INBOX, Sms.MESSAGE_TYPE_ALL))
|
||||||
|
.endGroup()
|
||||||
|
.or()
|
||||||
|
.beginGroup()
|
||||||
|
.equalTo("type", "mms")
|
||||||
|
.`in`("boxId", arrayOf(Mms.MESSAGE_BOX_INBOX, Mms.MESSAGE_BOX_ALL))
|
||||||
|
.endGroup()
|
||||||
|
.endGroup()
|
||||||
|
.sort("date", Sort.DESCENDING)
|
||||||
|
.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
override fun getUnreadCount(): Long {
|
override fun getUnreadCount(): Long {
|
||||||
return Realm.getDefaultInstance().use { realm ->
|
return Realm.getDefaultInstance().use { realm ->
|
||||||
realm.refresh()
|
realm.refresh()
|
||||||
@@ -239,13 +260,13 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(Telephony.Sms.SEEN, true)
|
values.put(Sms.SEEN, true)
|
||||||
values.put(Telephony.Sms.READ, true)
|
values.put(Sms.READ, true)
|
||||||
|
|
||||||
threadIds.forEach { threadId ->
|
threadIds.forEach { threadId ->
|
||||||
try {
|
try {
|
||||||
val uri = ContentUris.withAppendedId(Telephony.MmsSms.CONTENT_CONVERSATIONS_URI, threadId)
|
val uri = ContentUris.withAppendedId(Telephony.MmsSms.CONTENT_CONVERSATIONS_URI, threadId)
|
||||||
context.contentResolver.update(uri, values, "${Telephony.Sms.READ} = 0", null)
|
context.contentResolver.update(uri, values, "${Sms.READ} = 0", null)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Timber.w(exception)
|
Timber.w(exception)
|
||||||
}
|
}
|
||||||
@@ -421,7 +442,7 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
this.subId = subId
|
this.subId = subId
|
||||||
|
|
||||||
id = messageIds.newId()
|
id = messageIds.newId()
|
||||||
boxId = Telephony.Sms.MESSAGE_TYPE_OUTBOX
|
boxId = Sms.MESSAGE_TYPE_OUTBOX
|
||||||
type = "sms"
|
type = "sms"
|
||||||
read = true
|
read = true
|
||||||
seen = true
|
seen = true
|
||||||
@@ -432,20 +453,20 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
// Insert the message to the native content provider
|
// Insert the message to the native content provider
|
||||||
val values = contentValuesOf(
|
val values = contentValuesOf(
|
||||||
Telephony.Sms.ADDRESS to address,
|
Sms.ADDRESS to address,
|
||||||
Telephony.Sms.BODY to body,
|
Sms.BODY to body,
|
||||||
Telephony.Sms.DATE to System.currentTimeMillis(),
|
Sms.DATE to System.currentTimeMillis(),
|
||||||
Telephony.Sms.READ to true,
|
Sms.READ to true,
|
||||||
Telephony.Sms.SEEN to true,
|
Sms.SEEN to true,
|
||||||
Telephony.Sms.TYPE to Telephony.Sms.MESSAGE_TYPE_OUTBOX,
|
Sms.TYPE to Sms.MESSAGE_TYPE_OUTBOX,
|
||||||
Telephony.Sms.THREAD_ID to threadId
|
Sms.THREAD_ID to threadId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (prefs.canUseSubId.get()) {
|
if (prefs.canUseSubId.get()) {
|
||||||
values.put(Telephony.Sms.SUBSCRIPTION_ID, message.subId)
|
values.put(Sms.SUBSCRIPTION_ID, message.subId)
|
||||||
}
|
}
|
||||||
|
|
||||||
val uri = context.contentResolver.insert(Telephony.Sms.CONTENT_URI, values)
|
val uri = context.contentResolver.insert(Sms.CONTENT_URI, values)
|
||||||
|
|
||||||
// Update the contentId after the message has been inserted to the content provider
|
// Update the contentId after the message has been inserted to the content provider
|
||||||
// The message might have been deleted by now, so only proceed if it's valid
|
// The message might have been deleted by now, so only proceed if it's valid
|
||||||
@@ -479,7 +500,7 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
id = messageIds.newId()
|
id = messageIds.newId()
|
||||||
threadId = TelephonyCompat.getOrCreateThreadId(context, address)
|
threadId = TelephonyCompat.getOrCreateThreadId(context, address)
|
||||||
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
|
boxId = Sms.MESSAGE_TYPE_INBOX
|
||||||
type = "sms"
|
type = "sms"
|
||||||
read = activeConversationManager.getActiveConversation() == threadId
|
read = activeConversationManager.getActiveConversation() == threadId
|
||||||
}
|
}
|
||||||
@@ -489,16 +510,16 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
// Insert the message to the native content provider
|
// Insert the message to the native content provider
|
||||||
val values = contentValuesOf(
|
val values = contentValuesOf(
|
||||||
Telephony.Sms.ADDRESS to address,
|
Sms.ADDRESS to address,
|
||||||
Telephony.Sms.BODY to body,
|
Sms.BODY to body,
|
||||||
Telephony.Sms.DATE_SENT to sentTime
|
Sms.DATE_SENT to sentTime
|
||||||
)
|
)
|
||||||
|
|
||||||
if (prefs.canUseSubId.get()) {
|
if (prefs.canUseSubId.get()) {
|
||||||
values.put(Telephony.Sms.SUBSCRIPTION_ID, message.subId)
|
values.put(Sms.SUBSCRIPTION_ID, message.subId)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)?.lastPathSegment?.toLong()?.let { id ->
|
context.contentResolver.insert(Sms.Inbox.CONTENT_URI, values)?.lastPathSegment?.toLong()?.let { id ->
|
||||||
// Update the contentId after the message has been inserted to the content provider
|
// Update the contentId after the message has been inserted to the content provider
|
||||||
realm.executeTransaction { managedMessage?.contentId = id }
|
realm.executeTransaction { managedMessage?.contentId = id }
|
||||||
}
|
}
|
||||||
@@ -520,15 +541,15 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
// Update the message in realm
|
// Update the message in realm
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
message.boxId = when (message.isSms()) {
|
message.boxId = when (message.isSms()) {
|
||||||
true -> Telephony.Sms.MESSAGE_TYPE_OUTBOX
|
true -> Sms.MESSAGE_TYPE_OUTBOX
|
||||||
false -> Telephony.Mms.MESSAGE_BOX_OUTBOX
|
false -> Mms.MESSAGE_BOX_OUTBOX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the message in the native ContentProvider
|
// Update the message in the native ContentProvider
|
||||||
val values = when (message.isSms()) {
|
val values = when (message.isSms()) {
|
||||||
true -> contentValuesOf(Telephony.Sms.TYPE to Telephony.Sms.MESSAGE_TYPE_OUTBOX)
|
true -> contentValuesOf(Sms.TYPE to Sms.MESSAGE_TYPE_OUTBOX)
|
||||||
false -> contentValuesOf(Telephony.Mms.MESSAGE_BOX to Telephony.Mms.MESSAGE_BOX_OUTBOX)
|
false -> contentValuesOf(Mms.MESSAGE_BOX to Mms.MESSAGE_BOX_OUTBOX)
|
||||||
}
|
}
|
||||||
context.contentResolver.update(message.getUri(), values, null, null)
|
context.contentResolver.update(message.getUri(), values, null, null)
|
||||||
}
|
}
|
||||||
@@ -543,12 +564,12 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
message?.let {
|
message?.let {
|
||||||
// Update the message in realm
|
// Update the message in realm
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
message.boxId = Telephony.Sms.MESSAGE_TYPE_SENT
|
message.boxId = Sms.MESSAGE_TYPE_SENT
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the message in the native ContentProvider
|
// Update the message in the native ContentProvider
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_SENT)
|
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_SENT)
|
||||||
context.contentResolver.update(message.getUri(), values, null, null)
|
context.contentResolver.update(message.getUri(), values, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -562,14 +583,14 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
message?.let {
|
message?.let {
|
||||||
// Update the message in realm
|
// Update the message in realm
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
message.boxId = Telephony.Sms.MESSAGE_TYPE_FAILED
|
message.boxId = Sms.MESSAGE_TYPE_FAILED
|
||||||
message.errorCode = resultCode
|
message.errorCode = resultCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the message in the native ContentProvider
|
// Update the message in the native ContentProvider
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_FAILED)
|
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_FAILED)
|
||||||
values.put(Telephony.Sms.ERROR_CODE, resultCode)
|
values.put(Sms.ERROR_CODE, resultCode)
|
||||||
context.contentResolver.update(message.getUri(), values, null, null)
|
context.contentResolver.update(message.getUri(), values, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,16 +604,16 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
message?.let {
|
message?.let {
|
||||||
// Update the message in realm
|
// Update the message in realm
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
message.deliveryStatus = Telephony.Sms.STATUS_COMPLETE
|
message.deliveryStatus = Sms.STATUS_COMPLETE
|
||||||
message.dateSent = System.currentTimeMillis()
|
message.dateSent = System.currentTimeMillis()
|
||||||
message.read = true
|
message.read = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the message in the native ContentProvider
|
// Update the message in the native ContentProvider
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(Telephony.Sms.STATUS, Telephony.Sms.STATUS_COMPLETE)
|
values.put(Sms.STATUS, Sms.STATUS_COMPLETE)
|
||||||
values.put(Telephony.Sms.DATE_SENT, System.currentTimeMillis())
|
values.put(Sms.DATE_SENT, System.currentTimeMillis())
|
||||||
values.put(Telephony.Sms.READ, true)
|
values.put(Sms.READ, true)
|
||||||
context.contentResolver.update(message.getUri(), values, null, null)
|
context.contentResolver.update(message.getUri(), values, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,7 +627,7 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
message?.let {
|
message?.let {
|
||||||
// Update the message in realm
|
// Update the message in realm
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
message.deliveryStatus = Telephony.Sms.STATUS_FAILED
|
message.deliveryStatus = Sms.STATUS_FAILED
|
||||||
message.dateSent = System.currentTimeMillis()
|
message.dateSent = System.currentTimeMillis()
|
||||||
message.read = true
|
message.read = true
|
||||||
message.errorCode = resultCode
|
message.errorCode = resultCode
|
||||||
@@ -614,10 +635,10 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
// Update the message in the native ContentProvider
|
// Update the message in the native ContentProvider
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(Telephony.Sms.STATUS, Telephony.Sms.STATUS_FAILED)
|
values.put(Sms.STATUS, Sms.STATUS_FAILED)
|
||||||
values.put(Telephony.Sms.DATE_SENT, System.currentTimeMillis())
|
values.put(Sms.DATE_SENT, System.currentTimeMillis())
|
||||||
values.put(Telephony.Sms.READ, true)
|
values.put(Sms.READ, true)
|
||||||
values.put(Telephony.Sms.ERROR_CODE, resultCode)
|
values.put(Sms.ERROR_CODE, resultCode)
|
||||||
context.contentResolver.update(message.getUri(), values, null, null)
|
context.contentResolver.update(message.getUri(), values, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ interface MessageRepository {
|
|||||||
|
|
||||||
fun getMessageForPart(id: Long): Message?
|
fun getMessageForPart(id: Long): Message?
|
||||||
|
|
||||||
|
fun getLastIncomingMessage(threadId: Long): RealmResults<Message>
|
||||||
|
|
||||||
fun getUnreadCount(): Long
|
fun getUnreadCount(): Long
|
||||||
|
|
||||||
fun getPart(id: Long): MmsPart?
|
fun getPart(id: Long): MmsPart?
|
||||||
|
|||||||
@@ -19,16 +19,22 @@
|
|||||||
package com.moez.QKSMS.util
|
package com.moez.QKSMS.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import com.f2prateek.rx.preferences2.Preference
|
import com.f2prateek.rx.preferences2.Preference
|
||||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
import com.moez.QKSMS.common.util.extensions.versionCode
|
import com.moez.QKSMS.common.util.extensions.versionCode
|
||||||
|
import io.reactivex.Observable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Preferences @Inject constructor(context: Context, private val rxPrefs: RxSharedPreferences) {
|
class Preferences @Inject constructor(
|
||||||
|
context: Context,
|
||||||
|
private val rxPrefs: RxSharedPreferences,
|
||||||
|
private val sharedPrefs: SharedPreferences
|
||||||
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val NIGHT_MODE_SYSTEM = 0
|
const val NIGHT_MODE_SYSTEM = 0
|
||||||
@@ -118,12 +124,28 @@ class Preferences @Inject constructor(context: Context, private val rxPrefs: RxS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun theme(threadId: Long = 0): Preference<Int> {
|
/**
|
||||||
|
* Returns a stream of preference keys for changing preferences
|
||||||
|
*/
|
||||||
|
val keyChanges: Observable<String> = Observable.create<String> { emitter ->
|
||||||
|
// Making this a lambda would cause it to be GCd
|
||||||
|
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
|
emitter.onNext(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
emitter.setCancellable {
|
||||||
|
sharedPrefs.unregisterOnSharedPreferenceChangeListener(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
sharedPrefs.registerOnSharedPreferenceChangeListener(listener)
|
||||||
|
}.share()
|
||||||
|
|
||||||
|
fun theme(recipientId: Long = 0): Preference<Int> {
|
||||||
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
||||||
|
|
||||||
return when (threadId) {
|
return when (recipientId) {
|
||||||
0L -> default
|
0L -> default
|
||||||
else -> rxPrefs.getInteger("theme_$threadId", default.get())
|
else -> rxPrefs.getInteger("theme_$recipientId", default.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ import com.moez.QKSMS.R
|
|||||||
import com.moez.QKSMS.common.util.Colors
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.extensions.resolveThemeBoolean
|
import com.moez.QKSMS.common.util.extensions.resolveThemeBoolean
|
||||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||||
|
import com.moez.QKSMS.extensions.asObservable
|
||||||
|
import com.moez.QKSMS.extensions.mapNotNull
|
||||||
|
import com.moez.QKSMS.repository.ConversationRepository
|
||||||
|
import com.moez.QKSMS.repository.MessageRepository
|
||||||
|
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||||
import com.moez.QKSMS.util.Preferences
|
import com.moez.QKSMS.util.Preferences
|
||||||
import com.uber.autodispose.android.lifecycle.scope
|
import com.uber.autodispose.android.lifecycle.scope
|
||||||
import com.uber.autodispose.autoDisposable
|
import com.uber.autodispose.autoDisposable
|
||||||
@@ -51,6 +56,9 @@ import javax.inject.Inject
|
|||||||
abstract class QkThemedActivity : QkActivity() {
|
abstract class QkThemedActivity : QkActivity() {
|
||||||
|
|
||||||
@Inject lateinit var colors: Colors
|
@Inject lateinit var colors: Colors
|
||||||
|
@Inject lateinit var conversationRepo: ConversationRepository
|
||||||
|
@Inject lateinit var messageRepo: MessageRepository
|
||||||
|
@Inject lateinit var phoneNumberUtils: PhoneNumberUtils
|
||||||
@Inject lateinit var prefs: Preferences
|
@Inject lateinit var prefs: Preferences
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,10 +69,40 @@ abstract class QkThemedActivity : QkActivity() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch the theme if the threadId changes
|
* Switch the theme if the threadId changes
|
||||||
|
* Set it based on the latest message in the conversation
|
||||||
*/
|
*/
|
||||||
val theme = threadId
|
val theme: Observable<Colors.Theme> = threadId
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.switchMap { threadId -> colors.themeObservable(threadId) }
|
.switchMap { threadId ->
|
||||||
|
val conversation = conversationRepo.getConversation(threadId)
|
||||||
|
when {
|
||||||
|
conversation == null -> Observable.just(0L)
|
||||||
|
|
||||||
|
conversation.recipients.size == 1 -> Observable.just(conversation.recipients.first()?.id ?: 0L)
|
||||||
|
|
||||||
|
else -> messageRepo.getLastIncomingMessage(conversation.id)
|
||||||
|
.asObservable()
|
||||||
|
.mapNotNull { messages -> messages.firstOrNull() }
|
||||||
|
.distinctUntilChanged { message -> message.address }
|
||||||
|
.mapNotNull { message ->
|
||||||
|
conversation.recipients.find { recipient ->
|
||||||
|
phoneNumberUtils.compare(recipient.address, message.address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.map { recipient -> recipient.id }
|
||||||
|
.startWith(conversation.recipients.firstOrNull()?.id ?: 0)
|
||||||
|
.distinctUntilChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.switchMap { colors.themeObservable(it) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits an event whenever any theme changes, whether it be global or for some recipient. This is useful
|
||||||
|
* for invalidating recyclerviews
|
||||||
|
*/
|
||||||
|
val allThemes by lazy {
|
||||||
|
prefs.keyChanges.filter { key -> key.contains("theme") }
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ class Colors @Inject constructor(private val context: Context, private val prefs
|
|||||||
private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark))
|
private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark))
|
||||||
private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark))
|
private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark))
|
||||||
|
|
||||||
fun theme(threadId: Long = 0): Theme = Theme(prefs.theme(threadId).get(), this)
|
fun theme(recipientId: Long = 0): Theme = Theme(prefs.theme(recipientId).get(), this)
|
||||||
|
|
||||||
fun themeObservable(threadId: Long = 0): Observable<Theme> {
|
fun themeObservable(recipientId: Long = 0): Observable<Theme> {
|
||||||
return prefs.theme(threadId).asObservable()
|
return prefs.theme(recipientId).asObservable()
|
||||||
.map { color -> Theme(color, this) }
|
.map { color -> Theme(color, this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,11 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val conversation = conversationRepo.getConversation(threadId) ?: return
|
val conversation = conversationRepo.getConversation(threadId) ?: return
|
||||||
|
val lastRecipient = conversation.lastMessage?.let { lastMessage ->
|
||||||
|
conversation.recipients.find { recipient ->
|
||||||
|
phoneNumberUtils.compare(recipient.address, lastMessage.address)
|
||||||
|
}
|
||||||
|
} ?: conversation.recipients.firstOrNull()
|
||||||
|
|
||||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||||
@@ -134,7 +139,7 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
|
|
||||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||||
.setColor(colors.theme(threadId).theme)
|
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setNumber(messages.size)
|
.setNumber(messages.size)
|
||||||
@@ -158,8 +163,9 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
val person = Person.Builder()
|
val person = Person.Builder()
|
||||||
|
|
||||||
if (!message.isMe()) {
|
if (!message.isMe()) {
|
||||||
val recipient = conversation.recipients
|
val recipient = conversation.recipients.find { recipient ->
|
||||||
.firstOrNull { phoneNumberUtils.compare(it.address, message.address) }
|
phoneNumberUtils.compare(recipient.address, message.address)
|
||||||
|
}
|
||||||
|
|
||||||
person.setName(recipient?.getDisplayName() ?: message.address)
|
person.setName(recipient?.getDisplayName() ?: message.address)
|
||||||
person.setIcon(GlideApp.with(context)
|
person.setIcon(GlideApp.with(context)
|
||||||
@@ -302,6 +308,12 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val conversation = conversationRepo.getConversation(message.threadId) ?: return
|
val conversation = conversationRepo.getConversation(message.threadId) ?: return
|
||||||
|
val lastRecipient = conversation.lastMessage?.let { lastMessage ->
|
||||||
|
conversation.recipients.find { recipient ->
|
||||||
|
phoneNumberUtils.compare(recipient.address, lastMessage.address)
|
||||||
|
}
|
||||||
|
} ?: conversation.recipients.firstOrNull()
|
||||||
|
|
||||||
val threadId = conversation.id
|
val threadId = conversation.id
|
||||||
|
|
||||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||||
@@ -313,7 +325,7 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||||
.setContentTitle(context.getString(R.string.notification_message_failed_title))
|
.setContentTitle(context.getString(R.string.notification_message_failed_title))
|
||||||
.setContentText(context.getString(R.string.notification_message_failed_text, conversation.getTitle()))
|
.setContentText(context.getString(R.string.notification_message_failed_text, conversation.getTitle()))
|
||||||
.setColor(colors.theme(threadId).theme)
|
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
|
||||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||||
.setSmallIcon(R.drawable.ic_notification_failed)
|
.setSmallIcon(R.drawable.ic_notification_failed)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class AvatarView @JvmOverloads constructor(
|
|||||||
/**
|
/**
|
||||||
* This value can be changes if we should use the theme from a particular conversation
|
* This value can be changes if we should use the theme from a particular conversation
|
||||||
*/
|
*/
|
||||||
var threadId: Long = 0
|
var recipientId: Long = 0
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
field = value
|
field = value
|
||||||
@@ -81,13 +81,13 @@ class AvatarView @JvmOverloads constructor(
|
|||||||
super.onFinishInflate()
|
super.onFinishInflate()
|
||||||
|
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
applyTheme(threadId)
|
applyTheme(recipientId)
|
||||||
updateView()
|
updateView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyTheme(threadId: Long) {
|
private fun applyTheme(recipientId: Long) {
|
||||||
colors.theme(threadId).run {
|
colors.theme(recipientId).run {
|
||||||
setBackgroundTint(theme)
|
setBackgroundTint(theme)
|
||||||
initial.setTextColor(textPrimary)
|
initial.setTextColor(textPrimary)
|
||||||
icon.setTint(textPrimary)
|
icon.setTint(textPrimary)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class GroupAvatarView @JvmOverloads constructor(
|
|||||||
context: Context, attrs: AttributeSet? = null
|
context: Context, attrs: AttributeSet? = null
|
||||||
) : ConstraintLayout(context, attrs) {
|
) : ConstraintLayout(context, attrs) {
|
||||||
|
|
||||||
var contacts: List<Recipient> = ArrayList()
|
var recipients: List<Recipient> = ArrayList()
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value.sortedWith(compareByDescending { contact -> contact.contact?.lookupKey })
|
field = value.sortedWith(compareByDescending { contact -> contact.contact?.lookupKey })
|
||||||
updateView()
|
updateView()
|
||||||
@@ -54,17 +54,25 @@ class GroupAvatarView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateView() {
|
private fun updateView() {
|
||||||
avatar1Frame.setBackgroundTint(when (contacts.size > 1) {
|
avatar1Frame.setBackgroundTint(when (recipients.size > 1) {
|
||||||
true -> context.resolveThemeColor(android.R.attr.windowBackground)
|
true -> context.resolveThemeColor(android.R.attr.windowBackground)
|
||||||
false -> context.getColorCompat(android.R.color.transparent)
|
false -> context.getColorCompat(android.R.color.transparent)
|
||||||
})
|
})
|
||||||
avatar1Frame.updateLayoutParams<LayoutParams> {
|
avatar1Frame.updateLayoutParams<LayoutParams> {
|
||||||
matchConstraintPercentWidth = if (contacts.size > 1) 0.75f else 1.0f
|
matchConstraintPercentWidth = if (recipients.size > 1) 0.75f else 1.0f
|
||||||
}
|
}
|
||||||
avatar2.isVisible = contacts.size > 1
|
avatar2.isVisible = recipients.size > 1
|
||||||
|
|
||||||
avatar1.setContact(contacts.getOrNull(0)?.contact)
|
|
||||||
avatar2.setContact(contacts.getOrNull(1)?.contact)
|
recipients.getOrNull(0).let { recipient ->
|
||||||
|
avatar1.recipientId = recipient?.id ?: 0
|
||||||
|
avatar1.setContact(recipient?.contact)
|
||||||
|
}
|
||||||
|
|
||||||
|
recipients.getOrNull(1).let { recipient ->
|
||||||
|
avatar2.recipientId = recipient?.id ?: 0
|
||||||
|
avatar2.setContact(recipient?.contact)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
|
|
||||||
@Inject lateinit var colors: Colors
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
private val threadId: Subject<Long> = BehaviorSubject.create()
|
private val recipientId: Subject<Long> = BehaviorSubject.create()
|
||||||
|
|
||||||
var pager: ViewPager? = null
|
var pager: ViewPager? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -55,8 +55,8 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
if (!isInEditMode) appComponent.inject(this)
|
if (!isInEditMode) appComponent.inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setThreadId(id: Long) {
|
fun setRecipientId(id: Long) {
|
||||||
threadId.onNext(id)
|
recipientId.onNext(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recreate() {
|
private fun recreate() {
|
||||||
@@ -90,9 +90,9 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
intArrayOf(android.R.attr.state_activated),
|
intArrayOf(android.R.attr.state_activated),
|
||||||
intArrayOf(-android.R.attr.state_activated))
|
intArrayOf(-android.R.attr.state_activated))
|
||||||
|
|
||||||
threadId
|
recipientId
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.switchMap { threadId -> colors.themeObservable(threadId) }
|
.switchMap { recipientId -> colors.themeObservable(recipientId) }
|
||||||
.map { theme ->
|
.map { theme ->
|
||||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||||
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ class BlockedMessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
view.isActivated = isSelected(conversation.id)
|
view.isActivated = isSelected(conversation.id)
|
||||||
|
|
||||||
view.avatars.contacts = conversation.recipients
|
view.avatars.recipients = conversation.recipients
|
||||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||||
|
|||||||
@@ -150,6 +150,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
.doOnNext { attach.setBackgroundTint(it.theme) }
|
.doOnNext { attach.setBackgroundTint(it.theme) }
|
||||||
.doOnNext { attach.setTint(it.textPrimary) }
|
.doOnNext { attach.setTint(it.textPrimary) }
|
||||||
.doOnNext { messageAdapter.theme = it }
|
.doOnNext { messageAdapter.theme = it }
|
||||||
|
.autoDisposable(scope())
|
||||||
|
.subscribe()
|
||||||
|
|
||||||
|
allThemes
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { messageList.scrapViews() }
|
.subscribe { messageList.scrapViews() }
|
||||||
|
|
||||||
@@ -177,7 +181,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
threadId.onNext(state.selectedConversation)
|
threadId.onNext(state.threadId)
|
||||||
|
|
||||||
title = when {
|
title = when {
|
||||||
state.selectedMessages > 0 -> getString(R.string.compose_title_selected, state.selectedMessages)
|
state.selectedMessages > 0 -> getString(R.string.compose_title_selected, state.selectedMessages)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import io.realm.RealmResults
|
|||||||
data class ComposeState(
|
data class ComposeState(
|
||||||
val hasError: Boolean = false,
|
val hasError: Boolean = false,
|
||||||
val editingMode: Boolean = false,
|
val editingMode: Boolean = false,
|
||||||
val selectedConversation: Long = 0,
|
val threadId: Long = 0,
|
||||||
val selectedChips: List<Chip> = ArrayList(),
|
val selectedChips: List<Chip> = ArrayList(),
|
||||||
val sendAsGroup: Boolean = true,
|
val sendAsGroup: Boolean = true,
|
||||||
val conversationtitle: String = "",
|
val conversationtitle: String = "",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.moez.QKSMS.common.Navigator
|
|||||||
import com.moez.QKSMS.common.base.QkViewModel
|
import com.moez.QKSMS.common.base.QkViewModel
|
||||||
import com.moez.QKSMS.common.util.BillingManager
|
import com.moez.QKSMS.common.util.BillingManager
|
||||||
import com.moez.QKSMS.common.util.ClipboardUtils
|
import com.moez.QKSMS.common.util.ClipboardUtils
|
||||||
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.MessageDetailsFormatter
|
import com.moez.QKSMS.common.util.MessageDetailsFormatter
|
||||||
import com.moez.QKSMS.common.util.extensions.makeToast
|
import com.moez.QKSMS.common.util.extensions.makeToast
|
||||||
import com.moez.QKSMS.compat.SubscriptionManagerCompat
|
import com.moez.QKSMS.compat.SubscriptionManagerCompat
|
||||||
@@ -77,6 +78,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
@Named("addresses") private val addresses: List<String>,
|
@Named("addresses") private val addresses: List<String>,
|
||||||
@Named("text") private val sharedText: String,
|
@Named("text") private val sharedText: String,
|
||||||
@Named("attachments") private val sharedAttachments: Attachments,
|
@Named("attachments") private val sharedAttachments: Attachments,
|
||||||
|
private val colors: Colors,
|
||||||
private val contactRepo: ContactRepository,
|
private val contactRepo: ContactRepository,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val activeConversationManager: ActiveConversationManager,
|
private val activeConversationManager: ActiveConversationManager,
|
||||||
@@ -97,7 +99,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
private val subscriptionManager: SubscriptionManagerCompat
|
private val subscriptionManager: SubscriptionManagerCompat
|
||||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
|
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
|
||||||
editingMode = threadId == 0L && addresses.isEmpty(),
|
editingMode = threadId == 0L && addresses.isEmpty(),
|
||||||
selectedConversation = threadId,
|
threadId = threadId,
|
||||||
query = query)
|
query = query)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -171,13 +173,13 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.takeUntil(state.filter { state -> !state.editingMode })
|
.takeUntil(state.filter { state -> !state.editingMode })
|
||||||
.subscribe(selectedChips::onNext)
|
.subscribe(selectedChips::onNext)
|
||||||
|
|
||||||
// When the conversation changes, mark read, and update the threadId and the messages for the adapter
|
// When the conversation changes, mark read, and update the recipientId and the messages for the adapter
|
||||||
disposables += conversation
|
disposables += conversation
|
||||||
.distinctUntilChanged { conversation -> conversation.id }
|
.distinctUntilChanged { conversation -> conversation.id }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map { conversation ->
|
.map { conversation ->
|
||||||
val messages = messageRepo.getMessages(conversation.id)
|
val messages = messageRepo.getMessages(conversation.id)
|
||||||
newState { copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
newState { copy(threadId = conversation.id, messages = Pair(conversation, messages)) }
|
||||||
messages
|
messages
|
||||||
}
|
}
|
||||||
.switchMap { messages -> messages.asObservable() }
|
.switchMap { messages -> messages.asObservable() }
|
||||||
|
|||||||
@@ -98,9 +98,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
field = value
|
field = value
|
||||||
contactCache.clear()
|
contactCache.clear()
|
||||||
|
|
||||||
// Update the theme
|
|
||||||
theme = colors.theme(value?.first?.id ?: 0)
|
|
||||||
|
|
||||||
updateData(value?.second)
|
updateData(value?.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,9 +142,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
|
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
|
||||||
} else {
|
} else {
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||||
view.avatar.threadId = conversation?.id ?: 0
|
|
||||||
view.body.setTextColor(theme.textPrimary)
|
|
||||||
view.body.setBackgroundTint(theme.theme)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
@@ -187,6 +181,11 @@ class MessagesAdapter @Inject constructor(
|
|||||||
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
||||||
val view = viewHolder.containerView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
|
val theme = when (message.isOutgoingMessage()) {
|
||||||
|
true -> colors.theme()
|
||||||
|
false -> colors.theme(contactCache[message.address]?.id ?: 0)
|
||||||
|
}
|
||||||
|
|
||||||
// Update the selected state
|
// Update the selected state
|
||||||
view.isActivated = isSelected(message.id) || highlight == message.id
|
view.isActivated = isSelected(message.id) || highlight == message.id
|
||||||
|
|
||||||
@@ -231,11 +230,14 @@ class MessagesAdapter @Inject constructor(
|
|||||||
val media = message.parts.filter { !it.isSmil() && !it.isText() }
|
val media = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||||
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||||
|
|
||||||
// Bind the avatar
|
// Bind the avatar and bubble colour
|
||||||
if (!message.isMe()) {
|
if (!message.isMe()) {
|
||||||
view.avatar.threadId = conversation?.id ?: 0
|
view.avatar.recipientId = contactCache[message.address]?.id ?: 0
|
||||||
view.avatar.setContact(contactCache[message.address]?.contact)
|
view.avatar.setContact(contactCache[message.address]?.contact)
|
||||||
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||||
|
|
||||||
|
view.body.setTextColor(theme.textPrimary)
|
||||||
|
view.body.setBackgroundTint(theme.theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the body text
|
// Bind the body text
|
||||||
|
|||||||
+5
-5
@@ -87,7 +87,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
|
|||||||
|
|
||||||
view.icon.isVisible = false
|
view.icon.isVisible = false
|
||||||
|
|
||||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
view.avatar.recipients = listOf(Recipient(contact = contact))
|
||||||
|
|
||||||
view.title.text = contact.numbers.joinToString { it.address }
|
view.title.text = contact.numbers.joinToString { it.address }
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
|
|||||||
view.icon.isVisible = prev !is ComposeItem.Recent
|
view.icon.isVisible = prev !is ComposeItem.Recent
|
||||||
view.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
view.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||||
|
|
||||||
view.avatar.contacts = conversation.recipients
|
view.avatar.recipients = conversation.recipients
|
||||||
|
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
|
|||||||
view.icon.isVisible = prev !is ComposeItem.Starred
|
view.icon.isVisible = prev !is ComposeItem.Starred
|
||||||
view.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
view.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||||
|
|
||||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
view.avatar.recipients = listOf(Recipient(contact = contact))
|
||||||
|
|
||||||
view.title.text = contact.name
|
view.title.text = contact.name
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
|
|||||||
view.icon.isVisible = prev !is ComposeItem.Group
|
view.icon.isVisible = prev !is ComposeItem.Group
|
||||||
view.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
view.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||||
|
|
||||||
view.avatar.contacts = group.contacts.map { contact -> Recipient(contact = contact) }
|
view.avatar.recipients = group.contacts.map { contact -> Recipient(contact = contact) }
|
||||||
|
|
||||||
view.title.text = group.title
|
view.title.text = group.title
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
|
|||||||
|
|
||||||
view.icon.isVisible = false
|
view.icon.isVisible = false
|
||||||
|
|
||||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
view.avatar.recipients = listOf(Recipient(contact = contact))
|
||||||
|
|
||||||
view.title.text = contact.name
|
view.title.text = contact.name
|
||||||
|
|
||||||
|
|||||||
+7
-12
@@ -78,10 +78,9 @@ class ConversationInfoController(
|
|||||||
media.adapter = mediaAdapter
|
media.adapter = mediaAdapter
|
||||||
media.addItemDecoration(itemDecoration)
|
media.addItemDecoration(itemDecoration)
|
||||||
|
|
||||||
themedActivity
|
themedActivity?.theme
|
||||||
?.theme
|
|
||||||
?.autoDisposable(scope())
|
?.autoDisposable(scope())
|
||||||
?.subscribe { recipients?.scrapViews() }
|
?.subscribe { recipients.scrapViews() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttach(view: View) {
|
override fun onAttach(view: View) {
|
||||||
@@ -91,7 +90,9 @@ class ConversationInfoController(
|
|||||||
showBackButton(true)
|
showBackButton(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recipientClicks(): Observable<Long> = recipientAdapter.clicks
|
override fun contactClicks(): Observable<Long> = recipientAdapter.contactClicks
|
||||||
|
|
||||||
|
override fun themeClicks(): Observable<Long> = recipientAdapter.themeClicks
|
||||||
|
|
||||||
override fun nameClicks(): Observable<*> = name.clicks()
|
override fun nameClicks(): Observable<*> = name.clicks()
|
||||||
|
|
||||||
@@ -99,8 +100,6 @@ class ConversationInfoController(
|
|||||||
|
|
||||||
override fun notificationClicks(): Observable<*> = notifications.clicks()
|
override fun notificationClicks(): Observable<*> = notifications.clicks()
|
||||||
|
|
||||||
override fun themeClicks(): Observable<*> = themePrefs.clicks()
|
|
||||||
|
|
||||||
override fun archiveClicks(): Observable<*> = archive.clicks()
|
override fun archiveClicks(): Observable<*> = archive.clicks()
|
||||||
|
|
||||||
override fun blockClicks(): Observable<*> = block.clicks()
|
override fun blockClicks(): Observable<*> = block.clicks()
|
||||||
@@ -115,8 +114,6 @@ class ConversationInfoController(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
themedActivity?.threadId?.onNext(state.threadId)
|
|
||||||
recipientAdapter.threadId = state.threadId
|
|
||||||
recipientAdapter.updateData(state.recipients)
|
recipientAdapter.updateData(state.recipients)
|
||||||
|
|
||||||
name.setVisible(state.recipients?.size ?: 0 >= 2)
|
name.setVisible(state.recipients?.size ?: 0 >= 2)
|
||||||
@@ -124,8 +121,6 @@ class ConversationInfoController(
|
|||||||
|
|
||||||
notifications.isEnabled = !state.blocked
|
notifications.isEnabled = !state.blocked
|
||||||
|
|
||||||
themePrefs.isEnabled = !state.blocked
|
|
||||||
|
|
||||||
archive.isEnabled = !state.blocked
|
archive.isEnabled = !state.blocked
|
||||||
archive.title = activity?.getString(when (state.archived) {
|
archive.title = activity?.getString(when (state.archived) {
|
||||||
true -> R.string.info_unarchive
|
true -> R.string.info_unarchive
|
||||||
@@ -142,8 +137,8 @@ class ConversationInfoController(
|
|||||||
|
|
||||||
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
|
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
|
||||||
|
|
||||||
override fun showThemePicker(threadId: Long) {
|
override fun showThemePicker(recipientId: Long) {
|
||||||
router.pushController(RouterTransaction.with(ThemePickerController(threadId))
|
router.pushController(RouterTransaction.with(ThemePickerController(recipientId))
|
||||||
.pushChangeHandler(QkChangeHandler())
|
.pushChangeHandler(QkChangeHandler())
|
||||||
.popChangeHandler(QkChangeHandler()))
|
.popChangeHandler(QkChangeHandler()))
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -100,7 +100,7 @@ class ConversationInfoPresenter @Inject constructor(
|
|||||||
super.bindIntents(view)
|
super.bindIntents(view)
|
||||||
|
|
||||||
// Add or display the contact
|
// Add or display the contact
|
||||||
view.recipientClicks()
|
view.contactClicks()
|
||||||
.mapNotNull(conversationRepo::getRecipient)
|
.mapNotNull(conversationRepo::getRecipient)
|
||||||
.doOnNext { recipient ->
|
.doOnNext { recipient ->
|
||||||
recipient.contact?.lookupKey?.let(navigator::showContact)
|
recipient.contact?.lookupKey?.let(navigator::showContact)
|
||||||
@@ -109,6 +109,11 @@ class ConversationInfoPresenter @Inject constructor(
|
|||||||
.autoDisposable(view.scope(Lifecycle.Event.ON_DESTROY)) // ... this should be the default
|
.autoDisposable(view.scope(Lifecycle.Event.ON_DESTROY)) // ... this should be the default
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
|
// Show the theme settings for the conversation
|
||||||
|
view.themeClicks()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe(view::showThemePicker)
|
||||||
|
|
||||||
// Show the conversation title dialog
|
// Show the conversation title dialog
|
||||||
view.nameClicks()
|
view.nameClicks()
|
||||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||||
@@ -130,12 +135,6 @@ class ConversationInfoPresenter @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
|
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
|
||||||
|
|
||||||
// Show the theme settings for the conversation
|
|
||||||
view.themeClicks()
|
|
||||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
|
||||||
.autoDisposable(view.scope())
|
|
||||||
.subscribe { conversation -> view.showThemePicker(conversation.id) }
|
|
||||||
|
|
||||||
// Toggle the archived state of the conversation
|
// Toggle the archived state of the conversation
|
||||||
view.archiveClicks()
|
view.archiveClicks()
|
||||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||||
|
|||||||
+3
-3
@@ -23,18 +23,18 @@ import io.reactivex.Observable
|
|||||||
|
|
||||||
interface ConversationInfoView : QkViewContract<ConversationInfoState> {
|
interface ConversationInfoView : QkViewContract<ConversationInfoState> {
|
||||||
|
|
||||||
fun recipientClicks(): Observable<Long>
|
fun contactClicks(): Observable<Long>
|
||||||
|
fun themeClicks(): Observable<Long>
|
||||||
fun nameClicks(): Observable<*>
|
fun nameClicks(): Observable<*>
|
||||||
fun nameChanges(): Observable<String>
|
fun nameChanges(): Observable<String>
|
||||||
fun notificationClicks(): Observable<*>
|
fun notificationClicks(): Observable<*>
|
||||||
fun themeClicks(): Observable<*>
|
|
||||||
fun archiveClicks(): Observable<*>
|
fun archiveClicks(): Observable<*>
|
||||||
fun blockClicks(): Observable<*>
|
fun blockClicks(): Observable<*>
|
||||||
fun deleteClicks(): Observable<*>
|
fun deleteClicks(): Observable<*>
|
||||||
fun confirmDelete(): Observable<*>
|
fun confirmDelete(): Observable<*>
|
||||||
|
|
||||||
fun showNameDialog(name: String)
|
fun showNameDialog(name: String)
|
||||||
fun showThemePicker(threadId: Long)
|
fun showThemePicker(recipientId: Long)
|
||||||
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
|
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
|
||||||
fun requestDefaultSms()
|
fun requestDefaultSms()
|
||||||
fun showDeleteDialog()
|
fun showDeleteDialog()
|
||||||
|
|||||||
+16
-13
@@ -20,24 +20,24 @@ package com.moez.QKSMS.feature.conversationinfo
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
import com.moez.QKSMS.common.base.QkViewHolder
|
||||||
|
import com.moez.QKSMS.common.util.Colors
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setTint
|
||||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||||
import com.moez.QKSMS.model.Recipient
|
import com.moez.QKSMS.model.Recipient
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
|
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipient>() {
|
class ConversationRecipientAdapter @Inject constructor(
|
||||||
|
private val colors: Colors
|
||||||
|
) : QkRealmAdapter<Recipient>() {
|
||||||
|
|
||||||
var threadId: Long = 0L
|
val contactClicks: Subject<Long> = PublishSubject.create()
|
||||||
val clicks: Subject<Long> = PublishSubject.create()
|
val themeClicks: Subject<Long> = PublishSubject.create()
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||||
val layoutInflater = LayoutInflater.from(parent.context)
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
@@ -45,7 +45,12 @@ class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipi
|
|||||||
return QkViewHolder(view).apply {
|
return QkViewHolder(view).apply {
|
||||||
view.setOnClickListener {
|
view.setOnClickListener {
|
||||||
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
||||||
clicks.onNext(recipient.id)
|
contactClicks.onNext(recipient.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
view.theme.setOnClickListener {
|
||||||
|
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
||||||
|
themeClicks.onNext(recipient.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +59,7 @@ class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipi
|
|||||||
val recipient = getItem(position) ?: return
|
val recipient = getItem(position) ?: return
|
||||||
val view = holder.containerView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.avatar.threadId = threadId
|
view.avatar.recipientId = recipient.id
|
||||||
view.avatar.setContact(recipient.contact)
|
view.avatar.setContact(recipient.contact)
|
||||||
|
|
||||||
view.name.text = recipient.contact?.name ?: recipient.address
|
view.name.text = recipient.contact?.name ?: recipient.address
|
||||||
@@ -63,11 +68,9 @@ class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipi
|
|||||||
view.address.setVisible(recipient.contact != null)
|
view.address.setVisible(recipient.contact != null)
|
||||||
|
|
||||||
view.add.setVisible(recipient.contact == null)
|
view.add.setVisible(recipient.contact == null)
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
val theme = colors.theme(recipient.id)
|
||||||
super.onDetachedFromRecyclerView(recyclerView)
|
view.theme.setTint(theme.theme)
|
||||||
disposables.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-3
@@ -32,6 +32,7 @@ import com.moez.QKSMS.common.util.DateFormatter
|
|||||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||||
import com.moez.QKSMS.common.util.extensions.setTint
|
import com.moez.QKSMS.common.util.extensions.setTint
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
|
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||||
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -39,7 +40,8 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val dateFormatter: DateFormatter,
|
private val dateFormatter: DateFormatter,
|
||||||
private val navigator: Navigator
|
private val navigator: Navigator,
|
||||||
|
private val phoneNumberUtils: PhoneNumberUtils
|
||||||
) : QkRealmAdapter<Conversation>() {
|
) : QkRealmAdapter<Conversation>() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -60,7 +62,6 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
view.snippet.maxLines = 5
|
view.snippet.maxLines = 5
|
||||||
|
|
||||||
view.unread.isVisible = true
|
view.unread.isVisible = true
|
||||||
view.unread.setTint(colors.theme().theme)
|
|
||||||
|
|
||||||
view.date.setTypeface(view.date.typeface, Typeface.BOLD)
|
view.date.setTypeface(view.date.typeface, Typeface.BOLD)
|
||||||
view.date.setTextColor(textColorPrimary)
|
view.date.setTextColor(textColorPrimary)
|
||||||
@@ -85,11 +86,12 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||||
val conversation = getItem(position) ?: return
|
val conversation = getItem(position) ?: return
|
||||||
|
val lastMessage = conversation.lastMessage ?: return
|
||||||
val view = viewHolder.containerView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
view.isActivated = isSelected(conversation.id)
|
view.isActivated = isSelected(conversation.id)
|
||||||
|
|
||||||
view.avatars.contacts = conversation.recipients
|
view.avatars.recipients = conversation.recipients
|
||||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||||
@@ -99,6 +101,16 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
else -> conversation.snippet
|
else -> conversation.snippet
|
||||||
}
|
}
|
||||||
view.pinned.isVisible = conversation.pinned
|
view.pinned.isVisible = conversation.pinned
|
||||||
|
|
||||||
|
// If the last message wasn't incoming, then the colour doesn't really matter anyway
|
||||||
|
val recipient = when (conversation.recipients.size) {
|
||||||
|
1 -> conversation.recipients.firstOrNull()
|
||||||
|
else -> conversation.recipients.find { recipient ->
|
||||||
|
phoneNumberUtils.compare(recipient.address, lastMessage.address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view.unread.setTint(colors.theme(recipient?.id ?: 0).theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(index: Int): Long {
|
override fun getItemId(index: Int): Long {
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
|
|
||||||
// Set the theme color tint to the recyclerView, progressbar, and FAB
|
// Set the theme color tint to the recyclerView, progressbar, and FAB
|
||||||
theme
|
theme
|
||||||
.doOnNext { recyclerView.scrapViews() }
|
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { theme ->
|
.subscribe { theme ->
|
||||||
// Set the color for the drawer icons
|
// Set the color for the drawer icons
|
||||||
@@ -183,6 +182,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
compose.setTint(theme.textPrimary)
|
compose.setTint(theme.textPrimary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allThemes
|
||||||
|
.autoDisposable(scope())
|
||||||
|
.subscribe { recyclerView.scrapViews() }
|
||||||
|
|
||||||
itemTouchCallback.adapter = conversationsAdapter
|
itemTouchCallback.adapter = conversationsAdapter
|
||||||
conversationsAdapter.autoScrollToStart(recyclerView)
|
conversationsAdapter.autoScrollToStart(recyclerView)
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class SearchAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
view.title.text = title
|
view.title.text = title
|
||||||
|
|
||||||
view.avatars.contacts = result.conversation.recipients
|
view.avatars.recipients = result.conversation.recipients
|
||||||
|
|
||||||
when (result.messages == 0) {
|
when (result.messages == 0) {
|
||||||
true -> {
|
true -> {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
threadId.onNext(state.selectedConversation)
|
threadId.onNext(state.threadId)
|
||||||
|
|
||||||
title = state.title
|
title = state.title
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import io.realm.RealmResults
|
|||||||
|
|
||||||
data class QkReplyState(
|
data class QkReplyState(
|
||||||
val hasError: Boolean = false,
|
val hasError: Boolean = false,
|
||||||
val selectedConversation: Long = 0,
|
val threadId: Long = 0,
|
||||||
val title: String = "",
|
val title: String = "",
|
||||||
val expanded: Boolean = false,
|
val expanded: Boolean = false,
|
||||||
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class QkReplyViewModel @Inject constructor(
|
|||||||
private val navigator: Navigator,
|
private val navigator: Navigator,
|
||||||
private val sendMessage: SendMessage,
|
private val sendMessage: SendMessage,
|
||||||
private val subscriptionManager: SubscriptionManagerCompat
|
private val subscriptionManager: SubscriptionManagerCompat
|
||||||
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState(selectedConversation = threadId)) {
|
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState(threadId = threadId)) {
|
||||||
|
|
||||||
private val conversation by lazy {
|
private val conversation by lazy {
|
||||||
conversationRepo.getConversationAsync(threadId)
|
conversationRepo.getConversationAsync(threadId)
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
|||||||
val view = holder.containerView
|
val view = holder.containerView
|
||||||
|
|
||||||
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
||||||
view.avatars.contacts = message.recipients.map { address -> Recipient(address = address) }
|
view.avatars.recipients = message.recipients.map { address -> Recipient(address = address) }
|
||||||
|
|
||||||
view.recipients.text = message.recipients.joinToString(",") { address ->
|
view.recipients.text = message.recipients.joinToString(",") { address ->
|
||||||
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
|
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
|
||||||
|
|||||||
+4
-2
@@ -38,7 +38,9 @@ import kotlinx.android.synthetic.main.theme_picker_controller.*
|
|||||||
import kotlinx.android.synthetic.main.theme_picker_hsv.*
|
import kotlinx.android.synthetic.main.theme_picker_hsv.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ThemePickerController(val threadId: Long = 0L) : QkController<ThemePickerView, ThemePickerState, ThemePickerPresenter>(), ThemePickerView {
|
class ThemePickerController(
|
||||||
|
val recipientId: Long = 0L
|
||||||
|
) : QkController<ThemePickerView, ThemePickerState, ThemePickerPresenter>(), ThemePickerView {
|
||||||
|
|
||||||
@Inject override lateinit var presenter: ThemePickerPresenter
|
@Inject override lateinit var presenter: ThemePickerPresenter
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ class ThemePickerController(val threadId: Long = 0L) : QkController<ThemePickerV
|
|||||||
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
|
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
|
||||||
|
|
||||||
override fun render(state: ThemePickerState) {
|
override fun render(state: ThemePickerState) {
|
||||||
tabs.setThreadId(state.threadId)
|
tabs.setRecipientId(state.recipientId)
|
||||||
|
|
||||||
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
|
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -34,14 +34,14 @@ import javax.inject.Named
|
|||||||
|
|
||||||
class ThemePickerPresenter @Inject constructor(
|
class ThemePickerPresenter @Inject constructor(
|
||||||
prefs: Preferences,
|
prefs: Preferences,
|
||||||
@Named("threadId") private val threadId: Long,
|
@Named("recipientId") private val recipientId: Long,
|
||||||
private val billingManager: BillingManager,
|
private val billingManager: BillingManager,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val navigator: Navigator,
|
private val navigator: Navigator,
|
||||||
private val widgetManager: WidgetManager
|
private val widgetManager: WidgetManager
|
||||||
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(recipientId = recipientId)) {
|
||||||
|
|
||||||
private val theme: Preference<Int> = prefs.theme(threadId)
|
private val theme: Preference<Int> = prefs.theme(recipientId)
|
||||||
|
|
||||||
override fun bindIntents(view: ThemePickerView) {
|
override fun bindIntents(view: ThemePickerView) {
|
||||||
super.bindIntents(view)
|
super.bindIntents(view)
|
||||||
@@ -55,7 +55,7 @@ class ThemePickerPresenter @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color ->
|
.subscribe { color ->
|
||||||
theme.set(color)
|
theme.set(color)
|
||||||
if (threadId == 0L) {
|
if (recipientId == 0L) {
|
||||||
widgetManager.updateTheme()
|
widgetManager.updateTheme()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ class ThemePickerPresenter @Inject constructor(
|
|||||||
view.showQksmsPlusSnackbar()
|
view.showQksmsPlusSnackbar()
|
||||||
} else {
|
} else {
|
||||||
theme.set(color)
|
theme.set(color)
|
||||||
if (threadId == 0L) {
|
if (recipientId == 0L) {
|
||||||
widgetManager.updateTheme()
|
widgetManager.updateTheme()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
package com.moez.QKSMS.feature.themepicker
|
package com.moez.QKSMS.feature.themepicker
|
||||||
|
|
||||||
data class ThemePickerState(
|
data class ThemePickerState(
|
||||||
val threadId: Long = 0,
|
val recipientId: Long = 0,
|
||||||
val applyThemeVisible: Boolean = false,
|
val applyThemeVisible: Boolean = false,
|
||||||
val newColor: Int = -1,
|
val newColor: Int = -1,
|
||||||
val newTextColor: Int = -1
|
val newTextColor: Int = -1
|
||||||
|
|||||||
+2
-2
@@ -29,7 +29,7 @@ class ThemePickerModule(private val controller: ThemePickerController) {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ControllerScope
|
@ControllerScope
|
||||||
@Named("threadId")
|
@Named("recipientId")
|
||||||
fun provideThreadId(): Long = controller.threadId
|
fun provideThreadId(): Long = controller.recipientId
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ package com.moez.QKSMS.injection
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
@@ -101,8 +102,13 @@ class AppModule(private var application: Application) {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideRxPreferences(context: Context): RxSharedPreferences {
|
fun provideSharedPreferences(context: Context): SharedPreferences {
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideRxPreferences(preferences: SharedPreferences): RxSharedPreferences {
|
||||||
return RxSharedPreferences.create(preferences)
|
return RxSharedPreferences.create(preferences)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,13 +65,6 @@
|
|||||||
app:icon="@drawable/ic_notifications_black_24dp"
|
app:icon="@drawable/ic_notifications_black_24dp"
|
||||||
app:title="@string/info_notifications" />
|
app:title="@string/info_notifications" />
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.PreferenceView
|
|
||||||
android:id="@+id/themePrefs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:icon="@drawable/ic_palette_black_24dp"
|
|
||||||
app:title="@string/info_theme" />
|
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.PreferenceView
|
<com.moez.QKSMS.common.widget.PreferenceView
|
||||||
android:id="@+id/archive"
|
android:id="@+id/archive"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -42,7 +42,10 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
app:layout_constraintBottom_toTopOf="@id/address"
|
app:layout_constraintBottom_toTopOf="@id/address"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/add"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
@@ -54,6 +57,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/name"
|
||||||
app:layout_constraintStart_toStartOf="@id/name"
|
app:layout_constraintStart_toStartOf="@id/name"
|
||||||
app:layout_constraintTop_toBottomOf="@id/name"
|
app:layout_constraintTop_toBottomOf="@id/name"
|
||||||
tools:text="(123) 456-7890" />
|
tools:text="(123) 456-7890" />
|
||||||
@@ -62,10 +66,23 @@
|
|||||||
android:id="@+id/add"
|
android:id="@+id/add"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:src="@drawable/ic_person_add_black_24dp"
|
android:src="@drawable/ic_person_add_black_24dp"
|
||||||
android:tint="?android:attr/textColorSecondary"
|
android:tint="?android:attr/textColorSecondary"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/theme"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/theme"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:src="@drawable/ic_palette_black_24dp"
|
||||||
|
android:tint="?android:attr/textColorSecondary"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user