aboutsummaryrefslogtreecommitdiff
path: root/library/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-25 00:05:05 -0700
committerAllan Wang <me@allanwang.ca>2017-06-25 00:05:05 -0700
commitb51ce53886415bb4a6b320a3a53eee587ec8c288 (patch)
treeeb299ce570143c0fe2352793873a7876a8d4fc45 /library/src/main
parent35b26d771199c1dbf0d67377627c9d8b27da388c (diff)
downloadkau-b51ce53886415bb4a6b320a3a53eee587ec8c288.tar.gz
kau-b51ce53886415bb4a6b320a3a53eee587ec8c288.tar.bz2
kau-b51ce53886415bb4a6b320a3a53eee587ec8c288.zip
Add annotations
Diffstat (limited to 'library/src/main')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerDialog.kt17
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kotlin/LazyResettable.kt (renamed from library/src/main/kotlin/ca/allanwang/kau/utils/LazyResettable.kt)2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt12
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt13
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt1
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt8
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt23
-rw-r--r--library/src/main/res/layout/kau_search_view.xml18
11 files changed, 59 insertions, 38 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerDialog.kt b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerDialog.kt
index 53d94ef..07f5e17 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerDialog.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerDialog.kt
@@ -2,6 +2,8 @@ package ca.allanwang.kau.dialogs.color
import android.content.Context
import android.graphics.Color
+import android.support.annotation.DimenRes
+import android.support.annotation.StringRes
import ca.allanwang.kau.R
import ca.allanwang.kau.utils.string
import com.afollestad.materialdialogs.MaterialDialog
@@ -30,18 +32,19 @@ class ColorBuilder : ColorContract {
interface ColorContract {
var title: String?
- var titleRes: Int
+ var titleRes: Int @StringRes set
var allowCustom: Boolean
var allowCustomAlpha: Boolean
var isAccent: Boolean
- var defaultColor: Int
- var doneText: Int
- var backText: Int
- var cancelText: Int
+ var defaultColor: Int @StringRes set
+ var doneText: Int @StringRes set
+ var backText: Int @StringRes set
+ var cancelText: Int @StringRes set
var presetText: Int
- var customText: Int
+ @StringRes set
+ var customText: Int @StringRes set
var dynamicButtonColors: Boolean
- var circleSizeRes: Int
+ var circleSizeRes: Int @DimenRes set
var colorCallback: ((selectedColor: Int) -> Unit)?
var colorsTop: IntArray?
var colorsSub: Array<IntArray>?
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/LazyResettable.kt b/library/src/main/kotlin/ca/allanwang/kau/kotlin/LazyResettable.kt
index 6e7e43e..b74c5c7 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/LazyResettable.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kotlin/LazyResettable.kt
@@ -1,4 +1,4 @@
-package ca.allanwang.kau.utils
+package ca.allanwang.kau.kotlin
import java.io.Serializable
import kotlin.reflect.KProperty
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt b/library/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt
new file mode 100644
index 0000000..f3add48
--- /dev/null
+++ b/library/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt
@@ -0,0 +1,12 @@
+package ca.allanwang.kau.kotlin
+
+/**
+ * Created by Allan Wang on 2017-06-24.
+ *
+ * Credits to @zsmb13
+ *
+ * https://github.com/zsmb13/MaterialDrawerKt/blob/master/library/src/main/java/co/zsmb/materialdrawerkt/NonReadablePropertyException.kt
+ */
+class NonReadablePropertyException : Exception()
+
+fun nonReadable(): Nothing = throw NonReadablePropertyException() \ No newline at end of file
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
index 723af45..5fdb6bc 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
@@ -34,9 +34,13 @@ fun RecyclerView.setKPrefAdapter(globalOptions: GlobalOptions, builder: KPrefAda
return adapter
}
+@DslMarker
+annotation class KPrefMarker
+
/**
* Contains attributes shared amongst all kpref items
*/
+@KPrefMarker
interface CoreAttributeContract {
var textColor: (() -> Int)?
var accentColor: (() -> Int)?
@@ -67,11 +71,14 @@ class GlobalOptions(core: CoreAttributeContract, activity: KPrefActivityContract
* The arguments are all the mandatory values plus an optional builder housing all the possible configurations
* The mandatory values are final so they cannot be edited in the builder
*/
+@KPrefMarker
class KPrefAdapterBuilder(internal val globalOptions: GlobalOptions) {
+ @KPrefMarker
fun header(@StringRes title: Int)
= list.add(KPrefHeader(KPrefItemCore.CoreBuilder(globalOptions, title)))
+ @KPrefMarker
fun checkbox(@StringRes title: Int,
getter: (() -> Boolean),
setter: ((value: Boolean) -> Unit),
@@ -79,7 +86,7 @@ class KPrefAdapterBuilder(internal val globalOptions: GlobalOptions) {
= list.add(KPrefCheckbox(KPrefItemBase.BaseBuilder(globalOptions, title, getter, setter)
.apply { builder() }))
-
+ @KPrefMarker
fun colorPicker(@StringRes title: Int,
getter: (() -> Int),
setter: ((value: Int) -> Unit),
@@ -87,6 +94,7 @@ class KPrefAdapterBuilder(internal val globalOptions: GlobalOptions) {
= list.add(KPrefColorPicker(KPrefColorPicker.KPrefColorBuilder(globalOptions, title, getter, setter)
.apply { builder() }))
+ @KPrefMarker
fun <T> text(@StringRes title: Int,
getter: (() -> T),
setter: ((value: T) -> Unit),
@@ -94,16 +102,19 @@ class KPrefAdapterBuilder(internal val globalOptions: GlobalOptions) {
= list.add(KPrefText<T>(KPrefText.KPrefTextBuilder<T>(globalOptions, title, getter, setter)
.apply { builder() }))
+ @KPrefMarker
fun subItems(@StringRes title: Int,
itemBuilder: KPrefAdapterBuilder.() -> Unit,
builder: KPrefSubItems.KPrefSubItemsContract.() -> Unit)
= list.add(KPrefSubItems(KPrefSubItems.KPrefSubItemsBuilder(globalOptions, title, itemBuilder)
.apply { builder() }))
+ @KPrefMarker
fun plainText(@StringRes title: Int,
builder: KPrefItemBase.BaseContract<Unit>.() -> Unit = {})
= list.add(KPrefPlainText(KPrefPlainText.KPrefPlainTextBuilder(globalOptions, title)
.apply { builder() }))
+ @KPrefMarker
internal val list: MutableList<KPrefItemCore> = mutableListOf()
} \ No newline at end of file
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
index 4af837b..22cc927 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefCheckbox.kt
@@ -3,6 +3,7 @@ package ca.allanwang.kau.kpref.items
import android.view.View
import android.widget.CheckBox
import ca.allanwang.kau.R
+import ca.allanwang.kau.kpref.KPrefMarker
import ca.allanwang.kau.utils.tint
/**
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
index b22c4b3..c573939 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
@@ -8,6 +8,7 @@ import ca.allanwang.kau.dialogs.color.ColorContract
import ca.allanwang.kau.dialogs.color.colorPickerDialog
import ca.allanwang.kau.kpref.CoreAttributeContract
import ca.allanwang.kau.kpref.GlobalOptions
+import ca.allanwang.kau.kpref.KPrefMarker
/**
* Created by Allan Wang on 2017-06-07.
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
index c50556d..fa8efff 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefHeader.kt
@@ -2,6 +2,7 @@ package ca.allanwang.kau.kpref.items
import android.view.View
import ca.allanwang.kau.R
+import ca.allanwang.kau.kpref.KPrefMarker
/**
* Created by Allan Wang on 2017-06-07.
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt
index a0718a0..bb0f0a3 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt
@@ -12,7 +12,6 @@ import ca.allanwang.kau.utils.resolveDrawable
*
* Base class for pref setters that include the Shared Preference hooks
*/
-
abstract class KPrefItemBase<T>(val base: BaseContract<T>) : KPrefItemCore(base) {
open var pref: T
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
index 9c0ad79..7d0f9f7 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemCore.kt
@@ -3,6 +3,7 @@ package ca.allanwang.kau.kpref.items
import android.support.annotation.CallSuper
import android.support.annotation.IdRes
import android.support.annotation.LayoutRes
+import android.support.annotation.StringRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
@@ -12,6 +13,7 @@ import android.widget.LinearLayout
import android.widget.TextView
import ca.allanwang.kau.R
import ca.allanwang.kau.kpref.GlobalOptions
+import ca.allanwang.kau.kpref.KPrefMarker
import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.iconics.typeface.IIcon
@@ -69,10 +71,12 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
/**
* Core values for all kpref items
*/
+ @KPrefMarker
interface CoreContract {
val globalOptions: GlobalOptions
- val titleRes: Int
+ @get:StringRes val titleRes: Int
var descRes: Int
+ @StringRes get
var iicon: IIcon?
/**
@@ -85,7 +89,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
* Default implementation of [CoreContract]
*/
class CoreBuilder(override val globalOptions: GlobalOptions,
- override val titleRes: Int) : CoreContract {
+ override @param:StringRes val titleRes: Int) : CoreContract {
override var descRes: Int = -1
override var iicon: IIcon? = null
diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
index 2c3b0d3..e3931b9 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -4,6 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.support.annotation.ColorInt
import android.support.annotation.IdRes
+import android.support.annotation.StringRes
import android.support.transition.AutoTransition
import android.support.v7.widget.*
import android.util.AttributeSet
@@ -12,6 +13,7 @@ import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar
import ca.allanwang.kau.R
+import ca.allanwang.kau.kotlin.nonReadable
import ca.allanwang.kau.utils.*
import com.jakewharton.rxbinding2.widget.RxTextView
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
@@ -53,12 +55,6 @@ class SearchView @JvmOverloads constructor(
iconNav.setSearchIcon(value)
if (value == null) iconNav.gone()
}
- var micIcon: IIcon? = GoogleMaterial.Icon.gmd_mic
- set(value) {
- field = value
- iconMic.setSearchIcon(value)
- if (value == null) iconMic.gone()
- }
var clearIcon: IIcon? = GoogleMaterial.Icon.gmd_clear
set(value) {
field = value
@@ -79,6 +75,18 @@ class SearchView @JvmOverloads constructor(
field = value
if (value) divider.visible() else divider.invisible()
}
+ var hintText: String?
+ get() = editText.hint?.toString()
+ set(value) {
+ editText.hint = value
+ }
+
+ var hintTextRes: Int
+ @Deprecated(level = DeprecationLevel.ERROR, message = "Non readable property")
+ get() = nonReadable()
+ @StringRes set(value) {
+ hintText = context.string(value)
+ }
/**
* StringRes for a "no results found" item
* If [results] is ever set to an empty list, it will default to
@@ -137,7 +145,6 @@ class SearchView @JvmOverloads constructor(
private val editText: AppCompatEditText by bindView(R.id.search_edit_text)
val textEvents: Observable<String>
private val progress: ProgressBar by bindView(R.id.search_progress)
- private val iconMic: ImageView by bindView(R.id.search_mic)
private val iconClear: ImageView by bindView(R.id.search_clear)
private val divider: View by bindView(R.id.search_divider)
private val recycler: RecyclerView by bindView(R.id.search_recycler)
@@ -158,7 +165,6 @@ class SearchView @JvmOverloads constructor(
init {
View.inflate(context, R.layout.kau_search_view, this)
iconNav.setSearchIcon(configs.navIcon)
- iconMic.setSearchIcon(configs.micIcon)
iconClear.setSearchIcon(configs.clearIcon).setOnClickListener {
editText.text.clear()
}
@@ -239,7 +245,6 @@ class SearchView @JvmOverloads constructor(
fun tintForeground(@ColorInt color: Int) {
iconNav.drawable.setTint(color)
- iconMic.drawable.setTint(color)
iconClear.drawable.setTint(color)
SearchItem.foregroundColor = color
divider.setBackgroundColor(color.adjustAlpha(0.1f))
diff --git a/library/src/main/res/layout/kau_search_view.xml b/library/src/main/res/layout/kau_search_view.xml
index 5c2ad27..ddde753 100644
--- a/library/src/main/res/layout/kau_search_view.xml
+++ b/library/src/main/res/layout/kau_search_view.xml
@@ -68,24 +68,10 @@
android:layout_height="match_parent"
android:visibility="gone" />
- <FrameLayout
- android:layout_width="48dp"
- android:layout_height="match_parent">
-
- <ImageView
- android:id="@+id/search_mic"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="?android:attr/selectableItemBackgroundBorderless"
- android:clickable="true"
- android:contentDescription="@string/kau_search"
- android:focusable="true"
- android:scaleType="center"
- android:visibility="gone" />
<ImageView
android:id="@+id/search_clear"
- android:layout_width="match_parent"
+ android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
@@ -93,8 +79,6 @@
android:focusable="true"
android:scaleType="center" />
- </FrameLayout>
-
</LinearLayout>
<View