Skip to content

Commit b4bebd5

Browse files
committed
Add versions for Fragment and FrameLayout
1 parent c7dee19 commit b4bebd5

File tree

12 files changed

+134
-2
lines changed

12 files changed

+134
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.1'
7+
classpath 'com.android.tools.build:gradle:2.3.3'
88
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1010
}

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToClick.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.view.View
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
1014
= bindToClick { findViewById(viewId) }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
18+
= bindToClick { view.findViewById(viewId) }
19+
20+
fun FrameLayout.bindToClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
21+
= bindToClick { findViewById(viewId) }
22+
1223
fun View.bindToClick(): ReadWriteProperty<Any?, () -> Unit>
1324
= bindToClick { this }
1425

15-
private fun bindToClick(viewProvider: () -> View): ReadWriteProperty<Any?, () -> Unit>
26+
fun bindToClick(viewProvider: () -> View): ReadWriteProperty<Any?, () -> Unit>
1627
= OnClickBinding(lazy(viewProvider))
1728

1829
private class OnClickBinding(viewProvider: Lazy<View>) : ReadWriteProperty<Any?, () -> Unit> {

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToEditText.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.widget.EditText
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToEditText(@IdRes editTextId: Int): ReadWriteProperty<Any?, String>
1014
= bindToEditText { findViewById(editTextId) as EditText }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToEditText(@IdRes viewId: Int): ReadWriteProperty<Any?, String>
18+
= bindToEditText { view.findViewById(viewId) as EditText }
19+
20+
fun FrameLayout.bindToEditText(@IdRes viewId: Int): ReadWriteProperty<Any?, String>
21+
= bindToEditText { findViewById(viewId) as EditText }
22+
1223
fun EditText.bindToEditText(): ReadWriteProperty<Any?, String>
1324
= bindToEditText { this }
1425

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToEditorActions.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.view.inputmethod.EditorInfo
69
import android.widget.EditText
10+
import android.widget.FrameLayout
711
import kotlin.properties.ReadWriteProperty
812
import kotlin.reflect.KProperty
913

1014
fun Activity.bindToEditorActions(@IdRes editTextId: Int, predicate: (Int?, Int?) -> Boolean): ReadWriteProperty<Any?, () -> Unit>
1115
= bindToEditorActions(predicate, { findViewById(editTextId) as EditText })
1216

17+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
18+
fun Fragment.bindToEditorActions(@IdRes viewId: Int, predicate: (Int?, Int?) -> Boolean): ReadWriteProperty<Any?, () -> Unit>
19+
= bindToEditorActions(predicate, { view.findViewById(viewId) as EditText })
20+
21+
fun FrameLayout.bindToEditorActions(@IdRes viewId: Int, predicate: (Int?, Int?) -> Boolean): ReadWriteProperty<Any?, () -> Unit>
22+
= bindToEditorActions(predicate, { findViewById(viewId) as EditText })
23+
1324
fun EditText.bindToEditorActions(predicate: (Int?, Int?) -> Boolean): ReadWriteProperty<Any?, () -> Unit>
1425
= bindToEditorActions(predicate) { this }
1526

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToErrorId.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.widget.EditText
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToErrorId(@IdRes editTextId: Int): ReadWriteProperty<Any?, Int?>
1014
= bindToErrorId { findViewById(editTextId) as EditText }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToErrorId(@IdRes viewId: Int): ReadWriteProperty<Any?, Int?>
18+
= bindToErrorId { view.findViewById(viewId) as EditText }
19+
20+
fun FrameLayout.bindToErrorId(@IdRes viewId: Int): ReadWriteProperty<Any?, Int?>
21+
= bindToErrorId { findViewById(viewId) as EditText }
22+
1223
fun EditText.bindToErrorId(): ReadWriteProperty<Any?, Int?>
1324
= bindToErrorId { this }
1425

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToLoading.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.view.View
9+
import android.widget.EditText
10+
import android.widget.FrameLayout
611
import kotlin.properties.ReadWriteProperty
712
import kotlin.reflect.KProperty
813

@@ -14,6 +19,23 @@ fun Activity.bindToLoading(
1419
restViewHolderProvider = { findViewById(restViewHolderId) }
1520
)
1621

22+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
23+
fun Fragment.bindToLoading(
24+
@IdRes progressViewId: Int,
25+
@IdRes restViewHolderId: Int
26+
): ReadWriteProperty<Any?, Boolean> = bindToLoading(
27+
progressViewProvider = { view.findViewById(progressViewId) },
28+
restViewHolderProvider = { view.findViewById(restViewHolderId) }
29+
)
30+
31+
fun FrameLayout.bindToLoading(
32+
@IdRes progressViewId: Int,
33+
@IdRes restViewHolderId: Int
34+
): ReadWriteProperty<Any?, Boolean> = bindToLoading(
35+
progressViewProvider = { findViewById(progressViewId) },
36+
restViewHolderProvider = { findViewById(restViewHolderId) }
37+
)
38+
1739
fun Pair<View, View>.bindToLoading(): ReadWriteProperty<Any?, Boolean> = bindToLoading(
1840
progressViewProvider = { first },
1941
restViewHolderProvider = { second }

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToLongClick.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.view.View
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToLongClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
1014
= bindToLongClick { findViewById(viewId) }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToLongClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
18+
= bindToLongClick { view.findViewById(viewId) }
19+
20+
fun FrameLayout.bindToLongClick(@IdRes viewId: Int): ReadWriteProperty<Any?, () -> Unit>
21+
= bindToLongClick { findViewById(viewId) }
22+
1223
fun View.bindToLongClick(): ReadWriteProperty<Any?, () -> Unit>
1324
= bindToLongClick { this }
1425

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToRequestFocus.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.view.View
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadOnlyProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToRequestFocus(@IdRes editViewId: Int): ReadOnlyProperty<Any?, () -> Unit>
1014
= bindToRequestFocus { findViewById(editViewId) }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToRequestFocus(@IdRes editViewId: Int): ReadOnlyProperty<Any?, () -> Unit>
18+
= bindToRequestFocus { view.findViewById(editViewId) }
19+
20+
fun FrameLayout.bindToRequestFocus(@IdRes editViewId: Int): ReadOnlyProperty<Any?, () -> Unit>
21+
= bindToRequestFocus { findViewById(editViewId) }
22+
1223
fun View.bindToRequestFocus(): ReadOnlyProperty<Any?, () -> Unit>
1324
= bindToRequestFocus { this }
1425

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToSwipeRefresh.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
58
import android.support.v4.widget.SwipeRefreshLayout
9+
import android.widget.FrameLayout
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToSwipeRefresh(@IdRes swipeRefreshLayoutId: Int): ReadWriteProperty<Any?, Boolean>
1014
= bindToSwipeRefresh { findViewById(swipeRefreshLayoutId) as SwipeRefreshLayout }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToSwipeRefresh(@IdRes swipeRefreshLayoutId: Int): ReadWriteProperty<Any?, Boolean>
18+
= bindToSwipeRefresh { view.findViewById(swipeRefreshLayoutId) as SwipeRefreshLayout }
19+
20+
fun FrameLayout.bindToSwipeRefresh(@IdRes swipeRefreshLayoutId: Int): ReadWriteProperty<Any?, Boolean>
21+
= bindToSwipeRefresh { findViewById(swipeRefreshLayoutId) as SwipeRefreshLayout }
22+
1223
fun SwipeRefreshLayout.bindToSwipeRefresh(): ReadWriteProperty<Any?, Boolean>
1324
= bindToSwipeRefresh { this }
1425

kotlinandroidviewbindings/src/main/java/com/marcinmoskala/kotlinandroidviewbindings/BindToText.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package com.marcinmoskala.kotlinandroidviewbindings
22

33
import android.app.Activity
4+
import android.app.Fragment
5+
import android.os.Build
46
import android.support.annotation.IdRes
7+
import android.support.annotation.RequiresApi
8+
import android.widget.FrameLayout
59
import android.widget.TextView
610
import kotlin.properties.ReadWriteProperty
711
import kotlin.reflect.KProperty
812

913
fun Activity.bindToText(@IdRes textViewId: Int): ReadWriteProperty<Any?, String>
1014
= bindToText { findViewById(textViewId) as TextView }
1115

16+
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
17+
fun Fragment.bindToText(@IdRes textViewId: Int): ReadWriteProperty<Any?, String>
18+
= bindToText { view.findViewById(textViewId) as TextView }
19+
20+
fun FrameLayout.bindToText(@IdRes textViewId: Int): ReadWriteProperty<Any?, String>
21+
= bindToText { findViewById(textViewId) as TextView }
22+
1223
fun TextView.bindToText(): ReadWriteProperty<Any?, String>
1324
= bindToText { this }
1425

0 commit comments

Comments
 (0)