mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
dbc6f83aaf
commit
a31ed9d631
@ -1,6 +1,5 @@
|
||||
package io.legado.app.help.book
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
@ -17,6 +16,7 @@ import kotlinx.coroutines.Dispatchers.IO
|
||||
import org.apache.commons.text.similarity.JaccardSimilarity
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.CopyOnWriteArraySet
|
||||
@ -141,7 +141,7 @@ object BookHelp {
|
||||
val bytes = analyzeUrl.getByteArrayAwait()
|
||||
//某些图片被加密,需要进一步解密
|
||||
ImageUtils.decode(
|
||||
src, bytes, isCover = false, bookSource, book
|
||||
src, bytes, isCover = false, bookSource, book
|
||||
)?.let {
|
||||
FileUtils.createFileIfNotExist(
|
||||
downloadDir,
|
||||
@ -177,9 +177,9 @@ object BookHelp {
|
||||
return suffix
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
@Throws(IOException::class, FileNotFoundException::class)
|
||||
fun getEpubFile(book: Book): ZipFile {
|
||||
val uri = Uri.parse(book.bookUrl)
|
||||
val uri = book.getLocalUri()
|
||||
if (uri.isContentScheme()) {
|
||||
FileUtils.createFolderIfNotExist(downloadDir, cacheEpubFolderName)
|
||||
val path = FileUtils.getPath(downloadDir, cacheEpubFolderName, book.originName)
|
||||
|
@ -501,6 +501,8 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
fun upPageAnim()
|
||||
|
||||
fun exit()
|
||||
|
||||
fun notifyBookChanged()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class EpubFile(var book: Book) {
|
||||
}.onFailure {
|
||||
AppLog.put("读取Epub文件失败\n${it.localizedMessage}", it)
|
||||
it.printOnDebug()
|
||||
}.getOrNull()
|
||||
}.getOrThrow()
|
||||
}
|
||||
|
||||
private fun getContent(chapter: BookChapter): String? {
|
||||
|
@ -46,9 +46,13 @@ abstract class BaseReadBookActivity :
|
||||
override val viewModel by viewModels<ReadBookViewModel>()
|
||||
var bottomDialog = 0
|
||||
private val selectBookFolderResult = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let {
|
||||
it.uri?.let { uri ->
|
||||
ReadBook.book?.let { book ->
|
||||
viewModel.loadChapterList(book)
|
||||
FileDoc.fromUri(uri, true).find(book.originName)?.let { doc ->
|
||||
book.bookUrl = doc.uri.toString()
|
||||
book.save()
|
||||
viewModel.loadChapterList(book)
|
||||
} ?: ReadBook.upMsg("找不到文件")
|
||||
}
|
||||
} ?: ReadBook.upMsg("没有权限访问")
|
||||
}
|
||||
@ -123,11 +127,12 @@ abstract class BaseReadBookActivity :
|
||||
if (toolBarHide) {
|
||||
setLightStatusBar(ReadBookConfig.durConfig.curStatusIconDark())
|
||||
} else {
|
||||
val statusBarColor = if (AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0) {
|
||||
ReadBookConfig.bgMeanColor
|
||||
} else {
|
||||
ThemeStore.statusBarColor(this, AppConfig.isTransparentStatusBar)
|
||||
}
|
||||
val statusBarColor =
|
||||
if (AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0) {
|
||||
ReadBookConfig.bgMeanColor
|
||||
} else {
|
||||
ThemeStore.statusBarColor(this, AppConfig.isTransparentStatusBar)
|
||||
}
|
||||
setLightStatusBar(ColorUtils.isColorLight(statusBarColor))
|
||||
}
|
||||
}
|
||||
@ -202,7 +207,8 @@ abstract class BaseReadBookActivity :
|
||||
* 保持亮屏
|
||||
*/
|
||||
fun keepScreenOn(on: Boolean) {
|
||||
val isScreenOn = (window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
|
||||
val isScreenOn =
|
||||
(window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
|
||||
if (on == isScreenOn) return
|
||||
if (on) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
@ -167,7 +167,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible
|
||||
private val nextPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.NEXT) } }
|
||||
private val prevPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.PREV) } }
|
||||
private var isFirstResume = true
|
||||
private var bookChanged = false
|
||||
|
||||
//恢复跳转前进度对话框的交互结果
|
||||
private var confirmRestoreProcess: Boolean? = null
|
||||
@ -181,6 +181,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
binding.cursorRight.setOnTouchListener(this)
|
||||
window.setBackgroundDrawable(null)
|
||||
upScreenTimeOut()
|
||||
ReadBook.callBack?.notifyBookChanged()
|
||||
ReadBook.callBack = this
|
||||
}
|
||||
|
||||
@ -204,8 +205,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
ReadBook.readStartTime = System.currentTimeMillis()
|
||||
val bookUrl = intent.getStringExtra("bookUrl")
|
||||
if (!isFirstResume && ReadBook.book?.bookUrl != bookUrl) {
|
||||
if (bookChanged) {
|
||||
bookChanged = false
|
||||
ReadBook.callBack = this
|
||||
viewModel.initData(intent)
|
||||
} else {
|
||||
@ -218,9 +219,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
upSystemUiVisibility()
|
||||
registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter)
|
||||
binding.readView.upTime()
|
||||
if (isFirstResume) {
|
||||
isFirstResume = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -788,6 +786,10 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
} ?: super.finish()
|
||||
}
|
||||
|
||||
override fun notifyBookChanged() {
|
||||
bookChanged = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面改变
|
||||
*/
|
||||
|
@ -36,6 +36,7 @@ import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
|
||||
/**
|
||||
@ -144,7 +145,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}.onError {
|
||||
when (it) {
|
||||
is SecurityException -> {
|
||||
is SecurityException, is FileNotFoundException -> {
|
||||
permissionDenialLiveData.postValue(1)
|
||||
}
|
||||
else -> {
|
||||
|
@ -18,11 +18,8 @@ import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.longToastOnUi
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
@ -75,7 +72,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
val replaceRules = ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
||||
val useReplace = AppConfig.tocUiUseReplace && book.getUseReplaceRule()
|
||||
val items = getItems()
|
||||
async {
|
||||
launch {
|
||||
for (i in startIndex until items.size) {
|
||||
val item = items[i]
|
||||
if (displayTitleMap[item.title] == null) {
|
||||
@ -88,8 +85,8 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
async {
|
||||
}
|
||||
launch {
|
||||
for (i in startIndex downTo 0) {
|
||||
val item = items[i]
|
||||
if (displayTitleMap[item.title] == null) {
|
||||
@ -102,7 +99,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
|
||||
tabLayout.setSelectedTabIndicatorColor(accentColor)
|
||||
binding.viewPager.adapter = TabFragmentPageAdapter()
|
||||
tabLayout.setupWithViewPager(binding.viewPager)
|
||||
tabLayout.tabGravity = TabLayout.GRAVITY_CENTER
|
||||
viewModel.bookData.observe(this) {
|
||||
menu?.setGroupVisible(R.id.menu_group_text, it.isLocalTxt)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user