Refactor ThemeManager to Colors

This commit is contained in:
Moez Bhatti
2017-12-04 02:51:33 -05:00
parent 6d5ed6cdc6
commit 0bedf303ef
10 changed files with 29 additions and 29 deletions
@@ -11,9 +11,9 @@ import javax.inject.Inject
import javax.inject.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 switchThumbDisabled: Observable<Int>
@@ -33,7 +33,7 @@ class ThemeManager @Inject constructor(context: Context, prefs: Preferences) {
colorSubject.onNext(it)
}
color = colorSubject
theme = colorSubject
.buffer(80, TimeUnit.MILLISECONDS)
.filter { it.isNotEmpty() }
.map { it.last() }
@@ -22,7 +22,7 @@ import javax.inject.Singleton
@Singleton
class NotificationManager @Inject constructor(
private val context: Context,
private val themeManager: ThemeManager) {
private val colors: Colors) {
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 notification = NotificationCompat.Builder(context, "channel_1")
.setColor(themeManager.color.blockingFirst())
.setColor(colors.theme.blockingFirst())
.setSmallIcon(R.mipmap.ic_launcher)
.setNumber(messages.size)
.setAutoCancel(true)
@@ -6,7 +6,7 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
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 io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
@@ -16,7 +16,7 @@ import kotlin.reflect.KClass
abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
@Inject lateinit var themeManager: ThemeManager
@Inject lateinit var colors: Colors
protected abstract val viewModelClass: KClass<VM>
protected val viewModel: VM by lazy {
@@ -31,7 +31,7 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
onNewIntent(intent)
// Update the colours of the menu items
disposables += themeManager.color.subscribe { color ->
disposables += colors.theme.subscribe { color ->
menu?.let { menu ->
(0 until menu.size())
.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))
disposables += themeManager.color
.map { color -> ColorStateList(states, intArrayOf(color, themeManager.textTertiary)) }
disposables += colors.theme
.map { color -> ColorStateList(states, intArrayOf(color, colors.textTertiary)) }
.subscribe { tintList -> send.imageTintList = tintList }
window.callback = ComposeWindowCallback(window.callback, this)
@@ -6,7 +6,7 @@ import android.view.animation.AlphaAnimation
import android.widget.RelativeLayout
import com.moez.QKSMS.R
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.data.model.Contact
import io.reactivex.disposables.CompositeDisposable
@@ -17,7 +17,7 @@ import javax.inject.Inject
class DetailedChipView(context: Context) : RelativeLayout(context) {
@Inject lateinit var themeManager: ThemeManager
@Inject lateinit var colors: Colors
private val disposables = CompositeDisposable()
@@ -35,7 +35,7 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
override fun onAttachedToWindow() {
super.onAttachedToWindow()
disposables += themeManager.color
disposables += colors.theme
.subscribe { color -> card.setBackgroundTint(color) }
}
@@ -9,7 +9,7 @@ import com.jakewharton.rxbinding2.view.RxView
import com.moez.QKSMS.R
import com.moez.QKSMS.common.di.appComponent
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.setBackgroundTint
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 themeManager: ThemeManager
@Inject lateinit var colors: Colors
@Inject lateinit var dateFormatter: DateFormatter
val longClicks: Subject<Message> = PublishSubject.create<Message>()
@@ -54,11 +54,11 @@ class MessagesAdapter : RealmRecyclerViewAdapter<Message, QkViewHolder>(null, tr
when (viewType) {
VIEWTYPE_ME -> {
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
view.body.setBackgroundTint(themeManager.bubbleColor)
view.body.setBackgroundTint(colors.bubbleColor)
}
else -> {
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
disposables += themeManager.color
disposables += colors.theme
.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.common.di.appComponent
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.repository.MessageRepository
import com.moez.QKSMS.presentation.Navigator
@@ -26,7 +26,7 @@ class ConversationsAdapter(flowable: Flowable<List<ConversationMessagePair>>) :
@Inject lateinit var navigator: Navigator
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var dateFormatter: DateFormatter
@Inject lateinit var themeManager: ThemeManager
@Inject lateinit var colors: Colors
private val disposables = CompositeDisposable()
@@ -44,7 +44,7 @@ class ConversationsAdapter(flowable: Flowable<List<ConversationMessagePair>>) :
val view = layoutInflater.inflate(layoutRes, parent, false)
if (viewType == 1) {
disposables += themeManager.color
disposables += colors.theme
.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) }
.map { color -> ColorStateList(states, intArrayOf(color, themeManager.textSecondary)) }
.map { color -> ColorStateList(states, intArrayOf(color, colors.textSecondary)) }
.doOnNext { tintList -> inboxIcon.imageTintList = tintList }
.doOnNext { tintList -> archivedIcon.imageTintList = tintList }
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
@@ -8,7 +8,7 @@ import android.widget.FrameLayout
import com.moez.QKSMS.R
import com.moez.QKSMS.common.di.appComponent
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 io.reactivex.disposables.CompositeDisposable
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) {
@Inject lateinit var themeManager: ThemeManager
@Inject lateinit var colors: Colors
private val disposables = CompositeDisposable()
@@ -37,7 +37,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
override fun onAttachedToWindow() {
super.onAttachedToWindow()
disposables += themeManager.color
disposables += colors.theme
.subscribe { color -> background.setTint(color) }
}
@@ -5,7 +5,7 @@ import android.content.res.ColorStateList
import android.support.v7.widget.SwitchCompat
import android.util.AttributeSet
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 io.reactivex.disposables.CompositeDisposable
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) {
@Inject lateinit var themeManager: ThemeManager
@Inject lateinit var colors: Colors
private val disposables = CompositeDisposable()
@@ -30,12 +30,12 @@ class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet?
intArrayOf(android.R.attr.state_checked),
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) })
.map { values -> ColorStateList(states, values) }
.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) })
.map { values -> ColorStateList(states, values) }
.subscribe { tintList -> trackTintList = tintList }