@@ -3,67 +3,69 @@ package org.jetbrains.anko.appcompat.v7.coroutines
3
3
4
4
5
5
import kotlin.coroutines.CoroutineContext
6
- import kotlinx.coroutines.android.UI
6
+ import kotlinx.coroutines.Dispatchers
7
7
import kotlinx.coroutines.CoroutineScope
8
+ import kotlinx.coroutines.GlobalScope
8
9
import kotlinx.coroutines.launch
10
+ import kotlinx.coroutines.CoroutineStart
9
11
10
12
fun android.support.v7.widget.ActionMenuView.onMenuItemClick (
11
- context : CoroutineContext = UI ,
13
+ context : CoroutineContext = Dispatchers . Main ,
12
14
returnValue : Boolean = false,
13
15
handler : suspend CoroutineScope .(item: android.view.MenuItem ? ) -> Unit
14
16
) {
15
17
setOnMenuItemClickListener { item ->
16
- launch(context) {
18
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
17
19
handler(item)
18
20
}
19
21
returnValue
20
22
}
21
23
}
22
24
23
25
fun android.support.v7.widget.ActivityChooserView.onDismiss (
24
- context : CoroutineContext = UI ,
26
+ context : CoroutineContext = Dispatchers . Main ,
25
27
handler : suspend CoroutineScope .() -> Unit
26
28
) {
27
29
setOnDismissListener { ->
28
- launch(context, block = handler)
30
+ GlobalScope . launch(context, CoroutineStart . DEFAULT , block = handler)
29
31
}
30
32
}
31
33
32
34
fun android.support.v7.widget.FitWindowsFrameLayout.onFitSystemWindows (
33
- context : CoroutineContext = UI ,
35
+ context : CoroutineContext = Dispatchers . Main ,
34
36
handler : suspend CoroutineScope .(insets: android.graphics.Rect ? ) -> Unit
35
37
) {
36
38
setOnFitSystemWindowsListener { insets ->
37
- launch(context) {
39
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
38
40
handler(insets)
39
41
}
40
42
}
41
43
}
42
44
43
45
fun android.support.v7.widget.SearchView.onClose (
44
- context : CoroutineContext = UI ,
46
+ context : CoroutineContext = Dispatchers . Main ,
45
47
returnValue : Boolean = false,
46
48
handler : suspend CoroutineScope .() -> Unit
47
49
) {
48
50
setOnCloseListener { ->
49
- launch(context, block = handler)
51
+ GlobalScope . launch(context, CoroutineStart . DEFAULT , block = handler)
50
52
returnValue
51
53
}
52
54
}
53
55
54
56
fun android.support.v7.widget.SearchView.onQueryTextFocusChange (
55
- context : CoroutineContext = UI ,
57
+ context : CoroutineContext = Dispatchers . Main ,
56
58
handler : suspend CoroutineScope .(v: android.view.View , hasFocus: Boolean ) -> Unit
57
59
) {
58
60
setOnQueryTextFocusChangeListener { v, hasFocus ->
59
- launch(context) {
61
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
60
62
handler(v, hasFocus)
61
63
}
62
64
}
63
65
}
64
66
65
67
fun android.support.v7.widget.SearchView.onQueryTextListener (
66
- context : CoroutineContext = UI ,
68
+ context : CoroutineContext = Dispatchers . Main ,
67
69
init : __SearchView_OnQueryTextListener .() -> Unit
68
70
) {
69
71
val listener = __SearchView_OnQueryTextListener (context)
@@ -79,7 +81,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
79
81
override fun onQueryTextSubmit (query : String? ) : Boolean {
80
82
val returnValue = _onQueryTextSubmit_returnValue
81
83
val handler = _onQueryTextSubmit ? : return returnValue
82
- launch(context) {
84
+ GlobalScope . launch(context) {
83
85
handler(query)
84
86
}
85
87
return returnValue
@@ -99,7 +101,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
99
101
override fun onQueryTextChange (newText : String? ) : Boolean {
100
102
val returnValue = _onQueryTextChange_returnValue
101
103
val handler = _onQueryTextChange ? : return returnValue
102
- launch(context) {
104
+ GlobalScope . launch(context) {
103
105
handler(newText)
104
106
}
105
107
return returnValue
@@ -114,18 +116,18 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
114
116
}
115
117
116
118
}fun android.support.v7.widget.SearchView.onSearchClick(
117
- context : CoroutineContext = UI ,
119
+ context : CoroutineContext = Dispatchers . Main ,
118
120
handler : suspend CoroutineScope .(v: android.view.View ? ) -> Unit
119
121
) {
120
122
setOnSearchClickListener { v ->
121
- launch(context) {
123
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
122
124
handler(v)
123
125
}
124
126
}
125
127
}
126
128
127
129
fun android.support.v7.widget.SearchView.onSuggestionListener (
128
- context : CoroutineContext = UI ,
130
+ context : CoroutineContext = Dispatchers . Main ,
129
131
init : __SearchView_OnSuggestionListener .() -> Unit
130
132
) {
131
133
val listener = __SearchView_OnSuggestionListener (context)
@@ -141,7 +143,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
141
143
override fun onSuggestionSelect (position : Int ) : Boolean {
142
144
val returnValue = _onSuggestionSelect_returnValue
143
145
val handler = _onSuggestionSelect ? : return returnValue
144
- launch(context) {
146
+ GlobalScope . launch(context) {
145
147
handler(position)
146
148
}
147
149
return returnValue
@@ -161,7 +163,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
161
163
override fun onSuggestionClick (position : Int ) : Boolean {
162
164
val returnValue = _onSuggestionClick_returnValue
163
165
val handler = _onSuggestionClick ? : return returnValue
164
- launch(context) {
166
+ GlobalScope . launch(context) {
165
167
handler(position)
166
168
}
167
169
return returnValue
@@ -176,24 +178,24 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
176
178
}
177
179
178
180
}fun android.support.v7.widget.Toolbar.onMenuItemClick(
179
- context : CoroutineContext = UI ,
181
+ context : CoroutineContext = Dispatchers . Main ,
180
182
returnValue : Boolean = false ,
181
183
handler : suspend CoroutineScope .(item: android.view.MenuItem ? ) -> Unit
182
184
) {
183
185
setOnMenuItemClickListener { item ->
184
- launch(context) {
186
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
185
187
handler(item)
186
188
}
187
189
returnValue
188
190
}
189
191
}
190
192
191
193
fun android.support.v7.widget.ViewStubCompat.onInflate (
192
- context : CoroutineContext = UI ,
194
+ context : CoroutineContext = Dispatchers . Main ,
193
195
handler : suspend CoroutineScope .(stub: android.support.v7.widget.ViewStubCompat ? , inflated: android.view.View ? ) -> Unit
194
196
) {
195
197
setOnInflateListener { stub, inflated ->
196
- launch(context) {
198
+ GlobalScope . launch(context, CoroutineStart . DEFAULT ) {
197
199
handler(stub, inflated)
198
200
}
199
201
}
0 commit comments