Commit 54740a93 authored by Dayona Joseph's avatar Dayona Joseph
Browse files

Use system accent color in Message

parent 5ad96935
Pipeline #69735 passed with stage
in 11 minutes and 45 seconds
......@@ -18,9 +18,12 @@
*/
package com.moez.QKSMS.util
import android.R
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.util.TypedValue
import android.view.ContextThemeWrapper
import com.f2prateek.rx.preferences2.Preference
import com.f2prateek.rx.preferences2.RxSharedPreferences
import com.moez.QKSMS.common.util.extensions.versionCode
......@@ -28,7 +31,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class Preferences @Inject constructor(context: Context, private val rxPrefs: RxSharedPreferences) {
class Preferences @Inject constructor(private val context: Context, private val rxPrefs: RxSharedPreferences) {
companion object {
const val NIGHT_MODE_SYSTEM = 0
......@@ -118,12 +121,24 @@ class Preferences @Inject constructor(context: Context, private val rxPrefs: RxS
}
}
fun theme(threadId: Long = 0): Preference<Int> {
val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
fun systemColor(): Int {
val typedValue = TypedValue()
val contextThemeWrapper = ContextThemeWrapper(context,
R.style.Theme_DeviceDefault)
contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent,
typedValue, true)
return when (threadId) {
0L -> default
else -> rxPrefs.getInteger("theme_$threadId", default.get())
return typedValue.data
}
fun theme(
recipientId: Long = 0,
default: Int = rxPrefs.getInteger("theme", 0xFF7bb6ff.toInt()).get()
): Preference<Int> {
return when (recipientId) {
0L -> rxPrefs.getInteger("theme", systemColor())
// 0L -> rxPrefs.getInteger("theme", 0xFF0097A7.toInt())
else -> rxPrefs.getInteger("theme_$recipientId", default)
}
}
......
......@@ -109,7 +109,7 @@ abstract class QkThemedActivity : QkActivity() {
Observables.combineLatest(menu, theme) { menu, theme ->
menu.iterator().forEach { menuItem ->
val tint = when (menuItem.itemId) {
in getColoredMenuItems() -> theme.theme
in getColoredMenuItems() -> prefs.systemColor()
else -> textSecondary
}
......
......@@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget
import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.View
import android.widget.FrameLayout
import com.bumptech.glide.signature.ObjectKey
......@@ -32,6 +34,7 @@ import com.moez.QKSMS.injection.appComponent
import com.moez.QKSMS.model.Contact
import com.moez.QKSMS.model.Recipient
import com.moez.QKSMS.util.GlideApp
import com.moez.QKSMS.util.Preferences
import kotlinx.android.synthetic.main.avatar_view.view.*
import javax.inject.Inject
......@@ -39,6 +42,8 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
@Inject lateinit var colors: Colors
@Inject lateinit var navigator: Navigator
@Inject lateinit var prefs: Preferences
/**
* This value can be changes if we should use the theme from a particular conversation
......@@ -115,6 +120,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
}
private fun updateView() {
setBackgroundTint(prefs.systemColor())
if (name?.isNotEmpty() == true) {
initial.text = name?.substring(0, 1)
icon.visibility = GONE
......
......@@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget
import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.Gravity
import android.view.View
import android.widget.TextView
......@@ -29,11 +31,16 @@ import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute
import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.injection.appComponent
import com.moez.QKSMS.util.Preferences
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 prefs: Preferences
var title: String? = null
set(value) {
......@@ -72,7 +79,7 @@ class PreferenceView @JvmOverloads constructor(
orientation = HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary)
icon.setColorFilter(prefs.systemColor())
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run {
title = getString(R.styleable.PreferenceView_title)
......@@ -92,5 +99,4 @@ class PreferenceView @JvmOverloads constructor(
recycle()
}
}
}
\ No newline at end of file
......@@ -33,6 +33,8 @@ import android.provider.ContactsContract
import android.provider.MediaStore
import android.text.format.DateFormat
import android.util.Log
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
......@@ -147,10 +149,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
message.supportsInputContent = true
theme
.doOnNext { loading.setTint(it.theme) }
.doOnNext { attach.setBackgroundTint(it.theme) }
.doOnNext { attach.setTint(it.textPrimary) }
.doOnNext { messageAdapter.theme = it }
.doOnNext { loading.setTint(prefs.systemColor()) }
.doOnNext { attach.setBackgroundTint(prefs.systemColor()) }
.doOnNext { send.setTint(prefs.systemColor()) }
.autoDisposable(scope())
.subscribe { messageList.scrapViews() }
......
......@@ -26,6 +26,8 @@ import android.text.Layout
import android.text.Spannable
import android.text.SpannableString
import android.text.style.StyleSpan
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -59,6 +61,7 @@ import com.moez.QKSMS.util.Preferences
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import io.realm.RealmResults
import kotlinx.android.synthetic.main.message_list_item_in.*
import kotlinx.android.synthetic.main.message_list_item_in.view.*
import java.util.*
import java.util.concurrent.TimeUnit
......@@ -236,6 +239,9 @@ class MessagesAdapter @Inject constructor(
view.avatar.threadId = conversation?.id ?: 0
view.avatar.setContact(contactCache[message.address])
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
view.avatar.setBackgroundTint(prefs.systemColor())
view.body.setTextColor(theme.textPrimary)
view.body.setBackgroundTint(prefs.systemColor())
}
// Bind the body text
......@@ -333,4 +339,5 @@ class MessagesAdapter @Inject constructor(
}
}
}
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="10dp"
android:height="10dp"
android:viewportWidth="10"
android:viewportHeight="10">
<path
android:pathData="M7.6756,4.5149C7.6756,4.4603 7.6392,4.4055 7.6027,4.369C7.5663,4.3326 7.5113,4.2961 7.4566,4.2961H5.669V2.5084C5.669,2.4538 5.6327,2.3989 5.5961,2.3624C5.5597,2.326 5.5048,2.2895 5.4501,2.2895H5.2312C5.1583,2.2895 5.1036,2.3258 5.0671,2.3624C5.0307,2.3988 5.0125,2.4537 5.0125,2.5084V4.2961H3.2248C3.1518,4.2961 3.0971,4.3325 3.0606,4.369C3.0243,4.4054 3.0061,4.4602 3.0061,4.5149V4.7338C3.0061,4.8068 3.0243,4.8616 3.0606,4.898C3.097,4.9344 3.1518,4.9526 3.2248,4.9526H5.0125V6.7403C5.0125,6.8132 5.0307,6.8679 5.0671,6.9044C5.1035,6.9408 5.1583,6.959 5.2312,6.959H5.4501C5.5047,6.959 5.5596,6.9408 5.5961,6.9044C5.6325,6.868 5.669,6.8132 5.669,6.7403V4.9526H7.4566C7.5112,4.9526 7.5661,4.9344 7.6027,4.898C7.6391,4.8617 7.6756,4.8068 7.6756,4.7338V4.5149ZM9.8646,4.6243C9.8646,3.8217 9.6456,3.0556 9.2443,2.3624C8.843,1.6693 8.2958,1.122 7.6027,0.7207C6.9094,0.3194 6.1433,0.1005 5.3407,0.1005C4.5198,0.1005 3.7719,0.3194 3.0788,0.7207C2.3856,1.122 1.8201,1.6693 1.4188,2.3624C1.0175,3.0556 0.8168,3.8217 0.8168,4.6243C0.8168,5.4452 1.0175,6.1931 1.4188,6.8863C1.8201,7.5795 2.3856,8.1449 3.0788,8.5462C3.7719,8.9475 4.5198,9.1482 5.3407,9.1482C6.1433,9.1482 6.9094,8.9475 7.6027,8.5462C8.2958,8.1449 8.843,7.5795 9.2443,6.8863C9.6456,6.1931 9.8646,5.4452 9.8646,4.6243ZM9.2809,4.6243C9.2809,5.3357 9.0984,5.9924 8.7518,6.5944C8.387,7.2146 7.9127,7.6889 7.3107,8.0355C6.7088,8.4003 6.0521,8.5645 5.3407,8.5645C4.6293,8.5645 3.9726,8.4003 3.3706,8.0355C2.7504,7.6889 2.2762,7.2146 1.9295,6.6127C1.5647,6.0107 1.4006,5.3541 1.4006,4.6426C1.4006,3.9312 1.5647,3.2745 1.9295,2.6543C2.2762,2.0523 2.7503,1.578 3.3523,1.2132C3.9543,0.8666 4.611,0.6843 5.3225,0.6843C6.0338,0.6843 6.6906,0.8666 7.3107,1.2132C7.9127,1.578 8.387,2.0523 8.7518,2.6543C9.0984,3.2562 9.2809,3.9129 9.2809,4.6243Z"
android:fillColor="#000000"/>
</vector>
......@@ -560,14 +560,11 @@
android:layout_height="44dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/circle"
android:background="@drawable/ic_plus"
android:contentDescription="@string/compose_attach_cd"
android:elevation="4dp"
android:padding="10dp"
android:src="@drawable/ic_add_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:backgroundTint="@color/tools_theme"
tools:tint="@color/textPrimaryDark" />
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment