aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-06-07 12:41:13 -0400
committerGitHub <noreply@github.com>2019-06-07 12:41:13 -0400
commit1e3cb74579a3297460cd4085c57942138c5805a2 (patch)
treeba1ab2f42d3d4407c50c215ba85674700c047db7
parentb9feba20d45505a22162c386e18dfc1a4f117d3f (diff)
parent879ac366074697dd0a7fbb2c3d99a48d7aeeb22d (diff)
downloadkau-1e3cb74579a3297460cd4085c57942138c5805a2.tar.gz
kau-1e3cb74579a3297460cd4085c57942138c5805a2.tar.bz2
kau-1e3cb74579a3297460cd4085c57942138c5805a2.zip
Merge pull request #200 from AllanWang/material-dialogs-3
Material Dialogs 3
-rw-r--r--README.md1
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt2
-rw-r--r--colorpicker/README.md9
-rw-r--r--colorpicker/build.gradle2
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt2
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt2
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt102
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt359
-rw-r--r--colorpicker/src/main/res/values-da-rDK/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-de-rDE/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-es-rES/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-fr-rFR/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-gl-rES/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-hu-rHU/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-in-rID/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-it-rIT/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-ko-rKR/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-nl-rNL/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-no-rNO/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-pl-rPL/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-pt-rBR/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-pt-rPT/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-sr-rSP/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-sv-rSE/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-th-rTH/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-tr-rTR/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-uk-rUA/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-vi-rVN/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-zh-rCN/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values-zh-rTW/strings_colorpicker.xml6
-rw-r--r--colorpicker/src/main/res/values/dimens.xml3
-rw-r--r--colorpicker/src/main/res/values/strings_colorpicker.xml5
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt21
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt7
-rw-r--r--docs/Migration.md6
-rw-r--r--kpref-activity/build.gradle2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt35
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt6
-rw-r--r--sample/build.gradle2
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt27
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml8
41 files changed, 112 insertions, 621 deletions
diff --git a/README.md b/README.md
index 47a1414..0293545 100644
--- a/README.md
+++ b/README.md
@@ -143,7 +143,6 @@ This means that you'll need to explicitly include each submodule you'd like to u
![About Activity Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_about_activity.gif)
![Ink Indicator Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_ink_indicator.gif)
![Color Picker Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_color_picker.gif)
-![Color Picker Custom Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_color_picker_custom.gif)
![KPref Items Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_kpref_items.gif)
![SearchView Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_search_view.gif)
![Swipe Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_swipe.gif)
diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt
index 2bcedaa..8c14a92 100644
--- a/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt
@@ -49,7 +49,7 @@ open class Versions {
val iconicsCommunity = "3.5.95.1"
// https://github.com/afollestad/material-dialogs/releases
- val materialDialog = "0.9.6.0"
+ val materialDialog = "3.0.0-rc2"
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google
val espresso = "3.1.1"
diff --git a/colorpicker/README.md b/colorpicker/README.md
index c90809e..16977a9 100644
--- a/colorpicker/README.md
+++ b/colorpicker/README.md
@@ -1,10 +1,9 @@
# KAU :colorpicker
-Material Dialogs by default contains a color picker, but it requires an activity that also implements the color callback.
-KAU's colorpicker decouples the two, so it only needs a context and a separate callback.
-The color picker also animates the selection, and uses Kotlin's DSL to provide easy calling.
+As of Material Dialog 2.x, `:colorpicker` is effectively a very thin wrapper around [Material Dialog's color picker](https://github.com/afollestad/material-dialogs/blob/master/documentation/COLOR.md).
+The main difference is that it exposes an interface internal to KAU, which allows a greater level of consistency within other submodules.
+It also contains an extra palette for accent colors.
-To use it, call `Context.colorPickerDialog` and specify and configs as required through the builder.
+To use it, call `MaterialDialog.kauColorChooser` and specify the configs.
![Color Picker Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_color_picker.gif)
-![Color Picker Custom Gif](https://raw.githubusercontent.com/AllanWang/Storage-Hub/master/kau/kau_color_picker_custom.gif) \ No newline at end of file
diff --git a/colorpicker/build.gradle b/colorpicker/build.gradle
index 9b52cd4..4b89e10 100644
--- a/colorpicker/build.gradle
+++ b/colorpicker/build.gradle
@@ -7,7 +7,7 @@ apply from: '../android-lib.gradle'
dependencies {
implementation project(':core')
- implementation "com.afollestad.material-dialogs:commons:${kau.materialDialog}"
+ implementation "com.afollestad.material-dialogs:color:${kau.materialDialog}"
}
apply from: '../artifacts.gradle'
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
index 29257d8..e748677 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
@@ -238,4 +238,4 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
@ColorInt
fun shiftColorUp(@ColorInt color: Int): Int = shiftColor(color, 1.1f)
}
-}
+} \ No newline at end of file
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
index d9db160..113020c 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
@@ -19,6 +19,8 @@ import android.graphics.Color
/**
* @author Aidan Follestad (afollestad)
+ *
+ * Modified by Allan Wang
*/
internal object ColorPalette {
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt
index 4202db1..02a1fff 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt
@@ -15,90 +15,52 @@
*/
package ca.allanwang.kau.colorpicker
-import android.content.Context
+import android.annotation.SuppressLint
import android.graphics.Color
-import androidx.annotation.DimenRes
-import androidx.annotation.StringRes
-import ca.allanwang.kau.utils.INVALID_ID
-import ca.allanwang.kau.utils.string
+import androidx.annotation.ColorInt
import com.afollestad.materialdialogs.MaterialDialog
-import com.afollestad.materialdialogs.Theme
+import com.afollestad.materialdialogs.color.ColorCallback
+import com.afollestad.materialdialogs.color.colorChooser
+
+sealed class ColorOptions(val colors: IntArray, val subColors: Array<IntArray>?)
+
+object PrimaryColors : ColorOptions(ColorPalette.PRIMARY_COLORS, ColorPalette.PRIMARY_COLORS_SUB)
+object AccentColors : ColorOptions(ColorPalette.ACCENT_COLORS, ColorPalette.ACCENT_COLORS_SUB)
+class CustomColors(colors: IntArray, subColors: Array<IntArray>? = null) : ColorOptions(colors, subColors)
class ColorBuilder : ColorContract {
- override var title: String? = null
- override var titleRes: Int = INVALID_ID
+ override var colors: ColorOptions = PrimaryColors
override var allowCustom: Boolean = true
override var allowCustomAlpha: Boolean = false
- override var isAccent: Boolean = false
override var defaultColor: Int = Color.BLACK
- override var doneText: Int = R.string.kau_done
- override var backText: Int = R.string.kau_back
- override var cancelText: Int = R.string.kau_cancel
- override var presetText: Int = R.string.kau_md_presets
- override var customText: Int = R.string.kau_custom
- get() = if (allowCustom) field else 0
- override var dynamicButtonColors: Boolean = true
- override var circleSizeRes: Int = R.dimen.kau_color_circle_size
- override var colorCallback: ((selectedColor: Int) -> Unit)? = null
- override var colorsTop: IntArray? = null
- override var colorsSub: Array<IntArray>? = null
- override var theme: Theme? = null
+ override var callback: ColorCallback = null
}
interface ColorContract {
- var title: String?
- @setparam:StringRes
- var titleRes: Int
+ var colors: ColorOptions
var allowCustom: Boolean
var allowCustomAlpha: Boolean
- var isAccent: Boolean
- @setparam:StringRes
+ @setparam:ColorInt
var defaultColor: Int
- @setparam:StringRes
- var doneText: Int
- @setparam:StringRes
- var backText: Int
- @setparam:StringRes
- var cancelText: Int
- @setparam:StringRes
- var presetText: Int
- @setparam:StringRes
- var customText: Int
- var dynamicButtonColors: Boolean
- @setparam:DimenRes
- var circleSizeRes: Int
- var colorCallback: ((selectedColor: Int) -> Unit)?
- var colorsTop: IntArray?
- var colorsSub: Array<IntArray>?
- var theme: Theme?
+ var callback: ColorCallback
}
+@SuppressLint("CheckResult")
+fun MaterialDialog.kauColorChooser(action: ColorContract.() -> Unit) =
+ kauColorChooser(ColorBuilder().apply(action))
+
/**
- * This is the extension that allows us to initialize the dialog
- * Note that this returns just the dialog; you still need to call .show() to show it
+ * Thin wrapper that exposes color chooser options as [ColorContract]
*/
-fun Context.colorPickerDialog(action: ColorContract.() -> Unit): MaterialDialog {
- val b = ColorBuilder()
- b.action()
- return colorPickerDialog(b)
-}
-
-fun Context.colorPickerDialog(contract: ColorContract): MaterialDialog {
- val view = ColorPickerView(this)
- val dialog = with(MaterialDialog.Builder(this)) {
- title(string(contract.titleRes, contract.title) ?: string(R.string.kau_md_color_palette))
- customView(view, false)
- autoDismiss(false)
- positiveText(contract.doneText)
- negativeText(contract.cancelText)
- if (contract.allowCustom) neutralText(contract.presetText)
- onPositive { dialog, _ -> contract.colorCallback?.invoke(view.selectedColor); dialog.dismiss() }
- onNegative { _, _ -> view.backOrCancel() }
- if (contract.allowCustom) onNeutral { _, _ -> view.toggleCustom() }
- showListener { view.refreshColors() }
- if (contract.theme != null) theme(contract.theme!!)
- build()
- }
- view.bind(contract, dialog)
- return dialog
-}
+@SuppressLint("CheckResult")
+fun MaterialDialog.kauColorChooser(c: ColorContract) {
+ colorChooser(
+ colors = c.colors.colors,
+ subColors = c.colors.subColors,
+ initialSelection = c.defaultColor,
+ allowCustomArgb = c.allowCustom,
+ showAlphaSelector = c.allowCustomAlpha,
+ selection = c.callback
+ )
+ positiveButton(R.string.kau_done)
+} \ No newline at end of file
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt
deleted file mode 100644
index ab0b149..0000000
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * Copyright 2018 Allan Wang
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ca.allanwang.kau.colorpicker
-
-import android.annotation.SuppressLint
-import android.content.Context
-import android.graphics.Color
-import android.text.Editable
-import android.text.InputFilter
-import android.text.TextWatcher
-import android.util.AttributeSet
-import android.view.View
-import android.view.ViewGroup
-import android.widget.AbsListView
-import android.widget.BaseAdapter
-import android.widget.EditText
-import android.widget.LinearLayout
-import android.widget.ScrollView
-import android.widget.SeekBar
-import android.widget.TextView
-import androidx.annotation.ColorInt
-import androidx.core.content.res.ResourcesCompat
-import ca.allanwang.kau.utils.colorToForeground
-import ca.allanwang.kau.utils.dimen
-import ca.allanwang.kau.utils.fadeIn
-import ca.allanwang.kau.utils.fadeOut
-import ca.allanwang.kau.utils.gone
-import ca.allanwang.kau.utils.isColorDark
-import ca.allanwang.kau.utils.isColorVisibleOn
-import ca.allanwang.kau.utils.isVisible
-import ca.allanwang.kau.utils.resolveColor
-import ca.allanwang.kau.utils.tint
-import ca.allanwang.kau.utils.toHexString
-import ca.allanwang.kau.utils.visible
-import com.afollestad.materialdialogs.DialogAction
-import com.afollestad.materialdialogs.MaterialDialog
-import com.afollestad.materialdialogs.color.FillGridView
-import java.util.Locale
-
-/**
- * Created by Allan Wang on 2017-06-08.
- *
- * ColorPicker component of the ColorPickerDialog
- */
-internal class ColorPickerView @JvmOverloads constructor(
- context: Context,
- attrs: AttributeSet? = null,
- defStyleAttr: Int = 0
-) : ScrollView(context, attrs, defStyleAttr) {
- val selectedColor: Int
- get() = _selectedColor
- private var _selectedColor: Int = -1
- private var isInSub: Boolean = false
- private var isInCustom: Boolean = false
- private var circleSize: Int = context.dimen(R.dimen.kau_color_circle_size).toInt()
- @SuppressLint("PrivateResource")
- private val backgroundColor = context.resolveColor(
- R.attr.md_background_color,
- if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark) Color.WHITE else 0xff424242.toInt()
- )
- private val backgroundColorTint = backgroundColor.colorToForeground()
- private lateinit var dialog: MaterialDialog
- private lateinit var builder: ColorContract
- private lateinit var colorsTop: IntArray
- private var colorsSub: Array<IntArray>? = null
- private var topIndex: Int = -1
- private var subIndex: Int = -1
- private var colorIndex: Int
- get() = if (isInSub) subIndex else topIndex
- set(value) {
- if (isInSub) subIndex = value
- else {
- topIndex = value
- if (colorsSub != null && colorsSub!!.size > value) {
- dialog.setActionButton(DialogAction.NEGATIVE, builder.backText)
- isInSub = true
- invalidateGrid()
- }
- }
- }
-
- private val gridView: FillGridView
- private val customFrame: LinearLayout
- private val customColorIndicator: View
- private val hexInput: EditText
- private val alphaLabel: TextView
- private val alphaSeekbar: SeekBar
- private val alphaValue: TextView
- private val redSeekbar: SeekBar
- private val redValue: TextView
- private val greenSeekbar: SeekBar
- private val greenValue: TextView
- private val blueSeekbar: SeekBar
- private val blueValue: TextView
-
- private var customHexTextWatcher: TextWatcher? = null
- private var customRgbListener: SeekBar.OnSeekBarChangeListener? = null
-
- init {
- //noinspection PrivateResource
- View.inflate(context, R.layout.md_dialog_colorchooser, this)
- gridView = findViewById(R.id.md_grid)
- customFrame = findViewById(R.id.md_colorChooserCustomFrame)
- customColorIndicator = findViewById(R.id.md_colorIndicator)
- hexInput = findViewById(R.id.md_hexInput)
- alphaLabel = findViewById(R.id.md_colorALabel)
- alphaSeekbar = findViewById(R.id.md_colorA)
- alphaValue = findViewById(R.id.md_colorAValue)
- redSeekbar = findViewById(R.id.md_colorR)
- redValue = findViewById(R.id.md_colorRValue)
- greenSeekbar = findViewById(R.id.md_colorG)
- greenValue = findViewById(R.id.md_colorGValue)
- blueSeekbar = findViewById(R.id.md_colorB)
- blueValue = findViewById(R.id.md_colorBValue)
- }
-
- fun bind(builder: ColorContract, dialog: MaterialDialog) {
- this.builder = builder
- this.dialog = dialog
- this.colorsTop = with(builder) {
- when {
- colorsTop != null -> colorsTop!!
- isAccent -> ColorPalette.ACCENT_COLORS
- else -> ColorPalette.PRIMARY_COLORS
- }
- }
- this.colorsSub = with(builder) {
- when {
- colorsTop != null -> colorsSub
- isAccent -> ColorPalette.ACCENT_COLORS_SUB
- else -> ColorPalette.PRIMARY_COLORS_SUB
- }
- }
- this._selectedColor = builder.defaultColor
- if (builder.allowCustom) {
- if (!builder.allowCustomAlpha) {
- alphaLabel.gone()
- alphaSeekbar.gone()
- alphaValue.gone()
- hexInput.hint = String.format("%06X", _selectedColor)
- hexInput.filters = arrayOf(InputFilter.LengthFilter(6))
- } else {
- hexInput.hint = String.format("%08X", _selectedColor)
- hexInput.filters = arrayOf(InputFilter.LengthFilter(8))
- }
- }
- if (findColor(_selectedColor) || !builder.allowCustom) isInCustom = true // when toggled this will be false
- toggleCustom()
- }
-
- fun backOrCancel() {
- if (isInSub) {
- dialog.setActionButton(DialogAction.NEGATIVE, builder.cancelText)
- //to top
- isInSub = false
- subIndex = -1
- invalidateGrid()
- } else {
- dialog.cancel()
- }
- }
-
- fun toggleCustom() {
- isInCustom = !isInCustom
- if (isInCustom) {
- isInSub = false
- if (builder.allowCustom) dialog.setActionButton(DialogAction.NEUTRAL, builder.presetText)
- dialog.setActionButton(DialogAction.NEGATIVE, builder.cancelText)
- customHexTextWatcher = object : TextWatcher {
- override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
-
- override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
- _selectedColor = try {
- Color.parseColor("#$s")
- } catch (e: IllegalArgumentException) {
- Color.BLACK
- }
- customColorIndicator.setBackgroundColor(_selectedColor)
- if (alphaSeekbar.isVisible) {
- val alpha = Color.alpha(_selectedColor)
- alphaSeekbar.progress = alpha
- alphaValue.text = String.format(Locale.CANADA, "%d", alpha)
- }
- redSeekbar.progress = Color.red(_selectedColor)
- greenSeekbar.progress = Color.green(_selectedColor)
- blueSeekbar.progress = Color.blue(_selectedColor)
- isInSub = false
- topIndex = -1
- subIndex = -1
- refreshColors()
- }
-
- override fun afterTextChanged(s: Editable?) {}
- }
- hexInput.setText(_selectedColor.toHexString(builder.allowCustomAlpha, false))
- hexInput.addTextChangedListener(customHexTextWatcher)
- customRgbListener = object : SeekBar.OnSeekBarChangeListener {
- override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
- if (fromUser) {
- val color = if (builder.allowCustomAlpha)
- Color.argb(
- alphaSeekbar.progress,
- redSeekbar.progress,
- greenSeekbar.progress,
- blueSeekbar.progress
- )
- else Color.rgb(
- redSeekbar.progress,
- greenSeekbar.progress,
- blueSeekbar.progress
- )
-
- hexInput.setText(color.toHexString(builder.allowCustomAlpha, false))
- }
- if (builder.allowCustomAlpha) alphaValue.text = alphaSeekbar.progress.toString()
- redValue.text = redSeekbar.progress.toString()
- greenValue.text = greenSeekbar.progress.toString()
- blueValue.text = blueSeekbar.progress.toString()
- }
-
- override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
-
- override fun onStopTrackingTouch(seekBar: SeekBar) = Unit
- }
- redSeekbar.setOnSeekBarChangeListener(customRgbListener)
- greenSeekbar.setOnSeekBarChangeListener(customRgbListener)
- blueSeekbar.setOnSeekBarChangeListener(customRgbListener)
- if (alphaSeekbar.isVisible)
- alphaSeekbar.setOnSeekBarChangeListener(customRgbListener)
- hexInput.setText(_selectedColor.toHexString(alphaSeekbar.isVisible, false))
- gridView.fadeOut(onFinish = { gridView.gone() })
- customFrame.fadeIn()
- } else {
- findColor(_selectedColor)
- if (builder.allowCustom) dialog.setActionButton(DialogAction.NEUTRAL, builder.customText)
- dialog.setActionButton(DialogAction.NEGATIVE, if (isInSub) builder.backText else builder.cancelText)
- gridView.fadeIn(onStart = this::invalidateGrid)
- customFrame.fadeOut(onFinish = { customFrame.gone() })
- hexInput.removeTextChangedListener(customHexTextWatcher)
- customHexTextWatcher = null
- alphaSeekbar.setOnSeekBarChangeListener(null)
- redSeekbar.setOnSeekBarChangeListener(null)
- greenSeekbar.setOnSeekBarChangeListener(null)
- blueSeekbar.setOnSeekBarChangeListener(null)
- customRgbListener = null
- }
- }
-
- fun refreshColors() {
- if (!isInCustom) findColor(_selectedColor)
- // Ensure that our tinted color is still visible against the background
- val visibleColor = if (_selectedColor.isColorVisibleOn(backgroundColor)) _selectedColor else backgroundColorTint
- if (builder.dynamicButtonColors) {
- dialog.getActionButton(DialogAction.POSITIVE).setTextColor(visibleColor)
- dialog.getActionButton(DialogAction.NEGATIVE).setTextColor(visibleColor)
- dialog.getActionButton(DialogAction.NEUTRAL).setTextColor(visibleColor)
- }
- if (!builder.allowCustom || !isInCustom) return
- if (builder.allowCustomAlpha)
- alphaSeekbar.visible().tint(visibleColor)
- redSeekbar.tint(visibleColor)
- greenSeekbar.tint(visibleColor)
- blueSeekbar.tint(visibleColor)
- hexInput.tint(visibleColor)
- }
-
- private fun findColor(@ColorInt color: Int): Boolean {
- topIndex = -1
- subIndex = -1
- colorsTop.forEachIndexed { index, topColor ->
- // First check for sub colors, then if the top color matches
- if (findSubColor(color, index) || topColor == color) {
- topIndex = index
- return true
- }
- }
- return false
- }
-
- private fun findSubColor(@ColorInt color: Int, topIndex: Int): Boolean {
- subIndex = colorsSub?.getOrNull(topIndex)?.indexOfFirst { color == it } ?: -1
- return subIndex != -1
- }
-
- private fun invalidateGrid() {
- if (gridView.adapter == null) {
- gridView.adapter = ColorGridAdapter()
- gridView.selector = ResourcesCompat.getDrawable(resources, R.drawable.kau_transparent, null)
- } else {
- (gridView.adapter as BaseAdapter).notifyDataSetChanged()
- }
- }
-
- inner class ColorGridAdapter : BaseAdapter(), OnClickListener, OnLongClickListener {
- override fun onClick(v: View) {
- val (pos, color) = v.tagData ?: return
- if (colorIndex == pos && isInSub)
- return
- circleAt(colorIndex)?.animateSelected(false)
- _selectedColor = color
- colorIndex = pos
- refreshColors()
- if (isInSub)
- circleAt(colorIndex)?.animateSelected(true)
- // Otherwise we are invalidating our grid, so there is no point in animating
- }
-
- private fun circleAt(index: Int): CircleView? =
- if (index == -1) null
- else gridView.getChildAt(index) as? CircleView
-
- private val View.tagData: Pair<Int, Int>?
- get() {
- val tags = (tag as? String)?.split(":") ?: return null
- val pos = tags[0].toIntOrNull() ?: return null
- val color = tags[1].toIntOrNull() ?: return null
- return pos to color
- }
-
- override fun onLongClick(v: View): Boolean {
- val (_, color) = v.tagData ?: return false
- (v as? CircleView)?.showHint(color) ?: return false
- return true
- }
-
- override fun getItem(position: Int): Int = if (isInSub) colorsSub!![topIndex][position] else colorsTop[position]
-
- override fun getCount(): Int = if (isInSub) colorsSub!![topIndex].size else colorsTop.size
-
- override fun getItemId(position: Int): Long = position.toLong()
-
- override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
- val view: CircleView = convertView as? CircleView ?: CircleView(context).apply {
- layoutParams = AbsListView.LayoutParams(circleSize, circleSize)
- setOnClickListener(this@ColorGridAdapter)
- setOnLongClickListener(this@ColorGridAdapter)
- }
- val color: Int = getItem(position)
- return view.apply {
- setBackgroundColor(color)
- isSelected = colorIndex == position
- tag = "$position:$color"
- }
- }
- }
-}
diff --git a/colorpicker/src/main/res/values-da-rDK/strings_colorpicker.xml b/colorpicker/src/main/res/values-da-rDK/strings_colorpicker.xml
deleted file mode 100644
index 334896f..0000000
--- a/colorpicker/src/main/res/values-da-rDK/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Farvepalette</string>
- <string name="kau_md_presets">Forhåndsvalg</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-de-rDE/strings_colorpicker.xml b/colorpicker/src/main/res/values-de-rDE/strings_colorpicker.xml
deleted file mode 100644
index 5763d20..0000000
--- a/colorpicker/src/main/res/values-de-rDE/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Farbpalette</string>
- <string name="kau_md_presets">Vorlagen</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-es-rES/strings_colorpicker.xml b/colorpicker/src/main/res/values-es-rES/strings_colorpicker.xml
deleted file mode 100644
index 2be5b2c..0000000
--- a/colorpicker/src/main/res/values-es-rES/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Paleta de colores</string>
- <string name="kau_md_presets">Ajustes preestablecidos</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-fr-rFR/strings_colorpicker.xml b/colorpicker/src/main/res/values-fr-rFR/strings_colorpicker.xml
deleted file mode 100644
index 19c2935..0000000
--- a/colorpicker/src/main/res/values-fr-rFR/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Palette de couleurs</string>
- <string name="kau_md_presets">Réglages prédéfinis</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-gl-rES/strings_colorpicker.xml b/colorpicker/src/main/res/values-gl-rES/strings_colorpicker.xml
deleted file mode 100644
index 5a42281..0000000
--- a/colorpicker/src/main/res/values-gl-rES/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Paleta de cores</string>
- <string name="kau_md_presets">Axustes predefinidos</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-hu-rHU/strings_colorpicker.xml b/colorpicker/src/main/res/values-hu-rHU/strings_colorpicker.xml
deleted file mode 100644
index 69b3850..0000000
--- a/colorpicker/src/main/res/values-hu-rHU/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Színpaletta</string>
- <string name="kau_md_presets">Sablonok</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-in-rID/strings_colorpicker.xml b/colorpicker/src/main/res/values-in-rID/strings_colorpicker.xml
deleted file mode 100644
index d7ddb5d..0000000
--- a/colorpicker/src/main/res/values-in-rID/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Palet warna</string>
- <string name="kau_md_presets">Preset</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-it-rIT/strings_colorpicker.xml b/colorpicker/src/main/res/values-it-rIT/strings_colorpicker.xml
deleted file mode 100644
index b7c907d..0000000
--- a/colorpicker/src/main/res/values-it-rIT/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Tavolozza dei colori</string>
- <string name="kau_md_presets">Preimpostazioni</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-ko-rKR/strings_colorpicker.xml b/colorpicker/src/main/res/values-ko-rKR/strings_colorpicker.xml
deleted file mode 100644
index 92ad098..0000000
--- a/colorpicker/src/main/res/values-ko-rKR/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">색상 팔레트</string>
- <string name="kau_md_presets">사전 설정</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-nl-rNL/strings_colorpicker.xml b/colorpicker/src/main/res/values-nl-rNL/strings_colorpicker.xml
deleted file mode 100644
index 83e4089..0000000
--- a/colorpicker/src/main/res/values-nl-rNL/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Kleurenpalet</string>
- <string name="kau_md_presets">Voorinstellingen</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-no-rNO/strings_colorpicker.xml b/colorpicker/src/main/res/values-no-rNO/strings_colorpicker.xml
deleted file mode 100644
index fb15bbb..0000000
--- a/colorpicker/src/main/res/values-no-rNO/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Fargepalett</string>
- <string name="kau_md_presets">Forhåndsinnstillinger</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-pl-rPL/strings_colorpicker.xml b/colorpicker/src/main/res/values-pl-rPL/strings_colorpicker.xml
deleted file mode 100644
index e9fea97..0000000
--- a/colorpicker/src/main/res/values-pl-rPL/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Paleta kolorów</string>
- <string name="kau_md_presets">Zdefiniowane</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-pt-rBR/strings_colorpicker.xml b/colorpicker/src/main/res/values-pt-rBR/strings_colorpicker.xml
deleted file mode 100644
index 67d239d..0000000
--- a/colorpicker/src/main/res/values-pt-rBR/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Paleta de Cores</string>
- <string name="kau_md_presets">Predefinições</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-pt-rPT/strings_colorpicker.xml b/colorpicker/src/main/res/values-pt-rPT/strings_colorpicker.xml
deleted file mode 100644
index 9346ff5..0000000
--- a/colorpicker/src/main/res/values-pt-rPT/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Paleta de cores</string>
- <string name="kau_md_presets">Predefinições</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-sr-rSP/strings_colorpicker.xml b/colorpicker/src/main/res/values-sr-rSP/strings_colorpicker.xml
deleted file mode 100644
index 6459b1b..0000000
--- a/colorpicker/src/main/res/values-sr-rSP/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Палета боја</string>
- <string name="kau_md_presets">Предподешења</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-sv-rSE/strings_colorpicker.xml b/colorpicker/src/main/res/values-sv-rSE/strings_colorpicker.xml
deleted file mode 100644
index 565bb71..0000000
--- a/colorpicker/src/main/res/values-sv-rSE/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Färgpalett</string>
- <string name="kau_md_presets">Förval</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-th-rTH/strings_colorpicker.xml b/colorpicker/src/main/res/values-th-rTH/strings_colorpicker.xml
deleted file mode 100644
index 9dbf908..0000000
--- a/colorpicker/src/main/res/values-th-rTH/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">ชุดสี</string>
- <string name="kau_md_presets">ค่าที่ตั้งไว้</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-tr-rTR/strings_colorpicker.xml b/colorpicker/src/main/res/values-tr-rTR/strings_colorpicker.xml
deleted file mode 100644
index fd90b4a..0000000
--- a/colorpicker/src/main/res/values-tr-rTR/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Renk paleti</string>
- <string name="kau_md_presets">Hazır ayarlar</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-uk-rUA/strings_colorpicker.xml b/colorpicker/src/main/res/values-uk-rUA/strings_colorpicker.xml
deleted file mode 100644
index 9120a10..0000000
--- a/colorpicker/src/main/res/values-uk-rUA/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Кольорова палітра</string>
- <string name="kau_md_presets">Пресети</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-vi-rVN/strings_colorpicker.xml b/colorpicker/src/main/res/values-vi-rVN/strings_colorpicker.xml
deleted file mode 100644
index 68bacae..0000000
--- a/colorpicker/src/main/res/values-vi-rVN/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Bảng màu</string>
- <string name="kau_md_presets">Cài đặt sẵn</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-zh-rCN/strings_colorpicker.xml b/colorpicker/src/main/res/values-zh-rCN/strings_colorpicker.xml
deleted file mode 100644
index 38f4aeb..0000000
--- a/colorpicker/src/main/res/values-zh-rCN/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">调色板</string>
- <string name="kau_md_presets">预设</string>
-</resources>
diff --git a/colorpicker/src/main/res/values-zh-rTW/strings_colorpicker.xml b/colorpicker/src/main/res/values-zh-rTW/strings_colorpicker.xml
deleted file mode 100644
index a7fb17b..0000000
--- a/colorpicker/src/main/res/values-zh-rTW/strings_colorpicker.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--Generated by crowdin.com-->
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">調色板</string>
- <string name="kau_md_presets">預設</string>
-</resources>
diff --git a/colorpicker/src/main/res/values/dimens.xml b/colorpicker/src/main/res/values/dimens.xml
deleted file mode 100644
index 193940e..0000000
--- a/colorpicker/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<resources>
- <dimen name="kau_color_circle_size">56dp</dimen>
-</resources>
diff --git a/colorpicker/src/main/res/values/strings_colorpicker.xml b/colorpicker/src/main/res/values/strings_colorpicker.xml
deleted file mode 100644
index a470390..0000000
--- a/colorpicker/src/main/res/values/strings_colorpicker.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
- <string name="kau_md_color_palette">Color Palette</string>
- <string name="kau_md_presets">Presets</string>
-</resources>
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 94750e3..82d5608 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -45,7 +45,9 @@ import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import ca.allanwang.kau.R
import ca.allanwang.kau.logging.KL
+import com.afollestad.materialdialogs.DialogBehavior
import com.afollestad.materialdialogs.MaterialDialog
+import com.afollestad.materialdialogs.ModalDialog
/**
* Created by Allan Wang on 2017-06-03.
@@ -193,17 +195,20 @@ fun Context.resolveString(@AttrRes attr: Int, fallback: String = ""): String {
}
/**
- * Wrapper function for the MaterialDialog adapterBuilder
- * There is no need to call build() or show() as those are done by default
+ * Wrapper function for MaterialDialog
+ *
+ * Mainly handles invalid creations, such as showing a dialog when an activity is finishing
+ * See https://github.com/afollestad/material-dialogs/issues/1778
*/
-inline fun Context.materialDialog(action: MaterialDialog.Builder.() -> Unit): MaterialDialog {
- val builder = MaterialDialog.Builder(this)
- builder.action()
+inline fun Context.materialDialog(
+ dialogBehavior: DialogBehavior = ModalDialog,
+ action: MaterialDialog.() -> Unit
+) {
+ val dialog = MaterialDialog(this, dialogBehavior)
if (isFinishing) {
- KL.d { "Material Dialog triggered from finishing context; did not show" }
- return builder.build()
+ return KL.d { "Material Dialog triggered from finishing context; did not show" }
}
- return builder.show()
+ dialog.show(action)
}
fun Context.getDip(value: Float): Float =
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
index 22e8e76..2e66a97 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -30,6 +30,7 @@ import ca.allanwang.kau.utils.ctxCoroutine
import ca.allanwang.kau.utils.materialDialog
import ca.allanwang.kau.utils.use
import com.afollestad.materialdialogs.MaterialDialog
+import com.afollestad.materialdialogs.list.customListAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -40,13 +41,13 @@ import org.xmlpull.v1.XmlPullParser
*
* Easy changelog loader
*/
-fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.Builder.() -> Unit = {}) {
+fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.() -> Unit = {}) {
ctxCoroutine.launch {
val items = withContext(Dispatchers.Default) { parse(this@showChangelog, xmlRes) }
materialDialog {
title(R.string.kau_changelog)
- positiveText(R.string.kau_great)
- adapter(ChangelogAdapter(items, textColor), null)
+ positiveButton(R.string.kau_great)
+ customListAdapter(ChangelogAdapter(items, textColor), null)
customize()
}
}
diff --git a/docs/Migration.md b/docs/Migration.md
index cdaca4c..c0816d4 100644
--- a/docs/Migration.md
+++ b/docs/Migration.md
@@ -2,6 +2,12 @@
Below are some highlights on major refactoring/breaking changes
+# v5.0.0
+
+* Material Dialog is now 3.x. This leads to a whole new API, but fortunately it is based around kotlin. Please refer to [MD's documents](https://github.com/afollestad/material-dialogs/tree/3.0.0-rc2/documentation) for the new methods.
+ * Alongside such changes, `:colorpicker` is no longer as necessary. It exists mainly to provide an internal interface for other submodules.
+
+
# v4.0.1-alpha02
* `kauParseFaq` is now synchronous.
diff --git a/kpref-activity/build.gradle b/kpref-activity/build.gradle
index 8b2d12d..ef91e2b 100644
--- a/kpref-activity/build.gradle
+++ b/kpref-activity/build.gradle
@@ -6,8 +6,8 @@ apply from: '../android-lib.gradle'
dependencies {
implementation project(':core')
- implementation project(':adapter')
implementation project(':colorpicker')
+ implementation project(':adapter')
}
apply from: '../artifacts.gradle'
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
index 0b53797..8b051c5 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
@@ -18,11 +18,12 @@ package ca.allanwang.kau.kpref.activity.items
import ca.allanwang.kau.colorpicker.CircleView
import ca.allanwang.kau.colorpicker.ColorBuilder
import ca.allanwang.kau.colorpicker.ColorContract
-import ca.allanwang.kau.colorpicker.colorPickerDialog
+import ca.allanwang.kau.colorpicker.kauColorChooser
import ca.allanwang.kau.kpref.activity.GlobalOptions
import ca.allanwang.kau.kpref.activity.KClick
import ca.allanwang.kau.kpref.activity.KPrefItemActions
import ca.allanwang.kau.kpref.activity.R
+import com.afollestad.materialdialogs.MaterialDialog
/**
* Created by Allan Wang on 2017-06-07.
@@ -34,36 +35,37 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
- builder.apply {
- titleRes = core.titleFun()
- colorCallback = { pref = it }
- }
if (builder.showPreview) {
val preview = holder.bindInnerView<CircleView>(R.layout.kau_pref_color)
preview.setBackgroundColor(pref)
preview.withBorder = true
- builder.apply {
- colorCallback = {
- pref = it
- if (builder.showPreview)
- preview.setBackgroundColor(it)
- holder.updateTitle()
- holder.updateDesc()
- }
+ builder.callback = { _, color ->
+ pref = color
+ if (builder.showPreview)
+ preview.setBackgroundColor(color)
+ holder.updateTitle()
+ holder.updateDesc()
}
+ } else {
+ builder.callback = { _, color -> pref = color }
}
}
override fun KClick<Int>.defaultOnClick() {
builder.defaultColor = pref
- context.colorPickerDialog(builder).show()
+ MaterialDialog(context).show {
+ kauColorChooser(builder)
+ builder.dialogBuilder(this)
+ title(core.titleFun())
+ }
}
/**
* Extension of the base contract and [ColorContract] along with a showPreview option
*/
- interface KPrefColorContract : BaseContract<Int>, ColorContract {
+ interface KPrefColorContract : KPrefItemBase.BaseContract<Int>, ColorContract {
var showPreview: Boolean
+ var dialogBuilder: MaterialDialog.() -> Unit
}
/**
@@ -74,9 +76,10 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
titleId: Int,
getter: () -> Int,
setter: KPrefItemActions.(value: Int) -> Unit
- ) : KPrefColorContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
+ ) : KPrefColorContract, KPrefItemBase.BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
ColorContract by ColorBuilder() {
override var showPreview: Boolean = true
+ override var dialogBuilder: MaterialDialog.() -> Unit = {}
}
override fun getType(): Int = R.id.kau_item_pref_color_picker
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
index ca879ef..1941ec0 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
@@ -96,7 +96,7 @@ abstract class MediaActionCamera(
if (intent.resolveActivity(c.packageManager) == null) {
c.materialDialog {
title(R.string.kau_no_camera_found)
- content(R.string.kau_no_camera_found_content)
+ message(R.string.kau_no_camera_found_content)
}
return@kauRequestPermissions
}
@@ -106,7 +106,7 @@ abstract class MediaActionCamera(
} catch (e: java.io.IOException) {
c.materialDialog {
title(R.string.kau_error)
- content(R.string.kau_temp_file_creation_failed)
+ message(R.string.kau_temp_file_creation_failed)
}
return@kauRequestPermissions
}
@@ -131,7 +131,7 @@ class MediaActionCameraVideo(
if (intent.resolveActivity(c.packageManager) == null) {
c.materialDialog {
title(R.string.kau_no_camera_found)
- content(R.string.kau_no_camera_found_content)
+ message(R.string.kau_no_camera_found_content)
}
return
}
diff --git a/sample/build.gradle b/sample/build.gradle
index 7316f1e..bb7cab0 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -122,6 +122,8 @@ dependencies {
implementation project(':searchview')
implementation project(':mediapicker')
+ implementation "com.afollestad.material-dialogs:input:${kau.materialDialog}"
+
testImplementation kauDependency.kotlinTest
testImplementation kauDependency.junit
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index d4a30bb..d9586c4 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -38,6 +38,7 @@ import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.utils.withSceneTransitionAnimation
import ca.allanwang.kau.xml.showChangelog
+import com.afollestad.materialdialogs.input.input
import com.mikepenz.google_material_typeface_library.GoogleMaterial
class MainActivity : KPrefActivity() {
@@ -162,9 +163,10 @@ class MainActivity : KPrefActivity() {
descRes = R.string.text_desc
onClick = {
itemView.context.materialDialog {
- title("Type Text")
- input("Type here", item.pref, { _, input -> item.pref = input.toString() })
- inputRange(0, 20)
+ title(text = "Type Text")
+ input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input ->
+ item.pref = input.toString()
+ }
}
}
}
@@ -240,12 +242,11 @@ class MainActivity : KPrefActivity() {
descRes = R.string.text_desc
onClick = {
itemView.context.materialDialog {
- title("Type Text")
- input("Type here", item.pref) { _, input ->
+ title(text = "Type Text")
+ input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input ->
item.pref = input.toString()
reloadSelf()
}
- inputRange(0, 20)
}
}
}
@@ -260,9 +261,10 @@ class MainActivity : KPrefActivity() {
KPrefSample.version = BuildConfig.VERSION_CODE
if (!BuildConfig.DEBUG)
showChangelog(R.xml.kau_changelog, KPrefSample.textColor) {
- titleColor(KPrefSample.textColor)
- backgroundColor(KPrefSample.bgColor)
- positiveColor(KPrefSample.accentColor)
+ // TODO MD Color
+// titleColor(KPrefSample.textColor)
+// backgroundColor(KPrefSample.bgColor)
+// positiveColor(KPrefSample.accentColor)
}
}
supportActionBar?.apply {
@@ -297,9 +299,10 @@ class MainActivity : KPrefActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_changelog -> showChangelog(R.xml.kau_changelog, KPrefSample.textColor) {
- titleColor(KPrefSample.textColor)
- backgroundColor(KPrefSample.bgColor)
- positiveColor(KPrefSample.accentColor)
+ // TODO MD Color
+// titleColor(KPrefSample.textColor)
+// backgroundColor(KPrefSample.bgColor)
+// positiveColor(KPrefSample.accentColor)
}
R.id.action_settings -> startActivity<AnimActivity>()
R.id.action_email -> sendEmail(R.string.your_email, R.string.your_subject)
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 0b13dd4..53265d0 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,6 +6,14 @@
<item text="" />
-->
+ <version title="v5.0.0" />
+ <item text=":core: Update Material Dialogs to 3.x" />
+ <item text=":colorpicker: Strip down to just the interface; unless you require the accent palette, it may be fine to just use MD's color extension" />
+ <item text="" />
+ <item text="" />
+ <item text="" />
+ <item text="" />
+
<version title="v4.1.0" />
<item text=":core: Deprecate NetworkUtils, as the underlying functions are deprecated" />
<item text=":core: Permission manager no longer synchronized, as all actions should occur in the main thread" />