From 9c51c16cb04dec3e018708f4f764612ed4a62649 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 27 Nov 2017 18:20:12 +0100 Subject: [PATCH] add the new LineColorPicker to Customization activity --- .../activities/CustomizationActivity.kt | 39 ++++++++++++------- .../commons/dialogs/LineColorPickerDialog.kt | 7 ++-- .../commons/extensions/Activity-themes.kt | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt index 274b6c3d8..f8721e738 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt @@ -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) } } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt index a5892101d..59cb62385 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt @@ -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) } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity-themes.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity-themes.kt index b9bbec063..72ca15bcf 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity-themes.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity-themes.kt @@ -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