forked from upstream-mirrors/quik
@@ -19,9 +19,9 @@
|
||||
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.mapper.CursorToContactImpl
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.DynamicRealmObject
|
||||
import io.realm.FieldAttribute
|
||||
@@ -32,7 +32,7 @@ import javax.inject.Inject
|
||||
|
||||
class QkRealmMigration @Inject constructor(
|
||||
private val cursorToContact: CursorToContactImpl,
|
||||
private val prefs: RxSharedPreferences
|
||||
private val prefs: Preferences
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
@@ -176,7 +176,7 @@ class QkRealmMigration @Inject constructor(
|
||||
// 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")}")
|
||||
val pref = prefs.theme(conversation.getLong("id"))
|
||||
if (pref.isSet) {
|
||||
conversation.getList("Recipient").forEach { recipient ->
|
||||
recipients[recipient.getLong("id")] = pref.get()
|
||||
@@ -187,9 +187,12 @@ class QkRealmMigration @Inject constructor(
|
||||
}
|
||||
|
||||
recipients.forEach { (recipientId, theme) ->
|
||||
prefs.getInteger("theme_$recipientId").set(theme)
|
||||
prefs.theme(recipientId).set(theme)
|
||||
}
|
||||
|
||||
// This is enabled for new users, but the behaviour shouldn't change automatically for old users
|
||||
prefs.autoColor.set(false)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ class Preferences @Inject constructor(
|
||||
val nightStart = rxPrefs.getString("nightStart", "18:00")
|
||||
val nightEnd = rxPrefs.getString("nightEnd", "6:00")
|
||||
val black = rxPrefs.getBoolean("black", false)
|
||||
val autoColor = rxPrefs.getBoolean("autoColor", true)
|
||||
val systemFont = rxPrefs.getBoolean("systemFont", false)
|
||||
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
|
||||
val blockingManager = rxPrefs.getInteger("blockingManager", BLOCKING_MANAGER_QKSMS)
|
||||
@@ -140,12 +141,13 @@ class Preferences @Inject constructor(
|
||||
sharedPrefs.registerOnSharedPreferenceChangeListener(listener)
|
||||
}.share()
|
||||
|
||||
fun theme(recipientId: Long = 0): Preference<Int> {
|
||||
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
||||
|
||||
fun theme(
|
||||
recipientId: Long = 0,
|
||||
default: Int = rxPrefs.getInteger("theme", 0xFF0097A7.toInt()).get()
|
||||
): Preference<Int> {
|
||||
return when (recipientId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getInteger("theme_$recipientId", default.get())
|
||||
0L -> rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
||||
else -> rxPrefs.getInteger("theme_$recipientId", default)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeBoolean
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.extensions.Optional
|
||||
import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
@@ -76,9 +77,9 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
.switchMap { threadId ->
|
||||
val conversation = conversationRepo.getConversation(threadId)
|
||||
when {
|
||||
conversation == null -> Observable.just(0L)
|
||||
conversation == null -> Observable.just(Optional(null))
|
||||
|
||||
conversation.recipients.size == 1 -> Observable.just(conversation.recipients.first()?.id ?: 0L)
|
||||
conversation.recipients.size == 1 -> Observable.just(Optional(conversation.recipients.first()))
|
||||
|
||||
else -> messageRepo.getLastIncomingMessage(conversation.id)
|
||||
.asObservable()
|
||||
@@ -89,20 +90,12 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
phoneNumberUtils.compare(recipient.address, message.address)
|
||||
}
|
||||
}
|
||||
.map { recipient -> recipient.id }
|
||||
.startWith(conversation.recipients.firstOrNull()?.id ?: 0)
|
||||
.map { recipient -> Optional(recipient) }
|
||||
.startWith(Optional(conversation.recipients.firstOrNull()))
|
||||
.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") }
|
||||
}
|
||||
.switchMap { colors.themeObservable(it.value) }
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -20,15 +20,23 @@ package com.moez.QKSMS.common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import androidx.core.content.res.getColorOrThrow
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.getColorCompat
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.Observable
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
@Singleton
|
||||
class Colors @Inject constructor(private val context: Context, private val prefs: Preferences) {
|
||||
class Colors @Inject constructor(
|
||||
private val context: Context,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences
|
||||
) {
|
||||
|
||||
data class Theme(val theme: Int, private val colors: Colors) {
|
||||
val highlight by lazy { colors.highlightColorForTheme(theme) }
|
||||
@@ -37,27 +45,31 @@ class Colors @Inject constructor(private val context: Context, private val prefs
|
||||
val textTertiary by lazy { colors.textTertiaryOnThemeForColor(theme) }
|
||||
}
|
||||
|
||||
val materialColors = listOf(
|
||||
listOf(0xffffebee, 0xffffcdd2, 0xffef9a9a, 0xffe57373, 0xffef5350, 0xfff44336, 0xffe53935, 0xffd32f2f, 0xffc62828, 0xffb71c1c),
|
||||
listOf(0xffFCE4EC, 0xffF8BBD0, 0xffF48FB1, 0xffF06292, 0xffEC407A, 0xffE91E63, 0xffD81B60, 0xffC2185B, 0xffAD1457, 0xff880E4F),
|
||||
listOf(0xffF3E5F5, 0xffE1BEE7, 0xffCE93D8, 0xffBA68C8, 0xffAB47BC, 0xff9C27B0, 0xff8E24AA, 0xff7B1FA2, 0xff6A1B9A, 0xff4A148C),
|
||||
listOf(0xffEDE7F6, 0xffD1C4E9, 0xffB39DDB, 0xff9575CD, 0xff7E57C2, 0xff673AB7, 0xff5E35B1, 0xff512DA8, 0xff4527A0, 0xff311B92),
|
||||
listOf(0xffE8EAF6, 0xffC5CAE9, 0xff9FA8DA, 0xff7986CB, 0xff5C6BC0, 0xff3F51B5, 0xff3949AB, 0xff303F9F, 0xff283593, 0xff1A237E),
|
||||
listOf(0xffE3F2FD, 0xffBBDEFB, 0xff90CAF9, 0xff64B5F6, 0xff42A5F5, 0xff2196F3, 0xff1E88E5, 0xff1976D2, 0xff1565C0, 0xff0D47A1),
|
||||
listOf(0xffE1F5FE, 0xffB3E5FC, 0xff81D4FA, 0xff4FC3F7, 0xff29B6F6, 0xff03A9F4, 0xff039BE5, 0xff0288D1, 0xff0277BD, 0xff01579B),
|
||||
listOf(0xffE0F7FA, 0xffB2EBF2, 0xff80DEEA, 0xff4DD0E1, 0xff26C6DA, 0xff00BCD4, 0xff00ACC1, 0xff0097A7, 0xff00838F, 0xff006064),
|
||||
listOf(0xffE0F2F1, 0xffB2DFDB, 0xff80CBC4, 0xff4DB6AC, 0xff26A69A, 0xff009688, 0xff00897B, 0xff00796B, 0xff00695C, 0xff004D40),
|
||||
listOf(0xffE8F5E9, 0xffC8E6C9, 0xffA5D6A7, 0xff81C784, 0xff66BB6A, 0xff4CAF50, 0xff43A047, 0xff388E3C, 0xff2E7D32, 0xff1B5E20),
|
||||
listOf(0xffF1F8E9, 0xffDCEDC8, 0xffC5E1A5, 0xffAED581, 0xff9CCC65, 0xff8BC34A, 0xff7CB342, 0xff689F38, 0xff558B2F, 0xff33691E),
|
||||
listOf(0xffF9FBE7, 0xffF0F4C3, 0xffE6EE9C, 0xffDCE775, 0xffD4E157, 0xffCDDC39, 0xffC0CA33, 0xffAFB42B, 0xff9E9D24, 0xff827717),
|
||||
listOf(0xffFFFDE7, 0xffFFF9C4, 0xffFFF59D, 0xffFFF176, 0xffFFEE58, 0xffFFEB3B, 0xffFDD835, 0xffFBC02D, 0xffF9A825, 0xffF57F17),
|
||||
listOf(0xffFFF8E1, 0xffFFECB3, 0xffFFE082, 0xffFFD54F, 0xffFFCA28, 0xffFFC107, 0xffFFB300, 0xffFFA000, 0xffFF8F00, 0xffFF6F00),
|
||||
listOf(0xffFFF3E0, 0xffFFE0B2, 0xffFFCC80, 0xffFFB74D, 0xffFFA726, 0xffFF9800, 0xffFB8C00, 0xffF57C00, 0xffEF6C00, 0xffE65100),
|
||||
listOf(0xffFBE9E7, 0xffFFCCBC, 0xffFFAB91, 0xffFF8A65, 0xffFF7043, 0xffFF5722, 0xffF4511E, 0xffE64A19, 0xffD84315, 0xffBF360C),
|
||||
listOf(0xffEFEBE9, 0xffD7CCC8, 0xffBCAAA4, 0xffA1887F, 0xff8D6E63, 0xff795548, 0xff6D4C41, 0xff5D4037, 0xff4E342E, 0xff3E2723),
|
||||
listOf(0xffFAFAFA, 0xffF5F5F5, 0xffEEEEEE, 0xffE0E0E0, 0xffBDBDBD, 0xff9E9E9E, 0xff757575, 0xff616161, 0xff424242, 0xff212121),
|
||||
listOf(0xffECEFF1, 0xffCFD8DC, 0xffB0BEC5, 0xff90A4AE, 0xff78909C, 0xff607D8B, 0xff546E7A, 0xff455A64, 0xff37474F, 0xff263238))
|
||||
.map { it.map { it.toInt() } }
|
||||
val materialColors: List<List<Int>> = listOf(
|
||||
R.array.material_red,
|
||||
R.array.material_pink,
|
||||
R.array.material_purple,
|
||||
R.array.material_deep_purple,
|
||||
R.array.material_indigo,
|
||||
R.array.material_blue,
|
||||
R.array.material_light_blue,
|
||||
R.array.material_cyan,
|
||||
R.array.material_teal,
|
||||
R.array.material_green,
|
||||
R.array.material_light_green,
|
||||
R.array.material_lime,
|
||||
R.array.material_yellow,
|
||||
R.array.material_amber,
|
||||
R.array.material_orange,
|
||||
R.array.material_deep_orange,
|
||||
R.array.material_brown,
|
||||
R.array.material_gray,
|
||||
R.array.material_blue_gray)
|
||||
.map { res -> context.resources.obtainTypedArray(res) }
|
||||
.map { typedArray -> (0 until typedArray.length()).map(typedArray::getColorOrThrow) }
|
||||
|
||||
private val randomColors: List<Int> = context.resources.obtainTypedArray(R.array.random_colors)
|
||||
.let { typedArray -> (0 until typedArray.length()).map(typedArray::getColorOrThrow) }
|
||||
|
||||
private val minimumContrastRatio = 2
|
||||
|
||||
@@ -66,10 +78,21 @@ class Colors @Inject constructor(private val context: Context, private val prefs
|
||||
private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark))
|
||||
private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark))
|
||||
|
||||
fun theme(recipientId: Long = 0): Theme = Theme(prefs.theme(recipientId).get(), this)
|
||||
fun theme(recipient: Recipient? = null): Theme {
|
||||
val pref = prefs.theme(recipient?.id ?: 0)
|
||||
val color = when {
|
||||
recipient == null || !prefs.autoColor.get() || pref.isSet -> pref.get()
|
||||
else -> generateColor(recipient)
|
||||
}
|
||||
return Theme(color, this)
|
||||
}
|
||||
|
||||
fun themeObservable(recipientId: Long = 0): Observable<Theme> {
|
||||
return prefs.theme(recipientId).asObservable()
|
||||
fun themeObservable(recipient: Recipient? = null): Observable<Theme> {
|
||||
val pref = when {
|
||||
recipient == null || !prefs.autoColor.get() -> prefs.theme()
|
||||
else -> prefs.theme(recipient.id, generateColor(recipient))
|
||||
}
|
||||
return pref.asObservable()
|
||||
.map { color -> Theme(color, this) }
|
||||
}
|
||||
|
||||
@@ -110,4 +133,12 @@ class Colors @Inject constructor(private val context: Context, private val prefs
|
||||
return 0.2126 * array[0] + 0.7152 * array[1] + 0.0722 * array[2] + 0.05
|
||||
}
|
||||
|
||||
}
|
||||
private fun generateColor(recipient: Recipient): Int {
|
||||
val first = recipient.contact?.name?.firstOrNull()
|
||||
?: phoneNumberUtils.normalizeNumber(recipient.address).firstOrNull()
|
||||
?: '#'
|
||||
|
||||
val index = first.hashCode().absoluteValue % randomColors.size
|
||||
return randomColors[index]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
|
||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
|
||||
.setColor(colors.theme(lastRecipient).theme)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setNumber(messages.size)
|
||||
@@ -325,7 +325,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||
.setContentTitle(context.getString(R.string.notification_message_failed_title))
|
||||
.setContentText(context.getString(R.string.notification_message_failed_text, conversation.getTitle()))
|
||||
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
|
||||
.setColor(colors.theme(lastRecipient).theme)
|
||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||
.setSmallIcon(R.drawable.ic_notification_failed)
|
||||
.setAutoCancel(true)
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
@@ -40,28 +40,20 @@ class AvatarView @JvmOverloads constructor(
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
/**
|
||||
* This value can be changes if we should use the theme from a particular conversation
|
||||
*/
|
||||
var recipientId: Long = 0
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = value
|
||||
applyTheme(value)
|
||||
}
|
||||
|
||||
private var lookupKey: String? = null
|
||||
private var name: String? = null
|
||||
private var photoUri: String? = null
|
||||
private var lastUpdated: Long? = null
|
||||
private var theme: Colors.Theme
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
theme = colors.theme()
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
}
|
||||
@@ -69,11 +61,12 @@ class AvatarView @JvmOverloads constructor(
|
||||
/**
|
||||
* Use the [contact] information to display the avatar.
|
||||
*/
|
||||
fun setContact(contact: Contact?) {
|
||||
lookupKey = contact?.lookupKey
|
||||
name = contact?.name
|
||||
photoUri = contact?.photoUri
|
||||
lastUpdated = contact?.lastUpdate
|
||||
fun setRecipient(recipient: Recipient?) {
|
||||
lookupKey = recipient?.contact?.lookupKey
|
||||
name = recipient?.contact?.name
|
||||
photoUri = recipient?.contact?.photoUri
|
||||
lastUpdated = recipient?.contact?.lastUpdate
|
||||
theme = colors.theme(recipient)
|
||||
updateView()
|
||||
}
|
||||
|
||||
@@ -81,20 +74,16 @@ class AvatarView @JvmOverloads constructor(
|
||||
super.onFinishInflate()
|
||||
|
||||
if (!isInEditMode) {
|
||||
applyTheme(recipientId)
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyTheme(recipientId: Long) {
|
||||
colors.theme(recipientId).run {
|
||||
setBackgroundTint(theme)
|
||||
initial.setTextColor(textPrimary)
|
||||
icon.setTint(textPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
// Apply theme
|
||||
setBackgroundTint(theme.theme)
|
||||
initial.setTextColor(theme.textPrimary)
|
||||
icon.setTint(theme.textPrimary)
|
||||
|
||||
if (name?.isNotEmpty() == true) {
|
||||
val initials = name?.split(" ").orEmpty()
|
||||
.filter { name -> name.isNotEmpty() }
|
||||
|
||||
@@ -64,15 +64,8 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
avatar2.isVisible = recipients.size > 1
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
recipients.getOrNull(0).run(avatar1::setRecipient)
|
||||
recipients.getOrNull(1).run(avatar2::setRecipient)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forEach
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.extensions.Optional
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.uber.autodispose.android.ViewScopeProvider
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
@@ -40,6 +42,7 @@ import javax.inject.Inject
|
||||
class PagerTitleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
|
||||
private val recipientId: Subject<Long> = BehaviorSubject.create()
|
||||
|
||||
@@ -92,7 +95,8 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
recipientId
|
||||
.distinctUntilChanged()
|
||||
.switchMap { recipientId -> colors.themeObservable(recipientId) }
|
||||
.map { recipientId -> Optional(conversationRepo.getRecipient(recipientId)) }
|
||||
.switchMap { recipient -> colors.themeObservable(recipient.value) }
|
||||
.map { theme ->
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
||||
|
||||
@@ -153,10 +153,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
|
||||
allThemes
|
||||
.autoDisposable(scope())
|
||||
.subscribe { messageList.scrapViews() }
|
||||
|
||||
window.callback = ComposeWindowCallback(window.callback, this)
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
@@ -299,6 +295,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
startActivityForResult(intent, SelectContactRequestCode)
|
||||
}
|
||||
|
||||
override fun themeChanged() {
|
||||
messageList.scrapViews()
|
||||
}
|
||||
|
||||
override fun showKeyboard() {
|
||||
message.postDelayed({
|
||||
message.showKeyboard()
|
||||
|
||||
@@ -62,6 +62,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
fun requestStoragePermission()
|
||||
fun requestSmsPermission()
|
||||
fun showContacts(sharing: Boolean, chips: List<Chip>)
|
||||
fun themeChanged()
|
||||
fun showKeyboard()
|
||||
fun requestCamera()
|
||||
fun requestGallery()
|
||||
|
||||
@@ -394,6 +394,13 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::scrollToMessage)
|
||||
|
||||
// Theme changes
|
||||
prefs.keyChanges
|
||||
.filter { key -> key.contains("theme") }
|
||||
.doOnNext { view.themeChanged() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Retry sending
|
||||
view.messageClickIntent
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
|
||||
@@ -183,7 +183,7 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
val theme = when (message.isOutgoingMessage()) {
|
||||
true -> colors.theme()
|
||||
false -> colors.theme(contactCache[message.address]?.id ?: 0)
|
||||
false -> colors.theme(contactCache[message.address])
|
||||
}
|
||||
|
||||
// Update the selected state
|
||||
@@ -232,8 +232,7 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
// Bind the avatar and bubble colour
|
||||
if (!message.isMe()) {
|
||||
view.avatar.recipientId = contactCache[message.address]?.id ?: 0
|
||||
view.avatar.setContact(contactCache[message.address]?.contact)
|
||||
view.avatar.setRecipient(contactCache[message.address])
|
||||
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||
|
||||
view.body.setTextColor(theme.textPrimary)
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import kotlinx.android.synthetic.main.contact_chip.view.*
|
||||
@@ -60,7 +61,7 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
val chip = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
view.avatar.setContact(chip.contact)
|
||||
view.avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
view.name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import kotlinx.android.synthetic.main.contact_chip_detailed.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -54,7 +55,7 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||
}
|
||||
|
||||
fun setChip(chip: Chip) {
|
||||
avatar.setContact(chip.contact)
|
||||
avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
info.text = chip.address
|
||||
}
|
||||
|
||||
+2
-3
@@ -59,8 +59,7 @@ class ConversationRecipientAdapter @Inject constructor(
|
||||
val recipient = getItem(position) ?: return
|
||||
val view = holder.containerView
|
||||
|
||||
view.avatar.recipientId = recipient.id
|
||||
view.avatar.setContact(recipient.contact)
|
||||
view.avatar.setRecipient(recipient)
|
||||
|
||||
view.name.text = recipient.contact?.name ?: recipient.address
|
||||
|
||||
@@ -69,7 +68,7 @@ class ConversationRecipientAdapter @Inject constructor(
|
||||
|
||||
view.add.setVisible(recipient.contact == null)
|
||||
|
||||
val theme = colors.theme(recipient.id)
|
||||
val theme = colors.theme(recipient)
|
||||
view.theme.setTint(theme.theme)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
view.unread.setTint(colors.theme(recipient?.id ?: 0).theme)
|
||||
view.unread.setTint(colors.theme(recipient).theme)
|
||||
}
|
||||
|
||||
override fun getItemId(index: Int): Long {
|
||||
|
||||
@@ -83,7 +83,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
override val onNewIntentIntent: Subject<Intent> = PublishSubject.create()
|
||||
override val activityResumedIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val activityResumedIntent: Subject<Boolean> = PublishSubject.create()
|
||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||
override val composeIntent by lazy { compose.clicks() }
|
||||
override val drawerOpenIntent: Observable<Boolean> by lazy {
|
||||
@@ -182,10 +182,6 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
compose.setTint(theme.textPrimary)
|
||||
}
|
||||
|
||||
allThemes
|
||||
.autoDisposable(scope())
|
||||
.subscribe { recyclerView.scrapViews() }
|
||||
|
||||
itemTouchCallback.adapter = conversationsAdapter
|
||||
conversationsAdapter.autoScrollToStart(recyclerView)
|
||||
|
||||
@@ -330,7 +326,12 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
activityResumedIntent.onNext(Unit)
|
||||
activityResumedIntent.onNext(true)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
activityResumedIntent.onNext(false)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@@ -366,6 +367,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
conversationsAdapter.clearSelection()
|
||||
}
|
||||
|
||||
override fun themeChanged() {
|
||||
recyclerView.scrapViews()
|
||||
}
|
||||
|
||||
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
|
||||
blockingDialog.show(this, conversations, block)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import io.reactivex.Observable
|
||||
interface MainView : QkView<MainState> {
|
||||
|
||||
val onNewIntentIntent: Observable<Intent>
|
||||
val activityResumedIntent: Observable<*>
|
||||
val activityResumedIntent: Observable<Boolean>
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val composeIntent: Observable<Unit>
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
@@ -47,6 +47,7 @@ interface MainView : QkView<MainState> {
|
||||
fun requestPermissions()
|
||||
fun clearSearch()
|
||||
fun clearSelection()
|
||||
fun themeChanged()
|
||||
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
|
||||
fun showDeleteDialog(conversations: List<Long>)
|
||||
fun showChangelog(changelog: ChangelogManager.Changelog)
|
||||
|
||||
@@ -131,6 +131,7 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
val permissions = view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { Triple(permissionManager.isDefaultSms(), permissionManager.hasReadSms(), permissionManager.hasContacts()) }
|
||||
.distinctUntilChanged()
|
||||
@@ -202,6 +203,20 @@ class MainViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { data -> newState { copy(page = Searching(loading = false, data = data)) } }
|
||||
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> !resumed }
|
||||
.switchMap {
|
||||
// Take until the activity is resumed
|
||||
prefs.keyChanges
|
||||
.filter { key -> key.contains("theme") }
|
||||
.map { true }
|
||||
.mergeWith(prefs.autoColor.asObservable())
|
||||
.doOnNext { view.themeChanged() }
|
||||
.takeUntil(view.activityResumedIntent.filter { resumed -> resumed })
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose() }
|
||||
|
||||
@@ -161,6 +161,9 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
|
||||
textSize.summary = state.textSizeSummary
|
||||
textSizeDialog.adapter.selectedItem = state.textSizeId
|
||||
|
||||
autoColor.checkbox.isChecked = state.autoColor
|
||||
|
||||
systemFont.checkbox.isChecked = state.systemFontEnabled
|
||||
|
||||
unicode.checkbox.isChecked = state.stripUnicodeEnabled
|
||||
|
||||
@@ -100,6 +100,9 @@ class SettingsPresenter @Inject constructor(
|
||||
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
}
|
||||
|
||||
disposables += prefs.autoColor.asObservable()
|
||||
.subscribe { autoColor -> newState { copy(autoColor = autoColor) } }
|
||||
|
||||
disposables += prefs.systemFont.asObservable()
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
|
||||
@@ -164,6 +167,8 @@ class SettingsPresenter @Inject constructor(
|
||||
|
||||
R.id.textSize -> view.showTextSizePicker()
|
||||
|
||||
R.id.autoColor -> prefs.autoColor.set(!prefs.autoColor.get())
|
||||
|
||||
R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get())
|
||||
|
||||
R.id.unicode -> prefs.unicode.set(!prefs.unicode.get())
|
||||
|
||||
@@ -28,6 +28,7 @@ data class SettingsState(
|
||||
val nightStart: String = "",
|
||||
val nightEnd: String = "",
|
||||
val black: Boolean = false,
|
||||
val autoColor: Boolean = true,
|
||||
val autoEmojiEnabled: Boolean = true,
|
||||
val notificationsEnabled: Boolean = true,
|
||||
val sendDelaySummary: String = "",
|
||||
|
||||
@@ -84,6 +84,14 @@
|
||||
app:icon="@drawable/ic_format_size_black_24dp"
|
||||
app:title="@string/settings_text_size_title" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/autoColor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_person_black_24dp"
|
||||
app:title="@string/settings_automatic_colors_title"
|
||||
app:widget="@layout/settings_switch_widget" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/systemFont"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -64,4 +64,264 @@
|
||||
|
||||
<!-- This colour should only ever be used for attrs with the tools tag -->
|
||||
<color name="tools_theme">#00838F</color>
|
||||
|
||||
<array name="random_colors">
|
||||
<item>#e57373</item>
|
||||
<item>#7986CB</item>
|
||||
<item>#00BFA5</item>
|
||||
<item>#81C784</item>
|
||||
<item>#FFAB40</item>
|
||||
<item>#FF8A65</item>
|
||||
<item>#8d6e63</item>
|
||||
<item>#448AFF</item>
|
||||
<item>#78909c</item>
|
||||
</array>
|
||||
|
||||
<array name="material_red">
|
||||
<item>#FFEBEE</item>
|
||||
<item>#FFCDD2</item>
|
||||
<item>#EF9A9A</item>
|
||||
<item>#E57373</item>
|
||||
<item>#EF5350</item>
|
||||
<item>#F44336</item>
|
||||
<item>#E53935</item>
|
||||
<item>#D32F2F</item>
|
||||
<item>#C62828</item>
|
||||
<item>#B71C1C</item>
|
||||
</array>
|
||||
|
||||
<array name="material_pink">
|
||||
<item>#FCE4EC</item>
|
||||
<item>#F8BBD0</item>
|
||||
<item>#F48FB1</item>
|
||||
<item>#F06292</item>
|
||||
<item>#EC407A</item>
|
||||
<item>#E91E63</item>
|
||||
<item>#D81B60</item>
|
||||
<item>#C2185B</item>
|
||||
<item>#AD1457</item>
|
||||
<item>#880E4F</item>
|
||||
</array>
|
||||
|
||||
<array name="material_purple">
|
||||
<item>#F3E5F5</item>
|
||||
<item>#E1BEE7</item>
|
||||
<item>#CE93D8</item>
|
||||
<item>#BA68C8</item>
|
||||
<item>#AB47BC</item>
|
||||
<item>#9C27B0</item>
|
||||
<item>#8E24AA</item>
|
||||
<item>#7B1FA2</item>
|
||||
<item>#6A1B9A</item>
|
||||
<item>#4A148C</item>
|
||||
</array>
|
||||
|
||||
<array name="material_deep_purple">
|
||||
<item>#EDE7F6</item>
|
||||
<item>#D1C4E9</item>
|
||||
<item>#B39DDB</item>
|
||||
<item>#9575CD</item>
|
||||
<item>#7E57C2</item>
|
||||
<item>#673AB7</item>
|
||||
<item>#5E35B1</item>
|
||||
<item>#512DA8</item>
|
||||
<item>#4527A0</item>
|
||||
<item>#311B92</item>
|
||||
</array>
|
||||
|
||||
<array name="material_indigo">
|
||||
<item>#E8EAF6</item>
|
||||
<item>#C5CAE9</item>
|
||||
<item>#9FA8DA</item>
|
||||
<item>#7986CB</item>
|
||||
<item>#5C6BC0</item>
|
||||
<item>#3F51B5</item>
|
||||
<item>#3949AB</item>
|
||||
<item>#303F9F</item>
|
||||
<item>#283593</item>
|
||||
<item>#1A237E</item>
|
||||
</array>
|
||||
|
||||
<array name="material_blue">
|
||||
<item>#E3F2FD</item>
|
||||
<item>#BBDEFB</item>
|
||||
<item>#90CAF9</item>
|
||||
<item>#64B5F6</item>
|
||||
<item>#42A5F5</item>
|
||||
<item>#2196F3</item>
|
||||
<item>#1E88E5</item>
|
||||
<item>#1976D2</item>
|
||||
<item>#1565C0</item>
|
||||
<item>#0D47A1</item>
|
||||
</array>
|
||||
|
||||
<array name="material_light_blue">
|
||||
<item>#E1F5FE</item>
|
||||
<item>#B3E5FC</item>
|
||||
<item>#81D4FA</item>
|
||||
<item>#4FC3F7</item>
|
||||
<item>#29B6F6</item>
|
||||
<item>#03A9F4</item>
|
||||
<item>#039BE5</item>
|
||||
<item>#0288D1</item>
|
||||
<item>#0277BD</item>
|
||||
<item>#01579B</item>
|
||||
</array>
|
||||
|
||||
<array name="material_cyan">
|
||||
<item>#E0F7FA</item>
|
||||
<item>#B2EBF2</item>
|
||||
<item>#80DEEA</item>
|
||||
<item>#4DD0E1</item>
|
||||
<item>#26C6DA</item>
|
||||
<item>#00BCD4</item>
|
||||
<item>#00ACC1</item>
|
||||
<item>#0097A7</item>
|
||||
<item>#00838F</item>
|
||||
<item>#006064</item>
|
||||
</array>
|
||||
|
||||
<array name="material_teal">
|
||||
<item>#E0F2F1</item>
|
||||
<item>#B2DFDB</item>
|
||||
<item>#80CBC4</item>
|
||||
<item>#4DB6AC</item>
|
||||
<item>#26A69A</item>
|
||||
<item>#009688</item>
|
||||
<item>#00897B</item>
|
||||
<item>#00796B</item>
|
||||
<item>#00695C</item>
|
||||
<item>#004D40</item>
|
||||
</array>
|
||||
|
||||
<array name="material_green">
|
||||
<item>#E8F5E9</item>
|
||||
<item>#C8E6C9</item>
|
||||
<item>#A5D6A7</item>
|
||||
<item>#81C784</item>
|
||||
<item>#66BB6A</item>
|
||||
<item>#4CAF50</item>
|
||||
<item>#43A047</item>
|
||||
<item>#388E3C</item>
|
||||
<item>#2E7D32</item>
|
||||
<item>#1B5E20</item>
|
||||
</array>
|
||||
|
||||
<array name="material_light_green">
|
||||
<item>#F1F8E9</item>
|
||||
<item>#DCEDC8</item>
|
||||
<item>#C5E1A5</item>
|
||||
<item>#AED581</item>
|
||||
<item>#9CCC65</item>
|
||||
<item>#8BC34A</item>
|
||||
<item>#7CB342</item>
|
||||
<item>#689F38</item>
|
||||
<item>#558B2F</item>
|
||||
<item>#33691E</item>
|
||||
</array>
|
||||
|
||||
<array name="material_lime">
|
||||
<item>#F9FBE7</item>
|
||||
<item>#F0F4C3</item>
|
||||
<item>#E6EE9C</item>
|
||||
<item>#DCE775</item>
|
||||
<item>#D4E157</item>
|
||||
<item>#CDDC39</item>
|
||||
<item>#C0CA33</item>
|
||||
<item>#AFB42B</item>
|
||||
<item>#9E9D24</item>
|
||||
<item>#827717</item>
|
||||
</array>
|
||||
|
||||
<array name="material_yellow">
|
||||
<item>#FFFDE7</item>
|
||||
<item>#FFF9C4</item>
|
||||
<item>#FFF59D</item>
|
||||
<item>#FFF176</item>
|
||||
<item>#FFEE58</item>
|
||||
<item>#FFEB3B</item>
|
||||
<item>#FDD835</item>
|
||||
<item>#FBC02D</item>
|
||||
<item>#F9A825</item>
|
||||
<item>#F57F17</item>
|
||||
</array>
|
||||
|
||||
<array name="material_amber">
|
||||
<item>#FFF8E1</item>
|
||||
<item>#FFECB3</item>
|
||||
<item>#FFE082</item>
|
||||
<item>#FFD54F</item>
|
||||
<item>#FFCA28</item>
|
||||
<item>#FFC107</item>
|
||||
<item>#FFB300</item>
|
||||
<item>#FFA000</item>
|
||||
<item>#FF8F00</item>
|
||||
<item>#FF6F00</item>
|
||||
</array>
|
||||
|
||||
<array name="material_orange">
|
||||
<item>#FFF3E0</item>
|
||||
<item>#FFE0B2</item>
|
||||
<item>#FFCC80</item>
|
||||
<item>#FFB74D</item>
|
||||
<item>#FFA726</item>
|
||||
<item>#FF9800</item>
|
||||
<item>#FB8C00</item>
|
||||
<item>#F57C00</item>
|
||||
<item>#EF6C00</item>
|
||||
<item>#E65100</item>
|
||||
</array>
|
||||
|
||||
<array name="material_deep_orange">
|
||||
<item>#FBE9E7</item>
|
||||
<item>#FFCCBC</item>
|
||||
<item>#FFAB91</item>
|
||||
<item>#FF8A65</item>
|
||||
<item>#FF7043</item>
|
||||
<item>#FF5722</item>
|
||||
<item>#F4511E</item>
|
||||
<item>#E64A19</item>
|
||||
<item>#D84315</item>
|
||||
<item>#BF360C</item>
|
||||
</array>
|
||||
|
||||
<array name="material_brown">
|
||||
<item>#EFEBE9</item>
|
||||
<item>#D7CCC8</item>
|
||||
<item>#BCAAA4</item>
|
||||
<item>#A1887F</item>
|
||||
<item>#8D6E63</item>
|
||||
<item>#795548</item>
|
||||
<item>#6D4C41</item>
|
||||
<item>#5D4037</item>
|
||||
<item>#4E342E</item>
|
||||
<item>#3E2723</item>
|
||||
</array>
|
||||
|
||||
<array name="material_gray">
|
||||
<item>#FAFAFA</item>
|
||||
<item>#F5F5F5</item>
|
||||
<item>#EEEEEE</item>
|
||||
<item>#E0E0E0</item>
|
||||
<item>#BDBDBD</item>
|
||||
<item>#9E9E9E</item>
|
||||
<item>#757575</item>
|
||||
<item>#616161</item>
|
||||
<item>#424242</item>
|
||||
<item>#212121</item>
|
||||
</array>
|
||||
|
||||
<array name="material_blue_gray">
|
||||
<item>#ECEFF1</item>
|
||||
<item>#CFD8DC</item>
|
||||
<item>#B0BEC5</item>
|
||||
<item>#90A4AE</item>
|
||||
<item>#78909C</item>
|
||||
<item>#607D8B</item>
|
||||
<item>#546E7A</item>
|
||||
<item>#455A64</item>
|
||||
<item>#37474F</item>
|
||||
<item>#263238</item>
|
||||
</array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -213,6 +213,7 @@
|
||||
<string name="settings_black_title">Pure black night mode</string>
|
||||
<string name="settings_night_start_title">Start time</string>
|
||||
<string name="settings_night_end_title">End time</string>
|
||||
<string name="settings_automatic_colors_title">Automatic contact colors</string>
|
||||
<string name="settings_text_size_title">Font size</string>
|
||||
<string name="settings_system_font_title">Use system font</string>
|
||||
<string name="settings_auto_emoji_title">Automatic emoji</string>
|
||||
|
||||
Reference in New Issue
Block a user