Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
77187bb15c
36 files changed
+100
-38
No files matched your search
@@ -137,6 +137,7 @@ object PreferKey {
|
||||
const val batchChangeSourceDelay = "batchChangeSourceDelay"
|
||||
const val openBookInfoByClickTitle = "openBookInfoByClickTitle"
|
||||
const val defaultHomePage = "defaultHomePage"
|
||||
const val showBookshelfFastScroller = "showBookshelfFastScroller"
|
||||
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val cAccent = "colorAccent"
|
||||
|
||||
@@ -403,6 +403,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
appCtx.putPrefBoolean(PreferKey.openBookInfoByClickTitle, value)
|
||||
}
|
||||
|
||||
var showBookshelfFastScroller: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.showBookshelfFastScroller, false)
|
||||
set(value) {
|
||||
appCtx.putPrefBoolean(PreferKey.showBookshelfFastScroller, value)
|
||||
}
|
||||
|
||||
var contentSelectSpeakMod: Int
|
||||
get() = appCtx.getPrefInt(PreferKey.contentSelectSpeakMod)
|
||||
set(value) {
|
||||
|
||||
@@ -138,7 +138,7 @@ class Coroutine<T>(
|
||||
job.cancel(cause)
|
||||
}
|
||||
cancel?.let {
|
||||
MainScope().launch {
|
||||
MainScope().launch(executeContext) {
|
||||
if (null == it.context) {
|
||||
it.block.invoke(scope)
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.legado.app.help.http
|
||||
|
||||
import io.legado.app.utils.asIOException
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import splitties.init.appCtx
|
||||
@@ -55,6 +56,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
var preDownloadTask: Coroutine<*>? = null
|
||||
val downloadedChapters = hashSetOf<Int>()
|
||||
var contentProcessor: ContentProcessor? = null
|
||||
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
||||
|
||||
//暂时保存跳转前进度
|
||||
fun saveCurrentBookProcess() {
|
||||
@@ -355,7 +357,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
success?.invoke()
|
||||
}
|
||||
} ?: download(
|
||||
this,
|
||||
downloadScope,
|
||||
chapter,
|
||||
resetPageOffset = resetPageOffset,
|
||||
pageChanged = pageChanged
|
||||
@@ -386,7 +388,12 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
downloadedChapters.add(chapter.index)
|
||||
} else {
|
||||
delay(1000)
|
||||
download(this, chapter, resetPageOffset = false, pageChanged = false)
|
||||
download(
|
||||
downloadScope,
|
||||
chapter,
|
||||
resetPageOffset = false,
|
||||
pageChanged = false
|
||||
)
|
||||
}
|
||||
} ?: removeLoading(index)
|
||||
} catch (e: Exception) {
|
||||
@@ -503,7 +510,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
) {
|
||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
||||
chapterSize = cList.size
|
||||
nextTextChapter ?: loadContent(1)
|
||||
nextTextChapter ?: loadContent(durChapterIndex + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,16 +528,19 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
}
|
||||
|
||||
fun saveRead() {
|
||||
Coroutine.async {
|
||||
Coroutine.async(executeContext = IO) {
|
||||
val book = book ?: return@async
|
||||
book.lastCheckCount = 0
|
||||
book.durChapterTime = System.currentTimeMillis()
|
||||
val chapterChanged = book.durChapterIndex != durChapterIndex
|
||||
book.durChapterIndex = durChapterIndex
|
||||
book.durChapterPos = durChapterPos
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
||||
book.durChapterTitle = it.getDisplayTitle(
|
||||
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
||||
)
|
||||
if (chapterChanged) {
|
||||
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
||||
book.durChapterTitle = it.getDisplayTitle(
|
||||
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
||||
)
|
||||
}
|
||||
}
|
||||
appDb.bookDao.update(book)
|
||||
}
|
||||
|
||||
@@ -215,12 +215,16 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
viewModel.initData(intent)
|
||||
viewModel.initData(intent) {
|
||||
upMenu()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
viewModel.initData(intent ?: return)
|
||||
viewModel.initData(intent ?: return) {
|
||||
upMenu()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
@@ -244,7 +248,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
if (bookChanged) {
|
||||
bookChanged = false
|
||||
ReadBook.callBack = this
|
||||
viewModel.initData(intent)
|
||||
viewModel.initData(intent) {
|
||||
upMenu()
|
||||
}
|
||||
} else {
|
||||
//web端阅读时,app处于阅读界面,本地记录会覆盖web保存的进度,在此处恢复
|
||||
ReadBook.webBookProgress?.let {
|
||||
@@ -1368,6 +1374,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
ReadBook.callBack = null
|
||||
}
|
||||
ReadBook.preDownloadTask?.cancel()
|
||||
ReadBook.downloadScope.coroutineContext.cancelChildren()
|
||||
ReadBook.coroutineContext.cancelChildren()
|
||||
ReadBook.downloadedChapters.clear()
|
||||
if (!BuildConfig.DEBUG) {
|
||||
Backup.autoBack(this)
|
||||
|
||||
@@ -56,7 +56,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
fun initData(intent: Intent) {
|
||||
fun initData(intent: Intent, success: (() -> Unit)? = null) {
|
||||
execute {
|
||||
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
|
||||
ReadBook.tocChanged = intent.getBooleanExtra("tocChanged", false)
|
||||
@@ -70,6 +70,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
book != null -> initBook(book)
|
||||
else -> ReadBook.upMsg(context.getString(R.string.no_book))
|
||||
}
|
||||
}.onSuccess {
|
||||
success?.invoke()
|
||||
}.onError {
|
||||
val msg = "初始化数据失败\n${it.localizedMessage}"
|
||||
ReadBook.upMsg(msg)
|
||||
|
||||
@@ -285,14 +285,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
val offset = (ChapterProvider.visibleHeight - textPage.height).toInt()
|
||||
pageOffset = min(0, offset)
|
||||
} else if (pageOffset > 0) {
|
||||
pageFactory.moveToPrev(false)
|
||||
pageFactory.moveToPrev(true)
|
||||
textPage = pageFactory.curPage
|
||||
pageOffset -= textPage.height.toInt()
|
||||
upView?.invoke(textPage)
|
||||
contentDescription = textPage.text
|
||||
} else if (pageOffset < -textPage.height) {
|
||||
pageOffset += textPage.height.toInt()
|
||||
pageFactory.moveToNext(false)
|
||||
pageFactory.moveToNext(true)
|
||||
textPage = pageFactory.curPage
|
||||
upView?.invoke(textPage)
|
||||
contentDescription = textPage.text
|
||||
|
||||
@@ -39,8 +39,8 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
ReadBook.moveToNextChapter(upContent)
|
||||
} else {
|
||||
ReadBook.setPageIndex(pageIndex.plus(1))
|
||||
if (upContent) upContent(resetPageOffset = false)
|
||||
}
|
||||
if (upContent) upContent(resetPageOffset = false)
|
||||
true
|
||||
} else
|
||||
false
|
||||
@@ -52,8 +52,8 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
ReadBook.moveToPrevChapter(upContent)
|
||||
} else {
|
||||
ReadBook.setPageIndex(pageIndex.minus(1))
|
||||
if (upContent) upContent(resetPageOffset = false)
|
||||
}
|
||||
if (upContent) upContent(resetPageOffset = false)
|
||||
true
|
||||
} else
|
||||
false
|
||||
|
||||
@@ -138,7 +138,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
waitUpTocBooks.remove(bookUrl)
|
||||
upTocAdd(bookUrl)
|
||||
execute(context = upTocPool, executeContext = IO) {
|
||||
execute(context = upTocPool, executeContext = upTocPool) {
|
||||
kotlin.runCatching {
|
||||
val oldBook = book.copy()
|
||||
WebBook.runPreUpdateJs(source, book)
|
||||
@@ -170,10 +170,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
|
||||
appDb.bookDao.update(book)
|
||||
}
|
||||
}
|
||||
}.onCancel(upTocPool) {
|
||||
}.onCancel {
|
||||
upTocCancel(bookUrl)
|
||||
upTocCancel(book.bookUrl)
|
||||
}.onFinally(upTocPool) {
|
||||
}.onFinally {
|
||||
upTocFinally(bookUrl)
|
||||
upTocFinally(book.bookUrl)
|
||||
postUpBooksLiveData()
|
||||
|
||||
@@ -146,6 +146,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
swShowUnread.isChecked = AppConfig.showUnread
|
||||
swShowLastUpdateTime.isChecked = AppConfig.showLastUpdateTime
|
||||
swShowWaitUpBooks.isChecked = AppConfig.showWaitUpCount
|
||||
swShowBookshelfFastScroller.isChecked = AppConfig.showBookshelfFastScroller
|
||||
rgLayout.checkByIndex(bookshelfLayout)
|
||||
rgSort.checkByIndex(bookshelfSort)
|
||||
}
|
||||
@@ -168,6 +169,10 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
AppConfig.showWaitUpCount = swShowWaitUpBooks.isChecked
|
||||
activityViewModel.postUpBooksLiveData(true)
|
||||
}
|
||||
if (AppConfig.showBookshelfFastScroller != swShowBookshelfFastScroller.isChecked) {
|
||||
AppConfig.showBookshelfFastScroller = swShowBookshelfFastScroller.isChecked
|
||||
postEvent(EventBus.BOOKSHELF_REFRESH, "")
|
||||
}
|
||||
if (bookshelfSort != rgSort.getCheckedIndex()) {
|
||||
AppConfig.bookshelfSort = rgSort.getCheckedIndex()
|
||||
upSort()
|
||||
|
||||
@@ -71,6 +71,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
var bookSort = 0
|
||||
private set
|
||||
private var upLastUpdateTimeJob: Job? = null
|
||||
private var defaultScrollBarSize = 0
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
this.savedInstanceState = savedInstanceState
|
||||
@@ -86,6 +87,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
|
||||
private fun initRecyclerView() {
|
||||
binding.rvBookshelf.setEdgeEffectColor(primaryColor)
|
||||
defaultScrollBarSize = binding.rvBookshelf.scrollBarSize
|
||||
upFastScrollerBar()
|
||||
binding.refreshLayout.setColorSchemeColors(accentColor)
|
||||
binding.refreshLayout.setOnRefreshListener {
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
@@ -117,6 +120,16 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
startLastUpdateTimeJob()
|
||||
}
|
||||
|
||||
private fun upFastScrollerBar() {
|
||||
val showBookshelfFastScroller = AppConfig.showBookshelfFastScroller
|
||||
binding.rvBookshelf.setFastScrollEnabled(showBookshelfFastScroller)
|
||||
if (showBookshelfFastScroller) {
|
||||
binding.rvBookshelf.scrollBarSize = 0
|
||||
} else {
|
||||
binding.rvBookshelf.scrollBarSize = defaultScrollBarSize
|
||||
}
|
||||
}
|
||||
|
||||
fun upBookSort(sort: Int) {
|
||||
binding.root.post {
|
||||
arguments?.putInt("bookSort", sort)
|
||||
@@ -275,6 +288,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
observeEvent<String>(EventBus.BOOKSHELF_REFRESH) {
|
||||
booksAdapter.notifyDataSetChanged()
|
||||
startLastUpdateTimeJob()
|
||||
upFastScrollerBar()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user