Per-contact colours

Closes #1120
This commit is contained in:
Moez Bhatti
2019-12-15 20:46:33 -05:00
parent 5d62912508
commit 76e0f775d6
35 changed files with 315 additions and 153 deletions
@@ -30,6 +30,11 @@ 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.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.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
@@ -51,6 +56,9 @@ import javax.inject.Inject
abstract class QkThemedActivity : QkActivity() {
@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
/**
@@ -61,10 +69,40 @@ abstract class QkThemedActivity : QkActivity() {
/**
* 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()
.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")
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 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> {
return prefs.theme(threadId).asObservable()
fun themeObservable(recipientId: Long = 0): Observable<Theme> {
return prefs.theme(recipientId).asObservable()
.map { color -> Theme(color, this) }
}
@@ -113,6 +113,11 @@ class NotificationManagerImpl @Inject constructor(
}
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 taskStackBuilder = TaskStackBuilder.create(context)
@@ -134,7 +139,7 @@ class NotificationManagerImpl @Inject constructor(
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setColor(colors.theme(threadId).theme)
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_notification)
.setNumber(messages.size)
@@ -158,8 +163,9 @@ class NotificationManagerImpl @Inject constructor(
val person = Person.Builder()
if (!message.isMe()) {
val recipient = conversation.recipients
.firstOrNull { phoneNumberUtils.compare(it.address, message.address) }
val recipient = conversation.recipients.find { recipient ->
phoneNumberUtils.compare(recipient.address, message.address)
}
person.setName(recipient?.getDisplayName() ?: message.address)
person.setIcon(GlideApp.with(context)
@@ -302,6 +308,12 @@ class NotificationManagerImpl @Inject constructor(
}
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 contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
@@ -313,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(threadId).theme)
.setColor(colors.theme(lastRecipient?.id ?: 0).theme)
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
.setSmallIcon(R.drawable.ic_notification_failed)
.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
*/
var threadId: Long = 0
var recipientId: Long = 0
set(value) {
if (field == value) return
field = value
@@ -81,13 +81,13 @@ class AvatarView @JvmOverloads constructor(
super.onFinishInflate()
if (!isInEditMode) {
applyTheme(threadId)
applyTheme(recipientId)
updateView()
}
}
private fun applyTheme(threadId: Long) {
colors.theme(threadId).run {
private fun applyTheme(recipientId: Long) {
colors.theme(recipientId).run {
setBackgroundTint(theme)
initial.setTextColor(textPrimary)
icon.setTint(textPrimary)
@@ -35,7 +35,7 @@ class GroupAvatarView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : ConstraintLayout(context, attrs) {
var contacts: List<Recipient> = ArrayList()
var recipients: List<Recipient> = ArrayList()
set(value) {
field = value.sortedWith(compareByDescending { contact -> contact.contact?.lookupKey })
updateView()
@@ -54,17 +54,25 @@ class GroupAvatarView @JvmOverloads constructor(
}
private fun updateView() {
avatar1Frame.setBackgroundTint(when (contacts.size > 1) {
avatar1Frame.setBackgroundTint(when (recipients.size > 1) {
true -> context.resolveThemeColor(android.R.attr.windowBackground)
false -> context.getColorCompat(android.R.color.transparent)
})
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
private val threadId: Subject<Long> = BehaviorSubject.create()
private val recipientId: Subject<Long> = BehaviorSubject.create()
var pager: ViewPager? = null
set(value) {
@@ -55,8 +55,8 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
if (!isInEditMode) appComponent.inject(this)
}
fun setThreadId(id: Long) {
threadId.onNext(id)
fun setRecipientId(id: Long) {
recipientId.onNext(id)
}
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))
threadId
recipientId
.distinctUntilChanged()
.switchMap { threadId -> colors.themeObservable(threadId) }
.switchMap { recipientId -> colors.themeObservable(recipientId) }
.map { theme ->
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
@@ -73,7 +73,7 @@ class BlockedMessagesAdapter @Inject constructor(
view.isActivated = isSelected(conversation.id)
view.avatars.contacts = conversation.recipients
view.avatars.recipients = conversation.recipients
view.title.collapseEnabled = conversation.recipients.size > 1
view.title.text = conversation.getTitle()
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
@@ -150,6 +150,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
.doOnNext { attach.setBackgroundTint(it.theme) }
.doOnNext { attach.setTint(it.textPrimary) }
.doOnNext { messageAdapter.theme = it }
.autoDisposable(scope())
.subscribe()
allThemes
.autoDisposable(scope())
.subscribe { messageList.scrapViews() }
@@ -177,7 +181,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
return
}
threadId.onNext(state.selectedConversation)
threadId.onNext(state.threadId)
title = when {
state.selectedMessages > 0 -> getString(R.string.compose_title_selected, state.selectedMessages)
@@ -28,7 +28,7 @@ import io.realm.RealmResults
data class ComposeState(
val hasError: Boolean = false,
val editingMode: Boolean = false,
val selectedConversation: Long = 0,
val threadId: Long = 0,
val selectedChips: List<Chip> = ArrayList(),
val sendAsGroup: Boolean = true,
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.util.BillingManager
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.extensions.makeToast
import com.moez.QKSMS.compat.SubscriptionManagerCompat
@@ -77,6 +78,7 @@ class ComposeViewModel @Inject constructor(
@Named("addresses") private val addresses: List<String>,
@Named("text") private val sharedText: String,
@Named("attachments") private val sharedAttachments: Attachments,
private val colors: Colors,
private val contactRepo: ContactRepository,
private val context: Context,
private val activeConversationManager: ActiveConversationManager,
@@ -97,7 +99,7 @@ class ComposeViewModel @Inject constructor(
private val subscriptionManager: SubscriptionManagerCompat
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
editingMode = threadId == 0L && addresses.isEmpty(),
selectedConversation = threadId,
threadId = threadId,
query = query)
) {
@@ -171,13 +173,13 @@ class ComposeViewModel @Inject constructor(
.takeUntil(state.filter { state -> !state.editingMode })
.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
.distinctUntilChanged { conversation -> conversation.id }
.observeOn(AndroidSchedulers.mainThread())
.map { conversation ->
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
}
.switchMap { messages -> messages.asObservable() }
@@ -98,9 +98,6 @@ class MessagesAdapter @Inject constructor(
field = value
contactCache.clear()
// Update the theme
theme = colors.theme(value?.first?.id ?: 0)
updateData(value?.second)
}
@@ -145,9 +142,6 @@ class MessagesAdapter @Inject constructor(
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
} else {
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) {
@@ -187,6 +181,11 @@ class MessagesAdapter @Inject constructor(
val next = if (position == itemCount - 1) null else getItem(position + 1)
val view = viewHolder.containerView
val theme = when (message.isOutgoingMessage()) {
true -> colors.theme()
false -> colors.theme(contactCache[message.address]?.id ?: 0)
}
// Update the selected state
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() }
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
// Bind the avatar
// Bind the avatar and bubble colour
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.setVisible(!canGroup(message, next), View.INVISIBLE)
view.body.setTextColor(theme.textPrimary)
view.body.setBackgroundTint(theme.theme)
}
// Bind the body text
@@ -87,7 +87,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
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 }
@@ -102,7 +102,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
view.icon.isVisible = prev !is ComposeItem.Recent
view.icon.setImageResource(R.drawable.ic_history_black_24dp)
view.avatar.contacts = conversation.recipients
view.avatar.recipients = conversation.recipients
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.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
@@ -139,7 +139,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
view.icon.isVisible = prev !is ComposeItem.Group
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
@@ -158,7 +158,7 @@ class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAda
view.icon.isVisible = false
view.avatar.contacts = listOf(Recipient(contact = contact))
view.avatar.recipients = listOf(Recipient(contact = contact))
view.title.text = contact.name
@@ -78,10 +78,9 @@ class ConversationInfoController(
media.adapter = mediaAdapter
media.addItemDecoration(itemDecoration)
themedActivity
?.theme
themedActivity?.theme
?.autoDisposable(scope())
?.subscribe { recipients?.scrapViews() }
?.subscribe { recipients.scrapViews() }
}
override fun onAttach(view: View) {
@@ -91,7 +90,9 @@ class ConversationInfoController(
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()
@@ -99,8 +100,6 @@ class ConversationInfoController(
override fun notificationClicks(): Observable<*> = notifications.clicks()
override fun themeClicks(): Observable<*> = themePrefs.clicks()
override fun archiveClicks(): Observable<*> = archive.clicks()
override fun blockClicks(): Observable<*> = block.clicks()
@@ -115,8 +114,6 @@ class ConversationInfoController(
return
}
themedActivity?.threadId?.onNext(state.threadId)
recipientAdapter.threadId = state.threadId
recipientAdapter.updateData(state.recipients)
name.setVisible(state.recipients?.size ?: 0 >= 2)
@@ -124,8 +121,6 @@ class ConversationInfoController(
notifications.isEnabled = !state.blocked
themePrefs.isEnabled = !state.blocked
archive.isEnabled = !state.blocked
archive.title = activity?.getString(when (state.archived) {
true -> R.string.info_unarchive
@@ -142,8 +137,8 @@ class ConversationInfoController(
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
override fun showThemePicker(threadId: Long) {
router.pushController(RouterTransaction.with(ThemePickerController(threadId))
override fun showThemePicker(recipientId: Long) {
router.pushController(RouterTransaction.with(ThemePickerController(recipientId))
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
@@ -100,7 +100,7 @@ class ConversationInfoPresenter @Inject constructor(
super.bindIntents(view)
// Add or display the contact
view.recipientClicks()
view.contactClicks()
.mapNotNull(conversationRepo::getRecipient)
.doOnNext { recipient ->
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
.subscribe()
// Show the theme settings for the conversation
view.themeClicks()
.autoDisposable(view.scope())
.subscribe(view::showThemePicker)
// Show the conversation title dialog
view.nameClicks()
.withLatestFrom(conversation) { _, conversation -> conversation }
@@ -130,12 +135,6 @@ class ConversationInfoPresenter @Inject constructor(
.autoDisposable(view.scope())
.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
view.archiveClicks()
.withLatestFrom(conversation) { _, conversation -> conversation }
@@ -23,18 +23,18 @@ import io.reactivex.Observable
interface ConversationInfoView : QkViewContract<ConversationInfoState> {
fun recipientClicks(): Observable<Long>
fun contactClicks(): Observable<Long>
fun themeClicks(): Observable<Long>
fun nameClicks(): Observable<*>
fun nameChanges(): Observable<String>
fun notificationClicks(): Observable<*>
fun themeClicks(): Observable<*>
fun archiveClicks(): Observable<*>
fun blockClicks(): Observable<*>
fun deleteClicks(): Observable<*>
fun confirmDelete(): Observable<*>
fun showNameDialog(name: String)
fun showThemePicker(threadId: Long)
fun showThemePicker(recipientId: Long)
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
fun requestDefaultSms()
fun showDeleteDialog()
@@ -20,24 +20,24 @@ package com.moez.QKSMS.feature.conversationinfo
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkRealmAdapter
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.model.Recipient
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
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 clicks: Subject<Long> = PublishSubject.create()
private val disposables = CompositeDisposable()
val contactClicks: Subject<Long> = PublishSubject.create()
val themeClicks: Subject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
@@ -45,7 +45,12 @@ class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipi
return QkViewHolder(view).apply {
view.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 view = holder.containerView
view.avatar.threadId = threadId
view.avatar.recipientId = recipient.id
view.avatar.setContact(recipient.contact)
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.add.setVisible(recipient.contact == null)
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
disposables.clear()
val theme = colors.theme(recipient.id)
view.theme.setTint(theme.theme)
}
}
@@ -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.setTint
import com.moez.QKSMS.model.Conversation
import com.moez.QKSMS.util.PhoneNumberUtils
import kotlinx.android.synthetic.main.conversation_list_item.view.*
import javax.inject.Inject
@@ -39,7 +40,8 @@ class ConversationsAdapter @Inject constructor(
private val colors: Colors,
private val context: Context,
private val dateFormatter: DateFormatter,
private val navigator: Navigator
private val navigator: Navigator,
private val phoneNumberUtils: PhoneNumberUtils
) : QkRealmAdapter<Conversation>() {
init {
@@ -60,7 +62,6 @@ class ConversationsAdapter @Inject constructor(
view.snippet.maxLines = 5
view.unread.isVisible = true
view.unread.setTint(colors.theme().theme)
view.date.setTypeface(view.date.typeface, Typeface.BOLD)
view.date.setTextColor(textColorPrimary)
@@ -85,11 +86,12 @@ class ConversationsAdapter @Inject constructor(
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
val conversation = getItem(position) ?: return
val lastMessage = conversation.lastMessage ?: return
val view = viewHolder.containerView
view.isActivated = isSelected(conversation.id)
view.avatars.contacts = conversation.recipients
view.avatars.recipients = conversation.recipients
view.title.collapseEnabled = conversation.recipients.size > 1
view.title.text = conversation.getTitle()
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
@@ -99,6 +101,16 @@ class ConversationsAdapter @Inject constructor(
else -> conversation.snippet
}
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 {
@@ -108,4 +120,4 @@ class ConversationsAdapter @Inject constructor(
override fun getItemViewType(position: Int): Int {
return if (getItem(position)?.unread == false) 0 else 1
}
}
}
@@ -155,7 +155,6 @@ class MainActivity : QkThemedActivity(), MainView {
// Set the theme color tint to the recyclerView, progressbar, and FAB
theme
.doOnNext { recyclerView.scrapViews() }
.autoDisposable(scope())
.subscribe { theme ->
// Set the color for the drawer icons
@@ -183,6 +182,10 @@ class MainActivity : QkThemedActivity(), MainView {
compose.setTint(theme.textPrimary)
}
allThemes
.autoDisposable(scope())
.subscribe { recyclerView.scrapViews() }
itemTouchCallback.adapter = conversationsAdapter
conversationsAdapter.autoScrollToStart(recyclerView)
@@ -73,7 +73,7 @@ class SearchAdapter @Inject constructor(
}
view.title.text = title
view.avatars.contacts = result.conversation.recipients
view.avatars.recipients = result.conversation.recipients
when (result.messages == 0) {
true -> {
@@ -90,7 +90,7 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
finish()
}
threadId.onNext(state.selectedConversation)
threadId.onNext(state.threadId)
title = state.title
@@ -25,7 +25,7 @@ import io.realm.RealmResults
data class QkReplyState(
val hasError: Boolean = false,
val selectedConversation: Long = 0,
val threadId: Long = 0,
val title: String = "",
val expanded: Boolean = false,
val data: Pair<Conversation, RealmResults<Message>>? = null,
@@ -54,7 +54,7 @@ class QkReplyViewModel @Inject constructor(
private val navigator: Navigator,
private val sendMessage: SendMessage,
private val subscriptionManager: SubscriptionManagerCompat
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState(selectedConversation = threadId)) {
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState(threadId = threadId)) {
private val conversation by lazy {
conversationRepo.getConversationAsync(threadId)
@@ -68,7 +68,7 @@ class ScheduledMessageAdapter @Inject constructor(
val view = holder.containerView
// 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 ->
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
@@ -38,7 +38,9 @@ import kotlinx.android.synthetic.main.theme_picker_controller.*
import kotlinx.android.synthetic.main.theme_picker_hsv.*
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
@@ -107,7 +109,7 @@ class ThemePickerController(val threadId: Long = 0L) : QkController<ThemePickerV
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
override fun render(state: ThemePickerState) {
tabs.setThreadId(state.threadId)
tabs.setRecipientId(state.recipientId)
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
@@ -34,14 +34,14 @@ import javax.inject.Named
class ThemePickerPresenter @Inject constructor(
prefs: Preferences,
@Named("threadId") private val threadId: Long,
@Named("recipientId") private val recipientId: Long,
private val billingManager: BillingManager,
private val colors: Colors,
private val navigator: Navigator,
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) {
super.bindIntents(view)
@@ -55,7 +55,7 @@ class ThemePickerPresenter @Inject constructor(
.autoDisposable(view.scope())
.subscribe { color ->
theme.set(color)
if (threadId == 0L) {
if (recipientId == 0L) {
widgetManager.updateTheme()
}
}
@@ -81,7 +81,7 @@ class ThemePickerPresenter @Inject constructor(
view.showQksmsPlusSnackbar()
} else {
theme.set(color)
if (threadId == 0L) {
if (recipientId == 0L) {
widgetManager.updateTheme()
}
}
@@ -19,7 +19,7 @@
package com.moez.QKSMS.feature.themepicker
data class ThemePickerState(
val threadId: Long = 0,
val recipientId: Long = 0,
val applyThemeVisible: Boolean = false,
val newColor: Int = -1,
val newTextColor: Int = -1
@@ -29,7 +29,7 @@ class ThemePickerModule(private val controller: ThemePickerController) {
@Provides
@ControllerScope
@Named("threadId")
fun provideThreadId(): Long = controller.threadId
@Named("recipientId")
fun provideThreadId(): Long = controller.recipientId
}
@@ -21,6 +21,7 @@ package com.moez.QKSMS.injection
import android.app.Application
import android.content.ContentResolver
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.lifecycle.ViewModelProvider
import com.f2prateek.rx.preferences2.RxSharedPreferences
@@ -101,8 +102,13 @@ class AppModule(private var application: Application) {
@Provides
@Singleton
fun provideRxPreferences(context: Context): RxSharedPreferences {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
fun provideSharedPreferences(context: Context): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(context)
}
@Provides
@Singleton
fun provideRxPreferences(preferences: SharedPreferences): RxSharedPreferences {
return RxSharedPreferences.create(preferences)
}