Skip to content

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anggrayudi committed Aug 10, 2019
1 parent 1222bcc commit 6fb231e
Show file tree
Hide file tree
Showing 37 changed files with 763 additions and 333 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

## 3.3.0 (2019-11-08)

### Enhancements
* Introducing `IntegerListPreference` for `integer-array` type entry values.
* Added `OnBindTextInputLayoutListener` as replacement for `OnBindEditTextListener`.
* All preference classes are now `open`.

## 3.1.8 (2019-23-04)

### Enhancements
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
}
}
dependencies {
implementation 'com.anggrayudi:materialpreference:3.2.3'
implementation 'com.anggrayudi:materialpreference:3.3.0'
}
```

Expand Down Expand Up @@ -127,7 +127,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' // Add this line
dependencies {
implementation 'com.anggrayudi:materialpreference:3.2.3'
implementation 'com.anggrayudi:materialpreference:3.3.0'
kapt 'com.anggrayudi:materialpreference-compiler:1.1'
}
````
Expand All @@ -141,7 +141,7 @@ class SettingsFragment : PreferenceFragmentMaterial() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences)
// You can access the constant values with auto-generated class named PrefKey
findPreference(PrefKey.ABOUT)!!.summary = BuildConfig.VERSION_NAME
findPreference(PrefKey.ABOUT)?.summary = BuildConfig.VERSION_NAME
}
}
````
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ task clean(type: Delete) {
}

ext {
appVersionCode = 11
libVersion = '3.2.3'
appVersionCode = 13
libVersion = '3.3.0'
processorVersion = '1.1'
minSdkVersion = 17
targetSdkVersion = 28
Expand Down
4 changes: 3 additions & 1 deletion materialpreference/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ repositories {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api 'androidx.appcompat:appcompat:1.1.0-rc01'
api 'com.google.android.material:material:1.1.0-alpha08'
api 'com.google.android.material:material:1.1.0-alpha09'
api 'androidx.documentfile:documentfile:1.0.1'
api 'androidx.cardview:cardview:1.0.0'

api 'com.wdullaer:materialdatetimepicker:4.2.1'
api "com.afollestad.material-dialogs:core:$dialogVersion"
api "com.afollestad.material-dialogs:files:$dialogVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import androidx.annotation.ArrayRes
* @see ListPreference
* @see MultiSelectListPreference
*/
interface ArrayPreference<ValueType> {

/** Get or set value to this preference */
var value: ValueType?
internal interface ArrayPreference<EntryValuesType> {

/**
* Sets the human-readable entries to be shown in the list. This will be
Expand All @@ -29,7 +26,7 @@ interface ArrayPreference<ValueType> {
*
* @return The array of values to be saved for the preference.
*/
var entryValues: Array<CharSequence>?
var entryValues: Array<EntryValuesType>?

/**
* @param entriesResId The entries array as a resource.
Expand All @@ -49,7 +46,7 @@ interface ArrayPreference<ValueType> {
* @param value The value whose index should be returned.
* @return The index of the value, or -1 if not found.
*/
fun findIndexOfValue(value: String?): Int {
fun <T> findIndexOfValue(value: T?): Int {
if (value != null && entryValues != null) {
for (i in entryValues!!.indices.reversed()) {
if (entryValues!![i] == value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ import androidx.core.content.res.TypedArrayUtils
* @see SwitchPreference
*/
@SuppressLint("RestrictedApi")
class CheckBoxPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.checkBoxPreferenceStyle,
android.R.attr.checkBoxPreferenceStyle), defStyleRes: Int = 0)
: TwoStatePreference(context, attrs, defStyleAttr, defStyleRes) {
open class CheckBoxPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.checkBoxPreferenceStyle,
android.R.attr.checkBoxPreferenceStyle),
defStyleRes: Int = 0
) : TwoStatePreference(context, attrs, defStyleAttr, defStyleRes) {

private val listener = CompoundButton.OnCheckedChangeListener {
buttonView, isChecked ->
private val listener = CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
if (!callChangeListener(isChecked)) {
// Listener didn't like it, change it back.
// CompoundButton will make sure we don't recurse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import com.anggrayudi.materialpreference.widget.ColorCircleView
* | app:defaultColor | Color |
*/
@SuppressLint("RestrictedApi")
class ColorPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.colorPreferenceStyle,
android.R.attr.dialogPreferenceStyle), defStyleRes: Int = 0)
: DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
open class ColorPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.colorPreferenceStyle,
android.R.attr.dialogPreferenceStyle),
defStyleRes: Int = 0
) : DialogPreference(context, attrs, defStyleAttr, defStyleRes) {

var colorList = DEFAULT_COLOR_LIST
set(a) {
Expand All @@ -41,7 +43,8 @@ class ColorPreference @JvmOverloads constructor(
var defaultColor: Int

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference, defStyleAttr, defStyleRes)
val a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference,
defStyleAttr, defStyleRes)
defaultColor = a.getColor(R.styleable.ColorPreference_defaultColor, colorList[0])
a.recycle()
}
Expand Down Expand Up @@ -138,25 +141,25 @@ class ColorPreference @JvmOverloads constructor(
companion object {

val DEFAULT_COLOR_LIST = intArrayOf(
Color.parseColor("#F44336"), // red
Color.parseColor("#E91E63"), // pink
Color.parseColor("#9C27B0"), // purple
Color.parseColor("#673AB7"), // deep purple
Color.parseColor("#3F51B5"), // indigo
Color.parseColor("#2196F3"), // blue
Color.parseColor("#03A9F4"), // light blue
Color.parseColor("#00BCD4"), // cyan
Color.parseColor("#009688"), // teal
Color.parseColor("#4CAF50"), // green
Color.parseColor("#8BC34A"), // light green
Color.parseColor("#CDDC39"), // lime
Color.parseColor("#FFEB3B"), // yellow
Color.parseColor("#FFC107"), // amber
Color.parseColor("#FF9800"), // orange
Color.parseColor("#FF5722"), // deep orange
Color.parseColor("#795548"), // brown
Color.parseColor("#9E9E9E"), // gray
Color.parseColor("#607D8B"), // blue gray
Color.parseColor("#000000")) // black
Color.parseColor("#F44336"), // red
Color.parseColor("#E91E63"), // pink
Color.parseColor("#9C27B0"), // purple
Color.parseColor("#673AB7"), // deep purple
Color.parseColor("#3F51B5"), // indigo
Color.parseColor("#2196F3"), // blue
Color.parseColor("#03A9F4"), // light blue
Color.parseColor("#00BCD4"), // cyan
Color.parseColor("#009688"), // teal
Color.parseColor("#4CAF50"), // green
Color.parseColor("#8BC34A"), // light green
Color.parseColor("#CDDC39"), // lime
Color.parseColor("#FFEB3B"), // yellow
Color.parseColor("#FFC107"), // amber
Color.parseColor("#FF9800"), // orange
Color.parseColor("#FF5722"), // deep orange
Color.parseColor("#795548"), // brown
Color.parseColor("#9E9E9E"), // gray
Color.parseColor("#607D8B"), // blue gray
Color.parseColor("#000000")) // black
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

/**
*
* @see TimePreference
*/
@SuppressLint("RestrictedApi")
class DatePreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.preferenceStyle, defStyleRes: Int = 0)
: Preference(context, attrs, defStyleAttr, defStyleRes),
DatePickerDialog.OnDateSetListener {
open class DatePreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.preferenceStyle,
defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes), DatePickerDialog.OnDateSetListener {

var minDate: Long = 0

var maxDate: Long = 0

var disabledDays: Array<Calendar>? = null

var highlightedDays: Array<Calendar>? = null

var dateFormatter = SimpleDateFormat.getDateInstance()
var dateFormatter: DateFormat = SimpleDateFormat.getDateInstance()
set(f) {
field = f
val v = value
Expand Down Expand Up @@ -54,9 +58,9 @@ class DatePreference @JvmOverloads constructor(
val now = Calendar.getInstance()
now.timeInMillis = millis
val dialog = DatePickerDialog.newInstance(this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH))
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH))
dialog.version = DatePickerDialog.Version.VERSION_2
dialog.dismissOnPause(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.text.InputType
import android.util.AttributeSet
import android.widget.EditText
import androidx.core.content.res.TypedArrayUtils
import com.anggrayudi.materialpreference.callback.OnBindTextInputLayoutListener
import com.anggrayudi.materialpreference.dialog.DialogPreference
import com.anggrayudi.materialpreference.util.StringSummaryFormatter

Expand All @@ -50,11 +51,13 @@ import com.anggrayudi.materialpreference.util.StringSummaryFormatter
* | app:counterEnabled | Boolean |
*/
@SuppressLint("RestrictedApi")
class EditTextPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.editTextPreferenceStyle,
android.R.attr.editTextPreferenceStyle), defStyleRes: Int = 0)
: DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
open class EditTextPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.editTextPreferenceStyle,
android.R.attr.editTextPreferenceStyle),
defStyleRes: Int = 0
) : DialogPreference(context, attrs, defStyleAttr, defStyleRes) {

/**
* Saves the text to the [android.content.SharedPreferences].
Expand Down Expand Up @@ -93,22 +96,32 @@ class EditTextPreference @JvmOverloads constructor(
updateSummary()
}

var onBindTextInputLayoutListener: OnBindTextInputLayoutListener? = null

var hint: String? = null

var message: String? = null

var inputType: Int = 0

var maxLength: Int = 0

var minLength: Int = 0

var isCounterEnabled: Boolean = false

var inputFilters: Array<InputFilter>? = null

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.EditTextPreference, defStyleAttr, defStyleRes)
val a = context.obtainStyledAttributes(attrs, R.styleable.EditTextPreference,
defStyleAttr, defStyleRes)
isCounterEnabled = a.getBoolean(R.styleable.EditTextPreference_counterEnabled, true)
hint = a.getString(R.styleable.EditTextPreference_android_hint)
message = a.getString(R.styleable.EditTextPreference_android_dialogMessage)
maxLength = a.getInt(R.styleable.EditTextPreference_android_maxLength, 100)
minLength = a.getInt(R.styleable.EditTextPreference_minLength, 0)
inputType = a.getInt(R.styleable.EditTextPreference_android_inputType, InputType.TYPE_CLASS_TEXT)
inputType = a.getInt(R.styleable.EditTextPreference_android_inputType,
InputType.TYPE_CLASS_TEXT)
a.recycle()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import java.io.File
*/
@TargetApi(21)
@SuppressLint("RestrictedApi")
class FolderPreference @JvmOverloads constructor(
open class FolderPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = 0, defStyleRes: Int = 0)
: Preference(context, attrs, defStyleAttr, defStyleRes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import com.anggrayudi.materialpreference.util.applyTint
* | app:tint | Color |
*/
@SuppressLint("RestrictedApi")
class IndicatorPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.indicatorPreferenceStyle, 0),
defStyleRes: Int = 0)
: Preference(context, attrs, defStyleAttr, defStyleRes) {
open class IndicatorPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, R.attr.indicatorPreferenceStyle, 0),
defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes) {

override var isLegacySummary: Boolean
get() = true
Expand All @@ -48,7 +49,8 @@ class IndicatorPreference @JvmOverloads constructor(
private var _tint: Int = 0

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.IndicatorPreference, defStyleAttr, defStyleRes)
val a = context.obtainStyledAttributes(attrs, R.styleable.IndicatorPreference,
defStyleAttr, defStyleRes)
_tint = a.getColor(R.styleable.IndicatorPreference_tint, 0)
_drawable = a.getDrawable(R.styleable.IndicatorPreference_android_src)
a.recycle()
Expand All @@ -62,6 +64,7 @@ class IndicatorPreference @JvmOverloads constructor(

override fun onSetupFinished(fragment: PreferenceFragmentMaterial) {
tint = _tint
preferenceViewHolder?.itemView?.findViewById<View>(R.id.material_summary)!!.visibility = View.GONE
preferenceViewHolder?.itemView?.findViewById<View>(
R.id.material_summary)!!.visibility = View.GONE
}
}
Loading

0 comments on commit 6fb231e

Please sign in to comment.