Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
11af01cb4b
Merge 4abac380b5 into 7a8b2fe77a 2024-05-06 04:21:54 +00:00
44 changed files with 191 additions and 263 deletions

View File

@ -27,7 +27,7 @@ jobs:
with:
node-version: 16
- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:

1
.gitignore vendored
View File

@ -3,7 +3,6 @@
local.properties
.DS_Store
/build
build/
/captures
.externalNativeBuild
/release

View File

@ -1,7 +1,7 @@
[
{
"uploadUrl": "https://sy.mgz6.com/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.com/shuyuan/' + result",
"uploadUrl": "https://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.cc/shuyuan/' + result",
"summary": "喵公子网盘①(有效期7天)",
"compress": false
},

View File

@ -47,7 +47,7 @@ java.searchBook(bookName: string)
* 添加书架
```js
java.addBook(bookUrl: String)
java.addBook(bookUrl)
```
### [AnalyzeUrl](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt) 部分函数
@ -181,11 +181,6 @@ java.get*StringContent(url: String, path: String, charsetName: String): String
java.get*ByteArrayContent(url: String, path: String): ByteArray?
```
* URI编码
```js
java.encodeURI(str: String) //默认enc="UTF-8"
java.encodeURI(str: String, enc: String)
```
* base64
> flags参数可省略默认Base64.NO_WRAP查看[flags参数说明](https://blog.csdn.net/zcmain/article/details/97051870)
@ -389,23 +384,16 @@ source.getVariable()
* 登录头操作
```js
获取登录头
source.getLoginHeader()
获取登录头某一键值
source.getLoginHeaderMap().get(key: String)
保存登录头
source.putLoginHeader(header: String)
清除登录头
source.removeLoginHeader()
```
* 用户登录信息操作
> 使用`登录UI`规则并成功登录阅读自动加密保存登录UI规则中除type为button的信息
```js
login函数获取登录信息
source.getLoginInfo()
login函数获取登录信息键值
source.getLoginInfoMap().get(key: String)
清除登录信息
source.removeLoginInfo()
```
## cookie对象的部分可用函数
@ -414,10 +402,6 @@ source.removeLoginInfo()
cookie.getCookie(url)
获取cookie某一键值
cookie.getKey(url,key)
设置cookie
cookie.setCookie(url,cookie)
替换cookie
cookie.replaceCookie(url,cookie)
删除cookie
cookie.removeCookie(url)
```

View File

@ -33,7 +33,7 @@ abstract class BaseService : LifecycleService() {
override fun onCreate() {
super.onCreate()
LifecycleHelp.onServiceCreate(this)
checkPermission()
checkNotificationPermission()
}
@CallSuper
@ -71,9 +71,9 @@ abstract class BaseService : LifecycleService() {
}
/**
* 检测通知权限和后台权限
* 检测通知权限
*/
private fun checkPermission() {
private fun checkNotificationPermission() {
PermissionsCompat.Builder()
.addPermissions(Permissions.POST_NOTIFICATIONS)
.rationale(R.string.notification_permission_rationale)
@ -83,9 +83,5 @@ abstract class BaseService : LifecycleService() {
}
}
.request()
PermissionsCompat.Builder()
.addPermissions(Permissions.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.rationale(R.string.ignore_battery_permission_rationale)
.request()
}
}

View File

@ -284,6 +284,14 @@ data class Book(
}
}
fun getBookSource(): BookSource? {
return appDb.bookSourceDao.getBookSource(origin)
}
fun isLocalModified(): Boolean {
return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime
}
fun toSearchBook() = SearchBook(
name = name,
author = author,

View File

@ -73,7 +73,7 @@ object AppWebDav {
WebDav(bookProgressUrl, mAuthorization).makeAsDir()
WebDav(exportsWebDavUrl, mAuthorization).makeAsDir()
WebDav(bgWebDavUrl, mAuthorization).makeAsDir()
val rootBooksUrl = "${rootWebDavUrl}books/"
val rootBooksUrl = "${rootWebDavUrl}books"
defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization)
authorization = mAuthorization
}

View File

@ -5,26 +5,17 @@ package io.legado.app.help.book
import android.net.Uri
import com.script.SimpleBindings
import com.script.rhino.RhinoScriptEngine
import io.legado.app.constant.AppLog
import io.legado.app.constant.BookSourceType
import io.legado.app.constant.BookType
import io.legado.app.constant.*
import io.legado.app.data.appDb
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.FileDoc
import io.legado.app.utils.exists
import io.legado.app.utils.find
import io.legado.app.utils.inputStream
import io.legado.app.utils.isUri
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.*
import splitties.init.appCtx
import java.io.File
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.set
val Book.isAudio: Boolean
@ -232,14 +223,6 @@ fun Book.sync(oldBook: Book) {
canUpdate = curBook.canUpdate
}
fun Book.getBookSource(): BookSource? {
return appDb.bookSourceDao.getBookSource(origin)
}
fun Book.isLocalModified(): Boolean {
return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime
}
fun Book.isSameNameAuthor(other: Any?): Boolean {
if (other is BaseBook) {
return name == other.name && author == other.author

View File

@ -1,6 +1,5 @@
package io.legado.app.lib.permission
import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Build
@ -25,7 +24,6 @@ class PermissionActivity : AppCompatActivity() {
finish()
}
@SuppressLint("BatteryLife")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val rationale = intent.getStringExtra(KEY_RATIONALE)
@ -74,16 +72,6 @@ class PermissionActivity : AppCompatActivity() {
}
}
}
Request.TYPE_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS -> showSettingDialog(
permissions, rationale
) {
kotlin.runCatching {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
intent.setData(Uri.parse("package:$packageName"))
settingActivityResult.launch(intent)
}
}
}
onBackPressedDispatcher.addCallback(this) {

View File

@ -43,9 +43,6 @@ object Permissions {
const val ACCESS_MEDIA_LOCATION = "android.permission.ACCESS_MEDIA_LOCATION"
const val REQUEST_IGNORE_BATTERY_OPTIMIZATIONS =
"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
object Group {
val STORAGE = if (isManageExternalStorage()) {
arrayOf(MANAGE_EXTERNAL_STORAGE)

View File

@ -9,7 +9,6 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import io.legado.app.utils.startActivity
import splitties.init.appCtx
import splitties.systemservices.powerManager
@Suppress("MemberVisibilityCanBePrivate")
internal class Request : OnRequestPermissionsResultCallback {
@ -74,10 +73,6 @@ internal class Request : OnRequestPermissionsResultCallback {
}
} else if (deniedPermissions.contains(Permissions.POST_NOTIFICATIONS)) {
toNotificationSetting()
} else if (deniedPermissions.contains(Permissions.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
toIgnoreBatterySetting()
}
} else if (deniedPermissions.size > 1) {
appCtx.startActivity<PermissionActivity> {
putExtra(PermissionActivity.KEY_RATIONALE, rationale)
@ -103,7 +98,6 @@ internal class Request : OnRequestPermissionsResultCallback {
deniedPermissionList.add(permission)
}
}
Permissions.MANAGE_EXTERNAL_STORAGE -> {
if (Permissions.isManageExternalStorage()) {
if (!Environment.isExternalStorageManager()) {
@ -111,15 +105,6 @@ internal class Request : OnRequestPermissionsResultCallback {
}
}
}
Permissions.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!powerManager.isIgnoringBatteryOptimizations(appCtx.packageName)) {
deniedPermissionList.add(permission)
}
}
}
else -> {
if (
ContextCompat.checkSelfPermission(appCtx, permission)
@ -180,18 +165,6 @@ internal class Request : OnRequestPermissionsResultCallback {
}
}
private fun toIgnoreBatterySetting() {
appCtx.startActivity<PermissionActivity> {
putExtra(PermissionActivity.KEY_RATIONALE, rationale)
putExtra(
PermissionActivity.KEY_INPUT_REQUEST_TYPE,
TYPE_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
}
}
override fun onRequestPermissionsResult(
permissions: Array<String>,
grantResults: IntArray
@ -223,6 +196,5 @@ internal class Request : OnRequestPermissionsResultCallback {
const val TYPE_REQUEST_SETTING = 2
const val TYPE_MANAGE_ALL_FILES_ACCESS = 3
const val TYPE_REQUEST_NOTIFICATIONS = 4
const val TYPE_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = 5
}
}

View File

@ -71,8 +71,6 @@ open class WebDav(
<resourcetype />
</prop>
</propfind>"""
private const val DEFAULT_CONTENT_TYPE = "application/octet-stream"
}
@ -180,14 +178,13 @@ open class WebDav(
//依然是优化支持 caddy 自建的 WebDav ,其目录后缀都为“/”, 所以删除“/”的判定,不然无法获取该目录项
val href = element.findNS("href", ns)[0].text().replace("+", "%2B")
val hrefDecode = URLDecoder.decode(href, "UTF-8")
.removeSuffix("/")
val fileName = hrefDecode.substringAfterLast("/")
val webDavFile: WebDav
try {
val urlName = hrefDecode.ifEmpty {
url.file.replace("/", "")
}
val displayName = element
.findNS("displayname", ns)
.firstOrNull()?.text().orEmpty()
val contentType = element
.findNS("getcontenttype", ns)
.firstOrNull()?.text().orEmpty()
@ -209,7 +206,7 @@ open class WebDav(
webDavFile = WebDavFile(
fullURL,
authorization,
displayName = displayName,
displayName = fileName,
urlName = urlName,
size = size,
contentType = contentType,
@ -306,12 +303,18 @@ open class WebDav(
* 上传文件
*/
@Throws(WebDavException::class)
suspend fun upload(localPath: String, contentType: String = DEFAULT_CONTENT_TYPE) {
suspend fun upload(
localPath: String,
contentType: String = "application/octet-stream"
) {
upload(File(localPath), contentType)
}
@Throws(WebDavException::class)
suspend fun upload(file: File, contentType: String = DEFAULT_CONTENT_TYPE) {
suspend fun upload(
file: File,
contentType: String = "application/octet-stream"
) {
kotlin.runCatching {
withContext(IO) {
if (!file.exists()) throw WebDavException("文件不存在")
@ -332,7 +335,7 @@ open class WebDav(
}
@Throws(WebDavException::class)
suspend fun upload(byteArray: ByteArray, contentType: String = DEFAULT_CONTENT_TYPE) {
suspend fun upload(byteArray: ByteArray, contentType: String) {
// 务必注意RequestBody不要嵌套不然上传时内容可能会被追加多余的文件信息
kotlin.runCatching {
withContext(IO) {
@ -352,7 +355,7 @@ open class WebDav(
}
@Throws(WebDavException::class)
suspend fun upload(uri: Uri, contentType: String = DEFAULT_CONTENT_TYPE) {
suspend fun upload(uri: Uri, contentType: String) {
// 务必注意RequestBody不要嵌套不然上传时内容可能会被追加多余的文件信息
kotlin.runCatching {
withContext(IO) {

View File

@ -11,7 +11,6 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.getBookSource
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.service.AudioPlayService
import io.legado.app.utils.postEvent

View File

@ -3,6 +3,7 @@ package io.legado.app.model
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.content.ContextCompat
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
@ -15,7 +16,6 @@ import io.legado.app.service.TTSReadAloudService
import io.legado.app.utils.LogUtils
import io.legado.app.utils.StringUtils
import io.legado.app.utils.postEvent
import io.legado.app.utils.startForegroundServiceCompat
import io.legado.app.utils.toastOnUi
import splitties.init.appCtx
@ -56,7 +56,7 @@ object ReadAloud {
intent.putExtra("startPos", startPos)
LogUtils.d("ReadAloud", intent.toString())
try {
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
} catch (e: Exception) {
val msg = "启动朗读服务出错\n${e.localizedMessage}"
AppLog.put(msg, e)
@ -81,7 +81,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.pause
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -89,7 +89,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.resume
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -97,7 +97,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.stop
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -105,7 +105,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.prevParagraph
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -113,7 +113,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.nextParagraph
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -121,7 +121,7 @@ object ReadAloud {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.upTtsSpeechRate
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}
@ -130,7 +130,7 @@ object ReadAloud {
val intent = Intent(context, aloudClass)
intent.action = IntentAction.setTimer
intent.putExtra("minute", minute)
context.startForegroundServiceCompat(intent)
ContextCompat.startForegroundService(context, intent)
}
}

View File

@ -93,7 +93,7 @@ object ReadBook : CoroutineScope by MainScope() {
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
contentProcessor = ContentProcessor.get(book)
durChapterIndex = book.durChapterIndex
durChapterIndex = min(book.durChapterIndex, chapterSize - 1).coerceAtLeast(0)
durChapterPos = book.durChapterPos
isLocalBook = book.isLocal
clearTextChapter()

View File

@ -179,14 +179,6 @@ class EpubFile(var book: Book) {
elements.select("img[src=\"cover.jpeg\"]").forEachIndexed { i, it ->
if (i > 0) it.remove()
}
elements.select("img").forEach {
if (it.attributesSize() <= 1) {
return@forEach
}
val src = it.attr("src")
it.clearAttributes()
it.attr("src", src)
}
val tag = Book.rubyTag
if (book.getDelTag(tag)) {
elements.select("rp, rt").remove()

View File

@ -14,7 +14,10 @@ import io.legado.app.model.analyzeRule.CustomUrl
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.readBytes
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx
import java.io.File
class RemoteBookWebDav(
val rootBookUrl: String,
@ -68,17 +71,20 @@ class RemoteBookWebDav(
override suspend fun upload(book: Book) {
if (!NetworkUtils.isAvailable()) throw NoStackTraceException("网络不可用")
val localBookUri = Uri.parse(book.bookUrl)
val putUrl = "$rootBookUrl${book.originName}"
val putUrl = "$rootBookUrl${File.separator}${book.originName}"
val webDav = WebDav(putUrl, authorization)
if (localBookUri.isContentScheme()) {
webDav.upload(localBookUri)
webDav.upload(
byteArray = localBookUri.readBytes(appCtx),
contentType = "application/octet-stream"
)
} else {
webDav.upload(localBookUri.path!!)
}
book.origin = BookType.webDavTag + CustomUrl(putUrl)
.putAttribute("serverID", serverID)
.toString()
book.update()
book.save()
}
override suspend fun delete(remoteBookUrl: String) {

View File

@ -96,11 +96,12 @@ class WebService : BaseService() {
if (addressList.any()) {
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
hostAddress = notificationList.first()
startForegroundNotification()
} else {
hostAddress = getString(R.string.network_connection_unavailable)
notificationList.add(hostAddress)
startForegroundNotification()
}
startForegroundNotification()
postEvent(EventBus.WEB_SERVICE, hostAddress)
}
}
@ -183,7 +184,6 @@ class WebService : BaseService() {
*/
override fun startForegroundNotification() {
val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_web_service_noti)
.setOngoing(true)
.setContentTitle(getString(R.string.web_service))
@ -196,6 +196,7 @@ class WebService : BaseService() {
getString(R.string.cancel),
servicePendingIntent<WebService>(IntentAction.stop)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()
startForeground(NotificationId.WebService, notification)
}

View File

@ -11,7 +11,6 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.help.book.getBookSource
import io.legado.app.help.book.removeType
import io.legado.app.model.AudioPlay
import io.legado.app.model.AudioPlay.durChapter

View File

@ -20,7 +20,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import java.util.Collections
import java.util.*
class RemoteBookViewModel(application: Application) : BaseViewModel(application) {
var sortKey = RemoteBookSort.Default
@ -78,7 +78,6 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
}
return@sortedWith compare
}
else -> list.sortedWith { o1, o2 ->
val compare = -compareValues(o1.isDir, o2.isDir)
if (compare == 0) {
@ -133,8 +132,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
val downloadBookUri = bookWebDav.downloadRemoteBook(remoteBook)
LocalBook.importFiles(downloadBookUri).forEach { book ->
book.origin = BookType.webDavTag + CustomUrl(remoteBook.path)
.putAttribute("serverID", bookWebDav.serverID)
.toString()
.putAttribute(
"serverID",
bookWebDav.serverID
).toString()
book.save()
}
remoteBook.isOnBookShelf = true
@ -151,7 +152,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
}
fun updateCallBackFlow(filterKey: String?) {
dataCallback?.screen(filterKey)
dataCallback?.screen(filterKey)
}
interface DataCallback {

View File

@ -303,7 +303,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 {
@ -1302,7 +1304,7 @@ class ReadBookActivity : BaseReadBookActivity(),
when (dialogId) {
TEXT_COLOR -> {
setCurTextColor(color)
postEvent(EventBus.UP_CONFIG, arrayListOf(2, 6, 9, 11))
postEvent(EventBus.UP_CONFIG, arrayListOf(2, 9, 11))
}
BG_COLOR -> {
@ -1498,9 +1500,9 @@ class ReadBookActivity : BaseReadBookActivity(),
5 -> if (isInitFinish) ReadBook.loadContent(resetPageOffset = false)
6 -> readView.upContent(resetPageOffset = false)
8 -> ChapterProvider.upStyle()
9 -> readView.invalidateTextPage()
9 -> binding.readView.invalidateTextPage()
10 -> ChapterProvider.upLayout()
11 -> readView.submitRenderTask()
11 -> binding.readView.submitRenderTask()
}
}
}
@ -1541,10 +1543,10 @@ class ReadBookActivity : BaseReadBookActivity(),
viewModel.searchResultList = it
}
observeEvent<Boolean>(EventBus.UPDATE_READ_ACTION_BAR) {
readMenu.reset()
binding.readMenu.reset()
}
observeEvent<Boolean>(EventBus.UP_SEEK_BAR) {
readMenu.upSeekBar()
binding.readMenu.upSeekBar()
}
}

View File

@ -20,7 +20,6 @@ import io.legado.app.help.AppWebDav
import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.isLocalModified
import io.legado.app.help.book.removeType
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
@ -116,9 +115,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.loadOrUpContent()
checkLocalBookFileExist(book)
} else {
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
}
ReadBook.loadContent(resetPageOffset = false)
checkLocalBookFileExist(book)
}
@ -538,7 +534,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
override fun onCleared() {
super.onCleared()
if (BaseReadAloudService.isRun && BaseReadAloudService.pause) {
if (BaseReadAloudService.pause) {
ReadAloud.stop(context)
}
}

View File

@ -159,7 +159,6 @@ class MoreConfigDialog : DialogFragment() {
}
PreferKey.optimizeRender -> {
ChapterProvider.upStyle()
ReadBook.callBack?.upPageAnim(true)
ReadBook.loadContent(false)
}

View File

@ -200,7 +200,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
override fun selectFont(path: String) {
if (path != ReadBookConfig.textFont) {
ReadBookConfig.textFont = path
postEvent(EventBus.UP_CONFIG, arrayListOf(2, 5))
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
}
}

View File

@ -278,18 +278,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (textPos.compare(selectEnd) <= 0) {
selectStart.upData(pos = textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
if (textPos.isTouch) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
} else {
reverseStartCursor = true
reverseEndCursor = false
selectEnd.columnIndex++
selectStartMoveIndex(selectEnd)
selectEnd.upData(textPos)
upSelectedEnd(
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
}
@ -308,17 +307,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (textPos.compare(selectStart) >= 0) {
selectEnd.upData(textPos)
upSelectedEnd(
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
} else {
reverseEndCursor = true
reverseStartCursor = false
selectStart.columnIndex--
selectEndMoveIndex(selectStart)
selectStart.upData(textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
if (textPos.isTouch) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
@ -420,11 +418,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
val isLast = columns.first().start < x
val charIndex = if (isLast) columns.lastIndex + 1 else -1
val charIndex = if (isLast) columns.lastIndex else 0
val textColumn = if (isLast) columns.last() else columns.first()
touched.invoke(
relativeOffset,
TextPos(relativePos, lineIndex, charIndex),
TextPos(relativePos, lineIndex, charIndex, false, isLast),
textPage, textLine, textColumn
)
return
@ -491,14 +489,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
relativePagePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean = false
) {
selectStart.relativePagePos = relativePagePos
selectStart.lineIndex = lineIndex
selectStart.columnIndex = charIndex
selectStart.isTouch = isTouch
selectStart.isLast = isLast
val textLine = relativePage(relativePagePos).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex)
upSelectedStart(
if (charIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
textColumn.start,
textLine.lineBottom + relativeOffset(relativePagePos),
textLine.lineTop + relativeOffset(relativePagePos)
)
@ -506,7 +508,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
fun selectStartMoveIndex(textPos: TextPos) = textPos.run {
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex)
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
}
/**
@ -516,21 +518,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
relativePage: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean = false
) {
selectEnd.relativePagePos = relativePage
selectEnd.lineIndex = lineIndex
selectEnd.columnIndex = charIndex
selectEnd.isTouch = isTouch
selectEnd.isLast = isLast
val textLine = relativePage(relativePage).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex)
upSelectedEnd(
if (charIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset(relativePage)
)
upSelectedEnd(textColumn.end, textLine.lineBottom + relativeOffset(relativePage))
upSelectChars()
}
fun selectEndMoveIndex(textPos: TextPos) = textPos.run {
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex)
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
}
private fun upSelectChars() {
@ -550,8 +553,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val compareStart = textPos.compare(selectStart)
val compareEnd = textPos.compare(selectEnd)
column.selected = when {
compareStart == 0 -> true
compareEnd == 0 -> true
compareStart == 0 -> selectStart.isTouch
compareEnd == 0 -> selectEnd.isTouch || selectEnd.isLast
compareStart > 0 && compareEnd < 0 -> true
else -> false
}
@ -621,19 +624,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (column is TextColumn) {
when {
compareStart == 0 -> {
if (textPos.columnIndex < textLine.columns.lastIndex) {
if (selectStart.isTouch) {
builder.append(column.charData)
}
if (
textLine.isParagraphEnd
&& charIndex == textLine.columns.lastIndex
&& charIndex == textLine.charSize - 1
&& compareEnd != 0
) {
builder.append("\n")
}
}
compareEnd == 0 -> if (textPos.columnIndex > -1) {
compareEnd == 0 -> if (selectEnd.isTouch || selectEnd.isLast) {
builder.append(column.charData)
}
@ -641,7 +644,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
builder.append(column.charData)
if (
textLine.isParagraphEnd
&& charIndex == textLine.columns.lastIndex
&& charIndex == textLine.charSize - 1
) {
builder.append("\n")
}

View File

@ -404,9 +404,17 @@ class PageView(context: Context) : FrameLayout(context) {
fun selectStartMoveIndex(
relativePagePos: Int,
lineIndex: Int,
charIndex: Int
charIndex: Int,
isTouch: Boolean = true,
isLast: Boolean = false
) {
binding.contentTextView.selectStartMoveIndex(relativePagePos, lineIndex, charIndex)
binding.contentTextView.selectStartMoveIndex(
relativePagePos,
lineIndex,
charIndex,
isTouch,
isLast
)
}
fun selectStartMoveIndex(textPos: TextPos) {
@ -420,9 +428,17 @@ class PageView(context: Context) : FrameLayout(context) {
fun selectEndMoveIndex(
relativePagePos: Int,
lineIndex: Int,
charIndex: Int
charIndex: Int,
isTouch: Boolean = true,
isLast: Boolean = false
) {
binding.contentTextView.selectEndMoveIndex(relativePagePos, lineIndex, charIndex)
binding.contentTextView.selectEndMoveIndex(
relativePagePos,
lineIndex,
charIndex,
isTouch,
isLast
)
}
fun selectEndMoveIndex(textPos: TextPos) {

View File

@ -200,7 +200,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
MotionEvent.ACTION_MOVE -> {
if (!pressDown) return true
val absX = abs(startX - event.x)
val absY = abs(startY - event.y)
if (!isMove) {
@ -444,13 +443,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
curPage.selectText(x, y) { textPos ->
val compare = initialTextPos.compare(textPos)
when {
compare > 0 -> {
compare >= 0 -> {
curPage.selectStartMoveIndex(textPos)
curPage.selectEndMoveIndex(
initialTextPos.relativePagePos,
initialTextPos.lineIndex,
initialTextPos.columnIndex - 1
)
curPage.selectEndMoveIndex(initialTextPos)
}
else -> {

View File

@ -11,22 +11,30 @@ data class TextPos(
var relativePagePos: Int,
var lineIndex: Int,
var columnIndex: Int,
var isTouch: Boolean = true,
var isLast: Boolean = false
) {
fun upData(
relativePos: Int,
lineIndex: Int,
charIndex: Int,
isTouch: Boolean,
isLast: Boolean
) {
this.relativePagePos = relativePos
this.lineIndex = lineIndex
this.columnIndex = charIndex
this.isTouch = isTouch
this.isLast = isLast
}
fun upData(pos: TextPos) {
relativePagePos = pos.relativePagePos
lineIndex = pos.lineIndex
columnIndex = pos.columnIndex
isTouch = pos.isTouch
isLast = pos.isLast
}
fun compare(pos: TextPos): Int {
@ -57,6 +65,8 @@ data class TextPos(
relativePagePos = 0
lineIndex = -1
columnIndex = -1
isTouch = true
isLast = false
}
fun isSelected(): Boolean {

View File

@ -881,9 +881,7 @@ object ChapterProvider {
tPaint.typeface = titleFont
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx()
tPaint.isAntiAlias = true
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) {
tPaint.isLinearText = true
}
tPaint.isLinearText = true
//正文
val cPaint = TextPaint()
cPaint.color = ReadBookConfig.textColor
@ -891,9 +889,7 @@ object ChapterProvider {
cPaint.typeface = textFont
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx()
cPaint.isAntiAlias = true
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) {
cPaint.isLinearText = true
}
cPaint.isLinearText = true
return Pair(tPaint, cPaint)
}

View File

@ -10,7 +10,6 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.book.BookContent
import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.getBookSource
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine

View File

@ -14,8 +14,6 @@ import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView
import androidx.core.os.bundleOf
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
@ -52,7 +50,6 @@ import io.legado.app.utils.ACache
import io.legado.app.utils.applyTint
import io.legado.app.utils.cnCompare
import io.legado.app.utils.dpToPx
import io.legado.app.utils.flowWithLifecycleFirst
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.launch
@ -71,7 +68,6 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
@ -102,6 +98,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
override var sortAscending = true
private set
private var snackBar: Snackbar? = null
private var isPaused = false
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
showDialogFragment(ImportBookSourceDialog(it))
@ -128,19 +125,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
}
private val groupMenuLifecycleOwner = object : LifecycleOwner {
private val registry = LifecycleRegistry(this)
override val lifecycle: Lifecycle get() = registry
fun onMenuOpened() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_START)
}
fun onMenuClosed() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
@ -388,17 +372,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun initLiveDataGroup() {
lifecycleScope.launch {
appDb.bookSourceDao.flowGroups()
.flowWithLifecycle(lifecycle)
.flowWithLifecycleFirst(groupMenuLifecycleOwner.lifecycle)
.conflate()
.distinctUntilChanged()
.collect {
groups.clear()
groups.addAll(it)
upGroupMenu()
delay(500)
}
appDb.bookSourceDao.flowGroups().conflate().collect {
groups.clear()
groups.addAll(it)
upGroupMenu()
delay(500)
}
}
}
@ -421,20 +400,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
if (menu === groupMenu) {
groupMenuLifecycleOwner.onMenuOpened()
}
return super.onMenuOpened(featureId, menu)
}
override fun onPanelClosed(featureId: Int, menu: Menu) {
super.onPanelClosed(featureId, menu)
if (menu === groupMenu) {
groupMenuLifecycleOwner.onMenuClosed()
}
}
private fun initSelectActionBar() {
binding.selectActionBar.setMainActionText(R.string.delete)
binding.selectActionBar.inflateMenu(R.menu.book_source_sel)
@ -672,6 +637,16 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
override fun onPause() {
super.onPause()
isPaused = true
}
override fun onResume() {
super.onResume()
isPaused = false
}
override fun upCountView() {
binding.selectActionBar
.upCountView(adapter.selection.size, adapter.itemCount)

View File

@ -6,8 +6,10 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.os.Build
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.StaticLayout
import android.text.style.LineHeightSpan
import android.util.AttributeSet
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatTextView
@ -27,6 +29,13 @@ class BatteryView @JvmOverloads constructor(
private val outFrame = Rect()
private val polar = Rect()
private val canvasRecorder = CanvasRecorderFactory.create()
private val batterySpan = LineHeightSpan { _, _, _, _, _, fm ->
fm.top = -22
fm.ascent = -28
fm.descent = 7
fm.bottom = 1
fm.leading = 0
}
var isBattery = false
set(value) {
field = value
@ -39,9 +48,6 @@ class BatteryView @JvmOverloads constructor(
init {
setPadding(4.dpToPx(), 3.dpToPx(), 6.dpToPx(), 3.dpToPx())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
isFallbackLineSpacing = false
}
batteryPaint.strokeWidth = 1f.dpToPx()
batteryPaint.isAntiAlias = true
batteryPaint.color = paint.color
@ -63,9 +69,9 @@ class BatteryView @JvmOverloads constructor(
fun setBattery(battery: Int, text: String? = null) {
this.battery = battery
if (text.isNullOrEmpty()) {
setText(battery.toString())
setText(getBatteryText(battery.toString()))
} else {
setText("$text $battery")
setText(getBatteryText("$text $battery"))
}
}
@ -78,16 +84,17 @@ class BatteryView @JvmOverloads constructor(
if (AppConfig.optimizeRender) {
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
super.onDraw(this)
if (!isBattery) return@recordIfNeededThenDraw
drawBattery(this)
}
} else {
super.onDraw(canvas)
if (!isBattery) return
drawBattery(canvas)
}
}
private fun drawBattery(canvas: Canvas) {
if (!isBattery) return
layout.getLineBounds(0, outFrame)
val batteryStart = layout
.getPrimaryHorizontal(text.length - battery.toString().length)
@ -113,10 +120,22 @@ class BatteryView @JvmOverloads constructor(
canvas.drawRect(polar, batteryPaint)
}
@Suppress("UNNECESSARY_SAFE_CALL")
private fun getBatteryText(text: CharSequence?): SpannableStringBuilder? {
if (text == null) {
return null
}
return SpannableStringBuilder(text).apply {
setSpan(batterySpan, 0, text.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
override fun invalidate() {
super.invalidate()
canvasRecorder?.invalidate()
kotlin.runCatching {
canvasRecorder.invalidate()
}
}
}

View File

@ -123,14 +123,6 @@ inline fun <reified T : BroadcastReceiver> Context.broadcastPendingIntent(
return getBroadcast(this, 0, intent, flags)
}
fun Context.startForegroundServiceCompat(intent: Intent) {
try {
startService(intent)
} catch (e: IllegalStateException) {
ContextCompat.startForegroundService(this, intent)
}
}
val Context.defaultSharedPreferences: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(this)

View File

@ -194,10 +194,10 @@ object NetworkUtils {
enumeration = NetworkInterface.getNetworkInterfaces()
} catch (e: SocketException) {
e.printOnDebug()
return emptyList()
return mutableListOf()
}
val addressList = mutableListOf<InetAddress>()
var fallbackAddress: MutableList<InetAddress> = mutableListOf()
while (enumeration.hasMoreElements()) {
val nif = enumeration.nextElement()
@ -205,11 +205,13 @@ object NetworkUtils {
while (addresses.hasMoreElements()) {
val address = addresses.nextElement()
if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) {
addressList.add(address)
if (nif.name?.startsWith("wlan") == true) {
fallbackAddress.add(address)
}
}
}
}
return addressList
return fallbackAddress
}
/**

View File

@ -4,14 +4,17 @@ package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.cardview.widget.CardView
import androidx.fragment.app.Fragment
import io.legado.app.BuildConfig
import io.legado.app.databinding.ViewToastBinding
import io.legado.app.R
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import splitties.systemservices.layoutInflater
import splitties.views.inflate
private var toast: Toast? = null
@ -28,13 +31,14 @@ fun Context.toastOnUi(message: CharSequence?, duration: Int = Toast.LENGTH_SHORT
kotlin.runCatching {
toast?.cancel()
toast = Toast(this)
val toastView: View = inflate(R.layout.view_toast)
toast?.view = toastView
val cardView = toastView.findViewById<CardView>(R.id.cv_content)
cardView.setCardBackgroundColor(bottomBackground)
val isLight = ColorUtils.isColorLight(bottomBackground)
ViewToastBinding.inflate(layoutInflater).run {
toast?.view = root
cvToast.setCardBackgroundColor(bottomBackground)
tvText.setTextColor(getPrimaryTextColor(isLight))
tvText.text = message
}
val textView = toastView.findViewById<TextView>(R.id.tv_text)
textView.setTextColor(getPrimaryTextColor(isLight))
textView.text = message
toast?.duration = duration
toast?.show()
}

View File

@ -6,7 +6,7 @@
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/cv_toast"
android:id="@+id/cv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"

View File

@ -1147,5 +1147,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1150,5 +1150,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1150,5 +1150,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1146,5 +1146,4 @@ Còn </string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1147,5 +1147,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1149,5 +1149,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1149,5 +1149,4 @@
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>

View File

@ -1150,5 +1150,4 @@
<string name="font_weight_text">N/B/L</string>
<string name="keep_swipe_tip">Keep swiping to load the next chapter…</string>
<string name="enable_optimize_render">启用绘制优化</string>
<string name="ignore_battery_permission_rationale">阅读需要请求后台权限以保持服务正常运行</string>
</resources>