mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
@@ -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 = "",
|
||||
|
||||
Reference in New Issue
Block a user