From 5999e210433ff9b88d6038371e986546024ed85e Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 18:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/service/CheckSourceService.kt | 38 ++++++------------- .../io/legado/app/service/help/CheckSource.kt | 24 ++++++++++++ .../book/source/manage/BookSourceActivity.kt | 6 +-- 3 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/io/legado/app/service/help/CheckSource.kt 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 6507cb219..549d7fee2 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -1,13 +1,11 @@ package io.legado.app.service -import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst -import io.legado.app.data.entities.BookSource +import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -15,27 +13,10 @@ import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors class CheckSourceService : BaseService() { - - companion object{ - fun start(context: Context, selectedIds: Array) { - Intent(context, CheckSourceService::class.java).let { - it.action = IntentAction.start - it.putExtra("selectIds", selectedIds) - context.startService(it) - } - } - - fun stop(context: Context) { - Intent(context, CheckSourceService::class.java).let { - it.action = IntentAction.stop - context.startService(it) - } - } - } - private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() - private var sourceList: List? = null + private val allIds = LinkedHashSet() + private val unCheckIds = LinkedHashSet() override fun onCreate() { super.onCreate() @@ -44,7 +25,8 @@ class CheckSourceService : BaseService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - IntentAction.start -> { + IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let { + check(it) } else -> stopSelf() } @@ -56,6 +38,12 @@ class CheckSourceService : BaseService() { searchPool.close() } + private fun check(ids: List) { + allIds.addAll(ids) + unCheckIds.addAll(ids) + + } + /** * 更新通知 */ @@ -73,9 +61,7 @@ class CheckSourceService : BaseService() { getString(R.string.cancel), IntentHelp.servicePendingIntent(this, IntentAction.stop) ) - sourceList?.let { - builder.setProgress(it.size, state, false) - } + builder.setProgress(allIds.size, state, false) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(112202, notification) diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt new file mode 100644 index 000000000..47aa593f9 --- /dev/null +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -0,0 +1,24 @@ +package io.legado.app.service.help + +import android.content.Context +import android.content.Intent +import io.legado.app.constant.IntentAction +import io.legado.app.service.CheckSourceService + +object CheckSource { + + fun start(context: Context, selectedIds: ArrayList) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.start + it.putExtra("selectIds", selectedIds) + context.startService(it) + } + } + + fun stop(context: Context) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.stop + context.startService(it) + } + } +} \ No newline at end of file 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 52b433a32..82d823a0a 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 @@ -30,7 +30,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView -import io.legado.app.service.CheckSourceService +import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity @@ -40,7 +40,6 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.startService import org.jetbrains.anko.toast import java.io.FileNotFoundException @@ -94,8 +93,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) - R.id.menu_check_source -> - startService(Pair("data", adapter.getSelectionIds())) + R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds())) R.id.menu_import_source_onLine -> showImportDialog() } if (item.groupId == R.id.source_group) {