mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Set up dumb ThemeManager, don't rely on color resources for themed assets
This commit is contained in:
@@ -5,7 +5,9 @@ import com.moez.QKSMS.receiver.SmsReceiver
|
|||||||
import com.moez.QKSMS.ui.conversations.ConversationAdapter
|
import com.moez.QKSMS.ui.conversations.ConversationAdapter
|
||||||
import com.moez.QKSMS.ui.conversations.ConversationListViewModel
|
import com.moez.QKSMS.ui.conversations.ConversationListViewModel
|
||||||
import com.moez.QKSMS.ui.messages.MessageAdapter
|
import com.moez.QKSMS.ui.messages.MessageAdapter
|
||||||
|
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||||
import com.moez.QKSMS.ui.messages.MessageListViewModel
|
import com.moez.QKSMS.ui.messages.MessageListViewModel
|
||||||
|
import com.moez.QKSMS.util.NotificationManager
|
||||||
import dagger.Component
|
import dagger.Component
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -16,10 +18,14 @@ interface AppComponent {
|
|||||||
fun inject(receiver: SmsReceiver)
|
fun inject(receiver: SmsReceiver)
|
||||||
fun inject(receiver: MessageSentReceiver)
|
fun inject(receiver: MessageSentReceiver)
|
||||||
|
|
||||||
|
fun inject(activity: MessageListActivity)
|
||||||
|
|
||||||
fun inject(viewModel: ConversationListViewModel)
|
fun inject(viewModel: ConversationListViewModel)
|
||||||
fun inject(viewModel: MessageListViewModel)
|
fun inject(viewModel: MessageListViewModel)
|
||||||
|
|
||||||
fun inject(adapter: MessageAdapter)
|
fun inject(adapter: MessageAdapter)
|
||||||
fun inject(adapter: ConversationAdapter)
|
fun inject(adapter: ConversationAdapter)
|
||||||
|
|
||||||
|
fun inject(manager: NotificationManager)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import com.moez.QKSMS.data.sync.SyncManager
|
import com.moez.QKSMS.data.sync.SyncManager
|
||||||
import com.moez.QKSMS.util.DateFormatter
|
import com.moez.QKSMS.util.DateFormatter
|
||||||
import com.moez.QKSMS.util.NotificationManager
|
import com.moez.QKSMS.util.NotificationManager
|
||||||
|
import com.moez.QKSMS.util.ThemeManager
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@@ -32,6 +33,12 @@ class AppModule(var application: Application) {
|
|||||||
return SyncManager(context, contacts)
|
return SyncManager(context, contacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideThemeMaager(): ThemeManager {
|
||||||
|
return ThemeManager()
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideNotificationHelper(context: Context, messageRepository: MessageRepository): NotificationManager {
|
fun provideNotificationHelper(context: Context, messageRepository: MessageRepository): NotificationManager {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import com.moez.QKSMS.dagger.AppComponentManager
|
|||||||
import com.moez.QKSMS.data.model.Contact
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.util.DateFormatter
|
import com.moez.QKSMS.util.DateFormatter
|
||||||
|
import com.moez.QKSMS.util.ThemeManager
|
||||||
import com.moez.QKSMS.util.extensions.dpToPx
|
import com.moez.QKSMS.util.extensions.dpToPx
|
||||||
|
import com.moez.QKSMS.util.extensions.setBackgroundTint
|
||||||
import com.moez.QKSMS.util.extensions.setMargins
|
import com.moez.QKSMS.util.extensions.setMargins
|
||||||
import io.realm.OrderedRealmCollection
|
import io.realm.OrderedRealmCollection
|
||||||
import io.realm.RealmRecyclerViewAdapter
|
import io.realm.RealmRecyclerViewAdapter
|
||||||
@@ -27,6 +29,7 @@ class MessageAdapter(data: OrderedRealmCollection<Message>?) : RealmRecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
@Inject lateinit var context: Context
|
||||||
|
@Inject lateinit var themeManager: ThemeManager
|
||||||
@Inject lateinit var dateFormatter: DateFormatter
|
@Inject lateinit var dateFormatter: DateFormatter
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -34,12 +37,23 @@ class MessageAdapter(data: OrderedRealmCollection<Message>?) : RealmRecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MessageViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MessageViewHolder {
|
||||||
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val layoutRes: Int
|
||||||
val layoutRes = when (viewType) {
|
val bubbleColor: Int
|
||||||
VIEWTYPE_IN -> R.layout.message_list_item_in
|
when (viewType) {
|
||||||
else -> R.layout.message_list_item_out
|
VIEWTYPE_IN -> {
|
||||||
|
layoutRes = R.layout.message_list_item_in
|
||||||
|
bubbleColor = themeManager.bubbleColor
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
layoutRes = R.layout.message_list_item_out
|
||||||
|
bubbleColor = themeManager.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return MessageViewHolder(layoutInflater.inflate(layoutRes, parent, false))
|
|
||||||
|
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
val viewHolder = MessageViewHolder(layoutInflater.inflate(layoutRes, parent, false))
|
||||||
|
viewHolder.body.setBackgroundTint(bubbleColor)
|
||||||
|
return viewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
||||||
|
|||||||
@@ -8,20 +8,25 @@ import android.support.v7.widget.RecyclerView
|
|||||||
import com.jakewharton.rxbinding2.view.RxView
|
import com.jakewharton.rxbinding2.view.RxView
|
||||||
import com.jakewharton.rxbinding2.widget.RxTextView
|
import com.jakewharton.rxbinding2.widget.RxTextView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.dagger.AppComponentManager
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.ui.base.QkActivity
|
import com.moez.QKSMS.ui.base.QkActivity
|
||||||
|
import com.moez.QKSMS.util.ThemeManager
|
||||||
import com.moez.QKSMS.util.extensions.setTint
|
import com.moez.QKSMS.util.extensions.setTint
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import kotlinx.android.synthetic.main.message_list_activity.*
|
import kotlinx.android.synthetic.main.message_list_activity.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessageListActivity : QkActivity(), Observer<MessageListViewState> {
|
class MessageListActivity : QkActivity(), Observer<MessageListViewState> {
|
||||||
|
|
||||||
private lateinit var viewModel: MessageListViewModel
|
@Inject lateinit var themeManager: ThemeManager
|
||||||
|
|
||||||
|
private lateinit var viewModel: MessageListViewModel
|
||||||
private lateinit var layoutManager: LinearLayoutManager
|
private lateinit var layoutManager: LinearLayoutManager
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
AppComponentManager.appComponent.inject(this)
|
||||||
setContentView(R.layout.message_list_activity)
|
setContentView(R.layout.message_list_activity)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
@@ -29,6 +34,8 @@ class MessageListActivity : QkActivity(), Observer<MessageListViewState> {
|
|||||||
viewModel.threadId = intent.getLongExtra("threadId", 0)
|
viewModel.threadId = intent.getLongExtra("threadId", 0)
|
||||||
viewModel.state.observe(this, this)
|
viewModel.state.observe(this, this)
|
||||||
|
|
||||||
|
attach.setTint(themeManager.color)
|
||||||
|
|
||||||
layoutManager = LinearLayoutManager(this)
|
layoutManager = LinearLayoutManager(this)
|
||||||
layoutManager.stackFromEnd = true
|
layoutManager.stackFromEnd = true
|
||||||
messageList.layoutManager = layoutManager
|
messageList.layoutManager = layoutManager
|
||||||
@@ -45,7 +52,7 @@ class MessageListActivity : QkActivity(), Observer<MessageListViewState> {
|
|||||||
if (message.text.toString() != state.draft) message.setText(state.draft)
|
if (message.text.toString() != state.draft) message.setText(state.draft)
|
||||||
if (state.hasError) finish()
|
if (state.hasError) finish()
|
||||||
|
|
||||||
val color = if (state.canSend) R.color.colorPrimary else R.color.textTertiary
|
val color = if (state.canSend) themeManager.color else R.color.textTertiary
|
||||||
send.setTint(resources.getColor(color))
|
send.setTint(resources.getColor(color))
|
||||||
send.isEnabled = state.canSend
|
send.isEnabled = state.canSend
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,20 @@ import android.os.Build
|
|||||||
import android.support.v4.app.NotificationCompat
|
import android.support.v4.app.NotificationCompat
|
||||||
import android.support.v4.app.NotificationManagerCompat
|
import android.support.v4.app.NotificationManagerCompat
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.dagger.AppComponentManager
|
||||||
import com.moez.QKSMS.data.repository.MessageRepository
|
import com.moez.QKSMS.data.repository.MessageRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class NotificationManager(val context: Context, val messageRepo: MessageRepository) {
|
class NotificationManager(val context: Context, val messageRepo: MessageRepository) {
|
||||||
|
|
||||||
|
@Inject lateinit var themeManager: ThemeManager
|
||||||
|
|
||||||
private val notificationManager = NotificationManagerCompat.from(context)
|
private val notificationManager = NotificationManagerCompat.from(context)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
AppComponentManager.appComponent.inject(this)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if (Build.VERSION.SDK_INT >= 26) {
|
||||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
@@ -46,7 +52,7 @@ class NotificationManager(val context: Context, val messageRepo: MessageReposito
|
|||||||
}
|
}
|
||||||
|
|
||||||
val notification = NotificationCompat.Builder(context, "channel_1")
|
val notification = NotificationCompat.Builder(context, "channel_1")
|
||||||
.setColor(context.resources.getColor(R.color.colorPrimary))
|
.setColor(themeManager.color)
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setStyle(style)
|
.setStyle(style)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.moez.QKSMS.util
|
||||||
|
|
||||||
|
class ThemeManager {
|
||||||
|
|
||||||
|
val color = 0xFF0BAE9F.toInt()
|
||||||
|
val bubbleColor = 0xFFF4F4F4.toInt()
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,6 +9,10 @@ fun ImageView.setTint(color: Int) {
|
|||||||
imageTintList = ColorStateList.valueOf(color)
|
imageTintList = ColorStateList.valueOf(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun View.setBackgroundTint(color: Int) {
|
||||||
|
backgroundTintList = ColorStateList.valueOf(color)
|
||||||
|
}
|
||||||
|
|
||||||
fun View.setMargins(left: Int? = null, top: Int? = null, right: Int? = null, bottom: Int? = null) {
|
fun View.setMargins(left: Int? = null, top: Int? = null, right: Int? = null, bottom: Int? = null) {
|
||||||
val lp = layoutParams as? ViewGroup.MarginLayoutParams ?: return
|
val lp = layoutParams as? ViewGroup.MarginLayoutParams ?: return
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,7 @@
|
|||||||
android:layout_height="56dp"
|
android:layout_height="56dp"
|
||||||
android:background="?selectableItemBackgroundBorderless"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:src="@drawable/ic_add_black_24dp"
|
android:src="@drawable/ic_add_black_24dp" />
|
||||||
android:tint="@color/colorPrimary" />
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:background="@drawable/message_only"
|
android:background="@drawable/message_only"
|
||||||
android:backgroundTint="@color/colorPrimary"
|
|
||||||
android:gravity="start|center_vertical"
|
android:gravity="start|center_vertical"
|
||||||
android:minHeight="36dp"
|
android:minHeight="36dp"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
@@ -46,6 +45,7 @@
|
|||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:textColor="@color/textPrimaryLight"
|
android:textColor="@color/textPrimaryLight"
|
||||||
|
tools:backgroundTint="#0BAE9F"
|
||||||
tools:text="Hey! How's it going?" />
|
tools:text="Hey! How's it going?" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -57,8 +57,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
android:textColor="@color/textTertiary"
|
|
||||||
android:layout_marginRight="24dp"
|
android:layout_marginRight="24dp"
|
||||||
|
android:textColor="@color/textTertiary"
|
||||||
tools:text="Sending" />
|
tools:text="Sending" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="AppTheme" parent="AppBaseTheme">
|
||||||
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#0CB8A8</color>
|
|
||||||
<color name="colorPrimaryDark">#0AA596</color>
|
|
||||||
<color name="colorAccent">#FF4081</color>
|
|
||||||
|
|
||||||
<color name="white">#FFFFFF</color>
|
<color name="white">#FFFFFF</color>
|
||||||
|
|
||||||
<color name="textPrimary">#49555F</color>
|
<color name="textPrimary">#49555F</color>
|
||||||
@@ -17,6 +13,7 @@
|
|||||||
<color name="bubbleLight">#F4F4F4</color>
|
<color name="bubbleLight">#F4F4F4</color>
|
||||||
|
|
||||||
<color name="backgroundLight">#f8f8f8</color>
|
<color name="backgroundLight">#f8f8f8</color>
|
||||||
|
<color name="statusLight">#F1F1F1</color>
|
||||||
|
|
||||||
<color name="list_separator">#F2F2F2</color>
|
<color name="list_separator">#F2F2F2</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="AppBaseTheme" />
|
||||||
|
|
||||||
|
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||||
<item name="android:fontFamily">@font/lato</item>
|
<item name="android:fontFamily">@font/lato</item>
|
||||||
<item name="android:windowBackground">@color/white</item>
|
<item name="android:windowBackground">@color/white</item>
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/white</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/statusLight</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="TextPrimary">
|
<style name="TextPrimary">
|
||||||
|
|||||||
Reference in New Issue
Block a user