This commit is contained in:
Horis
2023-09-21 22:31:00 +08:00
parent 5a68dd6445
commit 4b2a3b4d65
4 changed files with 26 additions and 11 deletions

View File

@@ -300,10 +300,13 @@ object CacheBook {
WebBook.getContent(scope, bookSource, book, chapter, executeContext = IO)
.onSuccess { content ->
onSuccess(chapter)
ReadBook.downloadedChapters.add(chapter.index)
ReadBook.downloadFailChapters.remove(chapter.index)
downloadFinish(chapter, content, resetPageOffset)
}.onError {
onError(chapter, it)
ReadBook.downloadFailChapters.add(chapter.index)
ReadBook.downloadFailChapters[chapter.index] =
(ReadBook.downloadFailChapters[chapter.index] ?: 0) + 1
downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
}.onCancel {
onCancel(chapter.index)

View File

@@ -55,7 +55,7 @@ object ReadBook : CoroutineScope by MainScope() {
var preDownloadTask: Coroutine<*>? = null
val downloadedChapters = hashSetOf<Int>()
val downloadFailChapters = hashSetOf<Int>()
val downloadFailChapters = hashMapOf<Int, Int>()
var contentProcessor: ContentProcessor? = null
val downloadScope = CoroutineScope(SupervisorJob() + IO)
@@ -545,7 +545,7 @@ object ReadBook : CoroutineScope by MainScope() {
val maxChapterIndex = min(durChapterIndex + AppConfig.preDownloadNum, chapterSize)
for (i in durChapterIndex.plus(2)..maxChapterIndex) {
if (downloadedChapters.contains(i)) continue
if (downloadFailChapters.contains(i)) continue
if ((downloadFailChapters[i] ?: 0) >= 3) continue
downloadIndex(i)
}
}
@@ -553,7 +553,7 @@ object ReadBook : CoroutineScope by MainScope() {
val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum)
for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
if (downloadedChapters.contains(i)) continue
if (downloadFailChapters.contains(i)) continue
if ((downloadFailChapters[i] ?: 0) >= 3) continue
downloadIndex(i)
}
}

View File

@@ -95,6 +95,13 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
context?.obtainStyledAttributes(intArrayOf(android.R.attr.homeAsUpIndicator))?.use {
binding.toolBar.navigationIcon = it.getDrawable(0)
binding.toolBar.setNavigationContentDescription(androidx.appcompat.R.string.abc_action_bar_up_description)
binding.toolBar.setNavigationOnClickListener {
dismissAllowingStateLoss()
}
}
binding.toolBar.setBackgroundColor(primaryColor)
viewModel.initData(arguments, callBack?.oldBook, activity is ReadBookActivity)
showTitle()
@@ -109,6 +116,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
private fun showTitle() {
binding.toolBar.title = viewModel.name
binding.toolBar.subtitle = viewModel.author
context?.obtainStyledAttributes(intArrayOf(android.R.attr.homeAsUpIndicator))?.use {
binding.toolBar.navigationIcon = it.getDrawable(0)
}
}
private fun initMenu() {
@@ -152,6 +162,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
searchView.setOnSearchClickListener {
binding.toolBar.title = ""
binding.toolBar.subtitle = ""
binding.toolBar.navigationIcon = null
}
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {

View File

@@ -1,9 +1,9 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/background">
<androidx.appcompat.widget.Toolbar
@@ -13,9 +13,10 @@
android:background="@color/background_menu"
android:elevation="5dp"
android:theme="?attr/actionBarStyle"
app:layout_constraintTop_toTopOf="parent"
app:contentInsetStartWithNavigation="0dp"
app:displayHomeAsUp="false"
app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/ToolbarTitle" />
@@ -29,19 +30,19 @@
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@+id/ll_bottom_bar"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar" />
<LinearLayout
android:id="@+id/ll_bottom_bar"
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="@color/background"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
@@ -51,10 +52,10 @@
android:layout_weight="1"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:ellipsize="middle"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:gravity="center_vertical"
android:textColor="@color/primaryText"
android:textSize="12sp" />