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

Commit

Permalink
Merge branch '0.10.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
4u7 committed Dec 19, 2018
2 parents 8ca885d + e12c5cb commit 0d54d8c
Show file tree
Hide file tree
Showing 15 changed files with 872 additions and 855 deletions.
2 changes: 1 addition & 1 deletion anko/idea-plugin/preview/resources/META-INF/plugin.xml
Expand Up @@ -2,7 +2,7 @@
<id>org.jetbrains.kotlin.android.dsl</id>
<name>Anko Support</name>
<description>Anko Android library support.</description>
<version>0.10.7-2</version>
<version>0.10.8</version>
<vendor url="http://www.jetbrains.com">JetBrains s.r.o.</vendor>

<idea-version since-build="171.1" until-build="183.*"/>
Expand Down
Expand Up @@ -2,68 +2,70 @@
package org.jetbrains.anko.appcompat.v7.coroutines


import kotlin.coroutines.experimental.CoroutineContext
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.launch
import kotlin.coroutines.CoroutineContext
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
8 changes: 3 additions & 5 deletions anko/library/generated/coroutines/src/main/java/bg.kt
Expand Up @@ -19,15 +19,13 @@

package org.jetbrains.anko.coroutines.experimental

import kotlinx.coroutines.experimental.Deferred
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.newFixedThreadPoolContext
import kotlinx.coroutines.*

@PublishedApi
@Deprecated(message = "Use the default pool")
internal var POOL = newFixedThreadPoolContext(2 * Runtime.getRuntime().availableProcessors(), "bg")

@Deprecated(message = "Use the default pool", replaceWith = ReplaceWith("async(block)", "kotlinx.coroutines.experimental.async"))
inline fun <T> bg(crossinline block: () -> T): Deferred<T> = async(POOL) {
@Deprecated(message = "Use the default pool", replaceWith = ReplaceWith("async(block)", "kotlinx.coroutines.async"))
inline fun <T> bg(crossinline block: () -> T): Deferred<T> = GlobalScope.async(POOL, CoroutineStart.DEFAULT) {
block()
}
Expand Up @@ -18,13 +18,15 @@ package org.jetbrains.anko.coroutines.experimental

import java.lang.ref.WeakReference
import java.util.concurrent.CancellationException
import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
import kotlin.coroutines.intrinsics.intercepted
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn

class Ref<out T : Any> internal constructor(obj: T) {
private val weakRef = WeakReference(obj)

suspend operator fun invoke(): T {
return suspendCoroutineOrReturn {
return suspendCoroutineUninterceptedOrReturn {
it.intercepted()
weakRef.get() ?: throw CancellationException()
}
}
Expand Down
Expand Up @@ -2,24 +2,26 @@
package org.jetbrains.anko.design.coroutines


import kotlin.coroutines.experimental.CoroutineContext
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.launch
import kotlin.coroutines.CoroutineContext
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
Expand Up @@ -2,13 +2,14 @@
package org.jetbrains.anko.recyclerview.v7.coroutines


import kotlin.coroutines.experimental.CoroutineContext
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.launch
import kotlin.coroutines.CoroutineContext
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

0 comments on commit 0d54d8c

Please sign in to comment.