添加后台下载功能选项

pull/379/head
口口吕 4 years ago
parent 48e7d49ae7
commit 0616438402
  1. 3
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 3
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 14
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  4. 25
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  5. 2
      app/src/main/res/values-zh-rHK/strings.xml
  6. 2
      app/src/main/res/values-zh-rTW/strings.xml
  7. 2
      app/src/main/res/values-zh/strings.xml
  8. 1
      app/src/main/res/values/pref_key_value.xml
  9. 2
      app/src/main/res/values/strings.xml
  10. 7
      app/src/main/res/xml/pref_config_other.xml

@ -20,4 +20,7 @@ object EventBus {
const val WEB_SERVICE_STOP = "webServiceStop" const val WEB_SERVICE_STOP = "webServiceStop"
const val UP_DOWNLOAD = "upDownload" const val UP_DOWNLOAD = "upDownload"
const val SAVE_CONTENT = "saveContent" const val SAVE_CONTENT = "saveContent"
const val CHECK_INIT = "checkInit"
const val CHECK_UP_PROGRESS = "checkProgress"
const val CHECK_DONE = "checkDone"
} }

@ -58,6 +58,9 @@ object AppConfig {
App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) App.INSTANCE.putPrefBoolean(PreferKey.showRss, value)
} }
val backgroundVerification: Boolean
get() = App.INSTANCE.getPrefBoolean(R.string.pk_background_verification)
val autoRefreshBook: Boolean val autoRefreshBook: Boolean
get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh)

@ -6,12 +6,15 @@ import io.legado.app.App
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.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.AppConfig.backgroundVerification
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.service.help.CheckSource import io.legado.app.service.help.CheckSource
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.postEvent
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -42,8 +45,10 @@ class CheckSourceService : BaseService() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (backgroundVerification) {
updateNotification(0, getString(R.string.start)) updateNotification(0, getString(R.string.start))
} }
}
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) {
@ -59,6 +64,7 @@ class CheckSourceService : BaseService() {
super.onDestroy() super.onDestroy()
tasks.clear() tasks.clear()
searchPool.close() searchPool.close()
postEvent(EventBus.CHECK_DONE, 0)
} }
private fun check(ids: List<String>) { private fun check(ids: List<String>) {
@ -72,7 +78,11 @@ class CheckSourceService : BaseService() {
allIds.addAll(ids) allIds.addAll(ids)
processIndex = 0 processIndex = 0
threadCount = min(allIds.size, threadCount) threadCount = min(allIds.size, threadCount)
if (backgroundVerification) {
updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) updateNotification(0, getString(R.string.progress_show, 0, allIds.size))
} else {
postEvent(EventBus.CHECK_INIT, allIds.size)
}
for (i in 0 until threadCount) { for (i in 0 until threadCount) {
check() check()
} }
@ -106,10 +116,14 @@ class CheckSourceService : BaseService() {
synchronized(this) { synchronized(this) {
check() check()
checkedIds.add(sourceUrl) checkedIds.add(sourceUrl)
if (backgroundVerification) {
updateNotification( updateNotification(
checkedIds.size, checkedIds.size,
getString(R.string.progress_show, checkedIds.size, allIds.size) getString(R.string.progress_show, checkedIds.size, allIds.size)
) )
} else {
postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size)
}
if (processIndex >= allIds.size + threadCount - 1) { if (processIndex >= allIds.size + threadCount - 1) {
stopSelf() stopSelf()
} }

@ -21,6 +21,7 @@ import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.*
@ -65,6 +66,12 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private var sort = 0 private var sort = 0
private var sortAscending = 0 private var sortAscending = 0
private val progressDialogBuilder by lazy {
progressDialog("校验书源") {
setCancelable(false)
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
@ -263,6 +270,24 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
override fun observeLiveBus() {
observeEvent<Int>(EventBus.CHECK_INIT) { max->
progressDialogBuilder.max = max
progressDialogBuilder.show()
}
observeEvent<Int>(EventBus.CHECK_UP_PROGRESS) { progress->
progressDialogBuilder.progress = progress
}
observeEvent<Int>(EventBus.CHECK_DONE) {
if (progressDialogBuilder.isShowing) {
progressDialogBuilder.progress = it
progressDialogBuilder.max = it
progressDialogBuilder.dismiss()
}
toast("校验完成")
}
}
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection())

@ -94,6 +94,8 @@
閲讀3.0下載地址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release 閲讀3.0下載地址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release
</string> </string>
<string name="version_name">Version %s</string> <string name="version_name">Version %s</string>
<string name="pt_background_verification">後臺校驗書源</string>
<string name="ps_background_verification">打開后可以在校驗書源時自由操作</string>
<string name="pt_auto_refresh">自動刷新</string> <string name="pt_auto_refresh">自動刷新</string>
<string name="ps_auto_refresh">打開程式時自動更新書輯</string> <string name="ps_auto_refresh">打開程式時自動更新書輯</string>
<string name="pt_auto_download">自動下載最新章節</string> <string name="pt_auto_download">自動下載最新章節</string>

@ -94,6 +94,8 @@
閱讀3.0下載網址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release 閱讀3.0下載網址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release
</string> </string>
<string name="version_name">Version %s</string> <string name="version_name">Version %s</string>
<string name="pt_background_verification">後臺校驗書源</string>
<string name="ps_background_verification">打開后可以在校驗書源時自由操作</string>
<string name="pt_auto_refresh">自動重新整理</string> <string name="pt_auto_refresh">自動重新整理</string>
<string name="ps_auto_refresh">打開軟體時自動更新書籍</string> <string name="ps_auto_refresh">打開軟體時自動更新書籍</string>
<string name="pt_auto_download">自動下載最新章節</string> <string name="pt_auto_download">自動下載最新章節</string>

@ -96,6 +96,8 @@
阅读3.0下载地址:\nhttps://www.coolapk.com/apk/256030 阅读3.0下载地址:\nhttps://www.coolapk.com/apk/256030
</string> </string>
<string name="version_name">Version %s</string> <string name="version_name">Version %s</string>
<string name="pt_background_verification">后台校验书源</string>
<string name="ps_background_verification">打开后可以在校验书源时自由操作</string>
<string name="pt_auto_refresh">自动刷新</string> <string name="pt_auto_refresh">自动刷新</string>
<string name="ps_auto_refresh">打开软件时自动更新书籍</string> <string name="ps_auto_refresh">打开软件时自动更新书籍</string>
<string name="pt_auto_download">自动下载最新章节</string> <string name="pt_auto_download">自动下载最新章节</string>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="pk_background_verification" translatable="false">background_verification</string>
<string name="pk_auto_refresh" translatable="false">auto_refresh</string> <string name="pk_auto_refresh" translatable="false">auto_refresh</string>
<string name="pk_requested_direction" translatable="false">list_screen_direction</string> <string name="pk_requested_direction" translatable="false">list_screen_direction</string>
<string name="pk_full_screen" translatable="false">full_screen</string> <string name="pk_full_screen" translatable="false">full_screen</string>

@ -96,6 +96,8 @@
Legado (YueDu 3.0) download link:\n https://play.google.com/store/apps/details?id=io.legado.play.release Legado (YueDu 3.0) download link:\n https://play.google.com/store/apps/details?id=io.legado.play.release
</string> </string>
<string name="version_name">Version %s</string> <string name="version_name">Version %s</string>
<string name="pt_background_verification">Background-verification</string>
<string name="ps_background_verification">you can operate freely when verifying the book source</string>
<string name="pt_auto_refresh">Auto-refresh</string> <string name="pt_auto_refresh">Auto-refresh</string>
<string name="ps_auto_refresh">Update books automatically when opening the software</string> <string name="ps_auto_refresh">Update books automatically when opening the software</string>
<string name="pt_auto_download">Auto-download</string> <string name="pt_auto_download">Auto-download</string>

@ -51,6 +51,13 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category"> app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:key="@string/pk_background_verification"
android:summary="@string/ps_background_verification"
android:title="@string/pt_background_verification"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="replaceEnableDefault" android:key="replaceEnableDefault"

Loading…
Cancel
Save