Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -44,7 +44,7 @@ data class BookChapter(
|
|||||||
var isVip: Boolean = false, // 是否VIP
|
var isVip: Boolean = false, // 是否VIP
|
||||||
var isPay: Boolean = false, // 是否已购买
|
var isPay: Boolean = false, // 是否已购买
|
||||||
var resourceUrl: String? = null, // 音频真实URL
|
var resourceUrl: String? = null, // 音频真实URL
|
||||||
var tag: String? = null, //
|
var tag: String? = null, // 更新时间或其他章节附加信息
|
||||||
var start: Long? = null, // 章节起始位置
|
var start: Long? = null, // 章节起始位置
|
||||||
var end: Long? = null, // 章节终止位置
|
var end: Long? = null, // 章节终止位置
|
||||||
var startFragmentId: String? = null, //EPUB书籍当前章节的fragmentId
|
var startFragmentId: String? = null, //EPUB书籍当前章节的fragmentId
|
||||||
|
|||||||
@@ -303,6 +303,7 @@ object CacheBook {
|
|||||||
downloadFinish(chapter, content, resetPageOffset)
|
downloadFinish(chapter, content, resetPageOffset)
|
||||||
}.onError {
|
}.onError {
|
||||||
onError(chapter, it)
|
onError(chapter, it)
|
||||||
|
ReadBook.downloadFailChapters.add(chapter.index)
|
||||||
downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
||||||
}.onCancel {
|
}.onCancel {
|
||||||
onCancel(chapter.index)
|
onCancel(chapter.index)
|
||||||
@@ -314,14 +315,12 @@ object CacheBook {
|
|||||||
private fun downloadFinish(
|
private fun downloadFinish(
|
||||||
chapter: BookChapter,
|
chapter: BookChapter,
|
||||||
content: String,
|
content: String,
|
||||||
resetPageOffset: Boolean = false,
|
resetPageOffset: Boolean = false
|
||||||
pageChanged: Boolean = false,
|
|
||||||
) {
|
) {
|
||||||
if (ReadBook.book?.bookUrl == book.bookUrl) {
|
if (ReadBook.book?.bookUrl == book.bookUrl) {
|
||||||
ReadBook.contentLoadFinish(
|
ReadBook.contentLoadFinish(
|
||||||
book, chapter, content,
|
book, chapter, content,
|
||||||
resetPageOffset = resetPageOffset,
|
resetPageOffset = resetPageOffset,
|
||||||
pageChanged = pageChanged
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +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>()
|
||||||
var contentProcessor: ContentProcessor? = null
|
var contentProcessor: ContentProcessor? = null
|
||||||
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
||||||
|
|
||||||
@@ -202,7 +203,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
nextTextChapter = null
|
nextTextChapter = null
|
||||||
if (curTextChapter == null) {
|
if (curTextChapter == null) {
|
||||||
AppLog.putDebug("moveToNextChapter-章节未加载,开始加载")
|
AppLog.putDebug("moveToNextChapter-章节未加载,开始加载")
|
||||||
loadContent(durChapterIndex, upContent, resetPageOffset = false, pageChanged = true)
|
loadContent(durChapterIndex, upContent, resetPageOffset = false)
|
||||||
} else if (upContent) {
|
} else if (upContent) {
|
||||||
AppLog.putDebug("moveToNextChapter-章节已加载,刷新视图")
|
AppLog.putDebug("moveToNextChapter-章节已加载,刷新视图")
|
||||||
callBack?.upContent()
|
callBack?.upContent()
|
||||||
@@ -230,7 +231,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
curTextChapter = prevTextChapter
|
curTextChapter = prevTextChapter
|
||||||
prevTextChapter = null
|
prevTextChapter = null
|
||||||
if (curTextChapter == null) {
|
if (curTextChapter == null) {
|
||||||
loadContent(durChapterIndex, upContent, resetPageOffset = false, pageChanged = true)
|
loadContent(durChapterIndex, upContent, resetPageOffset = false)
|
||||||
} else if (upContent) {
|
} else if (upContent) {
|
||||||
callBack?.upContent()
|
callBack?.upContent()
|
||||||
}
|
}
|
||||||
@@ -312,14 +313,9 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
*/
|
*/
|
||||||
fun loadContent(
|
fun loadContent(
|
||||||
resetPageOffset: Boolean,
|
resetPageOffset: Boolean,
|
||||||
pageChanged: Boolean = false,
|
|
||||||
success: (() -> Unit)? = null
|
success: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
loadContent(
|
loadContent(durChapterIndex, resetPageOffset = resetPageOffset) {
|
||||||
durChapterIndex,
|
|
||||||
resetPageOffset = resetPageOffset,
|
|
||||||
pageChanged = pageChanged
|
|
||||||
) {
|
|
||||||
success?.invoke()
|
success?.invoke()
|
||||||
}
|
}
|
||||||
loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset)
|
loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset)
|
||||||
@@ -331,14 +327,12 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
* @param index 章节序号
|
* @param index 章节序号
|
||||||
* @param upContent 是否更新视图
|
* @param upContent 是否更新视图
|
||||||
* @param resetPageOffset 滚动阅读是否重置滚动位置
|
* @param resetPageOffset 滚动阅读是否重置滚动位置
|
||||||
* @param pageChanged 是否发生了翻页
|
|
||||||
* @param success 加载完成回调
|
* @param success 加载完成回调
|
||||||
*/
|
*/
|
||||||
fun loadContent(
|
fun loadContent(
|
||||||
index: Int,
|
index: Int,
|
||||||
upContent: Boolean = true,
|
upContent: Boolean = true,
|
||||||
resetPageOffset: Boolean = false,
|
resetPageOffset: Boolean = false,
|
||||||
pageChanged: Boolean = false,
|
|
||||||
success: (() -> Unit)? = null
|
success: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
if (addLoading(index)) {
|
if (addLoading(index)) {
|
||||||
@@ -351,16 +345,14 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
chapter,
|
chapter,
|
||||||
it,
|
it,
|
||||||
upContent,
|
upContent,
|
||||||
resetPageOffset,
|
resetPageOffset
|
||||||
pageChanged
|
|
||||||
) {
|
) {
|
||||||
success?.invoke()
|
success?.invoke()
|
||||||
}
|
}
|
||||||
} ?: download(
|
} ?: download(
|
||||||
downloadScope,
|
downloadScope,
|
||||||
chapter,
|
chapter,
|
||||||
resetPageOffset = resetPageOffset,
|
resetPageOffset
|
||||||
pageChanged = pageChanged
|
|
||||||
)
|
)
|
||||||
} ?: removeLoading(index)
|
} ?: removeLoading(index)
|
||||||
}.onError {
|
}.onError {
|
||||||
@@ -388,12 +380,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
downloadedChapters.add(chapter.index)
|
downloadedChapters.add(chapter.index)
|
||||||
} else {
|
} else {
|
||||||
delay(1000)
|
delay(1000)
|
||||||
download(
|
download(downloadScope, chapter, false)
|
||||||
downloadScope,
|
|
||||||
chapter,
|
|
||||||
resetPageOffset = false,
|
|
||||||
pageChanged = false
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} ?: removeLoading(index)
|
} ?: removeLoading(index)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -409,7 +396,6 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
chapter: BookChapter,
|
chapter: BookChapter,
|
||||||
resetPageOffset: Boolean,
|
resetPageOffset: Boolean,
|
||||||
pageChanged: Boolean,
|
|
||||||
success: (() -> Unit)? = null
|
success: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val book = book ?: return removeLoading(chapter.index)
|
val book = book ?: return removeLoading(chapter.index)
|
||||||
@@ -423,7 +409,6 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
chapter,
|
chapter,
|
||||||
"加载正文失败\n$msg",
|
"加载正文失败\n$msg",
|
||||||
resetPageOffset = resetPageOffset,
|
resetPageOffset = resetPageOffset,
|
||||||
pageChanged = pageChanged
|
|
||||||
) {
|
) {
|
||||||
success?.invoke()
|
success?.invoke()
|
||||||
}
|
}
|
||||||
@@ -453,7 +438,6 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
content: String,
|
content: String,
|
||||||
upContent: Boolean = true,
|
upContent: Boolean = true,
|
||||||
resetPageOffset: Boolean,
|
resetPageOffset: Boolean,
|
||||||
pageChanged: Boolean,
|
|
||||||
success: (() -> Unit)? = null
|
success: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
removeLoading(chapter.index)
|
removeLoading(chapter.index)
|
||||||
@@ -475,7 +459,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
curTextChapter = textChapter
|
curTextChapter = textChapter
|
||||||
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
||||||
callBack?.upMenuView()
|
callBack?.upMenuView()
|
||||||
if (pageChanged) curPageChanged()
|
curPageChanged()
|
||||||
callBack?.contentLoadFinish()
|
callBack?.contentLoadFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,6 +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
|
||||||
downloadIndex(i)
|
downloadIndex(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,6 +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
|
||||||
downloadIndex(i)
|
downloadIndex(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1377,6 +1377,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
ReadBook.downloadScope.coroutineContext.cancelChildren()
|
ReadBook.downloadScope.coroutineContext.cancelChildren()
|
||||||
ReadBook.coroutineContext.cancelChildren()
|
ReadBook.coroutineContext.cancelChildren()
|
||||||
ReadBook.downloadedChapters.clear()
|
ReadBook.downloadedChapters.clear()
|
||||||
|
ReadBook.downloadFailChapters.clear()
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
Backup.autoBack(this)
|
Backup.autoBack(this)
|
||||||
}
|
}
|
||||||
@@ -1399,7 +1400,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
readView.upStyle()
|
readView.upStyle()
|
||||||
readView.upBgAlpha()
|
readView.upBgAlpha()
|
||||||
if (it) {
|
if (it) {
|
||||||
ReadBook.loadContent(resetPageOffset = false)
|
if (isInitFinish) {
|
||||||
|
ReadBook.loadContent(resetPageOffset = false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
readView.upContent(resetPageOffset = false)
|
readView.upContent(resetPageOffset = false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||||
ReadBook.resetData(book)
|
ReadBook.resetData(book)
|
||||||
ReadBook.upMsg(null)
|
ReadBook.upMsg(null)
|
||||||
ReadBook.loadContent(resetPageOffset = true, pageChanged = true)
|
ReadBook.loadContent(resetPageOffset = true)
|
||||||
}.onError {
|
}.onError {
|
||||||
context.toastOnUi("换源失败\n${it.localizedMessage}")
|
context.toastOnUi("换源失败\n${it.localizedMessage}")
|
||||||
ReadBook.upMsg(null)
|
ReadBook.upMsg(null)
|
||||||
@@ -291,7 +291,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
ReadBook.durChapterIndex = index
|
ReadBook.durChapterIndex = index
|
||||||
ReadBook.durChapterPos = durChapterPos
|
ReadBook.durChapterPos = durChapterPos
|
||||||
ReadBook.saveRead()
|
ReadBook.saveRead()
|
||||||
ReadBook.loadContent(resetPageOffset = true, pageChanged = true) {
|
ReadBook.loadContent(resetPageOffset = true) {
|
||||||
success?.invoke()
|
success?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,11 +320,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
|
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
|
||||||
?.let { chapter ->
|
?.let { chapter ->
|
||||||
BookHelp.delContent(book, chapter)
|
BookHelp.delContent(book, chapter)
|
||||||
ReadBook.loadContent(
|
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
|
||||||
ReadBook.durChapterIndex,
|
|
||||||
resetPageOffset = false,
|
|
||||||
pageChanged = true
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻页动画完成后事件
|
* 翻页动画完成后事件
|
||||||
* @param direction 翻页翻页反向
|
* @param direction 翻页方向
|
||||||
*/
|
*/
|
||||||
fun fillPage(direction: PageDirection): Boolean {
|
fun fillPage(direction: PageDirection): Boolean {
|
||||||
return when (direction) {
|
return when (direction) {
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
|
|||||||
protected var curBitmap: Bitmap? = null
|
protected var curBitmap: Bitmap? = null
|
||||||
protected var prevBitmap: Bitmap? = null
|
protected var prevBitmap: Bitmap? = null
|
||||||
protected var nextBitmap: Bitmap? = null
|
protected var nextBitmap: Bitmap? = null
|
||||||
protected val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
|
private val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
|
||||||
|
|
||||||
override fun setDirection(direction: PageDirection) {
|
override fun setDirection(direction: PageDirection) {
|
||||||
super.setDirection(direction)
|
super.setDirection(direction)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import kotlin.math.min
|
|||||||
data class TextPage(
|
data class TextPage(
|
||||||
var index: Int = 0,
|
var index: Int = 0,
|
||||||
var text: String = appCtx.getString(R.string.data_loading),
|
var text: String = appCtx.getString(R.string.data_loading),
|
||||||
var title: String = "",
|
var title: String = appCtx.getString(R.string.data_loading),
|
||||||
private val textLines: ArrayList<TextLine> = arrayListOf(),
|
private val textLines: ArrayList<TextLine> = arrayListOf(),
|
||||||
var pageSize: Int = 0,
|
var pageSize: Int = 0,
|
||||||
var chapterSize: Int = 0,
|
var chapterSize: Int = 0,
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ object ChapterProvider {
|
|||||||
var absStartX = paddingLeft
|
var absStartX = paddingLeft
|
||||||
var durY = 0f
|
var durY = 0f
|
||||||
textPages.add(TextPage())
|
textPages.add(TextPage())
|
||||||
if (ReadBookConfig.titleMode != 2) {
|
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) {
|
||||||
//标题非隐藏
|
//标题非隐藏
|
||||||
displayTitle.splitNotBlank("\n").forEach { text ->
|
displayTitle.splitNotBlank("\n").forEach { text ->
|
||||||
setTypeText(
|
setTypeText(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.PopupMenu
|
import android.widget.PopupMenu
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
@@ -55,6 +56,13 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
binding.recyclerView.addItemDecoration(VerticalDivider(this))
|
binding.recyclerView.addItemDecoration(VerticalDivider(this))
|
||||||
binding.recyclerView.adapter = fileAdapter
|
binding.recyclerView.adapter = fileAdapter
|
||||||
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
|
if (viewModel.lastDir != viewModel.rootDoc) {
|
||||||
|
gotoLastDir()
|
||||||
|
return@addCallback
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initSearchView() {
|
private fun initSearchView() {
|
||||||
@@ -87,6 +95,12 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun gotoLastDir() {
|
||||||
|
viewModel.subDocs.removeLastOrNull()
|
||||||
|
pathAdapter.setItems(viewModel.subDocs)
|
||||||
|
viewModel.upFiles(viewModel.lastDir)
|
||||||
|
}
|
||||||
|
|
||||||
override fun observeLiveBus() {
|
override fun observeLiveBus() {
|
||||||
viewModel.filesLiveData.observe(this) {
|
viewModel.filesLiveData.observe(this) {
|
||||||
searchView.setQuery("", false)
|
searchView.setQuery("", false)
|
||||||
@@ -155,9 +169,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
val item = getItemByLayoutPosition(holder.layoutPosition)
|
val item = getItemByLayoutPosition(holder.layoutPosition)
|
||||||
item?.let {
|
item?.let {
|
||||||
if (item == viewModel.lastDir) {
|
if (item == viewModel.lastDir) {
|
||||||
viewModel.subDocs.removeLastOrNull()
|
gotoLastDir()
|
||||||
pathAdapter.setItems(viewModel.subDocs)
|
|
||||||
viewModel.upFiles(viewModel.subDocs.lastOrNull() ?: viewModel.rootDoc)
|
|
||||||
} else if (item.isDirectory) {
|
} else if (item.isDirectory) {
|
||||||
viewModel.subDocs.add(item)
|
viewModel.subDocs.add(item)
|
||||||
pathAdapter.setItems(viewModel.subDocs)
|
pathAdapter.setItems(viewModel.subDocs)
|
||||||
|
|||||||
Reference in New Issue
Block a user