diff --git a/presentation/src/main/java/common/MenuItemAdapter.kt b/presentation/src/main/java/common/MenuItemAdapter.kt index 800b1bdf..87f49d32 100644 --- a/presentation/src/main/java/common/MenuItemAdapter.kt +++ b/presentation/src/main/java/common/MenuItemAdapter.kt @@ -29,10 +29,9 @@ import com.moez.QKSMS.R import common.base.QkAdapter import common.base.QkViewHolder import common.util.Colors +import common.util.extensions.resolveThemeColor import common.util.extensions.setVisible import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.Observables -import io.reactivex.rxkotlin.plusAssign import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.menu_list_item.view.* @@ -65,17 +64,15 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.menu_list_item, parent, false) + val layoutInflater = LayoutInflater.from(parent.context) + val view = layoutInflater.inflate(R.layout.menu_list_item, parent, false) val states = arrayOf( intArrayOf(android.R.attr.state_selected), intArrayOf(-android.R.attr.state_selected)) - disposables += Observables - .combineLatest(colors.theme, colors.textTertiary, { theme, textSecondary -> - ColorStateList(states, intArrayOf(theme, textSecondary)) - }) - .subscribe { view.check.imageTintList = it } + val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary) + view.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text)) return QkViewHolder(view) } diff --git a/presentation/src/main/java/common/QKApplication.kt b/presentation/src/main/java/common/QKApplication.kt index a2870e5b..059da7f6 100644 --- a/presentation/src/main/java/common/QKApplication.kt +++ b/presentation/src/main/java/common/QKApplication.kt @@ -23,7 +23,6 @@ import android.app.Application import android.support.text.emoji.EmojiCompat import android.support.text.emoji.FontRequestEmojiCompatConfig import android.support.v4.provider.FontRequest -import com.akaita.java.rxjava2debug.RxJava2Debug import com.bugsnag.android.Bugsnag import com.bugsnag.android.Configuration import com.moez.QKSMS.BuildConfig @@ -63,7 +62,7 @@ class QKApplication : Application(), HasActivityInjector { projectPackages = packages }) - RxJava2Debug.enableRxJava2AssemblyTracking(packages) + //RxJava2Debug.enableRxJava2AssemblyTracking(packages) Realm.init(this) Realm.setDefaultConfiguration(RealmConfiguration.Builder() diff --git a/presentation/src/main/java/common/QkDialog.kt b/presentation/src/main/java/common/QkDialog.kt index 92f94e96..679fafa1 100644 --- a/presentation/src/main/java/common/QkDialog.kt +++ b/presentation/src/main/java/common/QkDialog.kt @@ -1,9 +1,9 @@ package common import android.app.Activity -import android.app.AlertDialog import android.content.Context import android.support.annotation.StringRes +import android.support.v7.app.AlertDialog import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import common.util.extensions.dpToPx @@ -23,7 +23,7 @@ class QkDialog @Inject constructor(private val context: Context, val adapter: Me } fun show(activity: Activity) { - val recyclerView = RecyclerView(context) + val recyclerView = RecyclerView(activity) recyclerView.layoutManager = LinearLayoutManager(context) recyclerView.adapter = adapter recyclerView.setPadding(top = 8.dpToPx(context), bottom = 8.dpToPx(context)) diff --git a/presentation/src/main/java/common/base/QkThemedActivity.kt b/presentation/src/main/java/common/base/QkThemedActivity.kt index 5ce7f875..3bdf4591 100644 --- a/presentation/src/main/java/common/base/QkThemedActivity.kt +++ b/presentation/src/main/java/common/base/QkThemedActivity.kt @@ -22,16 +22,20 @@ import android.annotation.SuppressLint import android.app.ActivityManager import android.arch.lifecycle.Lifecycle import android.graphics.BitmapFactory +import android.os.Build import android.os.Bundle +import android.view.View import com.moez.QKSMS.R import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.util.Colors -import common.util.extensions.setBackgroundTint +import common.util.extensions.resolveThemeColor +import io.reactivex.Observable import io.reactivex.rxkotlin.Observables import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.toolbar.* +import util.Preferences import javax.inject.Inject /** @@ -43,6 +47,7 @@ import javax.inject.Inject abstract class QkThemedActivity : QkActivity() { @Inject lateinit var colors: Colors + @Inject lateinit var prefs: Preferences /** * In case the activity should be themed for a specific conversation, the selected conversation @@ -55,40 +60,58 @@ abstract class QkThemedActivity : QkActivity() { */ protected val theme = threadId .distinctUntilChanged() - .switchMap { threadId -> colors.themeForConversation(threadId) } + .switchMap { threadId -> colors.themeObservable(threadId) } @SuppressLint("InlinedApi") override fun onCreate(savedInstanceState: Bundle?) { + + val night = prefs.night.get() + val black = prefs.black.get() + setTheme(getActivityThemeRes(night, black)) + super.onCreate(savedInstanceState) - getAppThemeResourcesObservable() + // When certain preferences change, we need to recreate the activity + Observable.merge( + listOf(prefs.night, prefs.black, prefs.textSize, prefs.systemFont) + .map { it.asObservable().skip(1) }) .autoDisposable(scope()) - .subscribe { res -> setTheme(res) } + .subscribe { recreate() } - colors.systemBarIcons - .autoDisposable(scope()) - .subscribe { systemUiVisibility -> window.decorView.systemUiVisibility = systemUiVisibility } + // Set the color for the status bar icons + // If night mode, or no dark icons supported, use light icons + // If night mode and only dark status icons supported, use dark status icons + // If night mode and all dark icons supported, use all dark icons + window.decorView.systemUiVisibility = when { + night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> 0 + Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + else -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } - colors.statusBar - .autoDisposable(scope()) - .subscribe { color -> window.statusBarColor = color } + // Set the color for the overflow and navigation icon + val textTertiary = resolveThemeColor(android.R.attr.textColorTertiary) + toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(textTertiary) } + toolbar?.navigationIcon = toolbar?.navigationIcon?.apply { setTint(textTertiary) } - colors.navigationBar - .autoDisposable(scope()) - .subscribe { color -> window.navigationBarColor = color } + // Set the color for the recent apps title + val toolbarColor = resolveThemeColor(R.attr.colorPrimary) + val icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher) + val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), icon, toolbarColor) + setTaskDescription(taskDesc) } override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) // Update the colours of the menu items - Observables.combineLatest(menu, theme, colors.textSecondary, { menu, theme, text -> + Observables.combineLatest(menu, theme, { menu, theme -> + val text = resolveThemeColor(android.R.attr.textColorSecondary) (0 until menu.size()) .map { position -> menu.getItem(position) } .forEach { menuItem -> menuItem?.icon?.run { setTint(when (menuItem.itemId) { - in getColoredMenuItems() -> theme + in getColoredMenuItems() -> theme.theme else -> text }) @@ -96,27 +119,6 @@ abstract class QkThemedActivity : QkActivity() { } } }).autoDisposable(scope(Lifecycle.Event.ON_DESTROY)).subscribe() - - colors.textTertiary - .doOnNext { color -> toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(color) } } - .doOnNext { color -> toolbar?.navigationIcon = toolbar?.navigationIcon?.apply { setTint(color) } } - .autoDisposable(scope(Lifecycle.Event.ON_DESTROY)) - .subscribe() - - colors.popupThemeResource - .autoDisposable(scope(Lifecycle.Event.ON_DESTROY)) - .subscribe { res -> toolbar?.popupTheme = res } - - colors.toolbarColor - .doOnNext { color -> toolbar?.setBackgroundTint(color) } - .doOnNext { color -> - // Set the color for the recent apps title - val icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher) - val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), icon, color) - setTaskDescription(taskDesc) - } - .autoDisposable(scope(Lifecycle.Event.ON_DESTROY)) - .subscribe { color -> toolbar?.setBackgroundTint(color) } } open fun getColoredMenuItems(): List { @@ -126,6 +128,10 @@ abstract class QkThemedActivity : QkActivity() { /** * This can be overridden in case an activity does not want to use the default themes */ - open fun getAppThemeResourcesObservable() = colors.appThemeResources + open fun getActivityThemeRes(night: Boolean, black: Boolean) = when { + night && black -> R.style.AppThemeBlack + night && !black -> R.style.AppThemeDark + else -> R.style.AppThemeLight + } } \ No newline at end of file diff --git a/presentation/src/main/java/common/util/Colors.kt b/presentation/src/main/java/common/util/Colors.kt index 9e09243d..ec8da3d2 100644 --- a/presentation/src/main/java/common/util/Colors.kt +++ b/presentation/src/main/java/common/util/Colors.kt @@ -18,15 +18,11 @@ */ package common.util -import android.annotation.SuppressLint import android.content.Context import android.graphics.Color -import android.os.Build -import android.support.annotation.ColorRes -import android.view.View import com.moez.QKSMS.R +import common.util.extensions.getColorCompat import io.reactivex.Observable -import io.reactivex.rxkotlin.Observables import util.Preferences import javax.inject.Inject import javax.inject.Singleton @@ -34,6 +30,13 @@ import javax.inject.Singleton @Singleton class Colors @Inject constructor(private val context: Context, private val prefs: Preferences) { + data class Theme(val theme: Int, private val colors: Colors) { + val highlight by lazy { colors.highlightColorForTheme(theme) } + val textPrimary by lazy { colors.textPrimaryOnThemeForColor(theme) } + val textSecondary by lazy { colors.textSecondaryOnThemeForColor(theme) } + val textTertiary by lazy { colors.textTertiaryOnThemeForColor(theme) } + } + val materialColors = listOf( listOf(0xffffebee, 0xffffcdd2, 0xffef9a9a, 0xffe57373, 0xffef5350, 0xfff44336, 0xffe53935, 0xffd32f2f, 0xffc62828, 0xffb71c1c), listOf(0xffFCE4EC, 0xffF8BBD0, 0xffF48FB1, 0xffF06292, 0xffEC407A, 0xffE91E63, 0xffD81B60, 0xffC2185B, 0xffAD1457, 0xff880E4F), @@ -59,228 +62,43 @@ class Colors @Inject constructor(private val context: Context, private val prefs private val minimumContrastRatio = 2 // Cache these values so they don't need to be recalculated - private val primaryTextLuminance = measureLuminance(getColor(R.color.textPrimaryDark)) - private val secondaryTextLuminance = measureLuminance(getColor(R.color.textSecondaryDark)) - private val tertiaryTextLuminance = measureLuminance(getColor(R.color.textTertiaryDark)) + private val primaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textPrimaryDark)) + private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark)) + private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark)) - val theme = themeForConversation() + fun theme(threadId: Long = 0): Theme = Theme(prefs.theme(threadId).get(), this) - val appThemeResources = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.style.AppThemeBlack - night && !black -> R.style.AppThemeDark - else -> R.style.AppThemeLight - } - }) - - val appDialogThemeResources = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.style.AppThemeBlackDialog - night && !black -> R.style.AppThemeDarkDialog - else -> R.style.AppThemeLightDialog - } - }) - - val popupThemeResource = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.style.PopupThemeBlack - night && !black -> R.style.PopupThemeDark - else -> R.style.PopupThemeLight - } - }) - - /** - * Returns the flags to be used for the system bars. This is used for tinting the icons - * according to the colour of the system bars (light or dark) - * - * If night mode, or no dark icons supported, use light icons - * - * If night mode and only dark status icons supported, use dark status icons - * - * If night mode and all dark icons supported, use all dark icons - */ - @SuppressLint("InlinedApi") - val systemBarIcons: Observable = prefs.night.asObservable() - .map { night -> - when { - night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> 0 - Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - else -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } - } - .distinctUntilChanged() - - val statusBar: Observable = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.color.black - night && !black -> R.color.statusBarDark - Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> R.color.black - else -> R.color.statusBarLight - } - }) - .map { res -> getColor(res) } - .distinctUntilChanged() - - val navigationBar: Observable = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.color.black - night && !black -> R.color.backgroundDark - Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> R.color.black - else -> R.color.white - } - }) - .map { res -> getColor(res) } - .distinctUntilChanged() - - val toolbarColor: Observable = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.color.black - night && !black -> R.color.toolbarDark - else -> R.color.toolbarLight - } - }) - .map { res -> getColor(res) } - .distinctUntilChanged() - - val background: Observable = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.color.black - night && !black -> R.color.backgroundDark - else -> R.color.white - } - }) - .map { res -> getColor(res) } - .distinctUntilChanged() - - val ripple: Observable = prefs.night.asObservable() - .map { night -> - when (night) { - true -> R.drawable.ripple_dark - false -> R.drawable.ripple - } - } - .distinctUntilChanged() - - val field: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.fieldDark else R.color.fieldLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val composeBackground: Observable = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), - { night, black -> - when { - night && black -> R.color.black - night && !black -> R.color.backgroundDark - else -> R.color.backgroundLight - } - }) - .map { res -> getColor(res) } - .distinctUntilChanged() - - val separator: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.separatorDark else R.color.separatorLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val textPrimary: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.textPrimaryDark else R.color.textPrimary } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val textSecondary: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.textSecondaryDark else R.color.textSecondary } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val textTertiary: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.textTertiaryDark else R.color.textTertiary } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val highlightColor: Observable = theme - .map { theme -> FloatArray(3).apply { Color.colorToHSV(theme, this) } } - .map { hsv -> hsv.apply { set(2, 0.75f) } } // 75% value - .map { hsv -> Color.HSVToColor(85, hsv) } // 33% alpha - - val textPrimaryOnTheme = textPrimaryOnThemeForConversation() - - val textSecondaryOnTheme = textSecondaryOnThemeForConversation() - - val textTertiaryOnTheme = textTertiaryOnThemeForConversation() - - val bubble: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.bubbleDark else R.color.bubbleLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val switchThumbEnabled: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val switchThumbDisabled: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val switchTrackEnabled: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - val switchTrackDisabled: Observable = prefs.night.asObservable() - .map { night -> if (night) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight } - .map { res -> getColor(res) } - .distinctUntilChanged() - - fun themeForConversation(threadId: Long = 0): Observable = prefs.theme(threadId) - .asObservable() - .distinctUntilChanged() - - fun textPrimaryOnThemeForConversation(threadId: Long = 0): Observable = themeForConversation(threadId) - .switchMap { color -> textPrimaryOnThemeForColor(color) } - - fun textPrimaryOnThemeForColor(color: Int): Observable = Observable.just(color) - .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 = themeForConversation(threadId) - .switchMap { color -> textSecondaryOnThemeForColor(color) } - - fun textSecondaryOnThemeForColor(color: Int): Observable = Observable.just(color) - .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 = themeForConversation(threadId) - .switchMap { color -> textTertiaryOnThemeForColor(color) } - - fun textTertiaryOnThemeForColor(color: Int): Observable = Observable.just(color) - .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 { - return context.resources.getColor(res) + fun themeObservable(threadId: Long = 0): Observable { + return prefs.theme(threadId).asObservable() + .map { color -> Theme(color, this) } } + fun highlightColorForTheme(theme: Int): Int = FloatArray(3) + .apply { Color.colorToHSV(theme, this) } + .let { hsv -> hsv.apply { set(2, 0.75f) } } // 75% value + .let { hsv -> Color.HSVToColor(85, hsv) } // 33% alpha + + fun textPrimaryOnThemeForColor(color: Int): Int = color + .let { theme -> measureLuminance(theme) } + .let { themeLuminance -> primaryTextLuminance / themeLuminance } + .let { contrastRatio -> contrastRatio < minimumContrastRatio } + .let { contrastRatio -> if (contrastRatio) R.color.textPrimary else R.color.textPrimaryDark } + .let { res -> context.getColorCompat(res) } + + fun textSecondaryOnThemeForColor(color: Int): Int = color + .let { theme -> measureLuminance(theme) } + .let { themeLuminance -> secondaryTextLuminance / themeLuminance } + .let { contrastRatio -> contrastRatio < minimumContrastRatio } + .let { contrastRatio -> if (contrastRatio) R.color.textSecondary else R.color.textSecondaryDark } + .let { res -> context.getColorCompat(res) } + + fun textTertiaryOnThemeForColor(color: Int): Int = color + .let { theme -> measureLuminance(theme) } + .let { themeLuminance -> tertiaryTextLuminance / themeLuminance } + .let { contrastRatio -> contrastRatio < minimumContrastRatio } + .let { contrastRatio -> if (contrastRatio) R.color.textTertiary else R.color.textTertiaryDark } + .let { res -> context.getColorCompat(res) } + /** * Measures the luminance value of a color to be able to measure the contrast ratio between two materialColors * Based on https://stackoverflow.com/a/9733420 diff --git a/presentation/src/main/java/common/util/FontProvider.kt b/presentation/src/main/java/common/util/FontProvider.kt index 51d83ae8..1faa79a0 100644 --- a/presentation/src/main/java/common/util/FontProvider.kt +++ b/presentation/src/main/java/common/util/FontProvider.kt @@ -22,28 +22,15 @@ import android.content.Context import android.graphics.Typeface import android.support.v4.content.res.ResourcesCompat import com.moez.QKSMS.R -import io.reactivex.Observable -import io.reactivex.subjects.BehaviorSubject -import io.reactivex.subjects.Subject import timber.log.Timber -import util.Preferences -import util.extensions.Optional import javax.inject.Inject import javax.inject.Singleton @Singleton -class FontProvider @Inject constructor(context: Context, prefs: Preferences) { +class FontProvider @Inject constructor(context: Context) { - val typeface: Observable> = prefs.systemFont.asObservable() - .distinctUntilChanged() - .switchMap { systemFont -> - when (systemFont) { - true -> Observable.just(Optional(null)) - false -> lato - } - } - - private val lato: Observable> = BehaviorSubject.create() + private var lato: Typeface? = null + private val pendingCallbacks = ArrayList<(Typeface) -> Unit>() init { ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() { @@ -52,10 +39,16 @@ class FontProvider @Inject constructor(context: Context, prefs: Preferences) { } override fun onFontRetrieved(typeface: Typeface) { - val subject = lato as Subject> - subject.onNext(Optional(typeface)) + lato = typeface + + pendingCallbacks.forEach { lato?.run(it) } + pendingCallbacks.clear() } }, null) } + fun getLato(callback: (Typeface) -> Unit) { + lato?.run(callback) ?: pendingCallbacks.add(callback) + } + } \ No newline at end of file diff --git a/presentation/src/main/java/common/util/NotificationManagerImpl.kt b/presentation/src/main/java/common/util/NotificationManagerImpl.kt index 9dc50497..50eaf96f 100644 --- a/presentation/src/main/java/common/util/NotificationManagerImpl.kt +++ b/presentation/src/main/java/common/util/NotificationManagerImpl.kt @@ -110,7 +110,7 @@ class NotificationManagerImpl @Inject constructor( val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId)) .setCategory(NotificationCompat.CATEGORY_MESSAGE) - .setColor(colors.themeForConversation(threadId).blockingFirst()) + .setColor(colors.theme(threadId).theme) .setPriority(NotificationCompat.PRIORITY_MAX) .setSmallIcon(R.drawable.ic_notification) .setNumber(messages.size) @@ -207,7 +207,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.themeForConversation(threadId).blockingFirst()) + .setColor(colors.theme(threadId).theme) .setPriority(NotificationManagerCompat.IMPORTANCE_MAX) .setSmallIcon(R.drawable.ic_notification_failed) .setAutoCancel(true) diff --git a/presentation/src/main/java/common/util/TextViewStyler.kt b/presentation/src/main/java/common/util/TextViewStyler.kt new file mode 100644 index 00000000..d5693402 --- /dev/null +++ b/presentation/src/main/java/common/util/TextViewStyler.kt @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * This file is part of QKSMS. + * + * QKSMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QKSMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QKSMS. If not, see . + */ +package common.util + +import android.graphics.Typeface +import android.util.AttributeSet +import android.widget.TextView +import com.moez.QKSMS.R +import common.util.extensions.getColorCompat +import common.util.extensions.resolveThemeColor +import common.widget.QkEditText +import common.widget.QkTextView +import util.Preferences +import javax.inject.Inject + +class TextViewStyler @Inject constructor( + private val prefs: Preferences, + private val colors: Colors, + private val fontProvider: FontProvider +) { + + companion object { + const val COLOR_PRIMARY = 0 + const val COLOR_SECONDARY = 1 + const val COLOR_TERTIARY = 2 + const val COLOR_PRIMARY_ON_THEME = 3 + const val COLOR_SECONDARY_ON_THEME = 4 + const val COLOR_TERTIARY_ON_THEME = 5 + const val COLOR_THEME = 6 + + const val SIZE_PRIMARY = 0 + const val SIZE_SECONDARY = 1 + const val SIZE_TERTIARY = 2 + const val SIZE_TOOLBAR = 3 + } + + fun applyAttributes(textView: TextView, attrs: AttributeSet?) { + textView.run { + when (this) { + is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run { + val colorAttr = getInt(R.styleable.QkTextView_textColor, -1) + val textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1) + applyAttributes(textView, colorAttr, textSizeAttr) + recycle() + } + + is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run { + val colorAttr = getInt(R.styleable.QkEditText_textColor, -1) + val textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1) + applyAttributes(textView, colorAttr, textSizeAttr) + recycle() + } + } + + if (!prefs.systemFont.get()) { + fontProvider.getLato { lato -> + setTypeface(lato, typeface?.style ?: Typeface.NORMAL) + } + } + } + } + + private fun applyAttributes(textView: TextView, colorAttr: Int, textSizeAttr: Int) { + textView.run { + if (isInEditMode) { + setTextColor(context.getColorCompat(when (colorAttr) { + COLOR_PRIMARY -> R.color.textPrimary + COLOR_SECONDARY -> R.color.textSecondary + COLOR_TERTIARY -> R.color.textTertiary + COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark + COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark + COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark + COLOR_THEME -> R.color.tools_theme + else -> R.color.textPrimary + })) + + textSize = when (textSizeAttr) { + SIZE_PRIMARY -> 16f + SIZE_SECONDARY -> 14f + SIZE_TERTIARY -> 12f + SIZE_TOOLBAR -> 20f + else -> textSize + } + } else { + setTextColor(when (colorAttr) { + COLOR_PRIMARY -> context.resolveThemeColor(android.R.attr.textColorPrimary) + COLOR_SECONDARY -> context.resolveThemeColor(android.R.attr.textColorSecondary) + COLOR_TERTIARY -> context.resolveThemeColor(android.R.attr.textColorTertiary) + COLOR_PRIMARY_ON_THEME -> colors.theme().textPrimary + COLOR_SECONDARY_ON_THEME -> colors.theme().textSecondary + COLOR_TERTIARY_ON_THEME -> colors.theme().textTertiary + COLOR_THEME -> colors.theme().theme + else -> currentTextColor + }) + + setTextSize(textView, textSizeAttr) + } + } + } + + /** + * @see SIZE_PRIMARY + * @see SIZE_SECONDARY + * @see SIZE_TERTIARY + * @see SIZE_TOOLBAR + */ + fun setTextSize(textView: TextView, textSizeAttr: Int) { + val textSizePref = prefs.textSize.get() + when (textSizeAttr) { + SIZE_PRIMARY -> textView.textSize = when (textSizePref) { + Preferences.TEXT_SIZE_SMALL -> 14f + Preferences.TEXT_SIZE_NORMAL -> 16f + Preferences.TEXT_SIZE_LARGE -> 18f + Preferences.TEXT_SIZE_LARGER -> 20f + else -> 16f + } + + SIZE_SECONDARY -> textView.textSize = when (textSizePref) { + Preferences.TEXT_SIZE_SMALL -> 12f + Preferences.TEXT_SIZE_NORMAL -> 14f + Preferences.TEXT_SIZE_LARGE -> 16f + Preferences.TEXT_SIZE_LARGER -> 18f + else -> 14f + } + + SIZE_TERTIARY -> textView.textSize = when (textSizePref) { + Preferences.TEXT_SIZE_SMALL -> 10f + Preferences.TEXT_SIZE_NORMAL -> 12f + Preferences.TEXT_SIZE_LARGE -> 14f + Preferences.TEXT_SIZE_LARGER -> 16f + else -> 12f + } + + SIZE_TOOLBAR -> textView.textSize = when (textSizePref) { + Preferences.TEXT_SIZE_SMALL -> 18f + Preferences.TEXT_SIZE_NORMAL -> 20f + Preferences.TEXT_SIZE_LARGE -> 22f + Preferences.TEXT_SIZE_LARGER -> 26f + else -> 20f + } + } + } + +} \ No newline at end of file diff --git a/presentation/src/main/java/common/util/extensions/ContextExtensions.kt b/presentation/src/main/java/common/util/extensions/ContextExtensions.kt index 0f042ef3..f67b2f86 100644 --- a/presentation/src/main/java/common/util/extensions/ContextExtensions.kt +++ b/presentation/src/main/java/common/util/extensions/ContextExtensions.kt @@ -22,6 +22,7 @@ import android.app.Activity import android.content.Context import android.support.annotation.StringRes import android.support.v4.content.ContextCompat +import android.util.TypedValue import android.view.inputmethod.InputMethodManager import android.widget.Toast @@ -29,6 +30,23 @@ fun Context.getColorCompat(colorRes: Int): Int { return ContextCompat.getColor(this, colorRes) } +/** + * Tries to resolve a resource id from the current theme, based on the [attributeId] + */ +fun Context.resolveThemeAttribute(attributeId: Int, default: Int = 0): Int { + val outValue = TypedValue() + val wasResolved = theme.resolveAttribute(attributeId, outValue, true) + + return if (wasResolved) outValue.resourceId else default +} + +fun Context.resolveThemeColor(attributeId: Int, default: Int = 0): Int { + val outValue = TypedValue() + val wasResolved = theme.resolveAttribute(attributeId, outValue, true) + + return if (wasResolved) getColorCompat(outValue.resourceId) else default +} + fun Context.makeToast(@StringRes res: Int, duration: Int = Toast.LENGTH_SHORT) { Toast.makeText(this, res, duration).show() } diff --git a/presentation/src/main/java/common/util/extensions/ViewExtensions.kt b/presentation/src/main/java/common/util/extensions/ViewExtensions.kt index f7456bf8..d994a133 100644 --- a/presentation/src/main/java/common/util/extensions/ViewExtensions.kt +++ b/presentation/src/main/java/common/util/extensions/ViewExtensions.kt @@ -22,6 +22,7 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.PorterDuff import android.os.Build +import android.support.v7.widget.RecyclerView import android.view.MotionEvent import android.view.View import android.view.inputmethod.InputMethodManager @@ -94,3 +95,15 @@ fun View.forwardTouches(parent: View) { } } +fun RecyclerView.scrapViews() { + val adapter = adapter + val layoutManager = layoutManager + + this.adapter = null + this.layoutManager = null + + this.adapter = adapter + this.layoutManager = layoutManager + + adapter?.notifyDataSetChanged() +} diff --git a/presentation/src/main/java/common/widget/AvatarView.kt b/presentation/src/main/java/common/widget/AvatarView.kt index f400a389..a0bf3950 100644 --- a/presentation/src/main/java/common/widget/AvatarView.kt +++ b/presentation/src/main/java/common/widget/AvatarView.kt @@ -25,10 +25,7 @@ import android.telephony.PhoneNumberUtils import android.util.AttributeSet import android.view.View import android.widget.FrameLayout -import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable import common.Navigator import common.util.Colors import common.util.GlideApp @@ -49,6 +46,16 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet * This value can be changes if we should use the theme from a particular conversation */ var threadId: Long = 0 + set(value) { + if (field == value) return + field = value + + colors.theme(value).run { + setBackgroundTint(theme) + initial.setTextColor(textPrimary) + icon.setTint(textPrimary) + } + } private var lookupKey: String? = null private var name: String? = null @@ -63,6 +70,16 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet setBackgroundResource(R.drawable.circle) clipToOutline = true + + setOnClickListener { + if (lookupKey.isNullOrEmpty()) { + address?.let { address -> navigator.addContact(address) } + } else { + val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) + ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri, + ContactsContract.QuickContact.MODE_MEDIUM, null) + } + } } fun setContact(recipient: Recipient?) { @@ -85,37 +102,16 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet updateView() } - override fun onAttachedToWindow() { - super.onAttachedToWindow() - - if (!isInEditMode) { - colors.themeForConversation(threadId) - .autoDisposable(scope()) - .subscribe { color -> setBackgroundTint(color) } - - colors.textPrimaryOnThemeForConversation(threadId) - .apply { initial.textColorObservable = this } - .autoDisposable(scope()) - .subscribe { color -> icon.setTint(color) } - - clicks() - .autoDisposable(scope()) - .subscribe { - if (lookupKey.isNullOrEmpty()) { - address?.let { address -> navigator.addContact(address) } - } else { - val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) - ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri, - ContactsContract.QuickContact.MODE_MEDIUM, null) - } - } - } - } - override fun onFinishInflate() { super.onFinishInflate() if (!isInEditMode) { + colors.theme(threadId).run { + setBackgroundTint(theme) + initial.setTextColor(textPrimary) + icon.setTint(textPrimary) + } + updateView() } } diff --git a/presentation/src/main/java/common/widget/PagerTitleView.kt b/presentation/src/main/java/common/widget/PagerTitleView.kt index 0e03d2f5..e2e11a95 100644 --- a/presentation/src/main/java/common/widget/PagerTitleView.kt +++ b/presentation/src/main/java/common/widget/PagerTitleView.kt @@ -30,8 +30,8 @@ import com.uber.autodispose.android.scope import com.uber.autodispose.kotlin.autoDisposable import common.util.Colors import common.util.extensions.forEach +import common.util.extensions.resolveThemeColor import injection.appComponent -import io.reactivex.rxkotlin.Observables import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.tab_view.view.* @@ -90,24 +90,19 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut intArrayOf(android.R.attr.state_selected), intArrayOf(-android.R.attr.state_selected)) - val theme = threadId + threadId .distinctUntilChanged() - .switchMap { threadId -> colors.themeForConversation(threadId) } - - Observables - .combineLatest(theme, colors.textSecondary, { theme, textSecondary -> - ColorStateList(states, intArrayOf(theme, textSecondary)) - }) + .switchMap { threadId -> colors.themeObservable(threadId) } + .map { theme -> + val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary) + ColorStateList(states, intArrayOf(theme.theme, textSecondary)) + } .autoDisposable(scope()) .subscribe { colorStateList -> childCount.forEach { index -> (getChildAt(index) as? TextView)?.setTextColor(colorStateList) } } - - colors.toolbarColor - .autoDisposable(scope()) - .subscribe { color -> setBackgroundColor(color) } } } diff --git a/presentation/src/main/java/common/widget/PreferenceView.kt b/presentation/src/main/java/common/widget/PreferenceView.kt index ec29e21e..8390dfdd 100644 --- a/presentation/src/main/java/common/widget/PreferenceView.kt +++ b/presentation/src/main/java/common/widget/PreferenceView.kt @@ -25,20 +25,15 @@ import android.view.Gravity import android.view.View import android.widget.TextView import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable -import common.util.Colors -import common.util.extensions.getColorCompat +import common.util.extensions.resolveThemeAttribute +import common.util.extensions.resolveThemeColor import common.util.extensions.setTint import common.util.extensions.setVisible import injection.appComponent import kotlinx.android.synthetic.main.preference_view.view.* -import javax.inject.Inject class PreferenceView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayoutCompat(context, attrs) { - @Inject lateinit var colors: Colors - var title: String? = null set(value) { field = value @@ -72,10 +67,13 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut } View.inflate(context, R.layout.preference_view, this) - setBackgroundResource(R.drawable.ripple) + setBackgroundResource(context.resolveThemeAttribute(R.attr.selectableItemBackground)) orientation = HORIZONTAL gravity = Gravity.CENTER_VERTICAL + val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary) + icon.setTint(textSecondary) + context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run { title = getString(R.styleable.PreferenceView_title) summary = getString(R.styleable.PreferenceView_summary) @@ -95,16 +93,4 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut } } - override fun onAttachedToWindow() { - super.onAttachedToWindow() - - if (isInEditMode) { - icon.setTint(context.getColorCompat(R.color.textSecondary)) - } else { - colors.textSecondary - .autoDisposable(scope()) - .subscribe { icon.setTint(it) } - } - } - } \ No newline at end of file diff --git a/presentation/src/main/java/common/widget/QkEditText.kt b/presentation/src/main/java/common/widget/QkEditText.kt index 85eaac2d..f3baa1b7 100644 --- a/presentation/src/main/java/common/widget/QkEditText.kt +++ b/presentation/src/main/java/common/widget/QkEditText.kt @@ -19,7 +19,6 @@ package common.widget import android.content.Context -import android.graphics.Typeface import android.os.Build import android.support.v13.view.inputmethod.EditorInfoCompat import android.support.v13.view.inputmethod.InputConnectionCompat @@ -31,22 +30,10 @@ import android.view.inputmethod.InputConnection import android.view.inputmethod.InputConnectionWrapper import android.widget.EditText import com.google.android.mms.ContentType -import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable -import common.util.Colors -import common.util.FontProvider -import common.widget.QkTextView.Companion.SIZE_PRIMARY -import common.widget.QkTextView.Companion.SIZE_SECONDARY -import common.widget.QkTextView.Companion.SIZE_TERTIARY -import common.widget.QkTextView.Companion.SIZE_TOOLBAR +import common.util.TextViewStyler import injection.appComponent -import io.reactivex.Observable -import io.reactivex.rxkotlin.Observables -import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject -import util.Preferences import util.tryOrNull import javax.inject.Inject @@ -59,132 +46,19 @@ import javax.inject.Inject */ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : EditText(context, attrs) { - companion object { - const val COLOR_PRIMARY = 0 - const val COLOR_SECONDARY = 1 - const val COLOR_TERTIARY = 2 - const val COLOR_PRIMARY_ON_THEME = 3 - const val COLOR_SECONDARY_ON_THEME = 4 - const val COLOR_TERTIARY_ON_THEME = 5 - - const val SIZE_PRIMARY = 0 - const val SIZE_SECONDARY = 1 - const val SIZE_TERTIARY = 2 - const val SIZE_TOOLBAR = 3 - } - - @Inject lateinit var colors: Colors - @Inject lateinit var fontProvider: FontProvider - @Inject lateinit var prefs: Preferences + @Inject lateinit var textViewStyler: TextViewStyler val backspaces: Subject = PublishSubject.create() val inputContentSelected: Subject = PublishSubject.create() var supportsInputContent: Boolean = false - private var textColorObservable: Observable? = null - private var textColorHintObservable: Observable? = null - - private var textSizeAttrSubject: Subject = BehaviorSubject.create() - init { if (!isInEditMode) { appComponent.inject(this) - - context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run { - val colorAttr = getInt(R.styleable.QkEditText_textColor, -1) - val colorHintAttr = getInt(R.styleable.QkEditText_textColorHint, -1) - val textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1) - - textColorObservable = when (colorAttr) { - COLOR_PRIMARY -> colors.textPrimary - COLOR_SECONDARY -> colors.textSecondary - COLOR_TERTIARY -> colors.textTertiary - COLOR_PRIMARY_ON_THEME -> colors.textPrimaryOnTheme - COLOR_SECONDARY_ON_THEME -> colors.textSecondaryOnTheme - COLOR_TERTIARY_ON_THEME -> colors.textTertiaryOnTheme - else -> null - } - - textColorHintObservable = when (colorHintAttr) { - COLOR_PRIMARY -> colors.textPrimary - COLOR_SECONDARY -> colors.textSecondary - COLOR_TERTIARY -> colors.textTertiary - else -> null - } - - setTextSize(textSizeAttr) - - recycle() - } + textViewStyler.applyAttributes(this, attrs) } } - /** - * @see SIZE_PRIMARY - * @see SIZE_SECONDARY - * @see SIZE_TERTIARY - * @see SIZE_TOOLBAR - */ - fun setTextSize(size: Int) { - textSizeAttrSubject.onNext(size) - } - - override fun onAttachedToWindow() { - super.onAttachedToWindow() - if (isInEditMode) return - - fontProvider.typeface - .autoDisposable(scope()) - .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } - - textColorObservable - ?.autoDisposable(scope()) - ?.subscribe { color -> setTextColor(color) } - - textColorHintObservable - ?.autoDisposable(scope()) - ?.subscribe { color -> setHintTextColor(color) } - - Observables - .combineLatest(prefs.textSize.asObservable(), textSizeAttrSubject, { textSizePref, textSizeAttr -> - when (textSizeAttr) { - SIZE_PRIMARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 14f - Preferences.TEXT_SIZE_NORMAL -> 16f - Preferences.TEXT_SIZE_LARGE -> 18f - Preferences.TEXT_SIZE_LARGER -> 20f - else -> 16f - } - - SIZE_SECONDARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 12f - Preferences.TEXT_SIZE_NORMAL -> 14f - Preferences.TEXT_SIZE_LARGE -> 16f - Preferences.TEXT_SIZE_LARGER -> 18f - else -> 14f - } - - SIZE_TERTIARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 10f - Preferences.TEXT_SIZE_NORMAL -> 12f - Preferences.TEXT_SIZE_LARGE -> 14f - Preferences.TEXT_SIZE_LARGER -> 16f - else -> 12f - } - - SIZE_TOOLBAR -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 18f - Preferences.TEXT_SIZE_NORMAL -> 20f - Preferences.TEXT_SIZE_LARGE -> 22f - Preferences.TEXT_SIZE_LARGER -> 26f - else -> 20f - } - } - }) - .autoDisposable(scope()) - .subscribe() - } - override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection { val inputConnection = object : InputConnectionWrapper(super.onCreateInputConnection(editorInfo), true) { diff --git a/presentation/src/main/java/common/widget/QkSwitch.kt b/presentation/src/main/java/common/widget/QkSwitch.kt index 5b4b1f13..9b56e4e8 100644 --- a/presentation/src/main/java/common/widget/QkSwitch.kt +++ b/presentation/src/main/java/common/widget/QkSwitch.kt @@ -22,17 +22,18 @@ import android.content.Context import android.content.res.ColorStateList import android.support.v7.widget.SwitchCompat import android.util.AttributeSet -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable +import com.moez.QKSMS.R import common.util.Colors +import common.util.extensions.getColorCompat import common.util.extensions.withAlpha import injection.appComponent -import io.reactivex.rxkotlin.Observables +import util.Preferences import javax.inject.Inject class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwitchCompat(context, attrs) { @Inject lateinit var colors: Colors + @Inject lateinit var prefs: Preferences init { if (!isInEditMode) { @@ -49,17 +50,26 @@ class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet? intArrayOf(android.R.attr.state_checked), intArrayOf()) - Observables.combineLatest(colors.theme, colors.switchThumbEnabled, colors.switchThumbDisabled, - { color, enabled, disabled -> intArrayOf(disabled, color, enabled) }) - .map { values -> ColorStateList(states, values) } - .autoDisposable(scope()) - .subscribe { tintList -> thumbTintList = tintList } + val themeColor = colors.theme().theme - Observables.combineLatest(colors.theme, colors.switchTrackEnabled, colors.switchTrackDisabled, - { color, enabled, disabled -> intArrayOf(disabled, color.withAlpha(0x4D), enabled) }) - .map { values -> ColorStateList(states, values) } - .autoDisposable(scope()) - .subscribe { tintList -> trackTintList = tintList } + val switchThumbEnabled: Int = prefs.night.get() + .let { night -> if (night) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight } + .let { res -> context.getColorCompat(res) } + + val switchThumbDisabled: Int = prefs.night.get() + .let { night -> if (night) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight } + .let { res -> context.getColorCompat(res) } + + val switchTrackEnabled: Int = prefs.night.get() + .let { night -> if (night) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight } + .let { res -> context.getColorCompat(res) } + + val switchTrackDisabled: Int = prefs.night.get() + .let { night -> if (night) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight } + .let { res -> context.getColorCompat(res) } + + thumbTintList = ColorStateList(states, intArrayOf(switchThumbDisabled, themeColor, switchThumbEnabled)) + trackTintList = ColorStateList(states, intArrayOf(switchTrackDisabled, themeColor.withAlpha(0x4D), switchTrackEnabled)) } } } \ No newline at end of file diff --git a/presentation/src/main/java/common/widget/QkTextView.kt b/presentation/src/main/java/common/widget/QkTextView.kt index 75502c4a..c7f06202 100644 --- a/presentation/src/main/java/common/widget/QkTextView.kt +++ b/presentation/src/main/java/common/widget/QkTextView.kt @@ -19,178 +19,27 @@ package common.widget import android.content.Context -import android.graphics.Typeface import android.support.text.emoji.widget.EmojiAppCompatTextView import android.util.AttributeSet -import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable -import common.util.Colors -import common.util.FontProvider -import common.util.extensions.getColorCompat +import common.util.TextViewStyler import injection.appComponent -import io.reactivex.Observable -import io.reactivex.disposables.Disposable -import io.reactivex.rxkotlin.Observables -import io.reactivex.subjects.BehaviorSubject -import io.reactivex.subjects.Subject -import util.Preferences import javax.inject.Inject open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : EmojiAppCompatTextView(context, attrs) { - companion object { - const val COLOR_PRIMARY = 0 - const val COLOR_SECONDARY = 1 - const val COLOR_TERTIARY = 2 - const val COLOR_PRIMARY_ON_THEME = 3 - const val COLOR_SECONDARY_ON_THEME = 4 - const val COLOR_TERTIARY_ON_THEME = 5 - const val COLOR_THEME = 6 - - const val SIZE_PRIMARY = 0 - const val SIZE_SECONDARY = 1 - const val SIZE_TERTIARY = 2 - const val SIZE_TOOLBAR = 3 - } - - @Inject lateinit var colors: Colors - @Inject lateinit var fontProvider: FontProvider - @Inject lateinit var prefs: Preferences - - var textColorObservable: Observable? = null - set(value) { - field = value - updateSubscription() - } - - private var textColorDisposable: Disposable? = null - set(value) { - field?.dispose() - field = value - } - - private var textSizeAttrSubject: Subject = BehaviorSubject.create() + @Inject lateinit var textViewStyler: TextViewStyler init { if (!isInEditMode) { appComponent.inject(this) - } - - context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run { - val colorAttr = getInt(R.styleable.QkTextView_textColor, -1) - val textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1) - - if (isInEditMode) { - setTextColor(context.getColorCompat(when (colorAttr) { - COLOR_PRIMARY -> R.color.textPrimary - COLOR_SECONDARY -> R.color.textSecondary - COLOR_TERTIARY -> R.color.textTertiary - COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark - COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark - COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark - COLOR_THEME -> R.color.tools_theme - else -> R.color.textPrimary - })) - - textSize = when (textSizeAttr) { - SIZE_PRIMARY -> 16f - SIZE_SECONDARY -> 14f - SIZE_TERTIARY -> 12f - SIZE_TOOLBAR -> 20f - else -> textSize - } - } else { - textColorObservable = when (colorAttr) { - COLOR_PRIMARY -> colors.textPrimary - COLOR_SECONDARY -> colors.textSecondary - COLOR_TERTIARY -> colors.textTertiary - COLOR_PRIMARY_ON_THEME -> colors.textPrimaryOnTheme - COLOR_SECONDARY_ON_THEME -> colors.textSecondaryOnTheme - COLOR_TERTIARY_ON_THEME -> colors.textTertiaryOnTheme - COLOR_THEME -> colors.theme - else -> null - } - - setTextSize(textSizeAttr) - } - - recycle() + textViewStyler.applyAttributes(this, attrs) } } - /** - * @see SIZE_PRIMARY - * @see SIZE_SECONDARY - * @see SIZE_TERTIARY - * @see SIZE_TOOLBAR - */ - fun setTextSize(size: Int) { - textSizeAttrSubject.onNext(size) + override fun setTextColor(color: Int) { + super.setTextColor(color) + setLinkTextColor(color) } - private fun updateSubscription() { - if (isAttachedToWindow) { - textColorDisposable = textColorObservable?.subscribe { color -> - setTextColor(color) - setLinkTextColor(color) - } - } - } - - override fun onAttachedToWindow() { - super.onAttachedToWindow() - if (isInEditMode) return - - updateSubscription() - - fontProvider.typeface - .autoDisposable(scope()) - .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } - - Observables - .combineLatest(prefs.textSize.asObservable(), textSizeAttrSubject, { textSizePref, textSizeAttr -> - when (textSizeAttr) { - SIZE_PRIMARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 14f - Preferences.TEXT_SIZE_NORMAL -> 16f - Preferences.TEXT_SIZE_LARGE -> 18f - Preferences.TEXT_SIZE_LARGER -> 20f - else -> 16f - } - - SIZE_SECONDARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 12f - Preferences.TEXT_SIZE_NORMAL -> 14f - Preferences.TEXT_SIZE_LARGE -> 16f - Preferences.TEXT_SIZE_LARGER -> 18f - else -> 14f - } - - SIZE_TERTIARY -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 10f - Preferences.TEXT_SIZE_NORMAL -> 12f - Preferences.TEXT_SIZE_LARGE -> 14f - Preferences.TEXT_SIZE_LARGER -> 16f - else -> 12f - } - - SIZE_TOOLBAR -> textSize = when (textSizePref) { - Preferences.TEXT_SIZE_SMALL -> 18f - Preferences.TEXT_SIZE_NORMAL -> 20f - Preferences.TEXT_SIZE_LARGE -> 22f - Preferences.TEXT_SIZE_LARGER -> 26f - else -> 20f - } - } - }) - .autoDisposable(scope()) - .subscribe() - } - - override fun onDetachedFromWindow() { - super.onDetachedFromWindow() - textColorDisposable?.dispose() - } } \ No newline at end of file diff --git a/presentation/src/main/java/common/widget/Separator.kt b/presentation/src/main/java/common/widget/Separator.kt deleted file mode 100644 index 9cae9492..00000000 --- a/presentation/src/main/java/common/widget/Separator.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2017 Moez Bhatti - * - * This file is part of QKSMS. - * - * QKSMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * QKSMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with QKSMS. If not, see . - */ -package common.widget - -import android.content.Context -import android.util.AttributeSet -import android.view.View -import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable -import common.util.Colors -import common.util.extensions.getColorCompat -import injection.appComponent -import javax.inject.Inject - -class Separator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) { - - @Inject lateinit var colors: Colors - - init { - if (!isInEditMode) { - appComponent.inject(this) - } - } - - override fun onAttachedToWindow() { - super.onAttachedToWindow() - - if (isInEditMode) { - setBackgroundColor(context.getColorCompat(R.color.separatorLight)) - } else { - colors.separator - .autoDisposable(scope()) - .subscribe { color -> setBackgroundColor(color) } - } - } -} \ No newline at end of file diff --git a/presentation/src/main/java/feature/blocked/BlockedActivity.kt b/presentation/src/main/java/feature/blocked/BlockedActivity.kt index 28985167..7422b487 100644 --- a/presentation/src/main/java/feature/blocked/BlockedActivity.kt +++ b/presentation/src/main/java/feature/blocked/BlockedActivity.kt @@ -24,8 +24,6 @@ import android.arch.lifecycle.ViewModelProviders import android.os.Bundle import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R -import com.uber.autodispose.android.lifecycle.scope -import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import dagger.android.AndroidInjection import io.reactivex.subjects.PublishSubject @@ -53,10 +51,6 @@ class BlockedActivity : QkThemedActivity(), BlockedView { showBackButton(true) viewModel.bindView(this) - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - blockedAdapter.emptyView = empty conversations.adapter = blockedAdapter } diff --git a/presentation/src/main/java/feature/blocked/BlockedAdapter.kt b/presentation/src/main/java/feature/blocked/BlockedAdapter.kt index ab6f016b..dbe83795 100644 --- a/presentation/src/main/java/feature/blocked/BlockedAdapter.kt +++ b/presentation/src/main/java/feature/blocked/BlockedAdapter.kt @@ -18,7 +18,6 @@ */ package feature.blocked -import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup import com.moez.QKSMS.R @@ -29,12 +28,12 @@ import kotlinx.android.synthetic.main.blocked_list_item.view.* import model.Conversation import javax.inject.Inject -class BlockedAdapter @Inject constructor(private val context: Context) : QkRealmAdapter() { +class BlockedAdapter @Inject constructor() : QkRealmAdapter() { val unblock: PublishSubject = PublishSubject.create() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - return QkViewHolder(LayoutInflater.from(context).inflate(R.layout.blocked_list_item, parent, false)) + return QkViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false)) } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { diff --git a/presentation/src/main/java/feature/compose/AttachmentAdapter.kt b/presentation/src/main/java/feature/compose/AttachmentAdapter.kt index 8c6bd3d1..09bf5cd5 100644 --- a/presentation/src/main/java/feature/compose/AttachmentAdapter.kt +++ b/presentation/src/main/java/feature/compose/AttachmentAdapter.kt @@ -27,19 +27,14 @@ import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R import common.base.QkAdapter import common.base.QkViewHolder -import common.util.Colors -import common.util.extensions.setBackgroundTint -import common.util.extensions.setTint import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.attachment_list_item.view.* import javax.inject.Inject class AttachmentAdapter @Inject constructor( - private val context: Context, - private val colors: Colors + private val context: Context ) : QkAdapter() { val attachmentDeleted: Subject = PublishSubject.create() @@ -47,16 +42,10 @@ class AttachmentAdapter @Inject constructor( private val disposables = CompositeDisposable() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.attachment_list_item, parent, false) + val view = LayoutInflater.from(parent.context).inflate(R.layout.attachment_list_item, parent, false) view.thumbnailBounds.clipToOutline = true - disposables += colors.bubble - .subscribe { color -> view.detach.setBackgroundTint(color) } - - disposables += colors.textSecondary - .subscribe { color -> view.detach.setTint(color) } - return QkViewHolder(view) } diff --git a/presentation/src/main/java/feature/compose/ChipsAdapter.kt b/presentation/src/main/java/feature/compose/ChipsAdapter.kt index 76624e59..88152969 100755 --- a/presentation/src/main/java/feature/compose/ChipsAdapter.kt +++ b/presentation/src/main/java/feature/compose/ChipsAdapter.kt @@ -30,9 +30,8 @@ import com.jakewharton.rxbinding2.widget.textChanges import com.moez.QKSMS.R import common.base.QkAdapter import common.base.QkViewHolder -import common.util.Colors import common.util.extensions.dpToPx -import common.util.extensions.setBackgroundTint +import common.util.extensions.resolveThemeColor import common.util.extensions.showKeyboard import common.widget.QkEditText import io.reactivex.subjects.PublishSubject @@ -40,7 +39,7 @@ import kotlinx.android.synthetic.main.contact_chip.view.* import model.Contact import javax.inject.Inject -class ChipsAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter() { +class ChipsAdapter @Inject constructor(private val context: Context) : QkAdapter() { companion object { private const val TYPE_EDIT_TEXT = 0 @@ -76,13 +75,15 @@ class ChipsAdapter @Inject constructor(private val context: Context, private val } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) { - TYPE_EDIT_TEXT -> QkViewHolder(editText) + TYPE_EDIT_TEXT -> { + editText.setTextColor(parent.context.resolveThemeColor(android.R.attr.textColorPrimary)) + editText.setHintTextColor(parent.context.resolveThemeColor(android.R.attr.textColorTertiary)) + QkViewHolder(editText) + } else -> { - val view = LayoutInflater.from(context).inflate(R.layout.contact_chip, parent, false) - colors.composeBackground.subscribe { color -> view.content.setBackgroundTint(color) } - - QkViewHolder(view) + val inflater = LayoutInflater.from(parent.context) + QkViewHolder(inflater.inflate(R.layout.contact_chip, parent, false)) } } @@ -102,7 +103,7 @@ class ChipsAdapter @Inject constructor(private val context: Context, private val contact.numbers.firstOrNull { it.address.isNotBlank() }?.address ?: "" } - view.setOnClickListener { showDetailedChip(contact) } + view.setOnClickListener { showDetailedChip(view.context, contact) } } } } @@ -111,7 +112,10 @@ class ChipsAdapter @Inject constructor(private val context: Context, private val override fun getItemViewType(position: Int) = if (position == itemCount - 1) TYPE_EDIT_TEXT else TYPE_ITEM - private fun showDetailedChip(contact: Contact) { + /** + * The [context] has to come from a view, because we're inflating a view that used themed attrs + */ + private fun showDetailedChip(context: Context, contact: Contact) { val detailedChipView = DetailedChipView(context) detailedChipView.setContact(contact) diff --git a/presentation/src/main/java/feature/compose/ComposeActivity.kt b/presentation/src/main/java/feature/compose/ComposeActivity.kt index daaa2e68..1594b717 100644 --- a/presentation/src/main/java/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/feature/compose/ComposeActivity.kt @@ -24,7 +24,6 @@ import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.content.ContentValues import android.content.Intent -import android.content.res.ColorStateList import android.graphics.PorterDuff import android.net.Uri import android.os.Bundle @@ -41,13 +40,13 @@ import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import common.util.extensions.autoScrollToStart +import common.util.extensions.scrapViews import common.util.extensions.setBackgroundTint import common.util.extensions.setTint import common.util.extensions.setVisible import common.util.extensions.showKeyboard import dagger.android.AndroidInjection import io.reactivex.Observable -import io.reactivex.rxkotlin.Observables import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.compose_activity.* @@ -123,50 +122,12 @@ class ComposeActivity : QkThemedActivity(), ComposeView { messageBackground.backgroundTintMode = PorterDuff.Mode.MULTIPLY message.supportsInputContent = true - val states = arrayOf( - 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 - .combineLatest(iconEnabled, iconDisabled, { primary, tertiary -> - ColorStateList(states, intArrayOf(primary, tertiary)) - }) - .autoDisposable(scope()) - .subscribe { tintList -> send.imageTintList = tintList } - theme + .doOnNext { send.setBackgroundTint(it.theme) } + .doOnNext { send.setTint(it.textPrimary) } + .doOnNext { messageAdapter.theme = it } .autoDisposable(scope()) - .subscribe { color -> send.setBackgroundTint(color) } - - colors.textSecondary - .autoDisposable(scope()) - .subscribe { color -> - attach.setTint(color) - camera.setTint(color) - gallery.setTint(color) - } - - colors.bubble - .autoDisposable(scope()) - .subscribe { color -> messageBackground.setBackgroundTint(color) } - - colors.background - .autoDisposable(scope()) - .subscribe { color -> contacts.setBackgroundColor(color) } - - colors.composeBackground - .doOnNext { color -> composeBackground.setBackgroundTint(color) } - .doOnNext { color -> window.decorView.setBackgroundColor(color) } - .autoDisposable(scope()) - .subscribe() + .subscribe { messageList.scrapViews() } window.callback = ComposeWindowCallback(window.callback, this) } @@ -236,6 +197,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { counter.setVisible(counter.text.isNotBlank()) send.isEnabled = state.canSend + send.imageAlpha = if (state.canSend) 255 else 128 } override fun clearSelection() { diff --git a/presentation/src/main/java/feature/compose/ContactAdapter.kt b/presentation/src/main/java/feature/compose/ContactAdapter.kt index 009dd9e8..fa260dde 100644 --- a/presentation/src/main/java/feature/compose/ContactAdapter.kt +++ b/presentation/src/main/java/feature/compose/ContactAdapter.kt @@ -38,9 +38,8 @@ class ContactAdapter @Inject constructor(private val context: Context) : QkAdapt val contactSelected: Subject = PublishSubject.create() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val layoutRes = R.layout.contact_list_item - val layoutInflater = LayoutInflater.from(context) - val view = layoutInflater.inflate(layoutRes, parent, false) + val layoutInflater = LayoutInflater.from(parent.context) + val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false) return QkViewHolder(view) } diff --git a/presentation/src/main/java/feature/compose/DetailedChipView.kt b/presentation/src/main/java/feature/compose/DetailedChipView.kt index 2cf05da8..4a88fa2b 100755 --- a/presentation/src/main/java/feature/compose/DetailedChipView.kt +++ b/presentation/src/main/java/feature/compose/DetailedChipView.kt @@ -23,8 +23,6 @@ import android.view.View import android.view.animation.AlphaAnimation import android.widget.RelativeLayout import com.moez.QKSMS.R -import com.uber.autodispose.android.scope -import com.uber.autodispose.kotlin.autoDisposable import common.util.Colors import common.util.extensions.setBackgroundTint import injection.appComponent @@ -47,14 +45,8 @@ class DetailedChipView(context: Context) : RelativeLayout(context) { isFocusable = true isFocusableInTouchMode = true - } - override fun onAttachedToWindow() { - super.onAttachedToWindow() - - colors.theme - .autoDisposable(scope()) - .subscribe { color -> card.setBackgroundTint(color) } + card.setBackgroundTint(colors.theme().theme) } fun setContact(contact: Contact) { diff --git a/presentation/src/main/java/feature/compose/MessagesAdapter.kt b/presentation/src/main/java/feature/compose/MessagesAdapter.kt index 83def776..6974ec91 100644 --- a/presentation/src/main/java/feature/compose/MessagesAdapter.kt +++ b/presentation/src/main/java/feature/compose/MessagesAdapter.kt @@ -43,13 +43,13 @@ import common.util.DateFormatter import common.util.GlideApp import common.util.extensions.dpToPx import common.util.extensions.forwardTouches +import common.util.extensions.resolveThemeColor import common.util.extensions.setBackgroundTint import common.util.extensions.setPadding import common.util.extensions.setTint import common.util.extensions.setVisible import common.widget.BubbleImageView.Style.* import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import io.realm.RealmResults @@ -90,9 +90,7 @@ class MessagesAdapter @Inject constructor( contactCache.clear() // Update the theme - val threadId = value?.first?.id ?: 0 - theme = colors.themeForConversation(threadId) - textPrimaryOnTheme = colors.textPrimaryOnThemeForConversation(threadId) + theme = colors.theme(value?.first?.id ?: 0) updateData(value?.second) } @@ -119,8 +117,7 @@ class MessagesAdapter @Inject constructor( private val expanded = HashMap() private val disposables = CompositeDisposable() - private var theme = colors.theme - private var textPrimaryOnTheme = colors.textPrimaryOnTheme + var theme: Colors.Theme = colors.theme() /** * If the viewType is negative, then the viewHolder has an attachment. We'll consider @@ -135,27 +132,15 @@ class MessagesAdapter @Inject constructor( if (viewType == VIEW_TYPE_MESSAGE_OUT) { view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false) - disposables += colors.bubble - .subscribe { color -> - view.body.setBackgroundTint(color) - view.findViewById(R.id.cancel).setBackgroundTint(color) - } - disposables += theme - .subscribe { color -> - view.findViewById(R.id.cancelIcon).setTint(color) - view.findViewById(R.id.cancel).setTint(color) - } + view.findViewById(R.id.cancelIcon).setTint(theme.theme) + view.findViewById(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.textColorObservable = textPrimaryOnTheme - disposables += theme - .subscribe { color -> view.body.setBackgroundTint(color) } + view.body.setTextColor(theme.textPrimary) + view.body.setBackgroundTint(theme.theme) } - disposables += colors.ripple - .subscribe { res -> view.setBackgroundResource(res) } - view.body.forwardTouches(view) return QkViewHolder(view) @@ -303,9 +288,9 @@ class MessagesAdapter @Inject constructor( // If we're on API 21, we need to re-tint the background if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { view.body.setBackgroundTint(when (message.isMe()) { - true -> colors.bubble - false -> theme - }.blockingFirst()) + true -> context.resolveThemeColor(R.attr.bubbleColor) + false -> theme.theme + }) } } diff --git a/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivity.kt b/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivity.kt index 9a0f0792..be4709e3 100644 --- a/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivity.kt +++ b/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivity.kt @@ -28,6 +28,7 @@ import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.Navigator import common.base.QkThemedActivity +import common.util.extensions.scrapViews import common.util.extensions.setVisible import dagger.android.AndroidInjection import io.reactivex.subjects.PublishSubject @@ -59,10 +60,6 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView { viewModel.bindView(this) setTitle(R.string.info_title) - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - mediaAdapter.thumbnailClicks .autoDisposable(scope()) .subscribe { view -> navigator.showImageAnimated(this, view) } @@ -71,6 +68,10 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView { media.adapter = mediaAdapter media.addItemDecoration(itemDecoration) + + theme + .autoDisposable(scope()) + .subscribe { recipients.scrapViews() } } override fun render(state: ConversationInfoState) { @@ -79,8 +80,9 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView { return } - recipientAdapter.updateData(state.recipients) + threadId.onNext(state.threadId) recipientAdapter.threadId = state.threadId + recipientAdapter.updateData(state.recipients) notifications.setVisible(!state.blocked) diff --git a/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivityModule.kt b/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivityModule.kt index c03c85b3..f020f077 100644 --- a/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivityModule.kt +++ b/presentation/src/main/java/feature/conversationinfo/ConversationInfoActivityModule.kt @@ -1,17 +1,18 @@ package feature.conversationinfo import android.arch.lifecycle.ViewModel -import android.content.Intent import dagger.Module import dagger.Provides import dagger.multibindings.IntoMap import injection.ViewModelKey +import javax.inject.Named @Module class ConversationInfoActivityModule { @Provides - fun provideIntent(activity: ConversationInfoActivity): Intent = activity.intent + @Named("threadId") + fun provideIntent(activity: ConversationInfoActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L @Provides @IntoMap diff --git a/presentation/src/main/java/feature/conversationinfo/ConversationInfoViewModel.kt b/presentation/src/main/java/feature/conversationinfo/ConversationInfoViewModel.kt index b872db2b..68261db8 100644 --- a/presentation/src/main/java/feature/conversationinfo/ConversationInfoViewModel.kt +++ b/presentation/src/main/java/feature/conversationinfo/ConversationInfoViewModel.kt @@ -18,7 +18,6 @@ */ package feature.conversationinfo -import android.content.Intent import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.Navigator @@ -35,29 +34,24 @@ import model.Conversation import repository.MessageRepository import util.extensions.asObservable import javax.inject.Inject +import javax.inject.Named class ConversationInfoViewModel @Inject constructor( - private val intent: Intent, - private val messageRepo: MessageRepository, + @Named("threadId") threadId: Long, + messageRepo: MessageRepository, private val markArchived: MarkArchived, private val markUnarchived: MarkUnarchived, private val markBlocked: MarkBlocked, private val markUnblocked: MarkUnblocked, private val navigator: Navigator, private val deleteConversations: DeleteConversations -) : QkViewModel(ConversationInfoState()) { - +) : QkViewModel( + ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId)) +) { private val conversation: Observable init { - val threadId = intent.extras?.getLong("threadId") ?: 0L - - newState { it.copy(threadId = threadId) } - - // Load the attachments from the conversation - newState { it.copy(media = messageRepo.getPartsForConversation(threadId)) } - conversation = messageRepo.getConversationAsync(threadId) .asObservable() .filter { conversation -> conversation.isLoaded } diff --git a/presentation/src/main/java/feature/conversationinfo/ConversationMediaAdapter.kt b/presentation/src/main/java/feature/conversationinfo/ConversationMediaAdapter.kt index d55f71f5..e5e2805f 100644 --- a/presentation/src/main/java/feature/conversationinfo/ConversationMediaAdapter.kt +++ b/presentation/src/main/java/feature/conversationinfo/ConversationMediaAdapter.kt @@ -26,18 +26,15 @@ import android.view.ViewGroup import com.moez.QKSMS.R import common.base.QkRealmAdapter import common.base.QkViewHolder -import common.util.Colors import common.util.GlideApp import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import io.reactivex.subjects.PublishSubject import kotlinx.android.synthetic.main.conversation_media_list_item.view.* import model.MmsPart import javax.inject.Inject class ConversationMediaAdapter @Inject constructor( - private val context: Context, - private val colors: Colors + private val context: Context ) : QkRealmAdapter() { val thumbnailClicks: PublishSubject = PublishSubject.create() @@ -45,10 +42,7 @@ class ConversationMediaAdapter @Inject constructor( private val disposables = CompositeDisposable() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.conversation_media_list_item, parent, false) - - disposables += colors.separator.subscribe { color -> view.setBackgroundColor(color) } - + val view = LayoutInflater.from(parent.context).inflate(R.layout.conversation_media_list_item, parent, false) return QkViewHolder(view) } diff --git a/presentation/src/main/java/feature/conversationinfo/ConversationRecipientAdapter.kt b/presentation/src/main/java/feature/conversationinfo/ConversationRecipientAdapter.kt index 4e23cf13..732c91ca 100644 --- a/presentation/src/main/java/feature/conversationinfo/ConversationRecipientAdapter.kt +++ b/presentation/src/main/java/feature/conversationinfo/ConversationRecipientAdapter.kt @@ -18,7 +18,6 @@ */ package feature.conversationinfo -import android.content.Context import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup @@ -26,18 +25,13 @@ import com.moez.QKSMS.R import common.Navigator import common.base.QkRealmAdapter import common.base.QkViewHolder -import common.util.Colors -import common.util.extensions.setTint import common.util.extensions.setVisible import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.* import model.Recipient import javax.inject.Inject class ConversationRecipientAdapter @Inject constructor( - private val context: Context, - private val colors: Colors, private val navigator: Navigator ) : QkRealmAdapter() { @@ -46,12 +40,8 @@ class ConversationRecipientAdapter @Inject constructor( private val disposables = CompositeDisposable() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val layoutInflater = LayoutInflater.from(context) + val layoutInflater = LayoutInflater.from(parent.context) val view = layoutInflater.inflate(R.layout.conversation_recipient_list_item, parent, false) - - disposables += colors.textSecondary - .subscribe { color -> view.add.setTint(color) } - return QkViewHolder(view) } diff --git a/presentation/src/main/java/feature/conversations/ConversationsAdapter.kt b/presentation/src/main/java/feature/conversations/ConversationsAdapter.kt index bd68250f..2e694558 100644 --- a/presentation/src/main/java/feature/conversations/ConversationsAdapter.kt +++ b/presentation/src/main/java/feature/conversations/ConversationsAdapter.kt @@ -20,52 +20,43 @@ package feature.conversations import android.content.Context import android.graphics.Typeface -import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup -import com.jakewharton.rxbinding2.view.clicks -import com.jakewharton.rxbinding2.view.longClicks import com.moez.QKSMS.R import common.Navigator import common.base.QkRealmAdapter import common.base.QkViewHolder -import common.util.Colors import common.util.DateFormatter -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign +import common.util.extensions.resolveThemeColor import kotlinx.android.synthetic.main.conversation_list_item.view.* import model.Conversation import javax.inject.Inject class ConversationsAdapter @Inject constructor( private val context: Context, - private val colors: Colors, private val dateFormatter: DateFormatter, private val navigator: Navigator ) : QkRealmAdapter() { - private val disposables = CompositeDisposable() - init { setHasStableIds(true) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val layoutInflater = LayoutInflater.from(context) + val layoutInflater = LayoutInflater.from(parent.context) val view = layoutInflater.inflate(R.layout.conversation_list_item, parent, false) - disposables += colors.ripple - .subscribe { res -> view.setBackgroundResource(res) } - if (viewType == 1) { + val textColorPrimary = parent.context.resolveThemeColor(android.R.attr.textColorPrimary) + view.title.setTypeface(view.title.typeface, Typeface.BOLD) view.snippet.setTypeface(view.snippet.typeface, Typeface.BOLD) - view.snippet.textColorObservable = colors.textPrimary + view.snippet.setTextColor(textColorPrimary) view.snippet.maxLines = 5 view.date.setTypeface(view.date.typeface, Typeface.BOLD) - view.date.textColorObservable = colors.textPrimary + view.date.setTextColor(textColorPrimary) } return QkViewHolder(view) @@ -75,15 +66,16 @@ class ConversationsAdapter @Inject constructor( val conversation = getItem(position)!! val view = viewHolder.itemView - view.clicks().subscribe { + view.setOnClickListener { when (toggleSelection(conversation.id, false)) { true -> view.isSelected = isSelected(conversation.id) false -> navigator.showConversation(conversation.id) } } - view.longClicks().subscribe { + view.setOnLongClickListener { toggleSelection(conversation.id) view.isSelected = isSelected(conversation.id) + true } view.isSelected = isSelected(conversation.id) @@ -97,11 +89,6 @@ class ConversationsAdapter @Inject constructor( } } - override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { - super.onDetachedFromRecyclerView(recyclerView) - disposables.clear() - } - override fun getItemId(index: Int): Long { return getItem(index)!!.id } diff --git a/presentation/src/main/java/feature/main/MainActivity.kt b/presentation/src/main/java/feature/main/MainActivity.kt index 08393899..c8c4d720 100644 --- a/presentation/src/main/java/feature/main/MainActivity.kt +++ b/presentation/src/main/java/feature/main/MainActivity.kt @@ -23,8 +23,6 @@ import android.app.AlertDialog import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.content.res.ColorStateList -import android.graphics.drawable.ColorDrawable -import android.graphics.drawable.StateListDrawable import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.ActivityCompat @@ -45,6 +43,8 @@ import common.Navigator import common.base.QkThemedActivity import common.util.extensions.autoScrollToStart import common.util.extensions.dismissKeyboard +import common.util.extensions.resolveThemeColor +import common.util.extensions.scrapViews import common.util.extensions.setBackgroundTint import common.util.extensions.setTint import common.util.extensions.setVisible @@ -52,7 +52,6 @@ import dagger.android.AndroidInjection import feature.conversations.ConversationItemTouchCallback import feature.conversations.ConversationsAdapter import io.reactivex.Observable -import io.reactivex.rxkotlin.Observables import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.drawer_view.* @@ -125,67 +124,40 @@ class MainActivity : QkThemedActivity(), MainView { scheduled.isEnabled = false - colors.background - .doOnNext { color -> window.decorView.setBackgroundColor(color) } - .doOnNext { color -> drawer.setBackgroundColor(color) } - .autoDisposable(scope()) - .subscribe() - - val states = arrayOf( - intArrayOf(android.R.attr.state_selected), - intArrayOf(-android.R.attr.state_selected)) - - val rowBackground = { separator: Int -> - StateListDrawable().apply { - addState(intArrayOf(android.R.attr.state_selected), ColorDrawable(separator)) - addState(intArrayOf(-android.R.attr.state_selected), getDrawable(R.drawable.ripple)) - mutate() - } - } - - // Set the theme color tint to the progressbar and FAB - colors.theme - .doOnNext { color -> syncingProgress.indeterminateTintList = ColorStateList.valueOf(color) } - .doOnNext { color -> itemTouchCallback.color = color } - .doOnNext { color -> rateIcon.setTint(color) } - .doOnNext { color -> compose.setBackgroundTint(color) } - .autoDisposable(scope()) - .subscribe() - - // Set the FAB compose icon color - colors.textPrimaryOnTheme - .doOnNext { color -> compose.setTint(color) } - .doOnNext { color -> itemTouchCallback.iconColor = color } + // Set the theme color tint to the recyclerView, progressbar, and FAB + colors.themeObservable() + .doOnNext { recyclerView.scrapViews() } + .doOnNext { theme -> + // Set the color for the drawer icons + val states = arrayOf(intArrayOf(android.R.attr.state_selected), intArrayOf(-android.R.attr.state_selected)) + resolveThemeColor(android.R.attr.textColorSecondary) + .let { textSecondary -> ColorStateList(states, intArrayOf(theme.theme, textSecondary)) } + .let { tintList -> + inboxIcon.imageTintList = tintList + archivedIcon.imageTintList = tintList + scheduledIcon.imageTintList = tintList + settingsIcon.imageTintList = tintList + plusIcon.imageTintList = tintList + helpIcon.imageTintList = tintList + } + } + .doOnNext { theme -> + // Miscellaneous views + syncingProgress.indeterminateTintList = ColorStateList.valueOf(theme.theme) + itemTouchCallback.color = theme.theme + rateIcon.setTint(theme.theme) + compose.setBackgroundTint(theme.theme) + } + .doOnNext { theme -> + // Set the FAB compose icon color + compose.setTint(theme.textPrimary) + itemTouchCallback.iconColor = theme.textPrimary + } .autoDisposable(scope()) .subscribe() // Set the hamburger icon color - colors.textSecondary - .autoDisposable(scope()) - .subscribe { color -> toggle.drawerArrowDrawable.color = color } - - // Set the color for the drawer icons - Observables - .combineLatest(colors.theme, colors.textSecondary, { theme, textSecondary -> - ColorStateList(states, intArrayOf(theme, textSecondary)) - }) - .doOnNext { tintList -> inboxIcon.imageTintList = tintList } - .doOnNext { tintList -> archivedIcon.imageTintList = tintList } - .doOnNext { tintList -> scheduledIcon.imageTintList = tintList } - .doOnNext { tintList -> settingsIcon.imageTintList = tintList } - .doOnNext { tintList -> plusIcon.imageTintList = tintList } - .doOnNext { tintList -> helpIcon.imageTintList = tintList } - .autoDisposable(scope()) - .subscribe() - - // Set the background highlight for the drawer options - colors.separator - .doOnNext { color -> inbox.background = rowBackground(color) } - .doOnNext { color -> archived.background = rowBackground(color) } - .doOnNext { color -> scheduled.background = rowBackground(color) } - .doOnNext { color -> rateLayout.setBackgroundTint(color) } - .autoDisposable(scope()) - .subscribe() + toggle.drawerArrowDrawable.color = resolveThemeColor(android.R.attr.textColorSecondary) conversationsAdapter.autoScrollToStart(recyclerView) conversationsAdapter.emptyView = empty diff --git a/presentation/src/main/java/feature/main/SearchAdapter.kt b/presentation/src/main/java/feature/main/SearchAdapter.kt index c7e8173d..ef9f010d 100644 --- a/presentation/src/main/java/feature/main/SearchAdapter.kt +++ b/presentation/src/main/java/feature/main/SearchAdapter.kt @@ -19,7 +19,6 @@ package feature.main import android.content.Context -import android.support.v7.widget.RecyclerView import android.text.SpannableString import android.text.Spanned import android.text.style.BackgroundColorSpan @@ -33,8 +32,6 @@ import common.base.QkViewHolder import common.util.Colors import common.util.DateFormatter import common.util.extensions.setVisible -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import kotlinx.android.synthetic.main.search_list_item.view.* import model.SearchResult import javax.inject.Inject @@ -46,12 +43,10 @@ class SearchAdapter @Inject constructor( private val navigator: Navigator ) : QkAdapter() { - private var highlightColor: Int = 0 - - private val disposables = CompositeDisposable() + private var highlightColor: Int = colors.theme().highlight override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val layoutInflater = LayoutInflater.from(context) + val layoutInflater = LayoutInflater.from(parent.context) val view = layoutInflater.inflate(R.layout.search_list_item, parent, false) return QkViewHolder(view) } @@ -105,14 +100,4 @@ class SearchAdapter @Inject constructor( old.conversation.id == new.conversation.id // Conversation id is the same && old.messages == new.messages // Result count is the same } - - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - disposables += colors.highlightColor - .doOnNext { color -> highlightColor = color } - .subscribe { notifyDataSetChanged() } - } - - override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { - disposables.dispose() - } } \ No newline at end of file diff --git a/presentation/src/main/java/feature/notificationprefs/NotificationPrefsActivity.kt b/presentation/src/main/java/feature/notificationprefs/NotificationPrefsActivity.kt index 359e1fae..71f75986 100644 --- a/presentation/src/main/java/feature/notificationprefs/NotificationPrefsActivity.kt +++ b/presentation/src/main/java/feature/notificationprefs/NotificationPrefsActivity.kt @@ -28,8 +28,6 @@ import android.os.Build import android.os.Bundle import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R -import com.uber.autodispose.android.lifecycle.scope -import com.uber.autodispose.kotlin.autoDisposable import common.QkDialog import common.base.QkThemedActivity import common.util.extensions.setVisible @@ -70,10 +68,6 @@ class NotificationPrefsActivity : QkThemedActivity(), NotificationPrefsView { previewModeDialog.setTitle(R.string.settings_notification_previews_title) previewModeDialog.adapter.setData(R.array.notification_preview_options) - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - // Listen to clicks for all of the preferences (0 until preferences.childCount) .map { index -> preferences.getChildAt(index) } diff --git a/presentation/src/main/java/feature/plus/PlusActivity.kt b/presentation/src/main/java/feature/plus/PlusActivity.kt index 56c76839..80680249 100644 --- a/presentation/src/main/java/feature/plus/PlusActivity.kt +++ b/presentation/src/main/java/feature/plus/PlusActivity.kt @@ -25,11 +25,10 @@ import android.os.Bundle import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.BuildConfig import com.moez.QKSMS.R -import com.uber.autodispose.android.lifecycle.scope -import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import common.util.BillingManager import common.util.FontProvider +import common.util.extensions.resolveThemeColor import common.util.extensions.setBackgroundTint import common.util.extensions.setTint import common.util.extensions.setVisible @@ -58,39 +57,22 @@ class PlusActivity : QkThemedActivity(), PlusView { free.setVisible(false) - fontProvider.typeface - .autoDisposable(scope()) - .subscribe { lato -> - val typeface = Typeface.create(lato.value, Typeface.BOLD) - collapsingToolbar.setCollapsedTitleTypeface(typeface) - collapsingToolbar.setExpandedTitleTypeface(typeface) - } + if (!prefs.systemFont.get()) { + fontProvider.getLato { lato -> + val typeface = Typeface.create(lato, Typeface.BOLD) + collapsingToolbar.setCollapsedTitleTypeface(typeface) + collapsingToolbar.setExpandedTitleTypeface(typeface) + } + } - colors.textPrimary - .autoDisposable(scope()) - .subscribe { color -> - collapsingToolbar.setCollapsedTitleTextColor(color) - collapsingToolbar.setExpandedTitleColor(color) - } + val textPrimary = resolveThemeColor(android.R.attr.textColorPrimary) + collapsingToolbar.setCollapsedTitleTextColor(textPrimary) + collapsingToolbar.setExpandedTitleColor(textPrimary) - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - - colors.separator - .autoDisposable(scope()) - .subscribe { color -> - upgradeDonate.setBackgroundTint(color) - upgraded.setBackgroundTint(color) - } - - colors.theme - .autoDisposable(scope()) - .subscribe { color -> - donate.setBackgroundTint(color) - upgrade.setBackgroundTint(color) - thanksIcon.setTint(color) - } + val theme = colors.theme().theme + donate.setBackgroundTint(theme) + upgrade.setBackgroundTint(theme) + thanksIcon.setTint(theme) } override fun render(state: PlusState) { diff --git a/presentation/src/main/java/feature/qkreply/QkReplyActivity.kt b/presentation/src/main/java/feature/qkreply/QkReplyActivity.kt index 1b0adc07..d05aaee1 100644 --- a/presentation/src/main/java/feature/qkreply/QkReplyActivity.kt +++ b/presentation/src/main/java/feature/qkreply/QkReplyActivity.kt @@ -20,7 +20,6 @@ package feature.qkreply import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders -import android.content.res.ColorStateList import android.os.Bundle import android.support.v7.widget.LinearLayoutManager import android.view.Menu @@ -31,25 +30,24 @@ import android.view.WindowManager import com.jakewharton.rxbinding2.view.clicks import com.jakewharton.rxbinding2.widget.textChanges import com.moez.QKSMS.R +import com.moez.QKSMS.R.id.* import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import common.util.extensions.autoScrollToStart import common.util.extensions.setBackgroundTint +import common.util.extensions.setTint import common.util.extensions.setVisible import dagger.android.AndroidInjection import feature.compose.MessagesAdapter -import io.reactivex.rxkotlin.Observables import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.qkreply_activity.* -import util.Preferences import javax.inject.Inject class QkReplyActivity : QkThemedActivity(), QkReplyView { @Inject lateinit var adapter: MessagesAdapter - @Inject lateinit var prefs: Preferences @Inject lateinit var viewModelFactory: ViewModelProvider.Factory override val menuItemIntent: Subject = PublishSubject.create() @@ -69,39 +67,12 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView { window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) viewModel.bindView(this) - colors.composeBackground - .doOnNext { color -> background.setBackgroundTint(color) } - .doOnNext { color -> composeBackground.setBackgroundTint(color) } - .doOnNext { color -> composeBackgroundGradient.setBackgroundTint(color) } - .autoDisposable(scope()) - .subscribe() - - colors.bubble - .autoDisposable(scope()) - .subscribe { color -> message.setBackgroundTint(color) } - theme .autoDisposable(scope()) - .subscribe { color -> send.setBackgroundTint(color) } - - val states = arrayOf( - 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 - .combineLatest(iconEnabled, iconDisabled, { primary, tertiary -> - ColorStateList(states, intArrayOf(primary, tertiary)) - }) - .autoDisposable(scope()) - .subscribe { tintList -> send.imageTintList = tintList } + .subscribe { theme -> + send.setBackgroundTint(theme.theme) + send.setTint(theme.textPrimary) + } toolbar.clipToOutline = true @@ -129,6 +100,7 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView { counter.setVisible(counter.text.isNotBlank()) send.isEnabled = state.canSend + send.imageAlpha = if (state.canSend) 255 else 128 } override fun setDraft(draft: String) { @@ -145,6 +117,10 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView { return true } - override fun getAppThemeResourcesObservable() = colors.appDialogThemeResources + override fun getActivityThemeRes(night: Boolean, black: Boolean) = when { + night && black -> R.style.AppThemeBlackDialog + night && !black -> R.style.AppThemeDarkDialog + else -> R.style.AppThemeLightDialog + } } \ No newline at end of file diff --git a/presentation/src/main/java/feature/settings/SettingsActivity.kt b/presentation/src/main/java/feature/settings/SettingsActivity.kt index 1f987c45..ee64e6b5 100644 --- a/presentation/src/main/java/feature/settings/SettingsActivity.kt +++ b/presentation/src/main/java/feature/settings/SettingsActivity.kt @@ -28,6 +28,7 @@ import android.text.format.DateFormat import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.BuildConfig import com.moez.QKSMS.R +import com.uber.autodispose.AutoDispose.autoDisposable import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable import common.QkDialog @@ -87,10 +88,6 @@ class SettingsActivity : QkThemedActivity(), SettingsView { about.summary = getString(R.string.settings_version, BuildConfig.VERSION_NAME) - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - // Listen to clicks for all of the preferences (0 until preferences.childCount) .map { index -> preferences.getChildAt(index) } @@ -100,6 +97,11 @@ class SettingsActivity : QkThemedActivity(), SettingsView { preferenceClickIntent.onNext(preference as PreferenceView) } } + + theme + .skip(1) + .autoDisposable(scope()) + .subscribe { recreate() } } override fun render(state: SettingsState) { diff --git a/presentation/src/main/java/feature/settings/SettingsViewModel.kt b/presentation/src/main/java/feature/settings/SettingsViewModel.kt index 3bb36773..04eb024f 100644 --- a/presentation/src/main/java/feature/settings/SettingsViewModel.kt +++ b/presentation/src/main/java/feature/settings/SettingsViewModel.kt @@ -49,8 +49,7 @@ class SettingsViewModel @Inject constructor( init { - disposables += colors.theme - .subscribe { color -> newState { it.copy(theme = color) } } + newState { it.copy(theme = colors.theme().theme) } val nightModeLabels = context.resources.getStringArray(R.array.night_modes) disposables += prefs.nightMode.asObservable() diff --git a/presentation/src/main/java/feature/settings/about/AboutActivity.kt b/presentation/src/main/java/feature/settings/about/AboutActivity.kt index cc42cba1..56259f87 100644 --- a/presentation/src/main/java/feature/settings/about/AboutActivity.kt +++ b/presentation/src/main/java/feature/settings/about/AboutActivity.kt @@ -6,8 +6,6 @@ import android.os.Bundle import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.BuildConfig import com.moez.QKSMS.R -import com.uber.autodispose.android.lifecycle.scope -import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import common.widget.PreferenceView import dagger.android.AndroidInjection @@ -34,10 +32,6 @@ class AboutActivity : QkThemedActivity(), AboutView { version.summary = BuildConfig.VERSION_NAME - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - // Listen to clicks for all of the preferences (0 until preferences.childCount) .map { index -> preferences.getChildAt(index) } diff --git a/presentation/src/main/java/feature/themepicker/ThemeAdapter.kt b/presentation/src/main/java/feature/themepicker/ThemeAdapter.kt index 984b1d9f..9cfeb245 100644 --- a/presentation/src/main/java/feature/themepicker/ThemeAdapter.kt +++ b/presentation/src/main/java/feature/themepicker/ThemeAdapter.kt @@ -20,26 +20,23 @@ package feature.themepicker import android.content.Context import android.content.res.Resources -import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup import com.google.android.flexbox.FlexDirection import com.google.android.flexbox.FlexWrap import com.google.android.flexbox.FlexboxLayout import com.moez.QKSMS.R +import common.base.QkAdapter +import common.base.QkViewHolder import common.util.Colors import common.util.extensions.dpToPx import common.util.extensions.setBackgroundTint import common.util.extensions.setTint import common.util.extensions.setVisible -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.theme_list_item.view.* import kotlinx.android.synthetic.main.theme_palette_list_item.view.* -import common.base.QkAdapter -import common.base.QkViewHolder import javax.inject.Inject class ThemeAdapter @Inject constructor( @@ -47,12 +44,6 @@ class ThemeAdapter @Inject constructor( private val colors: Colors ) : QkAdapter>() { - var threadId: Long = 0 - set(value) { - field = value - threadIdChanged() - } - val colorSelected: Subject = PublishSubject.create() var selectedColor: Int = -1 @@ -61,16 +52,16 @@ class ThemeAdapter @Inject constructor( val newPosition = data.indexOfFirst { it.contains(value) } field = value + iconTint = colors.textPrimaryOnThemeForColor(value) oldPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) } newPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) } } private var iconTint = 0 - private val disposables = CompositeDisposable() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.theme_palette_list_item, parent, false) + val view = LayoutInflater.from(parent.context).inflate(R.layout.theme_palette_list_item, parent, false) view.palette.flexWrap = FlexWrap.WRAP view.palette.flexDirection = FlexDirection.ROW @@ -119,15 +110,4 @@ class ThemeAdapter @Inject constructor( .forEach { theme -> view.palette.addView(theme) } } - private fun threadIdChanged() { - disposables.clear() - disposables += colors.textPrimaryOnThemeForConversation(threadId) - .subscribe { color -> iconTint = color } - - } - - override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { - disposables.clear() - } - } \ No newline at end of file diff --git a/presentation/src/main/java/feature/themepicker/ThemePickerActivity.kt b/presentation/src/main/java/feature/themepicker/ThemePickerActivity.kt index 12255938..8de730ef 100644 --- a/presentation/src/main/java/feature/themepicker/ThemePickerActivity.kt +++ b/presentation/src/main/java/feature/themepicker/ThemePickerActivity.kt @@ -25,11 +25,8 @@ import android.support.design.widget.Snackbar import android.support.v7.widget.LinearLayoutManager import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R -import com.uber.autodispose.android.lifecycle.scope -import com.uber.autodispose.kotlin.autoDisposable import common.base.QkThemedActivity import common.util.extensions.setBackgroundTint -import common.util.extensions.setTint import common.util.extensions.setVisible import dagger.android.AndroidInjection import io.reactivex.subjects.PublishSubject @@ -68,14 +65,6 @@ class ThemePickerActivity : QkThemedActivity(), ThemePickerView { materialColors.layoutManager = LinearLayoutManager(this) materialColors.adapter = themeAdapter - - colors.background - .autoDisposable(scope()) - .subscribe { color -> window.decorView.setBackgroundColor(color) } - - colors.textSecondary - .autoDisposable(scope()) - .subscribe { color -> clear.setTint(color) } } override fun showQksmsPlusSnackbar() { @@ -88,8 +77,6 @@ class ThemePickerActivity : QkThemedActivity(), ThemePickerView { override fun render(state: ThemePickerState) { tabs.setThreadId(state.threadId) - themeAdapter.threadId = state.threadId - hex.setText(Integer.toHexString(state.newColor).takeLast(6)) applyGroup.setVisible(state.applyThemeVisible) diff --git a/presentation/src/main/java/feature/themepicker/ThemePickerActivityModule.kt b/presentation/src/main/java/feature/themepicker/ThemePickerActivityModule.kt index 4a91f2f0..0243b404 100644 --- a/presentation/src/main/java/feature/themepicker/ThemePickerActivityModule.kt +++ b/presentation/src/main/java/feature/themepicker/ThemePickerActivityModule.kt @@ -1,17 +1,18 @@ package feature.themepicker import android.arch.lifecycle.ViewModel -import android.content.Intent import dagger.Module import dagger.Provides import dagger.multibindings.IntoMap import injection.ViewModelKey +import javax.inject.Named @Module class ThemePickerActivityModule { @Provides - fun provideIntent(activity: ThemePickerActivity): Intent = activity.intent + @Named("threadId") + fun provideThreadId(activity: ThemePickerActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L @Provides @IntoMap diff --git a/presentation/src/main/java/feature/themepicker/ThemePickerViewModel.kt b/presentation/src/main/java/feature/themepicker/ThemePickerViewModel.kt index e04dc426..8884e580 100644 --- a/presentation/src/main/java/feature/themepicker/ThemePickerViewModel.kt +++ b/presentation/src/main/java/feature/themepicker/ThemePickerViewModel.kt @@ -18,7 +18,6 @@ */ package feature.themepicker -import android.content.Intent import com.f2prateek.rx.preferences2.Preference import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.kotlin.autoDisposable @@ -30,23 +29,17 @@ import io.reactivex.rxkotlin.Observables import io.reactivex.rxkotlin.withLatestFrom import util.Preferences import javax.inject.Inject +import javax.inject.Named class ThemePickerViewModel @Inject constructor( - private val intent: Intent, + @Named("threadId") threadId: Long, private val billingManager: BillingManager, private val colors: Colors, private val navigator: Navigator, private val prefs: Preferences -) : QkViewModel(ThemePickerState()) { +) : QkViewModel(ThemePickerState(threadId = threadId)) { - private val threadId = intent.extras?.getLong("threadId") ?: 0L - private val theme: Preference - - init { - newState { it.copy(threadId = threadId) } - - theme = prefs.theme(threadId) - } + private val theme: Preference = prefs.theme(threadId) override fun bindView(view: ThemePickerView) { super.bindView(view) @@ -63,7 +56,7 @@ class ThemePickerViewModel @Inject constructor( // Update the color of the apply button view.hsvThemeSelectedIntent .doOnNext { color -> newState { it.copy(newColor = color) } } - .switchMap { color -> colors.textPrimaryOnThemeForColor(color) } + .map { color -> colors.textPrimaryOnThemeForColor(color) } .doOnNext { color -> newState { it.copy(newTextColor = color) } } .autoDisposable(view.scope()) .subscribe() diff --git a/presentation/src/main/java/feature/widget/WidgetAdapter.kt b/presentation/src/main/java/feature/widget/WidgetAdapter.kt index 2b643f59..ed0c3ffa 100644 --- a/presentation/src/main/java/feature/widget/WidgetAdapter.kt +++ b/presentation/src/main/java/feature/widget/WidgetAdapter.kt @@ -35,12 +35,14 @@ import common.util.Colors import common.util.DateFormatter import common.util.GlideApp import common.util.extensions.dpToPx +import common.util.extensions.getColorCompat import feature.main.MainActivity import injection.appComponent import model.Contact import model.Conversation import model.PhoneNumber import repository.MessageRepository +import util.Preferences import javax.inject.Inject class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory { @@ -53,6 +55,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory { @Inject lateinit var colors: Colors @Inject lateinit var dateFormatter: DateFormatter @Inject lateinit var messageRepo: MessageRepository + @Inject lateinit var prefs: Preferences private val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) private val smallWidget = intent.getBooleanExtra("small_widget", false) @@ -61,12 +64,19 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory { // Cache colors, load lazily. This entire class is recreated when the widget is recreated, // so if the theme changes then these values will be correct in the new instance - private val theme by lazy { colors.theme.blockingFirst() } - private val background by lazy { colors.background.blockingFirst() } - private val textPrimary by lazy { colors.textPrimary.blockingFirst() } - private val textSecondary by lazy { colors.textSecondary.blockingFirst() } - private val textTertiary by lazy { colors.textTertiary.blockingFirst() } - private val textPrimaryOnTheme by lazy { colors.textPrimaryOnTheme.blockingFirst() } + private val night by lazy { prefs.night.get() } + private val black by lazy { prefs.black.get() } + private val theme by lazy { colors.theme() } + private val background by lazy { + context.getColorCompat(when { + night && black -> R.color.black + night && !black -> R.color.backgroundDark + else -> R.color.white + }) + } + private val textPrimary by lazy { context.getColorCompat(if (night) R.color.textPrimaryDark else R.color.textPrimary) } + private val textSecondary by lazy { context.getColorCompat(if (night) R.color.textSecondaryDark else R.color.textSecondary) } + private val textTertiary by lazy { context.getColorCompat(if (night) R.color.textTertiaryDark else R.color.textTertiary) } override fun onCreate() { appComponent.inject(this) @@ -103,9 +113,9 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory { // Avatar remoteViews.setViewVisibility(R.id.avatar, if (smallWidget) View.GONE else View.VISIBLE) - remoteViews.setInt(R.id.avatar, "setBackgroundColor", theme) - remoteViews.setTextColor(R.id.initial, textPrimaryOnTheme) - remoteViews.setInt(R.id.icon, "setColorFilter", textPrimaryOnTheme) + remoteViews.setInt(R.id.avatar, "setBackgroundColor", theme.theme) + remoteViews.setTextColor(R.id.initial, theme.textPrimary) + remoteViews.setInt(R.id.icon, "setColorFilter", theme.textPrimary) remoteViews.setInt(R.id.avatarMask, "setColorFilter", background) val contact = conversation.recipients.map { recipient -> diff --git a/presentation/src/main/java/feature/widget/WidgetProvider.kt b/presentation/src/main/java/feature/widget/WidgetProvider.kt index 9499b2c1..60509555 100644 --- a/presentation/src/main/java/feature/widget/WidgetProvider.kt +++ b/presentation/src/main/java/feature/widget/WidgetProvider.kt @@ -30,16 +30,19 @@ import android.os.Bundle import android.widget.RemoteViews import com.moez.QKSMS.R import common.util.Colors +import common.util.extensions.getColorCompat import feature.compose.ComposeActivity import feature.main.MainActivity import injection.appComponent import manager.WidgetManager import timber.log.Timber +import util.Preferences import javax.inject.Inject class WidgetProvider : AppWidgetProvider() { @Inject lateinit var colors: Colors + @Inject lateinit var prefs: Preferences init { appComponent.inject(this) @@ -107,10 +110,27 @@ class WidgetProvider : AppWidgetProvider() { val remoteViews = RemoteViews(context.packageName, R.layout.widget) // Apply colors from theme - remoteViews.setInt(R.id.background, "setColorFilter", colors.background.blockingFirst()) - remoteViews.setInt(R.id.toolbar, "setColorFilter", colors.toolbarColor.blockingFirst()) - remoteViews.setTextColor(R.id.title, colors.textPrimary.blockingFirst()) - remoteViews.setInt(R.id.compose, "setColorFilter", colors.theme.blockingFirst()) + val night = prefs.night.get() + val black = prefs.black.get() + + remoteViews.setInt(R.id.background, "setColorFilter", context.getColorCompat(when { + night && black -> R.color.black + night && !black -> R.color.backgroundDark + else -> R.color.white + })) + + remoteViews.setInt(R.id.toolbar, "setColorFilter", context.getColorCompat(when { + night && black -> R.color.black + night && !black -> R.color.toolbarDark + else -> R.color.toolbarLight + })) + + remoteViews.setTextColor(R.id.title, context.getColorCompat(when (night) { + true -> R.color.textPrimaryDark + false -> R.color.textPrimary + })) + + remoteViews.setInt(R.id.compose, "setColorFilter", colors.theme().theme) // Set adapter for conversations val intent = Intent(context, WidgetService::class.java) diff --git a/presentation/src/main/java/injection/AppComponent.kt b/presentation/src/main/java/injection/AppComponent.kt index fc5d3224..86300ce8 100644 --- a/presentation/src/main/java/injection/AppComponent.kt +++ b/presentation/src/main/java/injection/AppComponent.kt @@ -27,7 +27,6 @@ import common.widget.PreferenceView import common.widget.QkEditText import common.widget.QkSwitch import common.widget.QkTextView -import common.widget.Separator import dagger.Component import dagger.android.support.AndroidSupportInjectionModule import feature.compose.DetailedChipView @@ -84,6 +83,5 @@ interface AppComponent { fun inject(view: QkEditText) fun inject(view: QkSwitch) fun inject(view: QkTextView) - fun inject(view: Separator) } \ No newline at end of file diff --git a/presentation/src/main/res/layout/about_activity.xml b/presentation/src/main/res/layout/about_activity.xml index 73ffd345..f33e6224 100644 --- a/presentation/src/main/res/layout/about_activity.xml +++ b/presentation/src/main/res/layout/about_activity.xml @@ -26,8 +26,7 @@ + app:layout_constraintTop_toTopOf="parent"> - \ No newline at end of file diff --git a/presentation/src/main/res/layout/attachment_list_item.xml b/presentation/src/main/res/layout/attachment_list_item.xml index fd2eaff9..ed174a71 100644 --- a/presentation/src/main/res/layout/attachment_list_item.xml +++ b/presentation/src/main/res/layout/attachment_list_item.xml @@ -47,8 +47,9 @@ android:layout_gravity="top|end" android:layout_margin="2dp" android:background="@drawable/circle" + android:backgroundTint="?attr/bubbleColor" android:src="@drawable/ic_cancel_black_24dp" - android:tint="@color/textSecondary" + android:tint="?android:attr/textColorSecondary" tools:backgroundTint="@color/backgroundLight" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/blocked_activity.xml b/presentation/src/main/res/layout/blocked_activity.xml index 47a1af18..66b581cd 100644 --- a/presentation/src/main/res/layout/blocked_activity.xml +++ b/presentation/src/main/res/layout/blocked_activity.xml @@ -65,9 +65,10 @@ app:title="@string/settings_should_i_answer_title" app:widget="@layout/settings_switch_widget" /> - + android:layout_height="1dp" + android:background="?android:attr/divider" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/compose_activity.xml b/presentation/src/main/res/layout/compose_activity.xml index 3f98db6d..d8ceaa78 100644 --- a/presentation/src/main/res/layout/compose_activity.xml +++ b/presentation/src/main/res/layout/compose_activity.xml @@ -22,8 +22,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:animateLayoutChanges="true" - android:orientation="vertical" - tools:background="@color/backgroundLight"> + android:background="?attr/composeBackground" + android:orientation="vertical"> + app:layout_constraintTop_toTopOf="@id/messageBackground" /> + app:layout_constraintStart_toStartOf="@id/messageBackground" /> + app:layout_constraintStart_toEndOf="@id/attach" /> + app:layout_constraintStart_toEndOf="@id/camera" /> - @@ -179,10 +182,10 @@ android:maxLines="6" android:minHeight="44dp" android:padding="12dp" + android:textColorHint="?android:attr/textColorTertiary" app:layout_constraintBottom_toBottomOf="@id/messageBackground" app:layout_constraintEnd_toEndOf="@id/messageBackground" - app:layout_constraintStart_toEndOf="@id/attachSeparator" - app:textColorHint="tertiary" /> + app:layout_constraintStart_toEndOf="@id/attachSeparator" /> + app:layout_constraintTop_toTopOf="parent"> - \ No newline at end of file diff --git a/presentation/src/main/res/layout/contact_chip.xml b/presentation/src/main/res/layout/contact_chip.xml index 1659d0e4..42181ef3 100755 --- a/presentation/src/main/res/layout/contact_chip.xml +++ b/presentation/src/main/res/layout/contact_chip.xml @@ -30,6 +30,7 @@ android:layout_height="36dp" android:layout_margin="4dp" android:background="@drawable/chip_background" + android:backgroundTint="?attr/composeBackground" android:orientation="horizontal"> diff --git a/presentation/src/main/res/layout/contact_list_item.xml b/presentation/src/main/res/layout/contact_list_item.xml index b87d8ef1..53c994ff 100644 --- a/presentation/src/main/res/layout/contact_list_item.xml +++ b/presentation/src/main/res/layout/contact_list_item.xml @@ -28,7 +28,7 @@ android:id="@+id/primary" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple" + android:background="?attr/selectableItemBackground" android:gravity="center_vertical" android:paddingBottom="8dp" android:paddingLeft="16dp" diff --git a/presentation/src/main/res/layout/contact_number_list_item.xml b/presentation/src/main/res/layout/contact_number_list_item.xml index 854afcbc..5a8ebee8 100644 --- a/presentation/src/main/res/layout/contact_number_list_item.xml +++ b/presentation/src/main/res/layout/contact_number_list_item.xml @@ -22,7 +22,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple"> + android:background="?attr/selectableItemBackground"> - + android:layout_marginBottom="8dp" + android:background="?android:attr/divider" /> - + android:layout_marginTop="8dp" + android:background="?android:attr/divider" /> - \ No newline at end of file diff --git a/presentation/src/main/res/layout/conversation_list_item.xml b/presentation/src/main/res/layout/conversation_list_item.xml index 167ce386..ae350f4e 100644 --- a/presentation/src/main/res/layout/conversation_list_item.xml +++ b/presentation/src/main/res/layout/conversation_list_item.xml @@ -22,7 +22,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple" + android:background="?attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" android:paddingBottom="12dp" diff --git a/presentation/src/main/res/layout/conversation_media_list_item.xml b/presentation/src/main/res/layout/conversation_media_list_item.xml index 0732ad6f..cb7d5954 100644 --- a/presentation/src/main/res/layout/conversation_media_list_item.xml +++ b/presentation/src/main/res/layout/conversation_media_list_item.xml @@ -22,5 +22,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?android:attr/divider" android:scaleType="centerCrop" tools:src="@tools:sample/backgrounds/scenic" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/conversation_recipient_list_item.xml b/presentation/src/main/res/layout/conversation_recipient_list_item.xml index 9bd568a4..fdb26933 100644 --- a/presentation/src/main/res/layout/conversation_recipient_list_item.xml +++ b/presentation/src/main/res/layout/conversation_recipient_list_item.xml @@ -22,7 +22,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple" + android:background="?attr/selectableItemBackground" android:paddingBottom="8dp" android:paddingEnd="16dp" android:paddingStart="24dp" @@ -64,9 +64,9 @@ android:layout_height="40dp" android:padding="8dp" android:src="@drawable/ic_person_add_black_24dp" + android:tint="?android:attr/textColorSecondary" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent" - tools:tint="@color/textSecondary" /> + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/drawer_view.xml b/presentation/src/main/res/layout/drawer_view.xml index e204623f..e4e00dbe 100644 --- a/presentation/src/main/res/layout/drawer_view.xml +++ b/presentation/src/main/res/layout/drawer_view.xml @@ -22,9 +22,9 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?android:attr/windowBackground" android:orientation="vertical" - android:paddingTop="8dp" - tools:background="@color/white"> + android:paddingTop="8dp"> + tools:tint="?android:attr/textColorSecondary" /> + tools:tint="?android:attr/textColorSecondary" /> - + android:layout_marginTop="8dp" + android:background="?android:attr/divider" /> + tools:tint="?android:attr/textColorSecondary" /> + tools:tint="?android:attr/textColorSecondary" /> + tools:tint="?android:attr/textColorSecondary" /> + android:backgroundTint="?android:attr/divider"> + android:layout_height="match_parent"> + app:layout_constraintTop_toTopOf="parent"> @@ -102,10 +100,11 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbar" /> - + android:layout_gravity="start" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/menu_list_item.xml b/presentation/src/main/res/layout/menu_list_item.xml index a21c084d..8df83adb 100644 --- a/presentation/src/main/res/layout/menu_list_item.xml +++ b/presentation/src/main/res/layout/menu_list_item.xml @@ -20,7 +20,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple" + android:background="?attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal"> @@ -30,7 +30,7 @@ android:layout_height="24dp" android:layout_marginStart="24dp" android:src="@drawable/radio_button" - tools:tint="@color/textTertiary" /> + tools:tint="?android:attr/textColorTertiary" /> + android:background="?attr/selectableItemBackground"> + android:background="?attr/selectableItemBackground"> + app:layout_constraintTop_toTopOf="parent"> - + android:layout_marginTop="8dp" + android:background="?android:attr/divider" /> - \ No newline at end of file diff --git a/presentation/src/main/res/layout/preference_view.xml b/presentation/src/main/res/layout/preference_view.xml index 14f6c0ee..7b620847 100644 --- a/presentation/src/main/res/layout/preference_view.xml +++ b/presentation/src/main/res/layout/preference_view.xml @@ -21,6 +21,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" tools:parentTag="common.widget.PreferenceView"> + app:layout_constraintTop_toTopOf="@id/message" /> + app:layout_constraintTop_toBottomOf="@id/composeBackgroundGradient" /> + app:layout_constraintTop_toBottomOf="@id/messages" /> diff --git a/presentation/src/main/res/layout/qksms_plus_activity.xml b/presentation/src/main/res/layout/qksms_plus_activity.xml index 6329e0ce..835a048a 100644 --- a/presentation/src/main/res/layout/qksms_plus_activity.xml +++ b/presentation/src/main/res/layout/qksms_plus_activity.xml @@ -21,8 +21,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:background="@color/white"> + android:layout_height="match_parent"> @@ -110,6 +110,7 @@ android:layout_marginEnd="24dp" android:layout_marginStart="24dp" android:background="@drawable/rounded_rectangle_2dp" + android:backgroundTint="?android:attr/divider" android:padding="16dp" tools:backgroundTint="@color/separatorLight"> @@ -173,10 +174,11 @@ - + android:layout_marginBottom="8dp" + android:background="?android:attr/divider" /> @@ -32,11 +32,12 @@ android:visibility="gone" app:constraint_referenced_ids="resultsSeparator, resultsTitle" /> - + app:layout_constraintTop_toTopOf="parent"> - + android:layout_marginTop="8dp" + android:background="?android:attr/divider" /> + app:title="@string/settings_delayed_title" + tools:summary="No delay" /> - + android:layout_marginTop="8dp" + android:background="?android:attr/divider" /> - \ No newline at end of file diff --git a/presentation/src/main/res/layout/tab_view.xml b/presentation/src/main/res/layout/tab_view.xml index 1b3d9c6b..a380fd0e 100644 --- a/presentation/src/main/res/layout/tab_view.xml +++ b/presentation/src/main/res/layout/tab_view.xml @@ -22,7 +22,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="@drawable/ripple" + android:background="?attr/selectableItemBackground" android:backgroundTint="@android:color/transparent" android:gravity="center" android:paddingEnd="12dp" diff --git a/presentation/src/main/res/layout/theme_palette_list_item.xml b/presentation/src/main/res/layout/theme_palette_list_item.xml index 5a0f722a..6c6baf4d 100644 --- a/presentation/src/main/res/layout/theme_palette_list_item.xml +++ b/presentation/src/main/res/layout/theme_palette_list_item.xml @@ -28,8 +28,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - + android:layout_height="1dp" + android:background="?android:attr/divider" /> \ No newline at end of file diff --git a/presentation/src/main/res/layout/theme_picker_activity.xml b/presentation/src/main/res/layout/theme_picker_activity.xml index a5b12040..51b9cead 100644 --- a/presentation/src/main/res/layout/theme_picker_activity.xml +++ b/presentation/src/main/res/layout/theme_picker_activity.xml @@ -30,6 +30,7 @@ android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="40dp" + android:background="?attr/colorPrimary" android:orientation="horizontal" android:paddingEnd="12dp" android:paddingStart="12dp" /> @@ -62,10 +63,11 @@ android:layout_height="8dp" android:background="@drawable/ab_shadow" /> - + android:layout_gravity="bottom" + android:background="?android:attr/divider" /> diff --git a/presentation/src/main/res/layout/theme_picker_hsv.xml b/presentation/src/main/res/layout/theme_picker_hsv.xml index c96f4256..19fe5e93 100644 --- a/presentation/src/main/res/layout/theme_picker_hsv.xml +++ b/presentation/src/main/res/layout/theme_picker_hsv.xml @@ -4,8 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:animateLayoutChanges="true" - tools:background="@color/white"> + android:animateLayoutChanges="true"> - @@ -76,22 +76,23 @@ android:layout_height="wrap_content" app:constraint_referenced_ids="applyDivider, clear, apply" /> - + app:layout_constraintStart_toStartOf="parent" /> + xmlns:tools="http://schemas.android.com/tools"> + tools:tint="@color/textPrimaryDark" /> diff --git a/presentation/src/main/res/values/attrs.xml b/presentation/src/main/res/values/attrs.xml index 8e14a941..9677ad8f 100644 --- a/presentation/src/main/res/values/attrs.xml +++ b/presentation/src/main/res/values/attrs.xml @@ -44,11 +44,6 @@ - - - - - diff --git a/presentation/src/main/res/values/colors.xml b/presentation/src/main/res/values/colors.xml index 901e2e3b..96f2476a 100644 --- a/presentation/src/main/res/values/colors.xml +++ b/presentation/src/main/res/values/colors.xml @@ -34,9 +34,6 @@ #ECEFF1 #192025 - #0C000000 - #0CFFFFFF - #49555F #70808D #B7B9C0 diff --git a/presentation/src/main/res/values/styles.xml b/presentation/src/main/res/values/styles.xml index 1e5e770a..aabda93d 100644 --- a/presentation/src/main/res/values/styles.xml +++ b/presentation/src/main/res/values/styles.xml @@ -50,7 +50,7 @@ - @color/black + ?attr/colorPrimary center_vertical @@ -88,7 +88,7 @@ - - - - - - diff --git a/presentation/src/main/res/values/themes.xml b/presentation/src/main/res/values/themes.xml index ab8bf677..5b14e18f 100644 --- a/presentation/src/main/res/values/themes.xml +++ b/presentation/src/main/res/values/themes.xml @@ -1,54 +1,106 @@ + + + + + + - + + + - + + \ No newline at end of file