优化
This commit is contained in:
@@ -300,10 +300,13 @@ object CacheBook {
|
|||||||
WebBook.getContent(scope, bookSource, book, chapter, executeContext = IO)
|
WebBook.getContent(scope, bookSource, book, chapter, executeContext = IO)
|
||||||
.onSuccess { content ->
|
.onSuccess { content ->
|
||||||
onSuccess(chapter)
|
onSuccess(chapter)
|
||||||
|
ReadBook.downloadedChapters.add(chapter.index)
|
||||||
|
ReadBook.downloadFailChapters.remove(chapter.index)
|
||||||
downloadFinish(chapter, content, resetPageOffset)
|
downloadFinish(chapter, content, resetPageOffset)
|
||||||
}.onError {
|
}.onError {
|
||||||
onError(chapter, it)
|
onError(chapter, it)
|
||||||
ReadBook.downloadFailChapters.add(chapter.index)
|
ReadBook.downloadFailChapters[chapter.index] =
|
||||||
|
(ReadBook.downloadFailChapters[chapter.index] ?: 0) + 1
|
||||||
downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
||||||
}.onCancel {
|
}.onCancel {
|
||||||
onCancel(chapter.index)
|
onCancel(chapter.index)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
|
|
||||||
var preDownloadTask: Coroutine<*>? = null
|
var preDownloadTask: Coroutine<*>? = null
|
||||||
val downloadedChapters = hashSetOf<Int>()
|
val downloadedChapters = hashSetOf<Int>()
|
||||||
val downloadFailChapters = hashSetOf<Int>()
|
val downloadFailChapters = hashMapOf<Int, Int>()
|
||||||
var contentProcessor: ContentProcessor? = null
|
var contentProcessor: ContentProcessor? = null
|
||||||
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
||||||
|
|
||||||
@@ -545,7 +545,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
val maxChapterIndex = min(durChapterIndex + AppConfig.preDownloadNum, chapterSize)
|
val maxChapterIndex = min(durChapterIndex + AppConfig.preDownloadNum, chapterSize)
|
||||||
for (i in durChapterIndex.plus(2)..maxChapterIndex) {
|
for (i in durChapterIndex.plus(2)..maxChapterIndex) {
|
||||||
if (downloadedChapters.contains(i)) continue
|
if (downloadedChapters.contains(i)) continue
|
||||||
if (downloadFailChapters.contains(i)) continue
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
||||||
downloadIndex(i)
|
downloadIndex(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum)
|
val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum)
|
||||||
for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
|
for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
|
||||||
if (downloadedChapters.contains(i)) continue
|
if (downloadedChapters.contains(i)) continue
|
||||||
if (downloadFailChapters.contains(i)) continue
|
if ((downloadFailChapters[i] ?: 0) >= 3) continue
|
||||||
downloadIndex(i)
|
downloadIndex(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
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)
|
binding.toolBar.setBackgroundColor(primaryColor)
|
||||||
viewModel.initData(arguments, callBack?.oldBook, activity is ReadBookActivity)
|
viewModel.initData(arguments, callBack?.oldBook, activity is ReadBookActivity)
|
||||||
showTitle()
|
showTitle()
|
||||||
@@ -109,6 +116,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
|||||||
private fun showTitle() {
|
private fun showTitle() {
|
||||||
binding.toolBar.title = viewModel.name
|
binding.toolBar.title = viewModel.name
|
||||||
binding.toolBar.subtitle = viewModel.author
|
binding.toolBar.subtitle = viewModel.author
|
||||||
|
context?.obtainStyledAttributes(intArrayOf(android.R.attr.homeAsUpIndicator))?.use {
|
||||||
|
binding.toolBar.navigationIcon = it.getDrawable(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initMenu() {
|
private fun initMenu() {
|
||||||
@@ -152,6 +162,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
|||||||
searchView.setOnSearchClickListener {
|
searchView.setOnSearchClickListener {
|
||||||
binding.toolBar.title = ""
|
binding.toolBar.title = ""
|
||||||
binding.toolBar.subtitle = ""
|
binding.toolBar.subtitle = ""
|
||||||
|
binding.toolBar.navigationIcon = null
|
||||||
}
|
}
|
||||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:background="@color/background">
|
android:background="@color/background">
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
@@ -13,9 +13,10 @@
|
|||||||
android:background="@color/background_menu"
|
android:background="@color/background_menu"
|
||||||
android:elevation="5dp"
|
android:elevation="5dp"
|
||||||
android:theme="?attr/actionBarStyle"
|
android:theme="?attr/actionBarStyle"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:contentInsetStartWithNavigation="0dp"
|
||||||
app:displayHomeAsUp="false"
|
app:displayHomeAsUp="false"
|
||||||
app:fitStatusBar="false"
|
app:fitStatusBar="false"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||||
app:titleTextAppearance="@style/ToolbarTitle" />
|
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||||
|
|
||||||
@@ -29,19 +30,19 @@
|
|||||||
android:id="@+id/recycler_view"
|
android:id="@+id/recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
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:layout_constraintBottom_toTopOf="@+id/ll_bottom_bar"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/ll_bottom_bar"
|
android:id="@+id/ll_bottom_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="36dp"
|
android:layout_height="36dp"
|
||||||
android:background="@color/background"
|
android:background="@color/background"
|
||||||
android:paddingLeft="10dp"
|
|
||||||
android:paddingRight="10dp"
|
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent">
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -51,10 +52,10 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
android:ellipsize="middle"
|
android:ellipsize="middle"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="10dp"
|
||||||
android:paddingRight="10dp"
|
android:paddingRight="10dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textColor="@color/primaryText"
|
android:textColor="@color/primaryText"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user