Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit e12c5cb

Browse files
committed
Fix compatibility with coroutines 1.0.0
1 parent bd490ad commit e12c5cb

File tree

11 files changed

+830
-813
lines changed

11 files changed

+830
-813
lines changed

anko/library/generated/appcompat-v7-coroutines/src/main/java/ListenersWithCoroutines.kt

+25-23
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,69 @@ package org.jetbrains.anko.appcompat.v7.coroutines
33

44

55
import kotlin.coroutines.CoroutineContext
6-
import kotlinx.coroutines.android.UI
6+
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.CoroutineScope
8+
import kotlinx.coroutines.GlobalScope
89
import kotlinx.coroutines.launch
10+
import kotlinx.coroutines.CoroutineStart
911

1012
fun android.support.v7.widget.ActionMenuView.onMenuItemClick(
11-
context: CoroutineContext = UI,
13+
context: CoroutineContext = Dispatchers.Main,
1214
returnValue: Boolean = false,
1315
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
1416
) {
1517
setOnMenuItemClickListener { item ->
16-
launch(context) {
18+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
1719
handler(item)
1820
}
1921
returnValue
2022
}
2123
}
2224

2325
fun android.support.v7.widget.ActivityChooserView.onDismiss(
24-
context: CoroutineContext = UI,
26+
context: CoroutineContext = Dispatchers.Main,
2527
handler: suspend CoroutineScope.() -> Unit
2628
) {
2729
setOnDismissListener { ->
28-
launch(context, block = handler)
30+
GlobalScope.launch(context, CoroutineStart.DEFAULT, block = handler)
2931
}
3032
}
3133

3234
fun android.support.v7.widget.FitWindowsFrameLayout.onFitSystemWindows(
33-
context: CoroutineContext = UI,
35+
context: CoroutineContext = Dispatchers.Main,
3436
handler: suspend CoroutineScope.(insets: android.graphics.Rect?) -> Unit
3537
) {
3638
setOnFitSystemWindowsListener { insets ->
37-
launch(context) {
39+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
3840
handler(insets)
3941
}
4042
}
4143
}
4244

4345
fun android.support.v7.widget.SearchView.onClose(
44-
context: CoroutineContext = UI,
46+
context: CoroutineContext = Dispatchers.Main,
4547
returnValue: Boolean = false,
4648
handler: suspend CoroutineScope.() -> Unit
4749
) {
4850
setOnCloseListener { ->
49-
launch(context, block = handler)
51+
GlobalScope.launch(context, CoroutineStart.DEFAULT, block = handler)
5052
returnValue
5153
}
5254
}
5355

5456
fun android.support.v7.widget.SearchView.onQueryTextFocusChange(
55-
context: CoroutineContext = UI,
57+
context: CoroutineContext = Dispatchers.Main,
5658
handler: suspend CoroutineScope.(v: android.view.View, hasFocus: Boolean) -> Unit
5759
) {
5860
setOnQueryTextFocusChangeListener { v, hasFocus ->
59-
launch(context) {
61+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
6062
handler(v, hasFocus)
6163
}
6264
}
6365
}
6466

6567
fun android.support.v7.widget.SearchView.onQueryTextListener(
66-
context: CoroutineContext = UI,
68+
context: CoroutineContext = Dispatchers.Main,
6769
init: __SearchView_OnQueryTextListener.() -> Unit
6870
) {
6971
val listener = __SearchView_OnQueryTextListener(context)
@@ -79,7 +81,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
7981
override fun onQueryTextSubmit(query: String?) : Boolean {
8082
val returnValue = _onQueryTextSubmit_returnValue
8183
val handler = _onQueryTextSubmit ?: return returnValue
82-
launch(context) {
84+
GlobalScope.launch(context) {
8385
handler(query)
8486
}
8587
return returnValue
@@ -99,7 +101,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
99101
override fun onQueryTextChange(newText: String?) : Boolean {
100102
val returnValue = _onQueryTextChange_returnValue
101103
val handler = _onQueryTextChange ?: return returnValue
102-
launch(context) {
104+
GlobalScope.launch(context) {
103105
handler(newText)
104106
}
105107
return returnValue
@@ -114,18 +116,18 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
114116
}
115117

116118
}fun android.support.v7.widget.SearchView.onSearchClick(
117-
context: CoroutineContext = UI,
119+
context: CoroutineContext = Dispatchers.Main,
118120
handler: suspend CoroutineScope.(v: android.view.View?) -> Unit
119121
) {
120122
setOnSearchClickListener { v ->
121-
launch(context) {
123+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
122124
handler(v)
123125
}
124126
}
125127
}
126128

127129
fun android.support.v7.widget.SearchView.onSuggestionListener(
128-
context: CoroutineContext = UI,
130+
context: CoroutineContext = Dispatchers.Main,
129131
init: __SearchView_OnSuggestionListener.() -> Unit
130132
) {
131133
val listener = __SearchView_OnSuggestionListener(context)
@@ -141,7 +143,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
141143
override fun onSuggestionSelect(position: Int) : Boolean {
142144
val returnValue = _onSuggestionSelect_returnValue
143145
val handler = _onSuggestionSelect ?: return returnValue
144-
launch(context) {
146+
GlobalScope.launch(context) {
145147
handler(position)
146148
}
147149
return returnValue
@@ -161,7 +163,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
161163
override fun onSuggestionClick(position: Int) : Boolean {
162164
val returnValue = _onSuggestionClick_returnValue
163165
val handler = _onSuggestionClick ?: return returnValue
164-
launch(context) {
166+
GlobalScope.launch(context) {
165167
handler(position)
166168
}
167169
return returnValue
@@ -176,24 +178,24 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
176178
}
177179

178180
}fun android.support.v7.widget.Toolbar.onMenuItemClick(
179-
context: CoroutineContext = UI,
181+
context: CoroutineContext = Dispatchers.Main,
180182
returnValue: Boolean = false,
181183
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
182184
) {
183185
setOnMenuItemClickListener { item ->
184-
launch(context) {
186+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
185187
handler(item)
186188
}
187189
returnValue
188190
}
189191
}
190192

191193
fun android.support.v7.widget.ViewStubCompat.onInflate(
192-
context: CoroutineContext = UI,
194+
context: CoroutineContext = Dispatchers.Main,
193195
handler: suspend CoroutineScope.(stub: android.support.v7.widget.ViewStubCompat?, inflated: android.view.View?) -> Unit
194196
) {
195197
setOnInflateListener { stub, inflated ->
196-
launch(context) {
198+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
197199
handler(stub, inflated)
198200
}
199201
}

anko/library/generated/design-coroutines/src/main/java/ListenersWithCoroutines.kt

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ package org.jetbrains.anko.design.coroutines
33

44

55
import kotlin.coroutines.CoroutineContext
6-
import kotlinx.coroutines.android.UI
6+
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.CoroutineScope
8+
import kotlinx.coroutines.GlobalScope
89
import kotlinx.coroutines.launch
10+
import kotlinx.coroutines.CoroutineStart
911

1012
fun android.support.design.widget.AppBarLayout.onOffsetChanged(
11-
context: CoroutineContext = UI,
13+
context: CoroutineContext = Dispatchers.Main,
1214
handler: suspend CoroutineScope.(appBarLayout: android.support.design.widget.AppBarLayout?, verticalOffset: Int) -> Unit
1315
) {
1416
addOnOffsetChangedListener { appBarLayout, verticalOffset ->
15-
launch(context) {
17+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
1618
handler(appBarLayout, verticalOffset)
1719
}
1820
}
1921
}
2022

2123
fun android.support.design.widget.TabLayout.onTabSelectedListener(
22-
context: CoroutineContext = UI,
24+
context: CoroutineContext = Dispatchers.Main,
2325
init: __TabLayout_OnTabSelectedListener.() -> Unit
2426
) {
2527
val listener = __TabLayout_OnTabSelectedListener(context)
@@ -34,7 +36,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :
3436

3537
override fun onTabSelected(tab: android.support.design.widget.TabLayout.Tab?) {
3638
val handler = _onTabSelected ?: return
37-
launch(context) {
39+
GlobalScope.launch(context) {
3840
handler(tab)
3941
}
4042
}
@@ -50,7 +52,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :
5052

5153
override fun onTabUnselected(tab: android.support.design.widget.TabLayout.Tab?) {
5254
val handler = _onTabUnselected ?: return
53-
launch(context) {
55+
GlobalScope.launch(context) {
5456
handler(tab)
5557
}
5658
}
@@ -66,7 +68,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :
6668

6769
override fun onTabReselected(tab: android.support.design.widget.TabLayout.Tab?) {
6870
val handler = _onTabReselected ?: return
69-
launch(context) {
71+
GlobalScope.launch(context) {
7072
handler(tab)
7173
}
7274
}
@@ -78,20 +80,20 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :
7880
}
7981

8082
}fun android.support.design.widget.BottomNavigationView.onNavigationItemSelected(
81-
context: CoroutineContext = UI,
83+
context: CoroutineContext = Dispatchers.Main,
8284
returnValue: Boolean = false,
8385
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
8486
) {
8587
setOnNavigationItemSelectedListener { item ->
86-
launch(context) {
88+
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
8789
handler(item)
8890
}
8991
returnValue
9092
}
9193
}
9294

9395
fun android.support.design.widget.CoordinatorLayout.onHierarchyChangeListener(
94-
context: CoroutineContext = UI,
96+
context: CoroutineContext = Dispatchers.Main,
9597
init: __ViewGroup_OnHierarchyChangeListener.() -> Unit
9698
) {
9799
val listener = __ViewGroup_OnHierarchyChangeListener(context)
@@ -106,7 +108,7 @@ class __ViewGroup_OnHierarchyChangeListener(private val context: CoroutineContex
106108

107109
override fun onChildViewAdded(parent: android.view.View?, child: android.view.View?) {
108110
val handler = _onChildViewAdded ?: return
109-
launch(context) {
111+
GlobalScope.launch(context) {
110112
handler(parent, child)
111113
}
112114
}
@@ -122,7 +124,7 @@ class __ViewGroup_OnHierarchyChangeListener(private val context: CoroutineContex
122124

123125
override fun onChildViewRemoved(parent: android.view.View?, child: android.view.View?) {
124126
val handler = _onChildViewRemoved ?: return
125-
launch(context) {
127+
GlobalScope.launch(context) {
126128
handler(parent, child)
127129
}
128130
}

anko/library/generated/recyclerview-v7-coroutines/src/main/java/ListenersWithCoroutines.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package org.jetbrains.anko.recyclerview.v7.coroutines
33

44

55
import kotlin.coroutines.CoroutineContext
6-
import kotlinx.coroutines.android.UI
6+
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.CoroutineScope
8+
import kotlinx.coroutines.GlobalScope
89
import kotlinx.coroutines.launch
910

1011
fun android.support.v7.widget.RecyclerView.onChildAttachStateChangeListener(
11-
context: CoroutineContext = UI,
12+
context: CoroutineContext = Dispatchers.Main,
1213
init: __RecyclerView_OnChildAttachStateChangeListener.() -> Unit
1314
) {
1415
val listener = __RecyclerView_OnChildAttachStateChangeListener(context)
@@ -23,7 +24,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou
2324

2425
override fun onChildViewAttachedToWindow(view: android.view.View?) {
2526
val handler = _onChildViewAttachedToWindow ?: return
26-
launch(context) {
27+
GlobalScope.launch(context) {
2728
handler(view)
2829
}
2930
}
@@ -39,7 +40,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou
3940

4041
override fun onChildViewDetachedFromWindow(view: android.view.View?) {
4142
val handler = _onChildViewDetachedFromWindow ?: return
42-
launch(context) {
43+
GlobalScope.launch(context) {
4344
handler(view)
4445
}
4546
}
@@ -51,7 +52,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou
5152
}
5253

5354
}fun android.support.v7.widget.RecyclerView.onItemTouchListener(
54-
context: CoroutineContext = UI,
55+
context: CoroutineContext = Dispatchers.Main,
5556
init: __RecyclerView_OnItemTouchListener.() -> Unit
5657
) {
5758
val listener = __RecyclerView_OnItemTouchListener(context)
@@ -67,7 +68,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)
6768
override fun onInterceptTouchEvent(rv: android.support.v7.widget.RecyclerView?, e: android.view.MotionEvent?) : Boolean {
6869
val returnValue = _onInterceptTouchEvent_returnValue
6970
val handler = _onInterceptTouchEvent ?: return returnValue
70-
launch(context) {
71+
GlobalScope.launch(context) {
7172
handler(rv, e)
7273
}
7374
return returnValue
@@ -86,7 +87,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)
8687

8788
override fun onTouchEvent(rv: android.support.v7.widget.RecyclerView?, e: android.view.MotionEvent?) {
8889
val handler = _onTouchEvent ?: return
89-
launch(context) {
90+
GlobalScope.launch(context) {
9091
handler(rv, e)
9192
}
9293
}
@@ -102,7 +103,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)
102103

103104
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
104105
val handler = _onRequestDisallowInterceptTouchEvent ?: return
105-
launch(context) {
106+
GlobalScope.launch(context) {
106107
handler(disallowIntercept)
107108
}
108109
}

0 commit comments

Comments
 (0)