diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 72d260d8a..0d1e5ef7e 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -72,6 +72,7 @@ object PreferKey { const val exportCharset = "exportCharset" const val exportUseReplace = "exportUseReplace" const val useZhLayout = "useZhLayout" + const val fullScreenGesturesSupport = "fullScreenGesturesSupport" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index c72078564..cda42eed4 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -190,6 +190,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val replaceEnableDefault get() = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true) + val fullScreenGesturesSupport: Boolean + get () = appCtx.getPrefBoolean(PreferKey.fullScreenGesturesSupport, false) + private fun getPrefUserAgent(): String { val ua = appCtx.getPrefString(PreferKey.userAgent) if (ua.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 65e83f278..53feb4054 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -334,7 +334,8 @@ interface JsExtensions { /** * 输出调试日志 */ - fun log(msg: String) { + fun log(msg: String): String { Debug.log(msg) + return msg } } diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index 71aa5b2b3..d86095390 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -3,6 +3,7 @@ package io.legado.app.model.rss import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleData @@ -38,7 +39,7 @@ object Rss { scope: CoroutineScope, rssArticle: RssArticle, ruleContent: String, - rssSource: RssSource?, + rssSource: RssSource, context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { @@ -46,9 +47,11 @@ object Rss { rssArticle.link, baseUrl = rssArticle.origin, ruleData = rssArticle, - headerMapF = rssSource?.getHeaderMap() + headerMapF = rssSource.getHeaderMap() ) val body = analyzeUrl.getStrResponse(rssArticle.origin).body + Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}") + Debug.log(rssSource.sourceUrl, body, state = 20) val analyzeRule = AnalyzeRule(rssArticle) analyzeRule.setContent(body) .setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link)) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index e2b702cce..6affe0b88 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -31,6 +31,7 @@ object RssParserByRule { ) } Debug.log(sourceUrl, "≡获取成功:$sourceUrl") + Debug.log(sourceUrl, body, state = 10) var ruleArticles = rssSource.ruleArticles if (ruleArticles.isNullOrBlank()) { Debug.log(sourceUrl, "⇒列表规则为空, 使用默认规则解析") diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 23b4289f3..fbdae644b 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.cache -import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -42,10 +41,6 @@ class CacheActivity : VMBaseActivity() private val exportDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) startExport(uri.toString()) } else { diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 185ba4f23..8dfa25975 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.local -import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle @@ -46,10 +45,6 @@ class ImportBookActivity : VMBaseActivity uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.importBookPath = uri.toString() initRootDoc() } else { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 5e4b9cec6..3fe8ed971 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -16,6 +16,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.bottomBackground import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.ui.book.read.page.ReadView import io.legado.app.utils.dp import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent @@ -127,6 +128,9 @@ class MoreConfigDialog : DialogFragment() { "clickRegionalConfig" -> { (activity as? ReadBookActivity)?.showClickRegionalConfig() } + "fullScreenGesturesSupport" -> { + ((activity as? ReadBookActivity)?.findViewById(R.id.read_view) as ReadView).setRect9x() + } } return super.onPreferenceTreeClick(preference) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index ef53ab14b..bba292427 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -77,15 +77,15 @@ class ReadView(context: Context, attrs: AttributeSet) : private var firstCharIndex: Int = 0 val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop } - private val tlRect = RectF(0f, 0f, width * 0.33f, height * 0.33f) - private val tcRect = RectF(width * 0.33f, 0f, width * 0.66f, height * 0.33f) - private val trRect = RectF(width * 0.36f, 0f, width - 0f, height * 0.33f) - private val mlRect = RectF(0f, height * 0.33f, width * 0.33f, height * 0.66f) - private val mcRect = RectF(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) - private val mrRect = RectF(width * 0.66f, height * 0.33f, width - 0f, height * 0.66f) - private val blRect = RectF(0f, height * 0.66f, width * 0.33f, height - 0f) - private val bcRect = RectF(width * 0.33f, height * 0.66f, width * 0.66f, height - 0f) - private val brRect = RectF(width * 0.66f, height * 0.66f, width - 0f, height - 0f) + private val tlRect = RectF() + private val tcRect = RectF() + private val trRect = RectF() + private val mlRect = RectF() + private val mcRect = RectF() + private val mrRect = RectF() + private val blRect = RectF() + private val bcRect = RectF() + private val brRect = RectF() private val autoPageRect by lazy { Rect() } private val autoPagePint by lazy { Paint().apply { color = context.accentColor } } private val boundary by lazy { BreakIterator.getWordInstance(Locale.getDefault()) } @@ -99,19 +99,25 @@ class ReadView(context: Context, attrs: AttributeSet) : setWillNotDraw(false) upPageAnim() } + setRect9x() } - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - tlRect.set(0f, 0f, width * 0.33f, height * 0.33f) + public fun setRect9x() { + val edge = if (AppConfig.fullScreenGesturesSupport) { 200f } else { 0f } + tlRect.set(0f + edge, 0f, width * 0.33f, height * 0.33f) tcRect.set(width * 0.33f, 0f, width * 0.66f, height * 0.33f) - trRect.set(width * 0.36f, 0f, width - 0f, height * 0.33f) - mlRect.set(0f, height * 0.33f, width * 0.33f, height * 0.66f) + trRect.set(width * 0.36f, 0f, width - 0f - edge, height * 0.33f) + mlRect.set(0f + edge, height * 0.33f, width * 0.33f, height * 0.66f) mcRect.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) - mrRect.set(width * 0.66f, height * 0.33f, width - 0f, height * 0.66f) - blRect.set(0f, height * 0.66f, width * 0.33f, height - 10f) - bcRect.set(width * 0.33f, height * 0.66f, width * 0.66f, height - 0f) - brRect.set(width * 0.66f, height * 0.66f, width - 0f, height - 0f) + mrRect.set(width * 0.66f, height * 0.33f, width - 0f - edge, height * 0.66f) + blRect.set(0f + edge, height * 0.66f, width * 0.33f, height - 10f - edge) + bcRect.set(width * 0.33f, height * 0.66f, width * 0.66f, height - 0f - edge) + brRect.set(width * 0.66f, height * 0.66f, width - 0f - edge, height - 0f - edge) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + setRect9x() prevPage.x = -w.toFloat() pageDelegate?.setViewSize(w, h) } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 8359259d4..1b6c8ba45 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.config -import android.content.Intent import android.content.SharedPreferences import android.net.Uri import android.os.Bundle @@ -40,11 +39,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val selectBackupPath = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() } else { AppConfig.backupPath = uri.path @@ -53,11 +47,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val backupDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() Coroutine.async { Backup.backup(appCtx, uri.toString()) @@ -78,11 +67,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val restoreDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() Coroutine.async { Restore.restore(appCtx, uri.toString()) diff --git a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt b/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt index bcbf8dce7..3c83b3845 100644 --- a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt +++ b/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt @@ -23,6 +23,12 @@ class FilePickerActivity : private val selectDocTree = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { + if (it.isContentScheme()) { + contentResolver.takePersistableUriPermission( + it, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + } onResult(Intent().setData(it)) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index cf3574f2e..a2faacfad 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -94,16 +94,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } private fun loadContent(rssArticle: RssArticle, ruleContent: String) { - Rss.getContent(this, rssArticle, ruleContent, rssSource) - .onSuccess(IO) { body -> - rssArticle.description = body - appDb.rssArticleDao.insert(rssArticle) - rssStar?.let { - it.description = body - appDb.rssStarDao.insert(it) + rssSource?.let { source -> + Rss.getContent(this, rssArticle, ruleContent, source) + .onSuccess(IO) { body -> + rssArticle.description = body + appDb.rssArticleDao.insert(rssArticle) + rssStar?.let { + it.description = body + appDb.rssStarDao.insert(it) + } + contentLiveData.postValue(body) } - contentLiveData.postValue(body) - } + } } fun favorite() { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt index e5cb45db4..4b790e5c1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -1,6 +1,8 @@ package io.legado.app.ui.rss.source.debug import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import android.widget.SearchView import androidx.activity.viewModels import io.legado.app.R @@ -8,6 +10,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivitySourceDebugBinding import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.gone import io.legado.app.utils.toastOnUi @@ -41,6 +44,21 @@ class RssSourceDebugActivity : VMBaseActivity + TextDialog.show(supportFragmentManager, viewModel.listSrc) + R.id.menu_content_src -> + TextDialog.show(supportFragmentManager, viewModel.contentSrc) + } + return super.onCompatOptionsItemSelected(item) + } + private fun initRecyclerView() { ATH.applyEdgeEffectColor(binding.recyclerView) adapter = RssSourceDebugAdapter(this) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt index 8ef97a780..9d1a5922a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt @@ -8,10 +8,10 @@ import io.legado.app.model.Debug class RssSourceDebugModel(application: Application) : BaseViewModel(application), Debug.Callback { - private var rssSource: RssSource? = null - private var callback: ((Int, String) -> Unit)? = null + var listSrc: String? = null + var contentSrc: String? = null fun initData(sourceUrl: String?, finally: () -> Unit) { sourceUrl?.let { @@ -36,7 +36,11 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application) } override fun printLog(state: Int, msg: String) { - callback?.invoke(state, msg) + when (state) { + 10 -> listSrc = msg + 20 -> contentSrc = msg + else -> callback?.invoke(state, msg) + } } override fun onCleared() { diff --git a/app/src/main/res/menu/book_source_debug.xml b/app/src/main/res/menu/book_source_debug.xml index bcf7b3856..ec7878377 100644 --- a/app/src/main/res/menu/book_source_debug.xml +++ b/app/src/main/res/menu/book_source_debug.xml @@ -12,22 +12,22 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 1df7c6415..ec507138c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -680,6 +680,7 @@ 信息 切換佈局 + 全面屏手勢優化 主色調 @@ -813,5 +814,10 @@ 系统TTS 导出格式 校验作者 + 搜索源码 + 书籍源码 + 目录源码 + 正文源码 + 列表源码 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2920fcc23..0b7551fc5 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -693,6 +693,7 @@ 訊息 切換布局 文章字重轉換 + 全面屏手勢優化 主色調 @@ -815,5 +816,10 @@ 系统TTS 导出格式 校验作者 + 搜索源码 + 书籍源码 + 目录源码 + 正文源码 + 列表源码 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index f64b848d7..0889ca112 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -693,6 +693,7 @@ 信息 切换布局 文章字重切换 + 全面屏手势优化 主色调 @@ -817,5 +818,10 @@ 系统TTS 导出格式 校验作者 + 搜索源码 + 书籍源码 + 目录源码 + 正文源码 + 列表源码 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4cb2fa208..da4faf74d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -694,6 +694,7 @@ Information Switch Layout Text font weight switching + Full screen gestures support Primary @@ -820,5 +821,10 @@ System TTS 导出格式 校验作者 + 搜索源码 + 书籍源码 + 目录源码 + 正文源码 + 列表源码 diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 9f240fc63..6f4b6e440 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -103,6 +103,13 @@ app:iconSpaceReserved="false" app:isBottomBackground="true" /> + +