forked from upstream-mirrors/quik
Refactor ThemeManager to Colors
This commit is contained in:
+3
-3
@@ -11,9 +11,9 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ThemeManager @Inject constructor(context: Context, prefs: Preferences) {
|
class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||||
|
|
||||||
val color: Observable<Int>
|
val theme: Observable<Int>
|
||||||
|
|
||||||
val switchThumbEnabled: Observable<Int>
|
val switchThumbEnabled: Observable<Int>
|
||||||
val switchThumbDisabled: Observable<Int>
|
val switchThumbDisabled: Observable<Int>
|
||||||
@@ -33,7 +33,7 @@ class ThemeManager @Inject constructor(context: Context, prefs: Preferences) {
|
|||||||
colorSubject.onNext(it)
|
colorSubject.onNext(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
color = colorSubject
|
theme = colorSubject
|
||||||
.buffer(80, TimeUnit.MILLISECONDS)
|
.buffer(80, TimeUnit.MILLISECONDS)
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.map { it.last() }
|
.map { it.last() }
|
||||||
@@ -22,7 +22,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class NotificationManager @Inject constructor(
|
class NotificationManager @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val themeManager: ThemeManager) {
|
private val colors: Colors) {
|
||||||
|
|
||||||
private val notificationManager = NotificationManagerCompat.from(context)
|
private val notificationManager = NotificationManagerCompat.from(context)
|
||||||
|
|
||||||
@@ -71,7 +71,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, "channel_1")
|
val notification = NotificationCompat.Builder(context, "channel_1")
|
||||||
.setColor(themeManager.color.blockingFirst())
|
.setColor(colors.theme.blockingFirst())
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setNumber(messages.size)
|
.setNumber(messages.size)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import android.os.Bundle
|
|||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.presentation.Navigator
|
import com.moez.QKSMS.presentation.Navigator
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
@@ -16,7 +16,7 @@ import kotlin.reflect.KClass
|
|||||||
|
|
||||||
abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
|
abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
|
||||||
|
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
protected abstract val viewModelClass: KClass<VM>
|
protected abstract val viewModelClass: KClass<VM>
|
||||||
protected val viewModel: VM by lazy {
|
protected val viewModel: VM by lazy {
|
||||||
@@ -31,7 +31,7 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
|
|||||||
onNewIntent(intent)
|
onNewIntent(intent)
|
||||||
|
|
||||||
// Update the colours of the menu items
|
// Update the colours of the menu items
|
||||||
disposables += themeManager.color.subscribe { color ->
|
disposables += colors.theme.subscribe { color ->
|
||||||
menu?.let { menu ->
|
menu?.let { menu ->
|
||||||
(0 until menu.size())
|
(0 until menu.size())
|
||||||
.map { position -> menu.getItem(position) }
|
.map { position -> menu.getItem(position) }
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ class ComposeActivity : QkActivity<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))
|
||||||
|
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.map { color -> ColorStateList(states, intArrayOf(color, themeManager.textTertiary)) }
|
.map { color -> ColorStateList(states, intArrayOf(color, colors.textTertiary)) }
|
||||||
.subscribe { tintList -> send.imageTintList = tintList }
|
.subscribe { tintList -> send.imageTintList = tintList }
|
||||||
|
|
||||||
window.callback = ComposeWindowCallback(window.callback, this)
|
window.callback = ComposeWindowCallback(window.callback, this)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import android.view.animation.AlphaAnimation
|
|||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
import com.moez.QKSMS.common.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
import com.moez.QKSMS.data.model.Contact
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
@@ -17,7 +17,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class DetailedChipView(context: Context) : RelativeLayout(context) {
|
class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||||
|
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
|
|||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.subscribe { color -> card.setBackgroundTint(color) }
|
.subscribe { color -> card.setBackgroundTint(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.jakewharton.rxbinding2.view.RxView
|
|||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
import com.moez.QKSMS.common.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.DateFormatter
|
import com.moez.QKSMS.common.util.DateFormatter
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
import com.moez.QKSMS.common.util.extensions.setPadding
|
import com.moez.QKSMS.common.util.extensions.setPadding
|
||||||
@@ -34,7 +34,7 @@ class MessagesAdapter : RealmRecyclerViewAdapter<Message, QkViewHolder>(null, tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
@Inject lateinit var context: Context
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
@Inject lateinit var dateFormatter: DateFormatter
|
@Inject lateinit var dateFormatter: DateFormatter
|
||||||
|
|
||||||
val longClicks: Subject<Message> = PublishSubject.create<Message>()
|
val longClicks: Subject<Message> = PublishSubject.create<Message>()
|
||||||
@@ -54,11 +54,11 @@ class MessagesAdapter : RealmRecyclerViewAdapter<Message, QkViewHolder>(null, tr
|
|||||||
when (viewType) {
|
when (viewType) {
|
||||||
VIEWTYPE_ME -> {
|
VIEWTYPE_ME -> {
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
|
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
|
||||||
view.body.setBackgroundTint(themeManager.bubbleColor)
|
view.body.setBackgroundTint(colors.bubbleColor)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.subscribe { color -> view.body.setBackgroundTint(color) }
|
.subscribe { color -> view.body.setBackgroundTint(color) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.jakewharton.rxbinding2.view.RxView
|
|||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
import com.moez.QKSMS.common.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.DateFormatter
|
import com.moez.QKSMS.common.util.DateFormatter
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.data.model.ConversationMessagePair
|
import com.moez.QKSMS.data.model.ConversationMessagePair
|
||||||
import com.moez.QKSMS.data.repository.MessageRepository
|
import com.moez.QKSMS.data.repository.MessageRepository
|
||||||
import com.moez.QKSMS.presentation.Navigator
|
import com.moez.QKSMS.presentation.Navigator
|
||||||
@@ -26,7 +26,7 @@ class ConversationsAdapter(flowable: Flowable<List<ConversationMessagePair>>) :
|
|||||||
@Inject lateinit var navigator: Navigator
|
@Inject lateinit var navigator: Navigator
|
||||||
@Inject lateinit var messageRepo: MessageRepository
|
@Inject lateinit var messageRepo: MessageRepository
|
||||||
@Inject lateinit var dateFormatter: DateFormatter
|
@Inject lateinit var dateFormatter: DateFormatter
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ class ConversationsAdapter(flowable: Flowable<List<ConversationMessagePair>>) :
|
|||||||
val view = layoutInflater.inflate(layoutRes, parent, false)
|
val view = layoutInflater.inflate(layoutRes, parent, false)
|
||||||
|
|
||||||
if (viewType == 1) {
|
if (viewType == 1) {
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.subscribe { color -> view.date.setTextColor(color) }
|
.subscribe { color -> view.date.setTextColor(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,9 +73,9 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.doOnNext { color -> compose.setBackgroundTint(color) }
|
.doOnNext { color -> compose.setBackgroundTint(color) }
|
||||||
.map { color -> ColorStateList(states, intArrayOf(color, themeManager.textSecondary)) }
|
.map { color -> ColorStateList(states, intArrayOf(color, colors.textSecondary)) }
|
||||||
.doOnNext { tintList -> inboxIcon.imageTintList = tintList }
|
.doOnNext { tintList -> inboxIcon.imageTintList = tintList }
|
||||||
.doOnNext { tintList -> archivedIcon.imageTintList = tintList }
|
.doOnNext { tintList -> archivedIcon.imageTintList = tintList }
|
||||||
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
|
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import android.widget.FrameLayout
|
|||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
import com.moez.QKSMS.common.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.GlideApp
|
import com.moez.QKSMS.common.util.GlideApp
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.data.model.Contact
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
@@ -17,7 +17,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
||||||
|
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
|||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
disposables += themeManager.color
|
disposables += colors.theme
|
||||||
.subscribe { color -> background.setTint(color) }
|
.subscribe { color -> background.setTint(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import android.content.res.ColorStateList
|
|||||||
import android.support.v7.widget.SwitchCompat
|
import android.support.v7.widget.SwitchCompat
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
import com.moez.QKSMS.common.di.appComponent
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.extensions.withAlpha
|
import com.moez.QKSMS.common.util.extensions.withAlpha
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
@@ -14,7 +14,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwitchCompat(context, attrs) {
|
class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwitchCompat(context, attrs) {
|
||||||
|
|
||||||
@Inject lateinit var themeManager: ThemeManager
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
@@ -30,12 +30,12 @@ class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
|||||||
intArrayOf(android.R.attr.state_checked),
|
intArrayOf(android.R.attr.state_checked),
|
||||||
intArrayOf())
|
intArrayOf())
|
||||||
|
|
||||||
disposables += Observables.combineLatest(themeManager.color, themeManager.switchThumbEnabled, themeManager.switchThumbDisabled,
|
disposables += Observables.combineLatest(colors.theme, colors.switchThumbEnabled, colors.switchThumbDisabled,
|
||||||
{ color, enabled, disabled -> intArrayOf(disabled, color, enabled) })
|
{ color, enabled, disabled -> intArrayOf(disabled, color, enabled) })
|
||||||
.map { values -> ColorStateList(states, values) }
|
.map { values -> ColorStateList(states, values) }
|
||||||
.subscribe { tintList -> thumbTintList = tintList }
|
.subscribe { tintList -> thumbTintList = tintList }
|
||||||
|
|
||||||
disposables += Observables.combineLatest(themeManager.color, themeManager.switchTrackEnabled, themeManager.switchTrackDisabled,
|
disposables += Observables.combineLatest(colors.theme, colors.switchTrackEnabled, colors.switchTrackDisabled,
|
||||||
{ color, enabled, disabled -> intArrayOf(disabled, color.withAlpha(0x4D), enabled) })
|
{ color, enabled, disabled -> intArrayOf(disabled, color.withAlpha(0x4D), enabled) })
|
||||||
.map { values -> ColorStateList(states, values) }
|
.map { values -> ColorStateList(states, values) }
|
||||||
.subscribe { tintList -> trackTintList = tintList }
|
.subscribe { tintList -> trackTintList = tintList }
|
||||||
|
|||||||
Reference in New Issue
Block a user