diff options
Diffstat (limited to 'library')
5 files changed, 35 insertions, 116 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerPreference.kt b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerPreference.kt deleted file mode 100644 index 043e287..0000000 --- a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerPreference.kt +++ /dev/null @@ -1,72 +0,0 @@ -package ca.allanwang.kau.dialogs.color - -import android.annotation.SuppressLint -import android.content.Context -import android.graphics.Color -import android.os.Build -import android.os.Bundle -import android.os.Parcelable -import android.support.annotation.ColorInt -import android.support.annotation.StringRes -import android.support.v4.content.res.ResourcesCompat -import android.support.v7.app.AppCompatActivity -import android.support.v7.preference.Preference -import android.text.Editable -import android.text.TextWatcher -import android.util.AttributeSet -import android.view.View -import android.view.ViewGroup -import android.widget.* -import ca.allanwang.kau.R -import ca.allanwang.kau.utils.ANDROID_NAMESPACE -import ca.allanwang.kau.utils.integer -import ca.allanwang.kau.utils.resolveColor -import ca.allanwang.kau.utils.toColor -import com.afollestad.materialdialogs.DialogAction -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.color.CircleView -import com.afollestad.materialdialogs.color.ColorChooserDialog -import com.afollestad.materialdialogs.internal.MDTintHelper -import com.afollestad.materialdialogs.util.DialogUtils -import java.util.* - -/** - * Created by Allan Wang on 2017-06-08. - */ -class ColorPickerPreference @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 -) : Preference(context, attrs, defStyleAttr, defStyleRes), Preference.OnPreferenceClickListener { - - var defaultColor: Int = Color.BLACK - var currentColor: Int - var accentMode = false - var dialogTitle: Int = 0 - - init { - onPreferenceClickListener = this - if (attrs != null) { - val defaultValue = attrs.getAttributeValue(ANDROID_NAMESPACE, "defaultValue") - if (defaultValue?.startsWith("#") ?: false) { - try { - defaultColor = defaultValue.toColor() - } catch (e: IllegalArgumentException) { - throw IllegalArgumentException("ColorPickerPreference $key has a default value that is not a color resource: $defaultValue") - } - } else { - val resourceId = attrs.getAttributeResourceValue(ANDROID_NAMESPACE, "defaultValue", 0) - if (resourceId != 0) - defaultColor = context.integer(resourceId) - else - throw IllegalArgumentException("ColorPickerPreference $key has a default value that is not a color resource: $defaultValue") - } - } - currentColor = getPersistedInt(defaultColor) - } - - override fun onPreferenceClick(preference: Preference): Boolean { - context.colorPickerDialog { - - }.show() - return true - } -}
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index d27a609..1bb8b52 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -86,7 +86,7 @@ fun Context.showChangelog(@XmlRes xmlRes: Int) { }).start() } -val isNetworkAvailable = fun Context.(): Boolean { +fun Context.isNetworkAvailable(): Boolean { val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetworkInfo = connectivityManager.activeNetworkInfo return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt index bd68b03..a8ddd2a 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -18,72 +18,72 @@ import kotlin.reflect.KProperty import android.support.v4.app.DialogFragment as SupportDialogFragment import android.support.v4.app.Fragment as SupportFragment -public fun <V : View> View.bindView(id: Int) +fun <V : View> View.bindView(id: Int) : ReadOnlyProperty<View, V> = required(id, viewFinder) -public fun <V : View> Activity.bindView(id: Int) +fun <V : View> Activity.bindView(id: Int) : ReadOnlyProperty<Activity, V> = required(id, viewFinder) -public fun <V : View> Dialog.bindView(id: Int) +fun <V : View> Dialog.bindView(id: Int) : ReadOnlyProperty<Dialog, V> = required(id, viewFinder) -public fun <V : View> DialogFragment.bindView(id: Int) +fun <V : View> DialogFragment.bindView(id: Int) : ReadOnlyProperty<DialogFragment, V> = required(id, viewFinder) -public fun <V : View> android.support.v4.app.DialogFragment.bindView(id: Int) +fun <V : View> android.support.v4.app.DialogFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V> = required(id, viewFinder) -public fun <V : View> Fragment.bindView(id: Int) +fun <V : View> Fragment.bindView(id: Int) : ReadOnlyProperty<Fragment, V> = required(id, viewFinder) -public fun <V : View> android.support.v4.app.Fragment.bindView(id: Int) +fun <V : View> android.support.v4.app.Fragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = required(id, viewFinder) -public fun <V : View> ViewHolder.bindView(id: Int) +fun <V : View> ViewHolder.bindView(id: Int) : ReadOnlyProperty<ViewHolder, V> = required(id, viewFinder) -public fun <V : View> View.bindOptionalView(id: Int) +fun <V : View> View.bindOptionalView(id: Int) : ReadOnlyProperty<View, V?> = optional(id, viewFinder) -public fun <V : View> Activity.bindOptionalView(id: Int) +fun <V : View> Activity.bindOptionalView(id: Int) : ReadOnlyProperty<Activity, V?> = optional(id, viewFinder) -public fun <V : View> Dialog.bindOptionalView(id: Int) +fun <V : View> Dialog.bindOptionalView(id: Int) : ReadOnlyProperty<Dialog, V?> = optional(id, viewFinder) -public fun <V : View> DialogFragment.bindOptionalView(id: Int) +fun <V : View> DialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<DialogFragment, V?> = optional(id, viewFinder) -public fun <V : View> android.support.v4.app.DialogFragment.bindOptionalView(id: Int) +fun <V : View> android.support.v4.app.DialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V?> = optional(id, viewFinder) -public fun <V : View> Fragment.bindOptionalView(id: Int) +fun <V : View> Fragment.bindOptionalView(id: Int) : ReadOnlyProperty<Fragment, V?> = optional(id, viewFinder) -public fun <V : View> android.support.v4.app.Fragment.bindOptionalView(id: Int) +fun <V : View> android.support.v4.app.Fragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optional(id, viewFinder) -public fun <V : View> ViewHolder.bindOptionalView(id: Int) +fun <V : View> ViewHolder.bindOptionalView(id: Int) : ReadOnlyProperty<ViewHolder, V?> = optional(id, viewFinder) -public fun <V : View> View.bindViews(vararg ids: Int) +fun <V : View> View.bindViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = required(ids, viewFinder) -public fun <V : View> Activity.bindViews(vararg ids: Int) +fun <V : View> Activity.bindViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = required(ids, viewFinder) -public fun <V : View> Dialog.bindViews(vararg ids: Int) +fun <V : View> Dialog.bindViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = required(ids, viewFinder) -public fun <V : View> DialogFragment.bindViews(vararg ids: Int) +fun <V : View> DialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = required(ids, viewFinder) -public fun <V : View> android.support.v4.app.DialogFragment.bindViews(vararg ids: Int) +fun <V : View> android.support.v4.app.DialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = required(ids, viewFinder) -public fun <V : View> Fragment.bindViews(vararg ids: Int) +fun <V : View> Fragment.bindViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = required(ids, viewFinder) -public fun <V : View> android.support.v4.app.Fragment.bindViews(vararg ids: Int) +fun <V : View> android.support.v4.app.Fragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = required(ids, viewFinder) -public fun <V : View> ViewHolder.bindViews(vararg ids: Int) +fun <V : View> ViewHolder.bindViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = required(ids, viewFinder) -public fun <V : View> View.bindOptionalViews(vararg ids: Int) +fun <V : View> View.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = optional(ids, viewFinder) -public fun <V : View> Activity.bindOptionalViews(vararg ids: Int) +fun <V : View> Activity.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = optional(ids, viewFinder) -public fun <V : View> Dialog.bindOptionalViews(vararg ids: Int) +fun <V : View> Dialog.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = optional(ids, viewFinder) -public fun <V : View> DialogFragment.bindOptionalViews(vararg ids: Int) +fun <V : View> DialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = optional(ids, viewFinder) -public fun <V : View> android.support.v4.app.DialogFragment.bindOptionalViews(vararg ids: Int) +fun <V : View> android.support.v4.app.DialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = optional(ids, viewFinder) -public fun <V : View> Fragment.bindOptionalViews(vararg ids: Int) +fun <V : View> Fragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = optional(ids, viewFinder) -public fun <V : View> android.support.v4.app.Fragment.bindOptionalViews(vararg ids: Int) +fun <V : View> android.support.v4.app.Fragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optional(ids, viewFinder) -public fun <V : View> ViewHolder.bindOptionalViews(vararg ids: Int) +fun <V : View> ViewHolder.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optional(ids, viewFinder) private val View.viewFinder: View.(Int) -> View? diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index c7ff9f2..79f80f3 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -6,6 +6,6 @@ import android.content.res.Resources * Created by Allan Wang on 2017-05-28. */ -val dpToPx = fun Int.(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() +fun Int.dpToPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() -val pxToDp = fun Int.(): Int = (this / Resources.getSystem().displayMetrics.density).toInt() +fun Int.pxToDp(px: Int) = (px / android.content.res.Resources.getSystem().displayMetrics.density).toInt()
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index a5204aa..bd8478d 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -44,15 +44,6 @@ fun View.matchParent() { } } -fun ProgressBar.tintRes(@ColorRes id: Int) = tint(ContextCompat.getColor(context, id)) - -fun ProgressBar.tint(@ColorInt color: Int) { - val sl = ColorStateList.valueOf(color) - progressTintList = sl - secondaryProgressTintList = sl - indeterminateTintList = sl -} - fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: (Snackbar) -> Unit = {}) { val snackbar = Snackbar.make(this, text, duration) builder.invoke(snackbar) |