Browse Source

| Interval 重置bug

drake 5 years ago
parent
commit
f633fd6fcf

+ 2 - 2
README.md

@@ -77,9 +77,9 @@ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
 
 // 支持自动下拉刷新和缺省页的, 可选
-implementation 'com.github.liangjingkanji:BRV:1.1.7'
+implementation 'com.github.liangjingkanji:BRV:1.2.1'
 
-implementation 'com.github.liangjingkanji:Net:2.0.3'
+implementation 'com.github.liangjingkanji:Net:2.0.4'
 ```
 
 

+ 1 - 1
net/build.gradle

@@ -40,7 +40,7 @@ dependencies {
 
     api 'com.yanzhenjie:okalle:0.1.7'
 
-    compileOnly 'com.github.liangjingkanji:BRV:1.2.0'
+    compileOnly 'com.github.liangjingkanji:BRV:1.2.1'
     compileOnly 'com.github.bumptech.glide:glide:4.9.0'
 
     implementation 'com.github.liangjingkanji:Tooltip:1.0.3'

+ 7 - 12
net/src/main/java/com/drake/net/scope/AndroidScope.kt

@@ -11,12 +11,15 @@ import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleOwner
 import kotlinx.coroutines.*
+import kotlin.coroutines.CoroutineContext
+import kotlin.coroutines.EmptyCoroutineContext
 
 /**
  * 异步协程作用域
  */
 @Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING")
-open class AndroidScope() {
+open class AndroidScope() : CoroutineScope {
+
 
     constructor(
         lifecycleOwner: LifecycleOwner,
@@ -39,15 +42,15 @@ open class AndroidScope() {
         catch(throwable)
     }
 
-    protected val scope
-        get() = CoroutineScope(Dispatchers.Main + exceptionHandler + SupervisorJob())
+    override val coroutineContext: CoroutineContext =
+        Dispatchers.Main + exceptionHandler + SupervisorJob()
 
 
     open fun launch(
         block: suspend CoroutineScope.() -> Unit
     ): AndroidScope {
         start()
-        scope.launch(block = block).invokeOnCompletion { finally(it) }
+        launch(EmptyCoroutineContext, block = block).invokeOnCompletion { finally(it) }
         return this
     }
 
@@ -87,14 +90,6 @@ open class AndroidScope() {
         e.printStackTrace()
     }
 
-    fun cancel(cause: CancellationException? = null) {
-        scope.cancel(cause)
-    }
-
-    fun cancel(message: String, cause: Throwable? = null) {
-        scope.cancel(message, cause)
-    }
-
     fun autoOff() {
         auto = false
     }

+ 3 - 1
net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt

@@ -12,8 +12,10 @@ import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleOwner
 import com.drake.net.NetConfig
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.cancel
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.supervisorScope
+import kotlin.coroutines.EmptyCoroutineContext
 
 
 /**
@@ -48,7 +50,7 @@ open class NetCoroutineScope() : AndroidScope() {
     override fun launch(
         block: suspend CoroutineScope.() -> Unit
     ): NetCoroutineScope {
-        scope.launch {
+        launch(EmptyCoroutineContext) {
             start()
             if (onCache != null && readCache) {
                 supervisorScope {

+ 1 - 0
net/src/main/java/com/drake/net/scope/PageCoroutineScope.kt

@@ -12,6 +12,7 @@ import com.drake.brv.BindingAdapter
 import com.drake.brv.PageRefreshLayout
 import com.drake.net.NetConfig
 import com.drake.net.R
+import kotlinx.coroutines.cancel
 
 @Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING")
 class PageCoroutineScope(

+ 1 - 0
net/src/main/java/com/drake/net/scope/RefreshCoroutineScope.kt

@@ -11,6 +11,7 @@ import android.view.View
 import com.drake.net.NetConfig
 import com.drake.net.R
 import com.scwang.smart.refresh.layout.SmartRefreshLayout
+import kotlinx.coroutines.cancel
 
 /**
  * 自动结束下拉刷新 协程作用域

+ 1 - 0
net/src/main/java/com/drake/net/scope/StateCoroutineScope.kt

@@ -14,6 +14,7 @@ import com.drake.net.NetConfig
 import com.drake.net.R
 import com.drake.statelayout.StateLayout
 import com.drake.statelayout.state
+import kotlinx.coroutines.cancel
 
 /**
  * 缺省页作用域

+ 1 - 0
net/src/main/java/com/drake/net/utils/Interval.kt

@@ -14,6 +14,7 @@ import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleOwner
 import com.drake.net.scope.AndroidScope
 import kotlinx.coroutines.ObsoleteCoroutinesApi
+import kotlinx.coroutines.cancel
 import kotlinx.coroutines.channels.ReceiveChannel
 import kotlinx.coroutines.channels.TickerMode
 import kotlinx.coroutines.channels.ticker

+ 1 - 1
sample/build.gradle

@@ -40,7 +40,7 @@ dependencies {
     implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
     kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
 
-    implementation 'com.github.liangjingkanji:BRV:1.2.0'
+    implementation 'com.github.liangjingkanji:BRV:1.2.1'
 
     implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1'
     implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1'