mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-20 12:48:53 +01:00
Add per-conversation theme support
This commit is contained in:
@@ -31,7 +31,7 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Colors @Inject constructor(private val context: Context, prefs: Preferences) {
|
class Colors @Inject constructor(private val context: Context, private val prefs: Preferences) {
|
||||||
|
|
||||||
val materialColors = listOf(
|
val materialColors = listOf(
|
||||||
listOf(0xffffebee, 0xffffcdd2, 0xffef9a9a, 0xffe57373, 0xffef5350, 0xfff44336, 0xffe53935, 0xffd32f2f, 0xffc62828, 0xffb71c1c),
|
listOf(0xffffebee, 0xffffcdd2, 0xffef9a9a, 0xffe57373, 0xffef5350, 0xfff44336, 0xffe53935, 0xffd32f2f, 0xffc62828, 0xffb71c1c),
|
||||||
@@ -62,8 +62,7 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
|
|||||||
private val secondaryTextLuminance = measureLuminance(getColor(R.color.textSecondaryDark))
|
private val secondaryTextLuminance = measureLuminance(getColor(R.color.textSecondaryDark))
|
||||||
private val tertiaryTextLuminance = measureLuminance(getColor(R.color.textTertiaryDark))
|
private val tertiaryTextLuminance = measureLuminance(getColor(R.color.textTertiaryDark))
|
||||||
|
|
||||||
val theme: Observable<Int> = prefs.theme.asObservable()
|
val theme = themeForConversation()
|
||||||
.distinctUntilChanged()
|
|
||||||
|
|
||||||
val appThemeResources = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
|
val appThemeResources = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
|
||||||
{ night, black ->
|
{ night, black ->
|
||||||
@@ -158,29 +157,11 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
|
|||||||
.map { res -> getColor(res) }
|
.map { res -> getColor(res) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val textPrimaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
val textPrimaryOnTheme = textPrimaryOnThemeForConversation()
|
||||||
.map { theme -> measureLuminance(theme) }
|
|
||||||
.map { themeLuminance -> primaryTextLuminance / themeLuminance }
|
|
||||||
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
|
||||||
.map { contrastRatio -> if (contrastRatio) R.color.textPrimary else R.color.textPrimaryDark }
|
|
||||||
.map { res -> getColor(res) }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
|
|
||||||
val textSecondaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
val textSecondaryOnTheme = textSecondaryOnThemeForConversation()
|
||||||
.map { theme -> measureLuminance(theme) }
|
|
||||||
.map { themeLuminance -> secondaryTextLuminance / themeLuminance }
|
|
||||||
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
|
||||||
.map { contrastRatio -> if (contrastRatio) R.color.textSecondary else R.color.textSecondaryDark }
|
|
||||||
.map { res -> getColor(res) }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
|
|
||||||
val textTertiaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
val textTertiaryOnTheme = textTertiaryOnThemeForConversation()
|
||||||
.map { theme -> measureLuminance(theme) }
|
|
||||||
.map { themeLuminance -> tertiaryTextLuminance / themeLuminance }
|
|
||||||
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
|
||||||
.map { contrastRatio -> if (contrastRatio) R.color.textTertiary else R.color.textTertiaryDark }
|
|
||||||
.map { res -> getColor(res) }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
|
|
||||||
val bubble: Observable<Int> = prefs.night.asObservable()
|
val bubble: Observable<Int> = prefs.night.asObservable()
|
||||||
.map { night -> if (night) R.color.bubbleDark else R.color.bubbleLight }
|
.map { night -> if (night) R.color.bubbleDark else R.color.bubbleLight }
|
||||||
@@ -207,6 +188,34 @@ class Colors @Inject constructor(private val context: Context, prefs: Preference
|
|||||||
.map { res -> getColor(res) }
|
.map { res -> getColor(res) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
fun themeForConversation(threadId: Long = 0): Observable<Int> = prefs.theme(threadId)
|
||||||
|
.asObservable()
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
fun textPrimaryOnThemeForConversation(threadId: Long = 0): Observable<Int> = themeForConversation(threadId)
|
||||||
|
.map { theme -> measureLuminance(theme) }
|
||||||
|
.map { themeLuminance -> primaryTextLuminance / themeLuminance }
|
||||||
|
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
||||||
|
.map { contrastRatio -> if (contrastRatio) R.color.textPrimary else R.color.textPrimaryDark }
|
||||||
|
.map { res -> getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
fun textSecondaryOnThemeForConversation(threadId: Long = 0): Observable<Int> = themeForConversation(threadId)
|
||||||
|
.map { theme -> measureLuminance(theme) }
|
||||||
|
.map { themeLuminance -> secondaryTextLuminance / themeLuminance }
|
||||||
|
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
||||||
|
.map { contrastRatio -> if (contrastRatio) R.color.textSecondary else R.color.textSecondaryDark }
|
||||||
|
.map { res -> getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
fun textTertiaryOnThemeForConversation(threadId: Long = 0): Observable<Int> = themeForConversation(threadId)
|
||||||
|
.map { theme -> measureLuminance(theme) }
|
||||||
|
.map { themeLuminance -> tertiaryTextLuminance / themeLuminance }
|
||||||
|
.map { contrastRatio -> contrastRatio < minimumContrastRatio }
|
||||||
|
.map { contrastRatio -> if (contrastRatio) R.color.textTertiary else R.color.textTertiaryDark }
|
||||||
|
.map { res -> getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
private fun getColor(@ColorRes res: Int): Int {
|
private fun getColor(@ColorRes res: Int): Int {
|
||||||
return context.resources.getColor(res)
|
return context.resources.getColor(res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class NotificationManager @Inject constructor(
|
|||||||
val readAction = NotificationCompat.Action(R.drawable.ic_done_black_24dp, context.getString(R.string.notification_read), readPI)
|
val readAction = NotificationCompat.Action(R.drawable.ic_done_black_24dp, context.getString(R.string.notification_read), readPI)
|
||||||
|
|
||||||
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
|
||||||
.setColor(colors.theme.blockingFirst())
|
.setColor(colors.themeForConversation(threadId).blockingFirst())
|
||||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setNumber(messages.size)
|
.setNumber(messages.size)
|
||||||
@@ -149,7 +149,7 @@ class NotificationManager @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.blockingFirst())
|
.setColor(colors.themeForConversation(threadId).blockingFirst())
|
||||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||||
.setSmallIcon(R.drawable.ic_notification_failed)
|
.setSmallIcon(R.drawable.ic_notification_failed)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
|||||||
}
|
}
|
||||||
|
|
||||||
val defaultSms = rxPrefs.getBoolean("defaultSms", false)
|
val defaultSms = rxPrefs.getBoolean("defaultSms", false)
|
||||||
val theme = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
|
||||||
val night = rxPrefs.getBoolean("night", false)
|
val night = rxPrefs.getBoolean("night", false)
|
||||||
val nightMode = rxPrefs.getInteger("nightModeSummary", NIGHT_MODE_OFF)
|
val nightMode = rxPrefs.getInteger("nightModeSummary", NIGHT_MODE_OFF)
|
||||||
val nightStart = rxPrefs.getString("nightStart", "6:00 PM")
|
val nightStart = rxPrefs.getString("nightStart", "6:00 PM")
|
||||||
@@ -46,6 +45,15 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
|||||||
val mms = rxPrefs.getBoolean("mms", true)
|
val mms = rxPrefs.getBoolean("mms", true)
|
||||||
val mmsSize = rxPrefs.getInteger("mmsSize", 100)
|
val mmsSize = rxPrefs.getInteger("mmsSize", 100)
|
||||||
|
|
||||||
|
fun theme(threadId: Long = 0): Preference<Int> {
|
||||||
|
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
|
||||||
|
|
||||||
|
return when (threadId) {
|
||||||
|
0L -> default
|
||||||
|
else -> rxPrefs.getInteger("theme_$threadId", default.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun notifications(threadId: Long = 0): Preference<Boolean> {
|
fun notifications(threadId: Long = 0): Preference<Boolean> {
|
||||||
val default = rxPrefs.getBoolean("notifications", true)
|
val default = rxPrefs.getBoolean("notifications", true)
|
||||||
|
|
||||||
|
|||||||
@@ -133,8 +133,9 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showThemePicker() {
|
fun showThemePicker(threadId: Long = 0) {
|
||||||
val intent = Intent(context, ThemePickerActivity::class.java)
|
val intent = Intent(context, ThemePickerActivity::class.java)
|
||||||
|
intent.putExtra("threadId", threadId)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
|||||||
NotificationPrefsViewModel::class.java -> NotificationPrefsViewModel(intent)
|
NotificationPrefsViewModel::class.java -> NotificationPrefsViewModel(intent)
|
||||||
SettingsViewModel::class.java -> SettingsViewModel()
|
SettingsViewModel::class.java -> SettingsViewModel()
|
||||||
BlockedViewModel::class.java -> BlockedViewModel()
|
BlockedViewModel::class.java -> BlockedViewModel()
|
||||||
ThemePickerViewModel::class.java -> ThemePickerViewModel()
|
ThemePickerViewModel::class.java -> ThemePickerViewModel(intent)
|
||||||
else -> throw IllegalArgumentException("Invalid ViewModel class. If this is a new ViewModel, please add it to Navigator.kt")
|
else -> throw IllegalArgumentException("Invalid ViewModel class. If this is a new ViewModel, please add it to Navigator.kt")
|
||||||
} as T
|
} as T
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import com.uber.autodispose.android.lifecycle.scope
|
|||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.util.Colors
|
import common.util.Colors
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
|
import io.reactivex.subjects.BehaviorSubject
|
||||||
|
import io.reactivex.subjects.Subject
|
||||||
import kotlinx.android.synthetic.main.toolbar.*
|
import kotlinx.android.synthetic.main.toolbar.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -39,6 +41,19 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
|
|||||||
|
|
||||||
@Inject lateinit var colors: Colors
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case the activity should be themed for a specific conversation, the selected conversation
|
||||||
|
* can be changed by pushing the threadId to this subject
|
||||||
|
*/
|
||||||
|
protected val threadId: Subject<Long> = BehaviorSubject.createDefault(0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch the theme if the threadId changes
|
||||||
|
*/
|
||||||
|
protected val theme = threadId
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.switchMap { threadId -> colors.themeForConversation(threadId) }
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -59,12 +74,12 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
|
|||||||
super.onPostCreate(savedInstanceState)
|
super.onPostCreate(savedInstanceState)
|
||||||
|
|
||||||
// Update the colours of the menu items
|
// Update the colours of the menu items
|
||||||
Observables.combineLatest(menu, colors.theme, colors.textTertiary, { menu, theme, textTertiary ->
|
Observables.combineLatest(menu, theme, colors.textTertiary, { menu, theme, textTertiary ->
|
||||||
(0 until menu.size())
|
(0 until menu.size())
|
||||||
.map { position -> menu.getItem(position) }
|
.map { position -> menu.getItem(position) }
|
||||||
.forEach { menuItem ->
|
.forEach { menuItem ->
|
||||||
menuItem?.icon?.run {
|
menuItem?.icon?.run {
|
||||||
setTint(when(menuItem.itemId) {
|
setTint(when (menuItem.itemId) {
|
||||||
R.id.info -> textTertiary
|
R.id.info -> textTertiary
|
||||||
else -> theme
|
else -> theme
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,13 +23,12 @@ import android.graphics.Typeface
|
|||||||
import android.support.v7.widget.AppCompatTextView
|
import android.support.v7.widget.AppCompatTextView
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.uber.autodispose.android.scope
|
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
|
||||||
import common.di.appComponent
|
import common.di.appComponent
|
||||||
import common.util.Colors
|
import common.util.Colors
|
||||||
import common.util.FontProvider
|
import common.util.FontProvider
|
||||||
import common.util.extensions.getColorCompat
|
import common.util.extensions.getColorCompat
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
||||||
@@ -47,7 +46,17 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
@Inject lateinit var colors: Colors
|
@Inject lateinit var colors: Colors
|
||||||
@Inject lateinit var fontProvider: FontProvider
|
@Inject lateinit var fontProvider: FontProvider
|
||||||
|
|
||||||
private var textColorObservable: Observable<Int>? = null
|
var textColorObservable: Observable<Int>? = null
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
updateSubscription()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var textColorDisposable: Disposable? = null
|
||||||
|
set(value) {
|
||||||
|
field?.dispose()
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
@@ -83,14 +92,22 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateSubscription() {
|
||||||
|
if (isAttachedToWindow) {
|
||||||
|
textColorDisposable = textColorObservable?.subscribe { color ->
|
||||||
|
setTextColor(color)
|
||||||
|
setLinkTextColor(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
|
updateSubscription()
|
||||||
|
}
|
||||||
|
|
||||||
textColorObservable
|
override fun onDetachedFromWindow() {
|
||||||
?.autoDisposable(scope())
|
super.onDetachedFromWindow()
|
||||||
?.subscribe { color ->
|
textColorDisposable?.dispose()
|
||||||
setTextColor(color)
|
|
||||||
setLinkTextColor(color)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,14 +136,22 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
|
|||||||
intArrayOf(android.R.attr.state_enabled),
|
intArrayOf(android.R.attr.state_enabled),
|
||||||
intArrayOf(-android.R.attr.state_enabled))
|
intArrayOf(-android.R.attr.state_enabled))
|
||||||
|
|
||||||
|
val iconEnabled = threadId
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.switchMap { threadId -> colors.textPrimaryOnThemeForConversation(threadId) }
|
||||||
|
|
||||||
|
val iconDisabled = threadId
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.switchMap { threadId -> colors.textTertiaryOnThemeForConversation(threadId) }
|
||||||
|
|
||||||
Observables
|
Observables
|
||||||
.combineLatest(colors.textPrimaryOnTheme, colors.textTertiaryOnTheme, { primary, tertiary ->
|
.combineLatest(iconEnabled, iconDisabled, { primary, tertiary ->
|
||||||
ColorStateList(states, intArrayOf(primary, tertiary))
|
ColorStateList(states, intArrayOf(primary, tertiary))
|
||||||
})
|
})
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { tintList -> sendIcon.imageTintList = tintList }
|
.subscribe { tintList -> sendIcon.imageTintList = tintList }
|
||||||
|
|
||||||
colors.theme
|
theme
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { color -> send.setBackgroundTint(color) }
|
.subscribe { color -> send.setBackgroundTint(color) }
|
||||||
|
|
||||||
@@ -184,6 +192,8 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
threadId.onNext(state.selectedConversation)
|
||||||
|
|
||||||
toolbarTitle.setVisible(!state.editingMode)
|
toolbarTitle.setVisible(!state.editingMode)
|
||||||
chips.setVisible(state.editingMode)
|
chips.setVisible(state.editingMode)
|
||||||
contacts.setVisible(state.contactsVisible)
|
contacts.setVisible(state.contactsVisible)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ data class ComposeState(
|
|||||||
val editingMode: Boolean = false,
|
val editingMode: Boolean = false,
|
||||||
val contacts: List<Contact> = ArrayList(),
|
val contacts: List<Contact> = ArrayList(),
|
||||||
val contactsVisible: Boolean = false,
|
val contactsVisible: Boolean = false,
|
||||||
|
val selectedConversation: Long = 0,
|
||||||
val selectedContacts: List<Contact> = ArrayList(),
|
val selectedContacts: List<Contact> = ArrayList(),
|
||||||
val title: String = "",
|
val title: String = "",
|
||||||
val archived: Boolean = false,
|
val archived: Boolean = false,
|
||||||
|
|||||||
@@ -110,17 +110,17 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
|
|
||||||
val initialConversation: Observable<Conversation> = when {
|
val initialConversation: Observable<Conversation> = when {
|
||||||
threadId != 0L -> {
|
threadId != 0L -> {
|
||||||
newState { ComposeState(editingMode = false) }
|
newState { it.copy(selectedConversation = threadId, editingMode = false) }
|
||||||
messageRepo.getConversationAsync(threadId).asObservable()
|
messageRepo.getConversationAsync(threadId).asObservable()
|
||||||
}
|
}
|
||||||
|
|
||||||
address.isNotBlank() -> {
|
address.isNotBlank() -> {
|
||||||
newState { ComposeState(editingMode = false) }
|
newState { it.copy(editingMode = false) }
|
||||||
messageRepo.getOrCreateConversation(address).toObservable()
|
messageRepo.getOrCreateConversation(address).toObservable()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
newState { ComposeState(editingMode = true) }
|
newState { it.copy(editingMode = true) }
|
||||||
Observable.empty()
|
Observable.empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,18 +129,15 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||||
|
|
||||||
// Map the selected contacts to a conversation so that we can display the message history
|
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
||||||
val selectedConversation = selectedContacts
|
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||||
|
conversation = selectedContacts
|
||||||
.skipUntil(state.filter { state -> state.editingMode })
|
.skipUntil(state.filter { state -> state.editingMode })
|
||||||
.takeUntil(state.filter { state -> !state.editingMode })
|
.takeUntil(state.filter { state -> !state.editingMode })
|
||||||
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
||||||
.flatMapMaybe { addresses -> messageRepo.getOrCreateConversation(addresses) }
|
.flatMapMaybe { addresses -> messageRepo.getOrCreateConversation(addresses) }
|
||||||
|
.mergeWith(initialConversation)
|
||||||
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
|
||||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
|
||||||
conversation = initialConversation
|
|
||||||
.filter { conversation -> conversation.isLoaded }
|
.filter { conversation -> conversation.isLoaded }
|
||||||
.mergeWith(selectedConversation)
|
|
||||||
.doOnNext { conversation ->
|
.doOnNext { conversation ->
|
||||||
if (!conversation.isValid) {
|
if (!conversation.isValid) {
|
||||||
newState { it.copy(hasError = true) }
|
newState { it.copy(hasError = true) }
|
||||||
@@ -150,13 +147,13 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
.filter { conversation -> conversation.id != 0L }
|
.filter { conversation -> conversation.id != 0L }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
// When the conversation changes, update the messages for the adapter
|
// When the conversation changes, update the threadId and the messages for the adapter
|
||||||
messages = conversation
|
messages = 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 { it.copy(messages = Pair(conversation, messages)) }
|
newState { it.copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||||
messages
|
messages
|
||||||
}
|
}
|
||||||
.switchMap { messages -> messages.asObservable() }
|
.switchMap { messages -> messages.asObservable() }
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ class MessagesAdapter @Inject constructor(
|
|||||||
field = value
|
field = value
|
||||||
people.clear()
|
people.clear()
|
||||||
contactMap.clear()
|
contactMap.clear()
|
||||||
|
|
||||||
|
// Update the theme
|
||||||
|
val threadId = value?.first?.id ?: 0
|
||||||
|
theme = colors.themeForConversation(threadId)
|
||||||
|
textPrimaryOnTheme = colors.textPrimaryOnThemeForConversation(threadId)
|
||||||
|
|
||||||
updateData(value?.second)
|
updateData(value?.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +81,9 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private val selected = HashMap<Long, Boolean>()
|
private val selected = HashMap<Long, Boolean>()
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
|
private var theme = colors.theme
|
||||||
|
private var textPrimaryOnTheme = colors.textPrimaryOnTheme
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the viewType is negative, then the viewHolder has an attachment. We'll consider
|
* If the viewType is negative, then the viewHolder has an attachment. We'll consider
|
||||||
* this a unique viewType even though it uses the same view, so that regular messages
|
* this a unique viewType even though it uses the same view, so that regular messages
|
||||||
@@ -88,17 +97,16 @@ class MessagesAdapter @Inject constructor(
|
|||||||
val hasThumbnail = viewType < 0
|
val hasThumbnail = viewType < 0
|
||||||
val absViewType = Math.abs(viewType)
|
val absViewType = Math.abs(viewType)
|
||||||
|
|
||||||
when (absViewType) {
|
if (absViewType == VIEW_TYPE_ME) {
|
||||||
VIEW_TYPE_ME -> {
|
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
|
disposables += colors.bubble
|
||||||
disposables += colors.bubble
|
.subscribe { color -> view.messageBackground.setBackgroundTint(color) }
|
||||||
.subscribe { color -> view.messageBackground.setBackgroundTint(color) }
|
} else {
|
||||||
}
|
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||||
else -> {
|
view.subject.textColorObservable = textPrimaryOnTheme
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
view.body.textColorObservable = textPrimaryOnTheme
|
||||||
disposables += colors.theme
|
disposables += theme
|
||||||
.subscribe { color -> view.messageBackground.setBackgroundTint(color) }
|
.subscribe { color -> view.messageBackground.setBackgroundTint(color) }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasThumbnail) {
|
if (hasThumbnail) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
|||||||
|
|
||||||
override val viewModelClass = ConversationInfoViewModel::class
|
override val viewModelClass = ConversationInfoViewModel::class
|
||||||
override val notificationsIntent by lazy { notifications.clicks() }
|
override val notificationsIntent by lazy { notifications.clicks() }
|
||||||
|
override val themeIntent by lazy { themePrefs.clicks() }
|
||||||
override val archiveIntent by lazy { archive.clicks() }
|
override val archiveIntent by lazy { archive.clicks() }
|
||||||
override val blockIntent by lazy { block.clicks() }
|
override val blockIntent by lazy { block.clicks() }
|
||||||
override val deleteIntent by lazy { delete.clicks() }
|
override val deleteIntent by lazy { delete.clicks() }
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import presentation.common.base.QkView
|
|||||||
interface ConversationInfoView : QkView<ConversationInfoState> {
|
interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||||
|
|
||||||
val notificationsIntent: Observable<Unit>
|
val notificationsIntent: Observable<Unit>
|
||||||
|
val themeIntent: Observable<Unit>
|
||||||
val archiveIntent: Observable<Unit>
|
val archiveIntent: Observable<Unit>
|
||||||
val blockIntent: Observable<Unit>
|
val blockIntent: Observable<Unit>
|
||||||
val deleteIntent: Observable<Unit>
|
val deleteIntent: Observable<Unit>
|
||||||
|
|||||||
@@ -103,6 +103,12 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
|||||||
.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.themeIntent
|
||||||
|
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { conversation -> navigator.showThemePicker(conversation.id) }
|
||||||
|
|
||||||
// Toggle the archived state of the conversation
|
// Toggle the archived state of the conversation
|
||||||
view.archiveIntent
|
view.archiveIntent
|
||||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||||
|
|||||||
+4
-1
@@ -46,8 +46,11 @@ class NotificationPrefsActivity : QkThemedActivity<NotificationPrefsViewModel>()
|
|||||||
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
||||||
override val ringtoneSelectedIntent: Subject<String> = PublishSubject.create()
|
override val ringtoneSelectedIntent: Subject<String> = PublishSubject.create()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.notification_prefs_activity)
|
setContentView(R.layout.notification_prefs_activity)
|
||||||
setTitle(R.string.title_notification_prefs)
|
setTitle(R.string.title_notification_prefs)
|
||||||
|
|||||||
@@ -38,8 +38,11 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
|||||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||||
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.theme_picker_activity)
|
setContentView(R.layout.theme_picker_activity)
|
||||||
setTitle(R.string.title_theme)
|
setTitle(R.string.title_theme)
|
||||||
@@ -58,14 +61,11 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
|||||||
colors.background
|
colors.background
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||||
|
|
||||||
colors.theme
|
|
||||||
.autoDisposable(scope())
|
|
||||||
.subscribe { color -> rgbPicker.setBackgroundColor(color) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: ThemePickerState) {
|
override fun render(state: ThemePickerState) {
|
||||||
rgbPicker.alpha = state.rgbAlpha
|
rgbPicker.alpha = state.rgbAlpha
|
||||||
|
rgbPicker.setBackgroundColor(state.selectedColor)
|
||||||
|
|
||||||
themeAdapter.selectedColor = state.selectedColor
|
themeAdapter.selectedColor = state.selectedColor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package presentation.feature.themepicker
|
package presentation.feature.themepicker
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import com.f2prateek.rx.preferences2.Preference
|
||||||
import com.uber.autodispose.android.lifecycle.scope
|
import com.uber.autodispose.android.lifecycle.scope
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.di.appComponent
|
import common.di.appComponent
|
||||||
@@ -27,14 +29,19 @@ import presentation.common.base.QkViewModel
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ThemePickerViewModel : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState()) {
|
class ThemePickerViewModel(intent: Intent) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState()) {
|
||||||
|
|
||||||
@Inject lateinit var prefs: Preferences
|
@Inject lateinit var prefs: Preferences
|
||||||
|
|
||||||
|
private val threadId = intent.extras?.getLong("threadId") ?: 0L
|
||||||
|
private val theme: Preference<Int>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
|
||||||
disposables += prefs.theme.asObservable()
|
theme = prefs.theme(threadId)
|
||||||
|
|
||||||
|
disposables += theme.asObservable()
|
||||||
.subscribe { color -> newState { it.copy(selectedColor = color) } }
|
.subscribe { color -> newState { it.copy(selectedColor = color) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +56,7 @@ class ThemePickerViewModel : QkViewModel<ThemePickerView, ThemePickerState>(Them
|
|||||||
|
|
||||||
view.themeSelectedIntent
|
view.themeSelectedIntent
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color -> prefs.theme.set(color) }
|
.subscribe { color -> theme.set(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -67,6 +67,13 @@
|
|||||||
app:icon="@drawable/ic_notifications_black_24dp"
|
app:icon="@drawable/ic_notifications_black_24dp"
|
||||||
app:title="@string/info_notifications" />
|
app:title="@string/info_notifications" />
|
||||||
|
|
||||||
|
<presentation.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" />
|
||||||
|
|
||||||
<presentation.common.widget.PreferenceView
|
<presentation.common.widget.PreferenceView
|
||||||
android:id="@+id/archive"
|
android:id="@+id/archive"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -88,7 +88,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/mmsPreview"
|
app:layout_constraintTop_toBottomOf="@id/mmsPreview"
|
||||||
app:layout_goneMarginBottom="8dp"
|
app:layout_goneMarginBottom="8dp"
|
||||||
app:textColor="primaryOnTheme"
|
|
||||||
tools:text="@tools:sample/lorem" />
|
tools:text="@tools:sample/lorem" />
|
||||||
|
|
||||||
<presentation.common.widget.TightTextView
|
<presentation.common.widget.TightTextView
|
||||||
@@ -108,7 +107,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/subject"
|
app:layout_constraintTop_toBottomOf="@id/subject"
|
||||||
app:layout_goneMarginTop="8dp"
|
app:layout_goneMarginTop="8dp"
|
||||||
app:textColor="primaryOnTheme"
|
|
||||||
tools:text="@tools:sample/lorem" />
|
tools:text="@tools:sample/lorem" />
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
<string name="info_title">Details</string>
|
<string name="info_title">Details</string>
|
||||||
<string name="info_notifications">Notifications</string>
|
<string name="info_notifications">Notifications</string>
|
||||||
|
<string name="info_theme">Theme</string>
|
||||||
<string name="info_archive">Archive</string>
|
<string name="info_archive">Archive</string>
|
||||||
<string name="info_unarchive">Unarchive</string>
|
<string name="info_unarchive">Unarchive</string>
|
||||||
<string name="info_block">Block</string>
|
<string name="info_block">Block</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user