diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 6fe8b5cea..53ec7d778 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -20,4 +20,7 @@ object EventBus { const val WEB_SERVICE_STOP = "webServiceStop" const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" + const val CHECK_INIT = "checkInit" + const val CHECK_UP_PROGRESS = "checkProgress" + const val CHECK_DONE = "checkDone" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index e2538e902..eddc4f428 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -58,6 +58,9 @@ object AppConfig { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } + val backgroundVerification: Boolean + get() = App.INSTANCE.getPrefBoolean(R.string.pk_background_verification) + val autoRefreshBook: Boolean get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) 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 09900d0d0..4ce08ff07 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -6,12 +6,15 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst +import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig +import io.legado.app.help.AppConfig.backgroundVerification import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.manage.BookSourceActivity +import io.legado.app.utils.postEvent import kotlinx.coroutines.asCoroutineDispatcher import org.jetbrains.anko.toast import java.util.concurrent.Executors @@ -42,7 +45,9 @@ class CheckSourceService : BaseService() { override fun onCreate() { super.onCreate() - updateNotification(0, getString(R.string.start)) + if (backgroundVerification) { + updateNotification(0, getString(R.string.start)) + } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -59,6 +64,7 @@ class CheckSourceService : BaseService() { super.onDestroy() tasks.clear() searchPool.close() + postEvent(EventBus.CHECK_DONE, 0) } private fun check(ids: List) { @@ -72,7 +78,11 @@ class CheckSourceService : BaseService() { allIds.addAll(ids) processIndex = 0 threadCount = min(allIds.size, threadCount) - updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + if (backgroundVerification) { + updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + } else { + postEvent(EventBus.CHECK_INIT, allIds.size) + } for (i in 0 until threadCount) { check() } @@ -106,10 +116,14 @@ class CheckSourceService : BaseService() { synchronized(this) { check() checkedIds.add(sourceUrl) - updateNotification( - checkedIds.size, - getString(R.string.progress_show, checkedIds.size, allIds.size) - ) + if (backgroundVerification) { + updateNotification( + checkedIds.size, + getString(R.string.progress_show, checkedIds.size, allIds.size) + ) + } else { + postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) + } if (processIndex >= allIds.size + threadCount - 1) { stopSelf() } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index 322e4a7a3..1118eb8cc 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -26,7 +26,11 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : tv_lasted.text = context.getString(R.string.lasted_show, item.latestChapterTitle) tv_lasted.visible() } - tv_introduce.text = context.getString(R.string.intro_show, item.intro) + if (item.intro.isNullOrEmpty()) { + tv_introduce.text = context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = context.getString(R.string.intro_show, item.intro) + } val kinds = item.getKindList() if (kinds.isEmpty()) { ll_kind.gone() diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index a96244113..4370e9697 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -42,7 +42,13 @@ class SearchAdapter(context: Context, val callBack: CallBack) : tv_author.text = context.getString(R.string.author_show, searchBook.author) bv_originCount.setBadgeCount(searchBook.origins.size) upLasted(itemView, searchBook.latestChapterTitle) - tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) + if (searchBook.intro.isNullOrEmpty()) { + tv_introduce.text = + context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) + } upKind(itemView, searchBook.getKindList()) iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) @@ -58,8 +64,15 @@ class SearchAdapter(context: Context, val callBack: CallBack) : context.getString(R.string.author_show, searchBook.author) "origins" -> bv_originCount.setBadgeCount(searchBook.origins.size) "last" -> upLasted(itemView, searchBook.latestChapterTitle) - "intro" -> tv_introduce.text = - context.getString(R.string.intro_show, searchBook.intro) + "intro" -> { + if (searchBook.intro.isNullOrEmpty()) { + tv_introduce.text = + context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) + } + } "kind" -> upKind(itemView, searchBook.getKindList()) "cover" -> iv_cover.load( searchBook.coverUrl, 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 07f959719..d6f1aab3f 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 @@ -21,6 +21,7 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern +import io.legado.app.constant.EventBus import io.legado.app.data.entities.BookSource import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.* @@ -65,6 +66,12 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var sort = 0 private var sortAscending = 0 + private val progressDialogBuilder by lazy { + progressDialog("校验书源") { + setCancelable(false) + } + } + override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() @@ -263,6 +270,30 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } + override fun observeLiveBus() { + observeEvent(EventBus.CHECK_INIT) { max-> + progressDialogBuilder.max = max + progressDialogBuilder.show() + } + observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> + progressDialogBuilder.progress = progress + } + observeEvent(EventBus.CHECK_DONE) { + if (progressDialogBuilder.isShowing) { + progressDialogBuilder.progress = it + progressDialogBuilder.max = it + progressDialogBuilder.dismiss() + } + toast("校验完成!") + groups.map { group-> + if (group.contains("失效")) { + search_view.setQuery("失效", true) + toast("发现有失效书源,已为您自动筛选!") + } + } + } + } + override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index ccfa5bf82..0fdfa373f 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -11,10 +11,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.ACache -import io.legado.app.utils.dp -import io.legado.app.utils.gone -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.coroutines.CoroutineScope @@ -55,12 +52,12 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca .inflate(R.layout.item_fillet_text, gl_child, false) gl_child.addView(tv) tv.text_view.text = kind.title - tv.text_view.onClick { - kind.url?.let { kindUrl -> + if (!kind.url.isNullOrEmpty()) { + tv.text_view.onClick { callBack.openExplore( item.bookSourceUrl, kind.title, - kindUrl + kind.url.toString() ) } } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index c585ffb97..649f57d1a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -94,6 +94,8 @@ 閲讀3.0下載地址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release Version %s + 後臺校驗書源 + 打開后可以在校驗書源時自由操作 自動刷新 打開程式時自動更新書輯 自動下載最新章節 @@ -223,6 +225,7 @@ 載入失敗,點擊重試 內容簡介 簡介: %s + 簡介: 暫無簡介 打開外部書籍 來源: %s 本地導入 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 006b4ff45..17cc16af4 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -94,6 +94,8 @@ 閱讀3.0下載網址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release Version %s + 後臺校驗書源 + 打開后可以在校驗書源時自由操作 自動重新整理 打開軟體時自動更新書籍 自動下載最新章節 @@ -223,6 +225,7 @@ 載入失敗,點擊重試 內容簡介 簡介:%s + 簡介: 暫無簡介 打開外部書籍 來源: %s 本機匯入 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 78487a2be..2a5645ab8 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -96,6 +96,8 @@ 阅读3.0下载地址:\nhttps://www.coolapk.com/apk/256030 Version %s + 后台校验书源 + 打开后可以在校验书源时自由操作 自动刷新 打开软件时自动更新书籍 自动下载最新章节 @@ -225,6 +227,7 @@ 加载失败,点击重试 内容简介 简介:%s + 简介: 暂无简介 打开外部书籍 来源: %s 本地导入 diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 42058ce0c..7ce2f7f13 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -1,5 +1,6 @@ + background_verification auto_refresh list_screen_direction full_screen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 893230b30..8ae687184 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,6 +96,8 @@ Legado (YueDu 3.0) download link:\n https://play.google.com/store/apps/details?id=io.legado.play.release Version %s + Background-verification + you can operate freely when verifying the book source Auto-refresh Update books automatically when opening the software Auto-download @@ -225,6 +227,7 @@ Load failed, tap to retry Book description Description:%s + Description: no introduction Open external book Origin: %s Import local rules diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0e3930546..f4f28ca94 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -51,6 +51,13 @@ app:iconSpaceReserved="false" app:layout="@layout/view_preference_category"> + +