Skip to content
This repository was archived by the owner on Apr 18, 2021. It is now read-only.

Commit 8c629c9

Browse files
committed
Include more anko style listeners. Upgrade android support version to 28.0.0.
1 parent 2312257 commit 8c629c9

File tree

14 files changed

+792
-103
lines changed

14 files changed

+792
-103
lines changed

MainScope/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ dependencies {
2424
implementation fileTree(dir: 'libs', include: ['*.jar'])
2525
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
2626
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
27+
28+
compileOnly "com.android.support:recyclerview-v7:$android_support_version"
29+
compileOnly "com.android.support:design:$android_support_version"
30+
compileOnly "com.android.support:appcompat-v7:$android_support_version"
2731
}
2832

2933

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
package com.bennyhuo.kotlin.coroutines.android.mainscope
2+
3+
import com.bennyhuo.kotlin.coroutines.android.mainscope.job.launch
4+
5+
interface AppCompatScoped: BasicScoped {
6+
fun android.support.v7.widget.ActionMenuView.onMenuItemClick(
7+
returnValue: Boolean = false,
8+
handler: suspend MainScope.(item: android.view.MenuItem?) -> Unit
9+
) {
10+
setOnMenuItemClickListener { item ->
11+
mainScope.launch {
12+
handler(item)
13+
}
14+
returnValue
15+
}
16+
}
17+
18+
fun android.support.v7.widget.ActivityChooserView.onDismiss(
19+
handler: suspend MainScope.() -> Unit
20+
) {
21+
setOnDismissListener { ->
22+
mainScope.launch(block = handler)
23+
}
24+
}
25+
26+
fun android.support.v7.widget.FitWindowsFrameLayout.onFitSystemWindows(
27+
handler: suspend MainScope.(insets: android.graphics.Rect?) -> Unit
28+
) {
29+
setOnFitSystemWindowsListener { insets ->
30+
mainScope.launch {
31+
handler(insets)
32+
}
33+
}
34+
}
35+
36+
fun android.support.v7.widget.SearchView.onClose(
37+
returnValue: Boolean = false,
38+
handler: suspend MainScope.() -> Unit
39+
) {
40+
setOnCloseListener { ->
41+
mainScope.launch(block = handler)
42+
returnValue
43+
}
44+
}
45+
46+
fun android.support.v7.widget.SearchView.onQueryTextFocusChange(
47+
handler: suspend MainScope.(v: android.view.View, hasFocus: Boolean) -> Unit
48+
) {
49+
setOnQueryTextFocusChangeListener { v, hasFocus ->
50+
mainScope.launch {
51+
handler(v, hasFocus)
52+
}
53+
}
54+
}
55+
56+
fun android.support.v7.widget.SearchView.onQueryTextListener(
57+
init: __SearchView_OnQueryTextListener.() -> Unit
58+
) {
59+
val listener = __SearchView_OnQueryTextListener(mainScope)
60+
listener.init()
61+
setOnQueryTextListener(listener)
62+
}
63+
64+
class __SearchView_OnQueryTextListener(private val mainScope: MainScope) : android.support.v7.widget.SearchView.OnQueryTextListener {
65+
66+
private var _onQueryTextSubmit: (suspend MainScope.(String?) -> Boolean)? = null
67+
private var _onQueryTextSubmit_returnValue: Boolean = false
68+
69+
override fun onQueryTextSubmit(query: String?) : Boolean {
70+
val returnValue = _onQueryTextSubmit_returnValue
71+
val handler = _onQueryTextSubmit ?: return returnValue
72+
mainScope.launch {
73+
handler(query)
74+
}
75+
return returnValue
76+
}
77+
78+
fun onQueryTextSubmit(
79+
returnValue: Boolean = false,
80+
listener: suspend MainScope.(String?) -> Boolean
81+
) {
82+
_onQueryTextSubmit = listener
83+
_onQueryTextSubmit_returnValue = returnValue
84+
}
85+
86+
private var _onQueryTextChange: (suspend MainScope.(String?) -> Boolean)? = null
87+
private var _onQueryTextChange_returnValue: Boolean = false
88+
89+
override fun onQueryTextChange(newText: String?) : Boolean {
90+
val returnValue = _onQueryTextChange_returnValue
91+
val handler = _onQueryTextChange ?: return returnValue
92+
mainScope.launch {
93+
handler(newText)
94+
}
95+
return returnValue
96+
}
97+
98+
fun onQueryTextChange(
99+
returnValue: Boolean = false,
100+
listener: suspend MainScope.(String?) -> Boolean
101+
) {
102+
_onQueryTextChange = listener
103+
_onQueryTextChange_returnValue = returnValue
104+
}
105+
106+
}fun android.support.v7.widget.SearchView.onSearchClick(
107+
handler: suspend MainScope.(v: android.view.View?) -> Unit
108+
) {
109+
setOnSearchClickListener { v ->
110+
mainScope.launch {
111+
handler(v)
112+
}
113+
}
114+
}
115+
116+
fun android.support.v7.widget.SearchView.onSuggestionListener(
117+
init: __SearchView_OnSuggestionListener.() -> Unit
118+
) {
119+
val listener = __SearchView_OnSuggestionListener(mainScope)
120+
listener.init()
121+
setOnSuggestionListener(listener)
122+
}
123+
124+
class __SearchView_OnSuggestionListener(private val mainScope: MainScope) : android.support.v7.widget.SearchView.OnSuggestionListener {
125+
126+
private var _onSuggestionSelect: (suspend MainScope.(Int) -> Boolean)? = null
127+
private var _onSuggestionSelect_returnValue: Boolean = false
128+
129+
override fun onSuggestionSelect(position: Int) : Boolean {
130+
val returnValue = _onSuggestionSelect_returnValue
131+
val handler = _onSuggestionSelect ?: return returnValue
132+
mainScope.launch {
133+
handler(position)
134+
}
135+
return returnValue
136+
}
137+
138+
fun onSuggestionSelect(
139+
returnValue: Boolean = false,
140+
listener: suspend MainScope.(Int) -> Boolean
141+
) {
142+
_onSuggestionSelect = listener
143+
_onSuggestionSelect_returnValue = returnValue
144+
}
145+
146+
private var _onSuggestionClick: (suspend MainScope.(Int) -> Boolean)? = null
147+
private var _onSuggestionClick_returnValue: Boolean = false
148+
149+
override fun onSuggestionClick(position: Int) : Boolean {
150+
val returnValue = _onSuggestionClick_returnValue
151+
val handler = _onSuggestionClick ?: return returnValue
152+
mainScope.launch {
153+
handler(position)
154+
}
155+
return returnValue
156+
}
157+
158+
fun onSuggestionClick(
159+
returnValue: Boolean = false,
160+
listener: suspend MainScope.(Int) -> Boolean
161+
) {
162+
_onSuggestionClick = listener
163+
_onSuggestionClick_returnValue = returnValue
164+
}
165+
166+
}fun android.support.v7.widget.Toolbar.onMenuItemClick(
167+
returnValue: Boolean = false,
168+
handler: suspend MainScope.(item: android.view.MenuItem?) -> Unit
169+
) {
170+
setOnMenuItemClickListener { item ->
171+
mainScope.launch {
172+
handler(item)
173+
}
174+
returnValue
175+
}
176+
}
177+
178+
fun android.support.v7.widget.ViewStubCompat.onInflate(
179+
handler: suspend MainScope.(stub: android.support.v7.widget.ViewStubCompat?, inflated: android.view.View?) -> Unit
180+
) {
181+
setOnInflateListener { stub, inflated ->
182+
mainScope.launch {
183+
handler(stub, inflated)
184+
}
185+
}
186+
}
187+
188+
}

0 commit comments

Comments
 (0)