pull/90/head^2
kunfei 5 years ago
parent 1e185b0ee9
commit 5999e21043
  1. 38
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  2. 24
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@ -1,13 +1,11 @@
package io.legado.app.service package io.legado.app.service
import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst 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.AppConfig
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
@ -15,27 +13,10 @@ import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors import java.util.concurrent.Executors
class CheckSourceService : BaseService() { class CheckSourceService : BaseService() {
companion object{
fun start(context: Context, selectedIds: Array<String>) {
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 = private var searchPool =
Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
private var sourceList: List<BookSource>? = null private val allIds = LinkedHashSet<String>()
private val unCheckIds = LinkedHashSet<String>()
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -44,7 +25,8 @@ class CheckSourceService : BaseService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
when (intent?.action) { when (intent?.action) {
IntentAction.start -> { IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let {
check(it)
} }
else -> stopSelf() else -> stopSelf()
} }
@ -56,6 +38,12 @@ class CheckSourceService : BaseService() {
searchPool.close() searchPool.close()
} }
private fun check(ids: List<String>) {
allIds.addAll(ids)
unCheckIds.addAll(ids)
}
/** /**
* 更新通知 * 更新通知
*/ */
@ -73,9 +61,7 @@ class CheckSourceService : BaseService() {
getString(R.string.cancel), getString(R.string.cancel),
IntentHelp.servicePendingIntent<CheckSourceService>(this, IntentAction.stop) IntentHelp.servicePendingIntent<CheckSourceService>(this, IntentAction.stop)
) )
sourceList?.let { builder.setProgress(allIds.size, state, false)
builder.setProgress(it.size, state, false)
}
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build() val notification = builder.build()
startForeground(112202, notification) startForeground(112202, notification)

@ -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<String>) {
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)
}
}
}

@ -30,7 +30,7 @@ import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.lib.theme.view.ATEAutoCompleteTextView 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.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.ui.qrcode.QrCodeActivity 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 kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.startService
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.FileNotFoundException import java.io.FileNotFoundException
@ -94,8 +93,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds()) R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds())
R.id.menu_check_source -> R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds()))
startService<CheckSourceService>(Pair("data", adapter.getSelectionIds()))
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()
} }
if (item.groupId == R.id.source_group) { if (item.groupId == R.id.source_group) {

Loading…
Cancel
Save