Skip to content

Commit

Permalink
Merge branch 'gedoor:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
550-q authored Jan 7, 2025
2 parents 03942f2 + 3710e91 commit ad0b037
Show file tree
Hide file tree
Showing 72 changed files with 435 additions and 147 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@
android:foregroundServiceType="dataSync"
android:icon="@drawable/ic_web_service_noti"
android:label="legado Web Service"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
tools:targetApi="24">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/assets/defaultData/coverRule.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"enable": true,
"searchUrl": "https://api.yousuu.com/api/search?type=title&value={{key}}&page=1&highlight=0&from=search",
"coverRule": "@js:java.getString(\"$..books[?(@.author == '\" + book.author + \"')].cover\")"
"enable": false,
"searchUrl": "",
"coverRule": ""
}
2 changes: 1 addition & 1 deletion app/src/main/assets/defaultData/directLinkUpload.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"uploadUrl": "http://v2.jt12.eu/up-v2.php,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.msg",
"summary": "橘涂网盘·过于卡顿,如非需要永久链接。否则不建议使用(永久有效)",
"summary": "橘涂书源网盘2.0 Beta(永久有效)",
"compress": false
}
]
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/constant/PreferKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ object PreferKey {
const val launcherIcon = "launcherIcon"
const val textSelectAble = "selectText"
const val shareLayout = "shareLayout"
const val comicStyleSelect = "comicStyleSelect"
const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh"
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/io/legado/app/data/entities/Book.kt
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,6 @@ data class Book(
}
}

fun update() {
appDb.bookDao.update(this)
}

fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/io/legado/app/help/AppWebDav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.WebDavException
import io.legado.app.lib.webdav.WebDavFile
import io.legado.app.model.remote.RemoteBookWebDav
import io.legado.app.utils.*
import io.legado.app.utils.AlphanumComparator
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.UrlUtil
import io.legado.app.utils.compress.ZipUtils
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString
import io.legado.app.utils.isJson
import io.legado.app.utils.removePref
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx
import java.io.File
import java.util.*

/**
* webDav初始化会访问网络,不要放到主线程
Expand Down Expand Up @@ -133,7 +141,7 @@ object AppWebDav {
WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile ->
if (webDavFile.displayName.startsWith("backup")) {
if (lastBackupFile == null
|| webDavFile.lastModify > lastBackupFile!!.lastModify
|| webDavFile.lastModify > lastBackupFile.lastModify
) {
lastBackupFile = webDavFile
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/legado/app/help/book/BookExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ fun Book.sync(oldBook: Book) {
canUpdate = curBook.canUpdate
}

fun Book.update() {
appDb.bookDao.update(this)
}

fun Book.getBookSource(): BookSource? {
return appDb.bookSourceDao.getBookSource(origin)
}
Expand Down
29 changes: 25 additions & 4 deletions app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object ReadBookConfig {
}
}

var isComic: Boolean = false
var bg: Drawable? = null
var bgMeanColor: Int = 0
val textColor: Int get() = durConfig.curTextColor()
Expand Down Expand Up @@ -149,9 +150,13 @@ object ReadBookConfig {

fun deleteDur(): Boolean {
if (configList.size > 5) {
configList.removeAt(styleSelect)
if (styleSelect > 0) {
styleSelect -= 1
val removeIndex = styleSelect
configList.removeAt(removeIndex)
if (removeIndex <= readStyleSelect) {
readStyleSelect -= 1
}
if (removeIndex <= comicStyleSelect) {
comicStyleSelect -= 1
}
return true
}
Expand All @@ -173,13 +178,29 @@ object ReadBookConfig {
field = value
appCtx.putPrefInt(PreferKey.autoReadSpeed, value)
}
var styleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
var styleSelect: Int
get() = if (isComic) comicStyleSelect else readStyleSelect
set(value) {
if (isComic) {
comicStyleSelect = value
} else {
readStyleSelect = value
}
}
var readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
set(value) {
field = value
if (appCtx.getPrefInt(PreferKey.readStyleSelect) != value) {
appCtx.putPrefInt(PreferKey.readStyleSelect, value)
}
}
var comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect, readStyleSelect)
set(value) {
field = value
if (appCtx.getPrefInt(PreferKey.comicStyleSelect) != value) {
appCtx.putPrefInt(PreferKey.comicStyleSelect, value)
}
}
var shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout)
set(value) {
field = value
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/legado/app/help/storage/Restore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ object Restore {
edit.apply()
}
ReadBookConfig.apply {
styleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect)
readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout)
hideStatusBar = appCtx.getPrefBoolean(PreferKey.hideStatusBar)
hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package io.legado.app.lib.prefs.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.DialogFragment
import androidx.preference.*
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.lib.prefs.EditTextPreferenceDialog
import io.legado.app.lib.prefs.ListPreferenceDialog
import io.legado.app.lib.prefs.MultiSelectListPreferenceDialog
import io.legado.app.utils.applyNavigationBarPadding

abstract class PreferenceFragment : PreferenceFragmentCompat() {

private val dialogFragmentTag = "androidx.preference.PreferenceFragment.DIALOG"

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
listView.clipToPadding = false
listView.applyNavigationBarPadding()
}

@SuppressLint("RestrictedApi")
override fun onDisplayPreferenceDialog(preference: Preference) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.drawable.ColorDrawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.databinding.ViewNavigationBadgeBinding
import io.legado.app.help.config.AppConfig
Expand Down Expand Up @@ -34,6 +35,8 @@ class ThemeBottomNavigationVIew(context: Context, attrs: AttributeSet) :
isItemHorizontalTranslationEnabled = false
itemBackground = ColorDrawable(Color.TRANSPARENT)
}

ViewCompat.setOnApplyWindowInsetsListener(this, null)
}

fun addBadgeView(index: Int): BadgeView {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ open class WebDav(
.toInstant(ZoneOffset.of("+8")).toEpochMilli()
}
}.getOrNull() ?: 0
val fullURL = NetworkUtils.getAbsoluteURL(baseUrl, hrefDecode)
var fullURL = NetworkUtils.getAbsoluteURL(baseUrl, hrefDecode)
if (WebDavFile.isDir(contentType, resourceType) && !fullURL.endsWith("/")) {
fullURL += "/"
}
webDavFile = WebDavFile(
fullURL,
authorization,
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ class WebDavFile(
) : WebDav(urlStr, authorization) {

val isDir by lazy {
contentType == "httpd/unix-directory" || resourceType.lowercase().contains("collection")
isDir(contentType, resourceType)
}

companion object {
fun isDir(contentType: String, resourceType: String): Boolean {
return contentType == "httpd/unix-directory"
|| resourceType.lowercase().contains("collection")
}
}

}
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/model/AudioPlay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.getBookSource
import io.legado.app.help.book.readSimulating
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.update
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.AudioPlayService
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.legado.app.model

import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus
import io.legado.app.constant.PageAnim.scrollPageAnim
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
Expand All @@ -11,9 +12,11 @@ import io.legado.app.data.entities.ReadRecord
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.isImage
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.readSimulating
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine
Expand All @@ -24,6 +27,7 @@ import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.LayoutProgressListener
import io.legado.app.utils.postEvent
import io.legado.app.utils.stackTraceStr
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -174,6 +178,14 @@ object ReadBook : CoroutineScope by MainScope() {
}
}

fun upReadBookConfig(book: Book) {
val oldIndex = ReadBookConfig.styleSelect
ReadBookConfig.isComic = book.isImage
if (oldIndex != ReadBookConfig.styleSelect) {
postEvent(EventBus.UP_CONFIG, arrayListOf(1, 2, 5))
}
}

fun setProgress(progress: BookProgress) {
if (progress.durChapterIndex < chapterSize &&
(durChapterIndex != progress.durChapterIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,15 @@ class AnalyzeUrl(
fun setBody(value: String?) {
body = when {
value.isNullOrBlank() -> null
value.isJsonObject() -> GSON.fromJsonObject<Map<String, Any>>(value)
value.isJsonArray() -> GSON.fromJsonArray<Map<String, Any>>(value)
value.isJsonObject() -> GSON.fromJsonObject<Map<String, Any>>(value).getOrNull()
value.isJsonArray() -> GSON.fromJsonArray<Map<String, Any>>(value).getOrNull()
else -> value
}
}

fun getBody(): String? {
return body?.let {
if (it is String) it else GSON.toJson(it)
it as? String ?: GSON.toJson(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.legado.app.constant.AppPattern.bookFileRegex
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.Authorization
import io.legado.app.lib.webdav.WebDav
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/io/legado/app/service/AudioPlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.legado.app.constant.NotificationId
import io.legado.app.constant.Status
import io.legado.app.help.MediaHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.exoplayer.ExoPlayerHelper
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.AudioPlay
Expand Down Expand Up @@ -109,6 +110,7 @@ class AudioPlayService : BaseService(),
private var needResumeOnAudioFocusGain = false
private var position = AudioPlay.book?.durChapterPos ?: 0
private var dsJob: Job? = null
private var upNotificationJob: Coroutine<*>? = null
private var upPlayProgressJob: Job? = null
private var playSpeed: Float = 1f
private var cover: Bitmap =
Expand Down Expand Up @@ -196,6 +198,9 @@ class AudioPlayService : BaseService(),
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
AudioPlay.unregisterService()
upNotificationJob?.invokeOnCompletion {
notificationManager.cancel(NotificationId.AudioPlayService)
}
}

/**
Expand Down Expand Up @@ -404,6 +409,8 @@ class AudioPlayService : BaseService(),
}
if (timeMinute == 0) {
AudioPlay.stop()
postEvent(EventBus.AUDIO_DS, timeMinute)
break
}
}
postEvent(EventBus.AUDIO_DS, timeMinute)
Expand Down Expand Up @@ -600,7 +607,7 @@ class AudioPlayService : BaseService(),
}

private fun upAudioPlayNotification() {
execute {
upNotificationJob = execute {
try {
val notification = createNotification()
notificationManager.notify(NotificationId.AudioPlayService, notification.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.constant.Status
import io.legado.app.help.MediaHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.glide.ImageLoader
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
Expand Down Expand Up @@ -123,6 +124,7 @@ abstract class BaseReadAloudService : BaseService(),
private var needResumeOnCallStateIdle = false
private var registeredPhoneStateListener = false
private var dsJob: Job? = null
private var upNotificationJob: Coroutine<*>? = null
private var cover: Bitmap =
BitmapFactory.decodeResource(appCtx.resources, R.drawable.icon_read_book)
var pageChanged = false
Expand Down Expand Up @@ -198,6 +200,9 @@ abstract class BaseReadAloudService : BaseService(),
mediaSessionCompat.release()
ReadBook.uploadProgress()
unregisterPhoneStateListener(phoneStateListener)
upNotificationJob?.invokeOnCompletion {
notificationManager.cancel(NotificationId.ReadAloudService)
}
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Expand Down Expand Up @@ -396,6 +401,8 @@ abstract class BaseReadAloudService : BaseService(),
}
if (timeMinute == 0) {
ReadAloud.stop(this@BaseReadAloudService)
postEvent(EventBus.READ_ALOUD_DS, timeMinute)
break
}
}
postEvent(EventBus.READ_ALOUD_DS, timeMinute)
Expand Down Expand Up @@ -502,7 +509,7 @@ abstract class BaseReadAloudService : BaseService(),
}

private fun upReadAloudNotification() {
execute {
upNotificationJob = execute {
try {
val notification = createNotification()
notificationManager.notify(NotificationId.ReadAloudService, notification.build())
Expand Down
Loading

0 comments on commit ad0b037

Please sign in to comment.