Merge pull request #392 from KKL369/master

push
pull/394/head
kunfei 4 years ago committed by GitHub
commit a2b058230d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 13
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 101
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  4. 36
      app/src/main/res/layout/dialog_progressbar_view.xml
  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. 2
      app/src/main/res/values/strings.xml

@ -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"
}

@ -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()

@ -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<BookSourceViewModel>(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<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("校验完成!")
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<BookSourceViewModel>(R.layout.activity
}.show().applyTint()
}
override fun observeLiveBus() {
observeEvent<Int>(EventBus.CHECK_INIT) { max->
val bundle = Bundle()
bundle.putInt("maxProgress", max)
CheckSourceDialog().apply {
arguments = bundle
}.show(supportFragmentManager, "CheckDialog")
}
observeEvent<Int>(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<BookSourceViewModel>(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<Int>(EventBus.CHECK_UP_PROGRESS) { progress->
ck_progress.progress = progress
}
observeEvent<String>(EventBus.CHECK_UP_PROGRESS_STRING) {
ck_progress_text.text = it
}
observeEvent<Int>(EventBus.CHECK_DONE) {
dismiss()
}
tv_footer_left.onClick {
CheckSource.stop(requireContext()).apply {
dismiss()
}
}
}
}
}
}

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.legado.app.lib.theme.view.ATEProgressBar
android:id="@+id/ck_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_marginRight="60dp"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/ck_progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
app:layout_constraintBottom_toBottomOf="@+id/ck_progress"
app:layout_constraintEnd_toEndOf="@+id/ck_progress" />
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_footer_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/ck_progress"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -293,7 +293,7 @@
<string name="padding_right">右邊距</string>
<string name="check_book_source">校驗書源</string>
<string name="check_select_source">校驗所選</string>
<string name="progress_show">進度 %1$d/%2$d</string>
<string name="progress_show">%1$s 進度 %2$d/%3$d</string>
<string name="tts_fix">請安裝並選擇中文 TTS!</string>
<string name="tts_init_failed">TTS 初始化失敗!</string>
<string name="jf_convert">簡繁轉換</string>

@ -293,7 +293,7 @@
<string name="padding_right">右邊距</string>
<string name="check_book_source">校驗書源</string>
<string name="check_select_source">校驗所選</string>
<string name="progress_show">進度 %1$d/%2$d</string>
<string name="progress_show">%1$s 進度 %2$d/%3$d</string>
<string name="tts_fix">請安裝並選擇中文TTS!</string>
<string name="tts_init_failed">TTS初始化失敗!</string>
<string name="jf_convert">簡繁轉換</string>

@ -295,7 +295,7 @@
<string name="padding_right">右边距</string>
<string name="check_book_source">校验书源</string>
<string name="check_select_source">校验所选</string>
<string name="progress_show">进度 %1$d/%2$d</string>
<string name="progress_show">%1$s 进度 %2$d/%3$d</string>
<string name="tts_fix">请安装并选择中文TTS!</string>
<string name="tts_init_failed">TTS初始化失败!</string>
<string name="jf_convert">简繁转换</string>

@ -295,7 +295,7 @@
<string name="padding_right">Padding right</string>
<string name="check_book_source">Check book sources</string>
<string name="check_select_source">Check the selected source</string>
<string name="progress_show">Progress %1$d/%2$d</string>
<string name="progress_show">%1$s Progress %2$d/%3$d</string>
<string name="tts_fix">Please install and select Chinese TTS!</string>
<string name="tts_init_failed">TTS initialization failed!</string>
<string name="jf_convert">Simplified conversion</string>

Loading…
Cancel
Save