Files
quik/presentation/src/main/java/feature/themepicker/ThemePickerActivity.kt
T
2018-04-09 16:35:07 -04:00

103 lines
3.6 KiB
Kotlin

/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package feature.themepicker
import android.os.Bundle
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 injection.appComponent
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.theme_picker_activity.*
import kotlinx.android.synthetic.main.theme_picker_hsv.*
import javax.inject.Inject
class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePickerView {
override val viewModelClass = ThemePickerViewModel::class
override val themeSelectedIntent by lazy { themeAdapter.colorSelected }
override val hsvThemeSelectedIntent by lazy { picker.selectedColor }
override val hsvThemeClearedIntent by lazy { clear.clicks() }
override val hsvThemeAppliedIntent by lazy { apply.clicks() }
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
@Inject lateinit var themeAdapter: ThemeAdapter
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
init {
appComponent.inject(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.theme_picker_activity)
setTitle(R.string.title_theme)
showBackButton(true)
viewModel.bindView(this)
pager.offscreenPageLimit = 1
pager.adapter = themePagerAdapter
tabs.pager = pager
themeAdapter.data = colors.materialColors
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() {
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
setAction(R.string.button_more, { viewQksmsPlusIntent.onNext(Unit) })
show()
}
}
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)
apply.setBackgroundTint(state.newColor)
apply.setTextColor(state.newTextColor)
}
override fun setCurrentTheme(color: Int) {
picker.setColor(color)
themeAdapter.selectedColor = color
}
}