splitNotBlank

pull/32/head
Administrator 5 years ago
parent 68cfe5513c
commit 7f20bc29ef
  1. 1
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 11
      app/src/main/java/io/legado/app/help/permission/Request.kt
  3. 5
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt
  4. 8
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt
  5. 13
      app/src/main/java/io/legado/app/utils/StringExtensions.kt

@ -2,6 +2,7 @@ package io.legado.app.help.coroutine
import kotlinx.coroutines.*
class Coroutine<T>() {
companion object {

@ -87,9 +87,9 @@ internal class Request : OnRequestPermissionsResultCallback {
} else {
if (deniedPermissions != null) {
source?.context?.startActivity<PermissionActivity>(
Pair(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION),
Pair(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode),
Pair(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_PERMISSION,
PermissionActivity.KEY_INPUT_PERMISSIONS_CODE to requestCode,
PermissionActivity.KEY_INPUT_PERMISSIONS to deniedPermissions
)
} else {
onPermissionsGranted(requestCode)
@ -133,10 +133,7 @@ internal class Request : OnRequestPermissionsResultCallback {
.setMessage(rationale)
.setPositiveButton(R.string.dialog_setting) { _, _ ->
it.startActivity<PermissionActivity>(
Pair(
PermissionActivity.KEY_INPUT_REQUEST_TYPE,
TYPE_REQUEST_SETTING
)
PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_SETTING
)
}
.setNegativeButton(R.string.dialog_cancel) { _, _ -> cancel() }

@ -3,6 +3,7 @@ package io.legado.app.model.analyzeRule
import android.text.TextUtils
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.ReadContext
import io.legado.app.utils.splitNotBlank
import java.util.*
import java.util.regex.Pattern
@ -24,10 +25,10 @@ class AnalyzeByJSonPath {
val rules: Array<String>
val elementsType: String
if (rule.contains("&&")) {
rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
rules = rule.splitNotBlank("&&")
elementsType = "&"
} else {
rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
rules = rule.splitNotBlank("||")
elementsType = "|"
}
if (rules.size == 1) {

@ -24,6 +24,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
channel.send(it)
}
}
val c = execute {
val response: String = HttpHelper.getApiService<CommonHttpApi>(
"http://www.baidu.com"
@ -32,7 +33,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
delay(2000L)
response
}
.onStart {
Log.e("TAG!", "start")
@ -54,7 +54,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val c2 = plus(c)
// .timeout { 100L }
// .onErrorReturn { "error return2" }
.onStart {//会拦截掉c的onStart
.onStart {
//会拦截掉c的onStart
Log.e("TAG!", "start2")
start?.let { it() }
}
@ -69,12 +70,11 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
if (finally != null) {
finally()
}
Log.e("TAG!", "rec2: " + channel.receive())
}
launch {
delay(1500L)
// c2.cancel()

@ -23,11 +23,14 @@ fun String?.htmlFormat(): String = if (this.isNullOrBlank()) "" else
.replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字
.replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行
fun String?.splitNotBlank(delim: String) = this?.run {
if (!this.contains(delim)) sequenceOf(this) else
this.split(delim).asSequence().map { it.trim() }.filterNot { it.isBlank() }
fun String.splitNotBlank(delimiter: String): Array<String> = run {
this.split(delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()
}
fun String?.startWithIgnoreCase(start: String): Boolean {
return if (this.isNullOrBlank()) false else startsWith(start, true)
fun String.splitNotBlank(regex: Regex): Array<String> = run {
this.split(regex).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()
}
fun String.startWithIgnoreCase(start: String): Boolean {
return if (this.isBlank()) false else startsWith(start, true)
}
Loading…
Cancel
Save