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

Commit

Permalink
Fix compatibility with coroutines 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
4u7 committed Nov 8, 2018
1 parent bd490ad commit e12c5cb
Show file tree
Hide file tree
Showing 11 changed files with 830 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,69 @@ package org.jetbrains.anko.appcompat.v7.coroutines


import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.android.UI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.CoroutineStart

fun android.support.v7.widget.ActionMenuView.onMenuItemClick(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
returnValue: Boolean = false,
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
) {
setOnMenuItemClickListener { item ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(item)
}
returnValue
}
}

fun android.support.v7.widget.ActivityChooserView.onDismiss(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.() -> Unit
) {
setOnDismissListener { ->
launch(context, block = handler)
GlobalScope.launch(context, CoroutineStart.DEFAULT, block = handler)
}
}

fun android.support.v7.widget.FitWindowsFrameLayout.onFitSystemWindows(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.(insets: android.graphics.Rect?) -> Unit
) {
setOnFitSystemWindowsListener { insets ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(insets)
}
}
}

fun android.support.v7.widget.SearchView.onClose(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
returnValue: Boolean = false,
handler: suspend CoroutineScope.() -> Unit
) {
setOnCloseListener { ->
launch(context, block = handler)
GlobalScope.launch(context, CoroutineStart.DEFAULT, block = handler)
returnValue
}
}

fun android.support.v7.widget.SearchView.onQueryTextFocusChange(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.(v: android.view.View, hasFocus: Boolean) -> Unit
) {
setOnQueryTextFocusChangeListener { v, hasFocus ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(v, hasFocus)
}
}
}

fun android.support.v7.widget.SearchView.onQueryTextListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __SearchView_OnQueryTextListener.() -> Unit
) {
val listener = __SearchView_OnQueryTextListener(context)
Expand All @@ -79,7 +81,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
override fun onQueryTextSubmit(query: String?) : Boolean {
val returnValue = _onQueryTextSubmit_returnValue
val handler = _onQueryTextSubmit ?: return returnValue
launch(context) {
GlobalScope.launch(context) {
handler(query)
}
return returnValue
Expand All @@ -99,7 +101,7 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
override fun onQueryTextChange(newText: String?) : Boolean {
val returnValue = _onQueryTextChange_returnValue
val handler = _onQueryTextChange ?: return returnValue
launch(context) {
GlobalScope.launch(context) {
handler(newText)
}
return returnValue
Expand All @@ -114,18 +116,18 @@ class __SearchView_OnQueryTextListener(private val context: CoroutineContext) :
}

}fun android.support.v7.widget.SearchView.onSearchClick(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.(v: android.view.View?) -> Unit
) {
setOnSearchClickListener { v ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(v)
}
}
}

fun android.support.v7.widget.SearchView.onSuggestionListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __SearchView_OnSuggestionListener.() -> Unit
) {
val listener = __SearchView_OnSuggestionListener(context)
Expand All @@ -141,7 +143,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
override fun onSuggestionSelect(position: Int) : Boolean {
val returnValue = _onSuggestionSelect_returnValue
val handler = _onSuggestionSelect ?: return returnValue
launch(context) {
GlobalScope.launch(context) {
handler(position)
}
return returnValue
Expand All @@ -161,7 +163,7 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
override fun onSuggestionClick(position: Int) : Boolean {
val returnValue = _onSuggestionClick_returnValue
val handler = _onSuggestionClick ?: return returnValue
launch(context) {
GlobalScope.launch(context) {
handler(position)
}
return returnValue
Expand All @@ -176,24 +178,24 @@ class __SearchView_OnSuggestionListener(private val context: CoroutineContext) :
}

}fun android.support.v7.widget.Toolbar.onMenuItemClick(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
returnValue: Boolean = false,
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
) {
setOnMenuItemClickListener { item ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(item)
}
returnValue
}
}

fun android.support.v7.widget.ViewStubCompat.onInflate(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.(stub: android.support.v7.widget.ViewStubCompat?, inflated: android.view.View?) -> Unit
) {
setOnInflateListener { stub, inflated ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(stub, inflated)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ package org.jetbrains.anko.design.coroutines


import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.android.UI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.CoroutineStart

fun android.support.design.widget.AppBarLayout.onOffsetChanged(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
handler: suspend CoroutineScope.(appBarLayout: android.support.design.widget.AppBarLayout?, verticalOffset: Int) -> Unit
) {
addOnOffsetChangedListener { appBarLayout, verticalOffset ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(appBarLayout, verticalOffset)
}
}
}

fun android.support.design.widget.TabLayout.onTabSelectedListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __TabLayout_OnTabSelectedListener.() -> Unit
) {
val listener = __TabLayout_OnTabSelectedListener(context)
Expand All @@ -34,7 +36,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :

override fun onTabSelected(tab: android.support.design.widget.TabLayout.Tab?) {
val handler = _onTabSelected ?: return
launch(context) {
GlobalScope.launch(context) {
handler(tab)
}
}
Expand All @@ -50,7 +52,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :

override fun onTabUnselected(tab: android.support.design.widget.TabLayout.Tab?) {
val handler = _onTabUnselected ?: return
launch(context) {
GlobalScope.launch(context) {
handler(tab)
}
}
Expand All @@ -66,7 +68,7 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :

override fun onTabReselected(tab: android.support.design.widget.TabLayout.Tab?) {
val handler = _onTabReselected ?: return
launch(context) {
GlobalScope.launch(context) {
handler(tab)
}
}
Expand All @@ -78,20 +80,20 @@ class __TabLayout_OnTabSelectedListener(private val context: CoroutineContext) :
}

}fun android.support.design.widget.BottomNavigationView.onNavigationItemSelected(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
returnValue: Boolean = false,
handler: suspend CoroutineScope.(item: android.view.MenuItem?) -> Unit
) {
setOnNavigationItemSelectedListener { item ->
launch(context) {
GlobalScope.launch(context, CoroutineStart.DEFAULT) {
handler(item)
}
returnValue
}
}

fun android.support.design.widget.CoordinatorLayout.onHierarchyChangeListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __ViewGroup_OnHierarchyChangeListener.() -> Unit
) {
val listener = __ViewGroup_OnHierarchyChangeListener(context)
Expand All @@ -106,7 +108,7 @@ class __ViewGroup_OnHierarchyChangeListener(private val context: CoroutineContex

override fun onChildViewAdded(parent: android.view.View?, child: android.view.View?) {
val handler = _onChildViewAdded ?: return
launch(context) {
GlobalScope.launch(context) {
handler(parent, child)
}
}
Expand All @@ -122,7 +124,7 @@ class __ViewGroup_OnHierarchyChangeListener(private val context: CoroutineContex

override fun onChildViewRemoved(parent: android.view.View?, child: android.view.View?) {
val handler = _onChildViewRemoved ?: return
launch(context) {
GlobalScope.launch(context) {
handler(parent, child)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package org.jetbrains.anko.recyclerview.v7.coroutines


import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.android.UI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

fun android.support.v7.widget.RecyclerView.onChildAttachStateChangeListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __RecyclerView_OnChildAttachStateChangeListener.() -> Unit
) {
val listener = __RecyclerView_OnChildAttachStateChangeListener(context)
Expand All @@ -23,7 +24,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou

override fun onChildViewAttachedToWindow(view: android.view.View?) {
val handler = _onChildViewAttachedToWindow ?: return
launch(context) {
GlobalScope.launch(context) {
handler(view)
}
}
Expand All @@ -39,7 +40,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou

override fun onChildViewDetachedFromWindow(view: android.view.View?) {
val handler = _onChildViewDetachedFromWindow ?: return
launch(context) {
GlobalScope.launch(context) {
handler(view)
}
}
Expand All @@ -51,7 +52,7 @@ class __RecyclerView_OnChildAttachStateChangeListener(private val context: Corou
}

}fun android.support.v7.widget.RecyclerView.onItemTouchListener(
context: CoroutineContext = UI,
context: CoroutineContext = Dispatchers.Main,
init: __RecyclerView_OnItemTouchListener.() -> Unit
) {
val listener = __RecyclerView_OnItemTouchListener(context)
Expand All @@ -67,7 +68,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)
override fun onInterceptTouchEvent(rv: android.support.v7.widget.RecyclerView?, e: android.view.MotionEvent?) : Boolean {
val returnValue = _onInterceptTouchEvent_returnValue
val handler = _onInterceptTouchEvent ?: return returnValue
launch(context) {
GlobalScope.launch(context) {
handler(rv, e)
}
return returnValue
Expand All @@ -86,7 +87,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)

override fun onTouchEvent(rv: android.support.v7.widget.RecyclerView?, e: android.view.MotionEvent?) {
val handler = _onTouchEvent ?: return
launch(context) {
GlobalScope.launch(context) {
handler(rv, e)
}
}
Expand All @@ -102,7 +103,7 @@ class __RecyclerView_OnItemTouchListener(private val context: CoroutineContext)

override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
val handler = _onRequestDisallowInterceptTouchEvent ?: return
launch(context) {
GlobalScope.launch(context) {
handler(disallowIntercept)
}
}
Expand Down
Loading

0 comments on commit e12c5cb

Please sign in to comment.