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