Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
f21e5df7cd
Merge 1535b668ae into 72ff30b1ea 2024-05-31 22:54:32 +08:00
10 changed files with 23 additions and 73 deletions

View File

@ -27,15 +27,6 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio
return Coroutine.async(scope, context, start, executeContext, block)
}
fun <T> executeLazy(
scope: CoroutineScope = viewModelScope,
context: CoroutineContext = Dispatchers.IO,
executeContext: CoroutineContext = Dispatchers.Main,
block: suspend CoroutineScope.() -> T
): Coroutine<T> {
return Coroutine.async(scope, context, CoroutineStart.LAZY, executeContext, block)
}
fun <R> submit(
scope: CoroutineScope = viewModelScope,
context: CoroutineContext = Dispatchers.IO,

View File

@ -188,7 +188,6 @@ class ContentProcessor private constructor(
mContent = mContent.replace('\u00A0', ' ')
}
val contents = arrayListOf<String>()
val paragraphIndent = ReadBookConfig.paragraphIndent
mContent.split("\n").forEach { str ->
val paragraph = str.trim {
it.code <= 0x20 || it == ' '
@ -197,14 +196,10 @@ class ContentProcessor private constructor(
if (contents.isEmpty() && includeTitle) {
contents.add(paragraph)
} else {
contents.add("$paragraphIndent$paragraph")
contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
}
}
}
if (contents.isEmpty()) {
contents.add("${paragraphIndent}加载正文失败")
contents.add("${paragraphIndent}内容处理后为空")
}
return BookContent(sameTitleRemoved, contents, effectiveReplaceRules)
}

View File

@ -81,10 +81,6 @@ class PermissionActivity : AppCompatActivity() {
kotlin.runCatching {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
intent.setData(Uri.parse("package:$packageName"))
intent.setClassName(
"com.android.settings",
"com.android.settings.fuelgauge.RequestIgnoreBatteryOptimizations"
)
settingActivityResult.launch(intent)
}
}

View File

@ -7,6 +7,7 @@ import android.net.wifi.WifiManager
import android.os.Build
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
@ -22,7 +23,6 @@ import io.legado.app.utils.postEvent
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.sendToClip
import io.legado.app.utils.servicePendingIntent
import io.legado.app.utils.startForegroundServiceCompat
import io.legado.app.utils.startService
import io.legado.app.utils.stopService
import io.legado.app.utils.toastOnUi
@ -45,7 +45,7 @@ class WebService : BaseService() {
fun startForeground(context: Context) {
val intent = Intent(context, WebService::class.java)
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
fun stop(context: Context) {
@ -94,13 +94,7 @@ class WebService : BaseService() {
val addressList = NetworkUtils.getLocalIPAddress()
notificationList.clear()
if (addressList.any()) {
notificationList.addAll(addressList.map { address ->
getString(
R.string.http_ip,
address.hostAddress,
getPort()
)
})
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
hostAddress = notificationList.first()
} else {
hostAddress = getString(R.string.network_connection_unavailable)
@ -160,13 +154,7 @@ class WebService : BaseService() {
httpServer?.start()
webSocketServer?.start(1000 * 30) // 通信超时设置
notificationList.clear()
notificationList.addAll(addressList.map { address ->
getString(
R.string.http_ip,
address.hostAddress,
getPort()
)
})
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
hostAddress = notificationList.first()
isRun = true
postEvent(EventBus.WEB_SERVICE, hostAddress)

View File

@ -13,7 +13,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.alert
@ -23,14 +22,7 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.import.BaseImportBookActivity
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.utils.ArchiveUtils
import io.legado.app.utils.FileDoc
import io.legado.app.utils.gone
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.isUri
import io.legado.app.utils.launch
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.visible
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job
@ -183,7 +175,6 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
selectFolder.launch()
}
}
else -> initRootPath(rootUri.path!!)
}
}
@ -300,9 +291,7 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
override fun startRead(fileDoc: FileDoc) {
if (!ArchiveUtils.isArchive(fileDoc.name)) {
appDb.bookDao.getBookByFileName(fileDoc.name)?.let {
startReadBook(it.bookUrl)
}
startReadBook(fileDoc.toString())
} else {
onArchiveFileClick(fileDoc)
}

View File

@ -170,11 +170,7 @@ class RemoteBookActivity : BaseImportBookActivity<RemoteBookViewModel>(),
private fun upPath() {
binding.tvGoBack.isEnabled = viewModel.dirList.isNotEmpty()
var path = if (viewModel.isDefaultWebdav) {
"books" + File.separator
} else {
File.separator
}
var path = "books" + File.separator
viewModel.dirList.forEach {
path = path + it.filename + File.separator
}

View File

@ -90,17 +90,14 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
}.flowOn(Dispatchers.IO)
private var remoteBookWebDav: RemoteBookWebDav? = null
var isDefaultWebdav = false
fun initData(onSuccess: () -> Unit) {
execute {
isDefaultWebdav = false
appDb.serverDao.get(AppConfig.remoteServerId)?.getWebDavConfig()?.let {
val authorization = Authorization(it)
remoteBookWebDav = RemoteBookWebDav(it.url, authorization, AppConfig.remoteServerId)
return@execute
}
isDefaultWebdav = true
remoteBookWebDav = AppWebDav.defaultBookWebDav
?: throw NoStackTraceException("webDav没有配置")
}.onError {
@ -111,7 +108,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
}
fun loadRemoteBookList(path: String?, loadCallback: (loading: Boolean) -> Unit) {
executeLazy {
execute {
val bookWebDav = remoteBookWebDav
?: throw NoStackTraceException("没有配置webDav")
dataCallback?.clear()
@ -125,7 +122,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
loadCallback.invoke(true)
}.onFinally {
loadCallback.invoke(false)
}.start()
}
}
fun addToBookshelf(remoteBooks: HashSet<RemoteBook>, finally: () -> Unit) {

View File

@ -278,7 +278,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (textPos.compare(selectEnd) <= 0) {
selectStart.upData(pos = textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end,
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
@ -318,7 +318,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
selectEndMoveIndex(selectStart)
selectStart.upData(textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end,
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
@ -498,7 +498,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val textLine = relativePage(relativePagePos).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex)
upSelectedStart(
if (charIndex < textLine.columns.size) textColumn.start else textColumn.end,
if (charIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset(relativePagePos),
textLine.lineTop + relativeOffset(relativePagePos)
)
@ -534,7 +534,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
private fun upSelectChars() {
if (!selectStart.isSelected() && !selectEnd.isSelected()) {
if (!selectStart.isSelected() || !selectEnd.isSelected()) {
return
}
val last = if (callBack.isScroll) 2 else 0
@ -621,7 +621,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (column is TextColumn) {
when {
compareStart == 0 -> {
if (textPos.columnIndex < textLine.columns.size) {
if (textPos.columnIndex < textLine.columns.lastIndex) {
builder.append(column.charData)
}
if (

View File

@ -154,8 +154,8 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
*/
private fun calcNextPageOffset(): Int {
val visibleHeight = ChapterProvider.visibleHeight
val book = ReadBook.book
if (book == null || book.isImage) {
val book = ReadBook.book!!
if (book.isImage) {
return -visibleHeight
}
val visiblePage = readView.getCurVisiblePage()
@ -170,8 +170,8 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
private fun calcPrevPageOffset(): Int {
val visibleHeight = ChapterProvider.visibleHeight
val book = ReadBook.book
if (book == null || book.isImage) {
val book = ReadBook.book!!
if (book.isImage) {
return visibleHeight
}
val visiblePage = readView.getCurVisiblePage()

View File

@ -106,13 +106,11 @@ public class PackageDocumentReader extends PackageDocumentBase {
NodeList originItemElements = manifestElement
.getElementsByTagNameNS(NAMESPACE_OPF, OPFTags.item);
for (int i = 0; i < originItemElements.getLength(); i++) {
Element itemElement = (Element) originItemElements.item(i).cloneNode(false);
String href = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
String resolvedHref = packagePath.resolve(href).toString();
itemElement.setAttribute("href", resolvedHref);
Element itemElement = (Element) originItemElements.item(i);
fixedElements.add(itemElement);
String href = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
try {
href = URLDecoder.decode(resolvedHref, Constants.CHARACTER_ENCODING);
href = URLDecoder.decode(packagePath.resolve(href).toString(), Constants.CHARACTER_ENCODING);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, e.getMessage());
}
@ -179,7 +177,7 @@ public class PackageDocumentReader extends PackageDocumentBase {
.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
try {
href = URLDecoder.decode(href, Constants.CHARACTER_ENCODING);
href = URLDecoder.decode(packagePath.resolve(href).toString(), Constants.CHARACTER_ENCODING);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, e.getMessage());
}