Merge pull request #5 from gedoor/master

sys code
pull/946/head
ag2s20150909 4 years ago committed by GitHub
commit 85aa7f3d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 3
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 3
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  4. 7
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  5. 1
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  6. 5
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  7. 5
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  9. 42
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  10. 16
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  11. 6
      app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt
  12. 20
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  13. 18
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt
  14. 10
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt
  15. 8
      app/src/main/res/menu/book_source_debug.xml
  16. 17
      app/src/main/res/menu/rss_source_debug.xml
  17. 6
      app/src/main/res/values-zh-rHK/strings.xml
  18. 6
      app/src/main/res/values-zh-rTW/strings.xml
  19. 6
      app/src/main/res/values-zh/strings.xml
  20. 6
      app/src/main/res/values/strings.xml
  21. 7
      app/src/main/res/xml/pref_config_read.xml

@ -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"

@ -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()) {

@ -334,7 +334,8 @@ interface JsExtensions {
/**
* 输出调试日志
*/
fun log(msg: String) {
fun log(msg: String): String {
Debug.log(msg)
return msg
}
}

@ -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<String> {
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))

@ -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, "⇒列表规则为空, 使用默认规则解析")

@ -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<ActivityCacheBookBinding, CacheViewModel>()
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 {

@ -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<ActivityImportBookBinding, ImportBookV
private val selectFolder = 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
)
AppConfig.importBookPath = uri.toString()
initRootDoc()
} else {

@ -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)
}

@ -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)
}

@ -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())

@ -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))
}

@ -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() {

@ -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<ActivitySourceDebugBinding, RssSou
}
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.rss_source_debug, menu)
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_list_src ->
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)

@ -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() {

@ -12,22 +12,22 @@
<item
android:id="@+id/menu_search_src"
android:title="搜索源码"
android:title="@string/search_src"
app:showAsAction="never" />
<item
android:id="@+id/menu_book_src"
android:title="书籍源码"
android:title="@string/boo_src"
app:showAsAction="never" />
<item
android:id="@+id/menu_toc_src"
android:title="目录源码"
android:title="@string/toc_src"
app:showAsAction="never" />
<item
android:id="@+id/menu_content_src"
android:title="正文源码"
android:title="@string/content_src"
app:showAsAction="never" />
<item

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/menu_list_src"
android:title="@string/list_src"
app:showAsAction="never" />
<item
android:id="@+id/menu_content_src"
android:title="@string/content_src"
app:showAsAction="never" />
</menu>

@ -680,6 +680,7 @@
<string name="middle"></string>
<string name="information">信息</string>
<string name="switchLayout">切換佈局</string>
<string name="full_screen_gestures_support">全面屏手勢優化</string>
<!--color-->
<string name="primary">主色調</string>
@ -813,5 +814,10 @@
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
<string name="checkAuthor">校验作者</string>
<string name="search_src">搜索源码</string>
<string name="boo_src">书籍源码</string>
<string name="toc_src">目录源码</string>
<string name="content_src">正文源码</string>
<string name="list_src">列表源码</string>
</resources>

@ -693,6 +693,7 @@
<string name="information">訊息</string>
<string name="switchLayout">切換布局</string>
<string name="text_font_weight_converter">文章字重轉換</string>
<string name="full_screen_gestures_support">全面屏手勢優化</string>
<!--color-->
<string name="primary">主色調</string>
@ -815,5 +816,10 @@
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
<string name="checkAuthor">校验作者</string>
<string name="search_src">搜索源码</string>
<string name="boo_src">书籍源码</string>
<string name="toc_src">目录源码</string>
<string name="content_src">正文源码</string>
<string name="list_src">列表源码</string>
</resources>

@ -693,6 +693,7 @@
<string name="information">信息</string>
<string name="switchLayout">切换布局</string>
<string name="text_font_weight_converter">文章字重切换</string>
<string name="full_screen_gestures_support">全面屏手势优化</string>
<!--color-->
<string name="primary">主色调</string>
@ -817,5 +818,10 @@
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
<string name="checkAuthor">校验作者</string>
<string name="search_src">搜索源码</string>
<string name="boo_src">书籍源码</string>
<string name="toc_src">目录源码</string>
<string name="content_src">正文源码</string>
<string name="list_src">列表源码</string>
</resources>

@ -694,6 +694,7 @@
<string name="information">Information</string>
<string name="switchLayout">Switch Layout</string>
<string name="text_font_weight_converter">Text font weight switching</string>
<string name="full_screen_gestures_support">Full screen gestures support</string>
<!--color-->
<string name="primary">Primary</string>
@ -820,5 +821,10 @@
<string name="system_tts">System TTS</string>
<string name="export_type">导出格式</string>
<string name="checkAuthor">校验作者</string>
<string name="search_src">搜索源码</string>
<string name="boo_src">书籍源码</string>
<string name="toc_src">目录源码</string>
<string name="content_src">正文源码</string>
<string name="list_src">列表源码</string>
</resources>

@ -103,6 +103,13 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:key="fullScreenGesturesSupport"
android:title="@string/full_screen_gestures_support"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.ui.widget.prefs.Preference
android:key="customPageKey"
android:title="@string/custom_page_key"

Loading…
Cancel
Save