forked from upstream-mirrors/quik
Fix menu icon tinting
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.moez.QKSMS.presentation.base
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
@@ -9,7 +8,10 @@ import android.view.MenuItem
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.presentation.Navigator
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.reflect.KClass
|
||||
@@ -23,31 +25,38 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
|
||||
ViewModelProviders.of(this, Navigator.ViewModelFactory(intent))[viewModelClass.java]
|
||||
}
|
||||
|
||||
protected var menu: Menu? = null
|
||||
protected val menu: Subject<Menu> = BehaviorSubject.create()
|
||||
|
||||
protected var disposables = CompositeDisposable()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
onNewIntent(intent)
|
||||
|
||||
// Update the colours of the menu items
|
||||
disposables += colors.theme.subscribe { color ->
|
||||
menu?.let { menu ->
|
||||
(0 until menu.size())
|
||||
.map { position -> menu.getItem(position) }
|
||||
.forEach { menuItem ->
|
||||
menuItem.icon?.let { newIcon ->
|
||||
newIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
|
||||
menuItem.icon = newIcon
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
// Update the colours of the menu items
|
||||
disposables += Observables.combineLatest(menu, colors.theme, { menu, color ->
|
||||
(0 until menu.size())
|
||||
.map { position -> menu.getItem(position) }
|
||||
.forEach { menuItem ->
|
||||
menuItem?.icon?.run {
|
||||
setTint(color)
|
||||
menuItem.icon = this
|
||||
}
|
||||
}
|
||||
}).subscribe()
|
||||
|
||||
disposables += colors.textTertiary
|
||||
.subscribe { color ->
|
||||
toolbar?.navigationIcon?.run {
|
||||
setTint(color)
|
||||
toolbar.navigationIcon = this
|
||||
}
|
||||
}
|
||||
|
||||
disposables += colors.background
|
||||
.doOnNext { color -> window.statusBarColor = color }
|
||||
.doOnNext { color -> toolbar?.setBackgroundColor(color) }
|
||||
@@ -81,8 +90,11 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
this.menu = menu
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
val result = super.onCreateOptionsMenu(menu)
|
||||
if (menu != null) {
|
||||
this.menu.onNext(menu)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
||||
override val chipSelectedIntent: Subject<Contact> by lazy { contactsAdapter.contactSelected }
|
||||
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
||||
override val menuReadyIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||
override val callIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val archiveIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val deleteIntent: Subject<Unit> = PublishSubject.create()
|
||||
@@ -109,17 +109,19 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
contacts.setVisible(state.contactsVisible)
|
||||
composeBar.setVisible(!state.contactsVisible)
|
||||
|
||||
menu?.findItem(R.id.call)?.run {
|
||||
isVisible = !state.editingMode
|
||||
}
|
||||
menu.take(1).subscribe { menu ->
|
||||
menu.findItem(R.id.call)?.run {
|
||||
isVisible = !state.editingMode
|
||||
}
|
||||
|
||||
menu?.findItem(R.id.archive)?.run {
|
||||
isVisible = !state.editingMode
|
||||
setTitle(if (state.archived) R.string.menu_unarchive else R.string.menu_archive)
|
||||
}
|
||||
menu.findItem(R.id.archive)?.run {
|
||||
isVisible = !state.editingMode
|
||||
setTitle(if (state.archived) R.string.menu_unarchive else R.string.menu_archive)
|
||||
}
|
||||
|
||||
menu?.findItem(R.id.delete)?.run {
|
||||
isVisible = !state.editingMode
|
||||
menu.findItem(R.id.delete)?.run {
|
||||
isVisible = !state.editingMode
|
||||
}
|
||||
}
|
||||
|
||||
if (chipsAdapter.data.isEmpty() && state.selectedContacts.isNotEmpty()) {
|
||||
@@ -176,9 +178,7 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.compose, menu)
|
||||
val result = super.onCreateOptionsMenu(menu)
|
||||
menuReadyIntent.onNext(Unit)
|
||||
return result
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
@@ -11,7 +11,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val chipSelectedIntent: Subject<Contact>
|
||||
val chipDeletedIntent: Subject<Contact>
|
||||
val menuReadyIntent: Subject<Unit>
|
||||
val menuReadyIntent: Observable<Unit>
|
||||
val callIntent: Subject<Unit>
|
||||
val archiveIntent: Subject<Unit>
|
||||
val deleteIntent: Subject<Unit>
|
||||
|
||||
Reference in New Issue
Block a user