Merge branch 'gedoor:master' into master

This commit is contained in:
Xwite 2022-01-11 17:26:33 +08:00 committed by GitHub
commit a69e9f5f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 17 deletions

View File

@ -261,8 +261,11 @@ object WebBook {
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}") Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
return bookChapter.url return bookChapter.url
} }
//章节名为卷名时 且 章节url没获取到返回空白 if(bookChapter.isVolume && bookChapter.url == bookChapter.title) {
if(bookChapter.isVolume && bookChapter.url == bookChapter.title) return "" //不返回空值,是为了过书源检测
Debug.log(bookSource.bookSourceUrl, "⇒一级目录正文,使用章节标题:${bookChapter.title}")
return bookChapter.title
}
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
BookContent.analyzeContent( BookContent.analyzeContent(
scope = scope, scope = scope,

View File

@ -4,7 +4,6 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.KeyEvent import android.view.KeyEvent
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -42,7 +41,6 @@ class MediaButtonReceiver : BroadcastReceiver() {
val keycode: Int = keyEvent.keyCode val keycode: Int = keyEvent.keyCode
val action: Int = keyEvent.action val action: Int = keyEvent.action
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
AppLog.put("mediaButton $action")
when (keycode) { when (keycode) {
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) { if (context.getPrefBoolean("mediaButtonPerNext", false)) {
@ -88,7 +86,6 @@ class MediaButtonReceiver : BroadcastReceiver() {
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) {
AppLog.put("readAloud start Service")
if (ReadBook.book != null) { if (ReadBook.book != null) {
ReadBook.readAloud() ReadBook.readAloud()
} else { } else {

View File

@ -279,18 +279,15 @@ abstract class BaseReadAloudService : BaseService(),
override fun onAudioFocusChange(focusChange: Int) { override fun onAudioFocusChange(focusChange: Int) {
when (focusChange) { when (focusChange) {
AudioManager.AUDIOFOCUS_GAIN -> { AudioManager.AUDIOFOCUS_GAIN -> {
AppLog.put("重新获得焦点, 恢复播放")
audioFocusLossTransient = false audioFocusLossTransient = false
if (!pause) resumeReadAloud() if (!pause) resumeReadAloud()
} }
AudioManager.AUDIOFOCUS_LOSS -> { AudioManager.AUDIOFOCUS_LOSS -> {
AppLog.put("永久丢失焦点")
if (audioFocusLossTransient) { if (audioFocusLossTransient) {
pauseReadAloud(true) pauseReadAloud(true)
} }
} }
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
AppLog.put("暂时丢失焦点, 暂停播放")
audioFocusLossTransient = true audioFocusLossTransient = true
if (!pause) pauseReadAloud(false) if (!pause) pauseReadAloud(false)
} }

View File

@ -50,7 +50,10 @@ class AppLogDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_clear -> AppLog.clear() R.id.menu_clear -> {
AppLog.clear()
adapter.clearItems()
}
} }
return true return true
} }

View File

@ -332,7 +332,7 @@ object ChapterProvider {
} }
lineIndex == layout.lineCount - 1 -> { lineIndex == layout.lineCount - 1 -> {
//最后一行 //最后一行
textLine.text = "$words\n" textLine.text = if(isVolumeTitle) "" else "$words\n"
isLastLine = true isLastLine = true
//标题居中 //标题居中
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle) val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle)
@ -349,7 +349,7 @@ object ChapterProvider {
} }
else -> { else -> {
//中间行 //中间行
textLine.text = words textLine.text = if(isVolumeTitle) "" else words
addCharsToLineMiddle( addCharsToLineMiddle(
absStartX, absStartX,
textLine, textLine,

View File

@ -140,12 +140,17 @@ object NetworkUtils {
} }
fun getBaseUrl(url: String?): String? { fun getBaseUrl(url: String?): String? {
if (url == null || !url.startsWith("http")) return null url ?: return null
if (url.startsWith("http://", true)
|| url.startsWith("https://", true)
) {
val index = url.indexOf("/", 9) val index = url.indexOf("/", 9)
return if (index == -1) { return if (index == -1) {
url url
} else url.substring(0, index) } else url.substring(0, index)
} }
return null
}
/** /**
* 获取二级域名供cookie保存和读取 * 获取二级域名供cookie保存和读取
@ -163,7 +168,7 @@ object NetworkUtils {
if (isIPAddress(host)) return baseUrl if (isIPAddress(host)) return baseUrl
//PublicSuffixDatabase处理域名 //PublicSuffixDatabase处理域名
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
}.getOrDefault(url) }.getOrDefault(baseUrl)
} }
/** /**