From c02c35a4c9c19af4aa247734b2f7904f4ea11194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Mon, 21 Sep 2020 23:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=A1=E9=AA=8C=E4=B9=A6?= =?UTF-8?q?=E6=BA=90=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/EventBus.kt | 1 + .../legado/app/service/CheckSourceService.kt | 13 +-- .../book/source/manage/BookSourceActivity.kt | 101 ++++++++++++------ .../res/layout/dialog_progressbar_view.xml | 36 +++++++ app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 8 files changed, 116 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/layout/dialog_progressbar_view.xml 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 53ec7d778..8ea4122b9 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -22,5 +22,6 @@ object EventBus { const val SAVE_CONTENT = "saveContent" const val CHECK_INIT = "checkInit" const val CHECK_UP_PROGRESS = "checkProgress" + const val CHECK_UP_PROGRESS_STRING = "checkProgressTxt" const val CHECK_DONE = "checkDone" } \ No newline at end of file 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 4ce08ff07..705ff19c9 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -79,7 +79,7 @@ class CheckSourceService : BaseService() { processIndex = 0 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) } @@ -101,28 +101,29 @@ class CheckSourceService : BaseService() { val sourceUrl = allIds[index] App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> if (source.searchUrl.isNullOrEmpty()) { - onNext(sourceUrl) + onNext(sourceUrl, source.bookSourceName) } else { CheckSource(source).check(this, searchPool) { - onNext(it) + onNext(it, source.bookSourceName) } } - } ?: onNext(sourceUrl) + } ?: onNext(sourceUrl, "") } } } - private fun onNext(sourceUrl: String) { + private fun onNext(sourceUrl: String, sourceName: String) { synchronized(this) { check() checkedIds.add(sourceUrl) if (backgroundVerification) { updateNotification( checkedIds.size, - getString(R.string.progress_show, checkedIds.size, allIds.size) + getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) ) } else { postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) + postEvent(EventBus.CHECK_UP_PROGRESS_STRING, getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size)) } if (processIndex >= allIds.size + threadCount - 1) { stopSelf() 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 d6f1aab3f..c461797dd 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 @@ -5,9 +5,8 @@ import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import android.view.SubMenu +import android.util.DisplayMetrics +import android.view.* import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.content.FileProvider @@ -19,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.BuildConfig import io.legado.app.R +import io.legado.app.base.BaseDialogFragment import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus @@ -40,8 +40,12 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* +import kotlinx.android.synthetic.main.activity_book_source.recycler_view import kotlinx.android.synthetic.main.dialog_edit_text.view.* +import kotlinx.android.synthetic.main.dialog_progressbar_view.* +import kotlinx.android.synthetic.main.dialog_progressbar_view.tv_footer_left import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -66,12 +70,6 @@ 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() @@ -270,30 +268,6 @@ 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()) @@ -415,6 +389,24 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }.show().applyTint() } + override fun observeLiveBus() { + observeEvent(EventBus.CHECK_INIT) { max-> + val bundle = Bundle() + bundle.putInt("maxProgress", max) + CheckSourceDialog().apply { + arguments = bundle + }.show(supportFragmentManager, "CheckDialog") + } + observeEvent(EventBus.CHECK_DONE) { + groups.map { group-> + if (group.contains("失效")) { + search_view.setQuery("失效", true) + toast("发现有失效书源,已为您自动筛选!") + } + } + } + } + override fun upCountView() { select_action_bar.upCountView(adapter.getSelection().size, adapter.getActualItemCount()) } @@ -509,4 +501,47 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity search_view.setQuery("", true) } } + + class CheckSourceDialog : BaseDialogFragment() { + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout( + (dm.widthPixels * 0.9).toInt(), + (dm.heightPixels * 0.14).toInt() + ) + dialog?.setCancelable(false) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_progressbar_view, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + arguments?.let { bundle -> + val maxProgress = bundle.getInt("maxProgress") + ck_progress_text.text = getString(R.string.progress_show, "", 0, maxProgress) + ck_progress.max = maxProgress + observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> + ck_progress.progress = progress + } + observeEvent(EventBus.CHECK_UP_PROGRESS_STRING) { + ck_progress_text.text = it + } + observeEvent(EventBus.CHECK_DONE) { + dismiss() + } + tv_footer_left.onClick { + CheckSource.stop(requireContext()).apply { + dismiss() + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_progressbar_view.xml b/app/src/main/res/layout/dialog_progressbar_view.xml new file mode 100644 index 000000000..f310c9ced --- /dev/null +++ b/app/src/main/res/layout/dialog_progressbar_view.xml @@ -0,0 +1,36 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 2e7d44236..5990fc38a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -293,7 +293,7 @@ 右邊距 校驗書源 校驗所選 - 進度 %1$d/%2$d + %1$s 進度 %2$d/%3$d 請安裝並選擇中文 TTS! TTS 初始化失敗! 簡繁轉換 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d7d39b40c..bab0077cc 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -293,7 +293,7 @@ 右邊距 校驗書源 校驗所選 - 進度 %1$d/%2$d + %1$s 進度 %2$d/%3$d 請安裝並選擇中文TTS! TTS初始化失敗! 簡繁轉換 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8e4821f0a..edabcafce 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -295,7 +295,7 @@ 右边距 校验书源 校验所选 - 进度 %1$d/%2$d + %1$s 进度 %2$d/%3$d 请安装并选择中文TTS! TTS初始化失败! 简繁转换 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 77e490b8c..515c117b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -295,7 +295,7 @@ Padding right Check book sources Check the selected source - Progress %1$d/%2$d + %1$s Progress %2$d/%3$d Please install and select Chinese TTS! TTS initialization failed! Simplified conversion