forked from upstream-mirrors/quik
Add ability to change theme
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.moez.QKSMS.common.util
|
package com.moez.QKSMS.common.util
|
||||||
|
|
||||||
import android.animation.ValueAnimator
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.subjects.BehaviorSubject
|
import io.reactivex.subjects.BehaviorSubject
|
||||||
@@ -10,7 +10,7 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ThemeManager @Inject constructor() {
|
class ThemeManager @Inject constructor(prefs: RxSharedPreferences) {
|
||||||
|
|
||||||
val color: Observable<Int>
|
val color: Observable<Int>
|
||||||
|
|
||||||
@@ -23,19 +23,15 @@ class ThemeManager @Inject constructor() {
|
|||||||
init {
|
init {
|
||||||
val colorSubject: Subject<Int> = BehaviorSubject.createDefault(0xFF008389.toInt())
|
val colorSubject: Subject<Int> = BehaviorSubject.createDefault(0xFF008389.toInt())
|
||||||
|
|
||||||
|
prefs.getInteger("theme").asObservable().subscribe {
|
||||||
|
colorSubject.onNext(it)
|
||||||
|
}
|
||||||
|
|
||||||
color = colorSubject
|
color = colorSubject
|
||||||
.buffer(80, TimeUnit.MILLISECONDS)
|
.buffer(80, TimeUnit.MILLISECONDS)
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.map { it.last() }
|
.map { it.last() }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
||||||
ValueAnimator.ofArgb(0xFF444444.toInt(), 0xFF008389.toInt()).run {
|
|
||||||
repeatMode = ValueAnimator.REVERSE
|
|
||||||
repeatCount = ValueAnimator.INFINITE
|
|
||||||
duration = 1500
|
|
||||||
addUpdateListener { animation -> colorSubject.onNext(animation.animatedValue as Int) }
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.moez.QKSMS.presentation.settings
|
package com.moez.QKSMS.presentation.settings
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.app.ProgressDialog
|
import android.app.ProgressDialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.AppComponentManager
|
import com.moez.QKSMS.common.di.AppComponentManager
|
||||||
import com.moez.QKSMS.presentation.base.QkActivity
|
import com.moez.QKSMS.presentation.base.QkActivity
|
||||||
@@ -13,9 +16,40 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
|||||||
override val preferencesAddedIntent by lazy { fragment.preferencesAdded }
|
override val preferencesAddedIntent by lazy { fragment.preferencesAdded }
|
||||||
override val preferenceClickIntent by lazy { fragment.preferenceClicks }
|
override val preferenceClickIntent by lazy { fragment.preferenceClicks }
|
||||||
override val preferenceChangeIntent by lazy { fragment.preferenceChanges }
|
override val preferenceChangeIntent by lazy { fragment.preferenceChanges }
|
||||||
|
override val themeSelectedIntent by lazy { themeAdapter.colorSelected }
|
||||||
|
|
||||||
private lateinit var fragment: SettingsFragment
|
private val fragment by lazy {
|
||||||
private lateinit var progressDialog: ProgressDialog // TODO remove this
|
fragmentManager.findFragmentById(fragmentFrame.id) as? SettingsFragment ?: SettingsFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val progressDialog by lazy { // TODO remove this
|
||||||
|
ProgressDialog(this).apply {
|
||||||
|
isIndeterminate = true
|
||||||
|
setCancelable(false)
|
||||||
|
setCanceledOnTouchOutside(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val themeDialog by lazy {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.settings_dialog_theme_title)
|
||||||
|
.setView(themeRecyclerView)
|
||||||
|
.setCancelable(false)
|
||||||
|
.create()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val themeRecyclerView by lazy {
|
||||||
|
RecyclerView(this).apply {
|
||||||
|
layoutManager = LinearLayoutManager(this@SettingsActivity, LinearLayoutManager.HORIZONTAL, false)
|
||||||
|
adapter = themeAdapter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val themeAdapter by lazy {
|
||||||
|
ThemeAdapter(this@SettingsActivity).apply {
|
||||||
|
data = listOf(0xFF008389, 0xFF04CBC9, 0xFF00D99B, 0xFF00A3F3).map { it.toInt() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
AppComponentManager.appComponent.inject(this)
|
AppComponentManager.appComponent.inject(this)
|
||||||
@@ -23,13 +57,6 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
|||||||
setContentView(R.layout.settings_activity)
|
setContentView(R.layout.settings_activity)
|
||||||
setTitle(R.string.title_settings)
|
setTitle(R.string.title_settings)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
progressDialog = ProgressDialog(this)
|
|
||||||
progressDialog.isIndeterminate = true
|
|
||||||
progressDialog.setCancelable(false)
|
|
||||||
progressDialog.setCanceledOnTouchOutside(false)
|
|
||||||
|
|
||||||
fragment = fragmentManager.findFragmentById(fragmentFrame.id) as? SettingsFragment ?: SettingsFragment()
|
|
||||||
viewModel.bindView(this)
|
viewModel.bindView(this)
|
||||||
|
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
@@ -38,9 +65,12 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: SettingsState) {
|
override fun render(state: SettingsState) {
|
||||||
if (progressDialog.isShowing && !state.syncing) progressDialog.hide()
|
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
||||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||||
|
|
||||||
|
if (themeDialog.isShowing && !state.selectingTheme) themeDialog.dismiss()
|
||||||
|
else if (!themeDialog.isShowing && state.selectingTheme) themeDialog.show()
|
||||||
|
|
||||||
fragment.preferenceManager?.findPreference("defaultSms")?.setSummary(when (state.isDefaultSmsApp) {
|
fragment.preferenceManager?.findPreference("defaultSms")?.setSummary(when (state.isDefaultSmsApp) {
|
||||||
true -> R.string.settings_default_sms_summary_true
|
true -> R.string.settings_default_sms_summary_true
|
||||||
else -> R.string.settings_default_sms_summary_false
|
else -> R.string.settings_default_sms_summary_false
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.moez.QKSMS.presentation.settings
|
package com.moez.QKSMS.presentation.settings
|
||||||
|
|
||||||
data class SettingsState(
|
data class SettingsState(
|
||||||
|
val selectingTheme: Boolean = false,
|
||||||
val syncing: Boolean = false,
|
val syncing: Boolean = false,
|
||||||
val isDefaultSmsApp: Boolean = false
|
val isDefaultSmsApp: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -10,6 +10,8 @@ interface SettingsView : QkView<SettingsState> {
|
|||||||
val preferenceClickIntent: Observable<Preference>
|
val preferenceClickIntent: Observable<Preference>
|
||||||
val preferenceChangeIntent: Observable<PreferenceChange>
|
val preferenceChangeIntent: Observable<PreferenceChange>
|
||||||
|
|
||||||
|
val themeSelectedIntent: Observable<Int>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class PreferenceChange(val preference: Preference, val newValue: Any)
|
data class PreferenceChange(val preference: Preference, val newValue: Any)
|
||||||
@@ -49,6 +49,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
|||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"theme" -> {
|
||||||
|
newState { it.copy(selectingTheme = true) }
|
||||||
|
}
|
||||||
|
|
||||||
"sync" -> {
|
"sync" -> {
|
||||||
newState { it.copy(syncing = true) }
|
newState { it.copy(syncing = true) }
|
||||||
fullSync.execute(Unit, {
|
fullSync.execute(Unit, {
|
||||||
@@ -57,5 +61,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intents += view.themeSelectedIntent.subscribe { color ->
|
||||||
|
prefs.getInteger("theme").set(color)
|
||||||
|
newState { it.copy(selectingTheme = false) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.moez.QKSMS.presentation.settings
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
|
import com.moez.QKSMS.presentation.base.QkAdapter
|
||||||
|
import com.moez.QKSMS.presentation.base.QkViewHolder
|
||||||
|
import io.reactivex.subjects.PublishSubject
|
||||||
|
import io.reactivex.subjects.Subject
|
||||||
|
import kotlinx.android.synthetic.main.theme_list_item.view.*
|
||||||
|
|
||||||
|
class ThemeAdapter(private val context: Context) : QkAdapter<Int>() {
|
||||||
|
|
||||||
|
val colorSelected: Subject<Int> = PublishSubject.create()
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.theme_list_item, parent, false)
|
||||||
|
return QkViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
|
val theme = getItem(position)
|
||||||
|
val view = holder.itemView
|
||||||
|
|
||||||
|
view.setOnClickListener { colorSelected.onNext(theme) }
|
||||||
|
|
||||||
|
view.theme.setBackgroundTint(theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="56dp"
|
||||||
|
android:layout_height="56dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/theme"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/circle"
|
||||||
|
tools:backgroundTint="@color/tools_theme" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -18,9 +18,12 @@
|
|||||||
<string name="settings_default_sms_title">Default SMS app</string>
|
<string name="settings_default_sms_title">Default SMS app</string>
|
||||||
<string name="settings_default_sms_summary_true">QKSMS is your default SMS app</string>
|
<string name="settings_default_sms_summary_true">QKSMS is your default SMS app</string>
|
||||||
<string name="settings_default_sms_summary_false">Set QKSMS as your default SMS app</string>
|
<string name="settings_default_sms_summary_false">Set QKSMS as your default SMS app</string>
|
||||||
|
<string name="settings_theme_title">Theme</string>
|
||||||
<string name="settings_sync_title">Sync messages</string>
|
<string name="settings_sync_title">Sync messages</string>
|
||||||
<string name="settings_sync_summary">Re-sync your messages with the native Android SMS database</string>
|
<string name="settings_sync_summary">Re-sync your messages with the native Android SMS database</string>
|
||||||
|
|
||||||
|
<string name="settings_dialog_theme_title">Theme</string>
|
||||||
|
|
||||||
<string name="notification_reply">Reply</string>
|
<string name="notification_reply">Reply</string>
|
||||||
<string name="notification_read">Mark read</string>
|
<string name="notification_read">Mark read</string>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
android:key="defaultSms"
|
android:key="defaultSms"
|
||||||
android:title="@string/settings_default_sms_title" />
|
android:title="@string/settings_default_sms_title" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="theme"
|
||||||
|
android:title="@string/settings_theme_title" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="sync"
|
android:key="sync"
|
||||||
android:summary="@string/settings_sync_summary"
|
android:summary="@string/settings_sync_summary"
|
||||||
|
|||||||
Reference in New Issue
Block a user