forked from upstream-mirrors/quik
Remove Observables from Views
commit 6bb74ca5201cba2fc5de2db349bb7627c028b617 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 15:15:27 2018 -0400 Fix crash when tapping on selected contact commit f5a45e2a600a8d373160dcb0273bab232e6cc0c5 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 15:10:44 2018 -0400 Add missing attributes for dialog themes commit 2188adbe5948b9b71f816dad5fb115829ba57e30 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:59:39 2018 -0400 Refresh settings activity when theme changed commit a9541019c566a3a6e41e64ea8136f7fd50a6d364 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:56:33 2018 -0400 Don't use themed attributes in widget commit 4823a3034848efac624eb82856f692c7f9e775a5 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:29:00 2018 -0400 Refresh adapter in conversation info when theme changed commit 7ea5837b99c2b6eac547dad383515ee7b79ff6e4 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 18:27:08 2018 -0400 Bundle theme colors into data class commit 6a832fdde98622c5a252aca0cac3150a6eb0f554 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 17:16:21 2018 -0400 Update conversation UI when theme changed commit ef6948e80ed8734a7fefbec1b00f1b32e8209072 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 16:15:39 2018 -0400 Fix avatar not respecting theme commit 4ea21b6a9963f91d3b9cdaf0ba4749a6f24e8a74 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 15:52:40 2018 -0400 Fix checkmark color in theme picker commit 270a9d3037439f165a110c7d7dcaf7dd84dad29f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 13:39:12 2018 -0400 Update views in MainActivity when theme changed commit cdc1187ccaee800e4305da5fab5d22220d04440f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 23:36:17 2018 -0400 Remove unnecessary programmatic creation of drawer item background commit bc6fbfa75c66bb81db9591617f8c1de4c0f2746f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 23:28:44 2018 -0400 Temporarily disable RxJava2Debug commit eae422be0bab8cedb3cb5ddf5f4ae61368ab5d1e Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 21:16:46 2018 -0400 Remove observable usage inside of custom views commit 2e65d55b9b283e74fb395d4828eb310395b4902b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 02:27:26 2018 -0400 Migrate ripple and text size to no longer use observables
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<Conversation>() {
|
||||
class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
|
||||
|
||||
val unblock: PublishSubject<Long> = 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) {
|
||||
|
||||
@@ -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<Attachment>() {
|
||||
|
||||
val attachmentDeleted: Subject<Attachment> = 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Contact>() {
|
||||
class ChipsAdapter @Inject constructor(private val context: Context) : QkAdapter<Contact>() {
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -38,9 +38,8 @@ class ContactAdapter @Inject constructor(private val context: Context) : QkAdapt
|
||||
val contactSelected: Subject<Contact> = 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Long, Boolean>()
|
||||
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<ProgressBar>(R.id.cancel).setBackgroundTint(color)
|
||||
}
|
||||
disposables += theme
|
||||
.subscribe { color ->
|
||||
view.findViewById<ImageView>(R.id.cancelIcon).setTint(color)
|
||||
view.findViewById<ProgressBar>(R.id.cancel).setTint(color)
|
||||
}
|
||||
view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
|
||||
view.findViewById<ProgressBar>(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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -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<ConversationInfoView, ConversationInfoState>(ConversationInfoState()) {
|
||||
|
||||
) : QkViewModel<ConversationInfoView, ConversationInfoState>(
|
||||
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
|
||||
) {
|
||||
|
||||
private val conversation: Observable<Conversation>
|
||||
|
||||
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<Conversation>()
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
|
||||
@@ -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<MmsPart>() {
|
||||
|
||||
val thumbnailClicks: PublishSubject<View> = 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)
|
||||
}
|
||||
|
||||
|
||||
+1
-11
@@ -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<Recipient>() {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Conversation>() {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<SearchResult>() {
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -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) }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Int> = 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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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<List<Int>>() {
|
||||
|
||||
var threadId: Long = 0
|
||||
set(value) {
|
||||
field = value
|
||||
threadIdChanged()
|
||||
}
|
||||
|
||||
val colorSelected: Subject<Int> = 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()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<ThemePickerView, ThemePickerState>(ThemePickerState()) {
|
||||
) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
||||
|
||||
private val threadId = intent.extras?.getLong("threadId") ?: 0L
|
||||
private val theme: Preference<Int>
|
||||
|
||||
init {
|
||||
newState { it.copy(threadId = threadId) }
|
||||
|
||||
theme = prefs.theme(threadId)
|
||||
}
|
||||
private val theme: Preference<Int> = 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()
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user