add the new LineColorPicker to Customization activity

This commit is contained in:
tibbi 2017-11-27 18:20:12 +01:00
parent 67fc045817
commit 9c51c16cb0
3 changed files with 29 additions and 19 deletions

View file

@ -6,11 +6,9 @@ import android.view.MenuItem
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.dialogs.LineColorPickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.THEME_CUSTOM
import com.simplemobiletools.commons.helpers.THEME_DARK
import com.simplemobiletools.commons.helpers.THEME_LIGHT
@ -18,11 +16,11 @@ import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.activity_customization.*
class CustomizationActivity : BaseSimpleActivity() {
var curTextColor = 0
var curBackgroundColor = 0
var curPrimaryColor = 0
var curSelectedThemeId = 0
var hasUnsavedChanges = false
private var curTextColor = 0
private var curBackgroundColor = 0
private var curPrimaryColor = 0
private var curSelectedThemeId = 0
private var hasUnsavedChanges = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -39,6 +37,11 @@ class CustomizationActivity : BaseSimpleActivity() {
setupThemePicker()
}
override fun onResume() {
super.onResume()
updateBackgroundColor(curBackgroundColor)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_customization, menu)
return true
@ -87,17 +90,20 @@ class CustomizationActivity : BaseSimpleActivity() {
curTextColor = getColor(R.color.default_light_theme_text_color)
curBackgroundColor = getColor(R.color.default_light_theme_background_color)
curPrimaryColor = getColor(R.color.color_primary)
setTheme(getThemeId(curPrimaryColor))
colorChanged()
} else if (themeId == THEME_DARK) {
curTextColor = getColor(R.color.default_dark_theme_text_color)
curBackgroundColor = getColor(R.color.default_dark_theme_background_color)
curPrimaryColor = getColor(R.color.color_primary)
setTheme(getThemeId(curPrimaryColor))
colorChanged()
} else {
if (useStored) {
curTextColor = baseConfig.customTextColor
curBackgroundColor = baseConfig.customBackgroundColor
curPrimaryColor = baseConfig.customPrimaryColor
setTheme(getThemeId(curPrimaryColor))
setupColorsPickers()
} else {
baseConfig.customPrimaryColor = curPrimaryColor
@ -219,11 +225,16 @@ class CustomizationActivity : BaseSimpleActivity() {
}
private fun pickPrimaryColor() {
ColorPickerDialog(this, curPrimaryColor) {
if (hasColorChanged(curPrimaryColor, it)) {
setCurrentPrimaryColor(it)
colorChanged()
updateColorTheme()
LineColorPickerDialog(this, curPrimaryColor) { wasPositivePressed, color ->
if (wasPositivePressed) {
if (hasColorChanged(curPrimaryColor, color)) {
setCurrentPrimaryColor(color)
colorChanged()
updateColorTheme()
setTheme(getThemeId(color))
}
} else {
updateActionbarColor(curPrimaryColor)
}
}
}

View file

@ -5,13 +5,12 @@ import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.interfaces.LineColorPickerListener
import kotlinx.android.synthetic.main.dialog_line_color_picker.view.*
import java.util.*
class LineColorPickerDialog(val activity: BaseSimpleActivity, val callback: (wasChanged: Boolean, color: Int) -> Unit) {
class LineColorPickerDialog(val activity: BaseSimpleActivity, val color: Int, val callback: (wasPositivePressed: Boolean, color: Int) -> Unit) {
private val PRIMARY_COLORS_COUNT = 19
private val DEFAULT_COLOR_VALUE = -689152
private val DEFAULT_PRIMARY_COLOR_INDEX = 14
@ -22,7 +21,7 @@ class LineColorPickerDialog(val activity: BaseSimpleActivity, val callback: (was
init {
view = activity.layoutInflater.inflate(R.layout.dialog_line_color_picker, null).apply {
val indexes = getColorIndexes(context.baseConfig.primaryColor)
val indexes = getColorIndexes(color)
primary_line_color_picker.updateColors(getColors(R.array.md_primary_colors), indexes.first)
primary_line_color_picker.listener = object : LineColorPickerListener {
@ -46,7 +45,7 @@ class LineColorPickerDialog(val activity: BaseSimpleActivity, val callback: (was
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setNegativeButton(R.string.cancel, { dialog, which -> dialogDismissed() })
.setOnDismissListener { dialogDismissed() }
.setOnCancelListener { dialogDismissed() }
.create().apply {
context.setupDialogStuff(view, this)
}

View file

@ -3,7 +3,7 @@ package com.simplemobiletools.commons.extensions
import android.app.Activity
import com.simplemobiletools.commons.R
fun Activity.getThemeId() = when (baseConfig.primaryColor) {
fun Activity.getThemeId(color: Int = baseConfig.primaryColor) = when (color) {
-12846 -> R.style.AppTheme_Red_100
-1074534 -> R.style.AppTheme_Red_200
-1739917 -> R.style.AppTheme_Red_300