diff --git a/app/src/main/java/io/legado/app/base/BaseService.kt b/app/src/main/java/io/legado/app/base/BaseService.kt index 54b409f39..852dc0d5f 100644 --- a/app/src/main/java/io/legado/app/base/BaseService.kt +++ b/app/src/main/java/io/legado/app/base/BaseService.kt @@ -6,10 +6,7 @@ import android.os.IBinder import androidx.annotation.CallSuper import io.legado.app.help.LifecycleHelp import io.legado.app.help.coroutine.Coroutine -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.cancel +import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext abstract class BaseService : Service(), CoroutineScope by MainScope() { @@ -17,8 +14,9 @@ abstract class BaseService : Service(), CoroutineScope by MainScope() { fun execute( scope: CoroutineScope = this, context: CoroutineContext = Dispatchers.IO, + start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T - ) = Coroutine.async(scope, context) { block() } + ) = Coroutine.async(scope, context, start) { block() } @CallSuper override fun onCreate() { diff --git a/app/src/main/java/io/legado/app/help/config/LocalConfig.kt b/app/src/main/java/io/legado/app/help/config/LocalConfig.kt index 09da7a194..99384e194 100644 --- a/app/src/main/java/io/legado/app/help/config/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/LocalConfig.kt @@ -43,7 +43,7 @@ object LocalConfig : get() = !isLastVersion(5, "httpTtsVersion") val needUpTxtTocRule: Boolean - get() = !isLastVersion(1, "txtTocRuleVersion") + get() = !isLastVersion(2, "txtTocRuleVersion") val needUpRssSources: Boolean get() = !isLastVersion(4, "rssSourceVersion") diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index 73f8f9edf..a1f1c08cf 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -12,6 +12,7 @@ import kotlin.coroutines.CoroutineContext class Coroutine( val scope: CoroutineScope, context: CoroutineContext = Dispatchers.IO, + val startOption: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T ) { @@ -22,9 +23,10 @@ class Coroutine( fun async( scope: CoroutineScope = DEFAULT, context: CoroutineContext = Dispatchers.IO, + start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T ): Coroutine { - return Coroutine(scope, context, block) + return Coroutine(scope, context, start, block) } } @@ -135,11 +137,15 @@ class Coroutine( return job.invokeOnCompletion(handler) } + fun start() { + job.start() + } + private fun executeInternal( context: CoroutineContext, block: suspend CoroutineScope.() -> T ): Job { - return (scope + Dispatchers.Main).launch { + return (scope + Dispatchers.Main).launch(start = startOption) { try { start?.let { dispatchVoidCallback(this, it) } ensureActive() diff --git a/app/src/main/java/io/legado/app/model/CheckSource.kt b/app/src/main/java/io/legado/app/model/CheckSource.kt index e3d313bca..c43aafe33 100644 --- a/app/src/main/java/io/legado/app/model/CheckSource.kt +++ b/app/src/main/java/io/legado/app/model/CheckSource.kt @@ -38,6 +38,12 @@ object CheckSource { } } + fun resume(context: Context) { + context.startService { + action = IntentAction.resume + } + } + fun putConfig() { CacheManager.put("checkSourceTimeout", timeout) CacheManager.put("checkSearch", checkSearch) diff --git a/app/src/main/java/io/legado/app/receiver/NetworkChangedListener.kt b/app/src/main/java/io/legado/app/receiver/NetworkChangedListener.kt index 12de57e90..b3e9af33d 100644 --- a/app/src/main/java/io/legado/app/receiver/NetworkChangedListener.kt +++ b/app/src/main/java/io/legado/app/receiver/NetworkChangedListener.kt @@ -1,5 +1,6 @@ package io.legado.app.receiver +import android.annotation.SuppressLint import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -34,6 +35,7 @@ class NetworkChangedListener(private val context: Context) { return@lazy null } + @SuppressLint("MissingPermission") fun register() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { networkCallback?.let { diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 62637d428..bb92871fc 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -24,10 +24,8 @@ import io.legado.app.utils.activityPendingIntent import io.legado.app.utils.postEvent import io.legado.app.utils.servicePendingIntent import io.legado.app.utils.toastOnUi +import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.TimeoutCancellationException -import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.launch import org.mozilla.javascript.WrappedException import java.util.concurrent.Executors import kotlin.math.min @@ -71,6 +69,7 @@ class CheckSourceService : BaseService() { IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let { check(it) } + IntentAction.resume -> upNotification() else -> stopSelf() } return super.onStartCommand(intent, flags, startId) @@ -122,7 +121,7 @@ class CheckSourceService : BaseService() { *校验书源 */ private fun check(source: BookSource) { - execute(context = searchCoroutine) { + execute(context = searchCoroutine, start = CoroutineStart.LAZY) { Debug.startChecking(source) var searchWord = CheckSource.keyword source.ruleSearch?.checkKeyWord?.let { @@ -162,7 +161,7 @@ class CheckSourceService : BaseService() { } } if (url.isNullOrBlank()) { - source.addGroup("发现规则为空") + source.addGroup("发现规则为空") } else { source.removeGroup("发现规则为空") val exploreBooks = WebBook.exploreBookAwait(this, source, url) @@ -194,7 +193,7 @@ class CheckSourceService : BaseService() { source.respondTime = Debug.getRespondTime(source.bookSourceUrl) appDb.bookSourceDao.update(source) onNext(source.bookSourceUrl, source.bookSourceName) - } + }.start() } /** diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index bd9cd1cf9..6f79b5d5c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -1,10 +1,10 @@ package io.legado.app.ui.book.source.manage import android.annotation.SuppressLint +import android.content.Context +import android.hardware.display.DisplayManager import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import android.view.SubMenu +import android.view.* import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.PopupMenu @@ -28,6 +28,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryTextColor import io.legado.app.model.CheckSource import io.legado.app.model.Debug +import io.legado.app.service.CheckSourceService import io.legado.app.ui.association.ImportBookSourceDialog import io.legado.app.ui.book.local.rule.TxtTocRuleActivity import io.legado.app.ui.book.source.debug.BookSourceDebugActivity @@ -69,6 +70,9 @@ class BookSourceActivity : VMBaseActivity viewModel.saveToFile(adapter.selection) { share(it) } + R.id.menu_check_selected_interval -> adapter.checkSelectedInterval() } return true } @@ -376,6 +382,7 @@ class BookSourceActivity : VMBaseActivity(EventBus.CHECK_SOURCE_DONE) { + keepScreenOn(false) snackBar?.dismiss() snackBar = null groups.map { group -> @@ -512,11 +529,21 @@ class BookSourceActivity : VMBaseActivity() + getItems().forEachIndexed { index, it -> + if (selected.contains(it)) { + selectedPosition.add(index) + } + } + val minPosition = Collections.min(selectedPosition) + val maxPosition = Collections.max(selectedPosition) + val itemCount = maxPosition - minPosition + 1 + for (i in minPosition..maxPosition) { + getItem(i)?.let { + selected.add(it) + } + } + notifyItemRangeChanged(minPosition, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() + } + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) diff --git a/app/src/main/res/layout/item_txt_toc_rule.xml b/app/src/main/res/layout/item_txt_toc_rule.xml index fd969afcb..6737630ef 100644 --- a/app/src/main/res/layout/item_txt_toc_rule.xml +++ b/app/src/main/res/layout/item_txt_toc_rule.xml @@ -10,13 +10,13 @@ + android:layout_height="match_parent" + android:gravity="center_vertical"> + + diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1b8b20c70..2a7ff5263 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1007,4 +1007,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) Ejemplo + 选中所选区间 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 3ab62635c..67ffe8fd9 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) + 选中所选区间 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7c11db47e..60d2886bd 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) Exemplo + 选中所选区间 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 99a15125e..34ba2a46a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1007,4 +1007,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 928a00828..7b8de3a1b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1009,4 +1009,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index e395e543c..de1f51ece 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1009,4 +1009,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b1824116..18656565b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) + 选中所选区间 diff --git a/epublib/src/main/java/me/ag2s/epublib/epub/EpubReader.java b/epublib/src/main/java/me/ag2s/epublib/epub/EpubReader.java index 21a2b2e17..7f74b836f 100644 --- a/epublib/src/main/java/me/ag2s/epublib/epub/EpubReader.java +++ b/epublib/src/main/java/me/ag2s/epublib/epub/EpubReader.java @@ -69,8 +69,7 @@ public class EpubReader { */ public EpubBook readEpubLazy(@NonNull ZipFile zipFile, @NonNull String encoding) throws IOException { - return readEpubLazy(zipFile, encoding, - Arrays.asList(MediaTypes.mediaTypes)); + return readEpubLazy(zipFile, encoding, Arrays.asList(MediaTypes.mediaTypes)); } public EpubBook readEpub(@NonNull ZipInputStream in, @NonNull String encoding) throws IOException { @@ -107,8 +106,7 @@ public class EpubReader { } handleMimeType(result, resources); String packageResourceHref = getPackageResourceHref(resources); - Resource packageResource = processPackageResource(packageResourceHref, - result, resources); + Resource packageResource = processPackageResource(packageResourceHref, result, resources); result.setOpfResource(packageResource); Resource ncxResource = processNcxResource(packageResource, result); result.setNcxResource(ncxResource); diff --git a/epublib/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java b/epublib/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java index 058299db2..8c8bdd72e 100644 --- a/epublib/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java +++ b/epublib/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java @@ -46,9 +46,11 @@ public class ResourcesLoader { * @return Resources * @throws IOException IOException */ - public static Resources loadResources(ZipFile zipFile, - String defaultHtmlEncoding, - List lazyLoadedTypes) throws IOException { + public static Resources loadResources( + ZipFile zipFile, + String defaultHtmlEncoding, + List lazyLoadedTypes + ) throws IOException { LazyResourceProvider resourceProvider = new EpubResourceProvider(zipFile.getName());