Merge pull request #42 from gedoor/master

merge
pull/403/head
口口吕 6 years ago committed by GitHub
commit 4d4c93cb8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/assets/updateLog.md
  2. 3
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 8
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt
  4. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  5. 14
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  6. 13
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  7. 6
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  8. 13
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  9. 25
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  10. 6
      app/src/main/res/menu/change_source.xml
  11. 5
      app/src/main/res/values-zh-rHK/strings.xml
  12. 5
      app/src/main/res/values-zh-rTW/strings.xml
  13. 5
      app/src/main/res/values-zh/strings.xml
  14. 5
      app/src/main/res/values/strings.xml
  15. 4
      app/src/main/res/xml/pref_config_backup.xml

@ -5,6 +5,7 @@
**2020/09/21** **2020/09/21**
* 修复规则解析bug * 修复规则解析bug
* 换源时无最新章节信息时可加载详情页来获取(默认关闭)
**2020/09/20** **2020/09/20**
* 优化正文搜索 * 优化正文搜索

@ -33,8 +33,9 @@ object PreferKey {
const val webDavAccount = "web_dav_account" const val webDavAccount = "web_dav_account"
const val webDavPassword = "web_dav_password" const val webDavPassword = "web_dav_password"
const val webDavCreateDir = "webDavCreateDir" const val webDavCreateDir = "webDavCreateDir"
const val webDavExport = "webDavExport" const val webDavCacheBackup = "webDavCacheBackup"
const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadToc = "changeSourceLoadToc"
const val changeSourceLoadInfo = "changeSourceLoadInfo"
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon" const val launcherIcon = "launcherIcon"
const val textSelectAble = "selectText" const val textSelectAble = "selectText"

@ -125,13 +125,13 @@ object WebDavHelp {
fun exportWebDav(path: String, fileName: String) { fun exportWebDav(path: String, fileName: String) {
try { try {
if (initWebDav()) { if (initWebDav()) {
//默认导出到legado文件夹下exports目录 // 默认导出到legado文件夹下exports目录
val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/" val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/"
//在legado文件夹创建exports目录,如果不存在的话 // 在legado文件夹创建exports目录,如果不存在的话
WebDav(exportsWebDavUrl).makeAsDir() WebDav(exportsWebDavUrl).makeAsDir()
val file = File("${path}${File.separator}${fileName}") val file = File("${path}${File.separator}${fileName}")
//如果导出的本地文件存在,开始上传 // 如果导出的本地文件存在,开始上传
if(file.exists()){ if(file.exists()) {
val putUrl = exportsWebDavUrl + fileName val putUrl = exportsWebDavUrl + fileName
WebDav(putUrl).upload("${path}${File.separator}${fileName}") WebDav(putUrl).upload("${path}${File.separator}${fileName}")
} }

@ -458,7 +458,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
} }
tmp = evalMatcher.group() tmp = evalMatcher.group()
when { when {
tmp.startsWith("$") && !rule.contains("##") -> { tmp.startsWith("$") -> {
ruleType.add(tmp.substring(1).toInt()) ruleType.add(tmp.substring(1).toInt())
ruleParam.add(tmp) ruleParam.add(tmp)
} }

@ -368,7 +368,19 @@ object ReadBook {
val currentLine = currentPage.textLines[lineIndex] val currentLine = currentPage.textLines[lineIndex]
length -= currentLine.text.length length -= currentLine.text.length
val charIndex = contentPosition - length val charIndex = contentPosition - length
return arrayOf(pageIndex, lineIndex, charIndex) var addLine = 0
var charIndex2 = 0
// change line
if ((charIndex + query.length) > currentLine.text.length){
addLine = 1
charIndex2 = charIndex + query.length - currentLine.text.length - 1
}
// changePage
if ((lineIndex + addLine + 1) > currentPage.textLines.size){
addLine = -1
charIndex2 = charIndex + query.length - currentLine.text.length - 1
}
return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2)
} }
/** /**

@ -40,15 +40,14 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
val content = getAllContents(book) val content = getAllContents(book)
DocumentUtils.createFileIfNotExist(doc, filename) DocumentUtils.createFileIfNotExist(doc, filename)
?.writeText(context, content) ?.writeText(context, content)
if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { if(App.INSTANCE.getPrefBoolean(PreferKey.webDavCacheBackup,false)) {
//写出文件到cache目录
FileUtils.createFileIfNotExist( FileUtils.createFileIfNotExist(
File(FileUtils.getCachePath()), File(FileUtils.getCachePath()),
filename filename
).writeText(content) ).writeText(content) // 写出文件到cache目录
//导出到webdav // 导出到webdav
WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename)
//上传完删除cache文件 // 上传完删除cache文件
FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}")
} }
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter ->
@ -79,8 +78,8 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
val filename = "${book.name} by ${book.author}.txt" val filename = "${book.name} by ${book.author}.txt"
FileUtils.createFileIfNotExist(file, filename) FileUtils.createFileIfNotExist(file, filename)
.writeText(getAllContents(book)) .writeText(getAllContents(book))
if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { if(App.INSTANCE.getPrefBoolean(PreferKey.webDavCacheBackup,false)) {
WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav WebDavHelp.exportWebDav(file.absolutePath, filename) // 导出到webdav
} }
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->

@ -88,6 +88,8 @@ class ChangeSourceDialog : BaseDialogFragment(),
tool_bar.setOnMenuItemClickListener(this) tool_bar.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_load_toc)?.isChecked = tool_bar.menu.findItem(R.id.menu_load_toc)?.isChecked =
getPrefBoolean(PreferKey.changeSourceLoadToc) getPrefBoolean(PreferKey.changeSourceLoadToc)
tool_bar.menu.findItem(R.id.menu_load_info)?.isChecked =
getPrefBoolean(PreferKey.changeSourceLoadInfo)
} }
private fun initRecyclerView() { private fun initRecyclerView() {
@ -159,6 +161,10 @@ class ChangeSourceDialog : BaseDialogFragment(),
putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked)
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
} }
R.id.menu_load_info -> {
putPrefBoolean(PreferKey.changeSourceLoadInfo, !item.isChecked)
item.isChecked = !item.isChecked
}
R.id.menu_stop -> viewModel.stopSearch() R.id.menu_stop -> viewModel.stopSearch()
} }
return false return false

@ -120,11 +120,11 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
.onSuccess(IO) { .onSuccess(IO) {
it.forEach { searchBook -> it.forEach { searchBook ->
if (searchBook.name == name && searchBook.author == author) { if (searchBook.name == name && searchBook.author == author) {
if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { if (searchBook.latestChapterTitle.isNullOrEmpty()) {
if (searchBook.tocUrl.isEmpty()) { if (context.getPrefBoolean(PreferKey.changeSourceLoadInfo) || context.getPrefBoolean(PreferKey.changeSourceLoadToc)) {
loadBookInfo(searchBook.toBook()) loadBookInfo(searchBook.toBook())
} else { } else {
loadChapter(searchBook.toBook()) searchFinish(searchBook)
} }
} else { } else {
searchFinish(searchBook) searchFinish(searchBook)
@ -156,7 +156,14 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book, this) WebBook(bookSource).getBookInfo(book, this)
.onSuccess { .onSuccess {
if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) {
loadChapter(it) loadChapter(it)
} else {
//从详情页里获取最新章节
book.latestChapterTitle = it.latestChapterTitle
val searchBook = book.toSearchBook()
searchFinish(searchBook)
}
}.onError { }.onError {
debug { context.getString(R.string.error_get_book_info) } debug { context.getString(R.string.error_get_book_info) }
} }

@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.Log
import android.view.* import android.view.*
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.core.view.get import androidx.core.view.get
@ -56,16 +57,14 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.android.synthetic.main.view_read_menu.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.lang.Runnable
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_book_read), class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_book_read),
View.OnTouchListener, View.OnTouchListener,
@ -789,14 +788,22 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
pages = ReadBook.curTextChapter?.pages pages = ReadBook.curTextChapter?.pages
} }
val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!) val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!)
//todo: show selected text while (ReadBook.durPageIndex != positions[0]){
val job1 = async(Main){ delay(100L)
ReadBook.skipToPage(positions[0]) ReadBook.skipToPage(positions[0])
page_view.curPage.selectStartMoveIndex(positions[0], positions[1], 0) }
page_view.curPage.selectEndMoveIndex(positions[0], positions[1], 0 + query.length ) withContext(Main){
page_view.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L)
when (positions[3]){
0 -> page_view.curPage.selectEndMoveIndex(0, positions[1], positions[2] + query.length - 1)
1 -> page_view.curPage.selectEndMoveIndex(0, positions[1] + 1, positions[4])
//todo: consider change page, jump to scroll position
-1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4])
}
page_view.isTextSelected = true page_view.isTextSelected = true
delay(100L)
} }
job1.await()
} }
} }
requestCodeReplace -> onReplaceRuleSave() requestCodeReplace -> onReplaceRuleSave()

@ -24,4 +24,10 @@
android:checkable="true" android:checkable="true"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_load_info"
android:title="@string/load_info"
android:checkable="true"
app:showAsAction="never" />
</menu> </menu>

@ -10,8 +10,8 @@
<string name="menu_import_old">導入閲讀數據</string> <string name="menu_import_old">導入閲讀數據</string>
<string name="mkdirs">創建子文件夾</string> <string name="mkdirs">創建子文件夾</string>
<string name="mkdirs_description">創建 legado 文件夾作爲備份路徑</string> <string name="mkdirs_description">創建 legado 文件夾作爲備份路徑</string>
<string name="export_webdav">離線導出WebDav</string> <string name="webdav_cache_backup">離線緩存書籍備份</string>
<string name="export_webdav_s">默認導出到legado文件夾下exports目錄</string> <string name="webdav_cache_backup_s">導出本地同時備份到legado文件夾下exports目錄</string>
<string name="backup_path">備份路徑</string> <string name="backup_path">備份路徑</string>
<string name="menu_import_old_version">導入舊版數據</string> <string name="menu_import_old_version">導入舊版數據</string>
<string name="menu_import_github">導入 Github 數據</string> <string name="menu_import_github">導入 Github 數據</string>
@ -568,6 +568,7 @@
<string name="export_selection">導出所選</string> <string name="export_selection">導出所選</string>
<string name="export">導出</string> <string name="export">導出</string>
<string name="load_toc">加載目錄</string> <string name="load_toc">加載目錄</string>
<string name="load_info">加載詳情頁</string>
<string name="tts">TTS</string> <string name="tts">TTS</string>
<string name="web_dav_pw">WebDav 密碼</string> <string name="web_dav_pw">WebDav 密碼</string>
<string name="web_dav_pw_s">輸入你的 WebDav 授權密碼</string> <string name="web_dav_pw_s">輸入你的 WebDav 授權密碼</string>

@ -10,8 +10,8 @@
<string name="menu_import_old">匯入閱讀資料</string> <string name="menu_import_old">匯入閱讀資料</string>
<string name="mkdirs">建立子資料夾</string> <string name="mkdirs">建立子資料夾</string>
<string name="mkdirs_description">建立legado資料夾作為備份資料夾</string> <string name="mkdirs_description">建立legado資料夾作為備份資料夾</string>
<string name="export_webdav">離線導出WebDav</string> <string name="webdav_cache_backup">離線緩存書籍備份</string>
<string name="export_webdav_s">默認導出到legado文件夾下exports目錄</string> <string name="webdav_cache_backup_s">導出本地同時備份到legado文件夾下exports目錄</string>
<string name="backup_path">備份路徑</string> <string name="backup_path">備份路徑</string>
<string name="menu_import_old_version">匯入舊版資料</string> <string name="menu_import_old_version">匯入舊版資料</string>
<string name="menu_import_github">匯入Github資料</string> <string name="menu_import_github">匯入Github資料</string>
@ -569,6 +569,7 @@
<string name="export_selection">匯出所選</string> <string name="export_selection">匯出所選</string>
<string name="export">匯出</string> <string name="export">匯出</string>
<string name="load_toc">載入目錄</string> <string name="load_toc">載入目錄</string>
<string name="load_info">載入詳情頁</string>
<string name="tts">TTS</string> <string name="tts">TTS</string>
<string name="web_dav_pw">WebDav 密碼</string> <string name="web_dav_pw">WebDav 密碼</string>
<string name="web_dav_pw_s">輸入你的WebDav授權密碼</string> <string name="web_dav_pw_s">輸入你的WebDav授權密碼</string>

@ -10,8 +10,8 @@
<string name="menu_import_old">导入阅读数据</string> <string name="menu_import_old">导入阅读数据</string>
<string name="mkdirs">创建子文件夹</string> <string name="mkdirs">创建子文件夹</string>
<string name="mkdirs_description">创建legado文件夹作为备份文件夹</string> <string name="mkdirs_description">创建legado文件夹作为备份文件夹</string>
<string name="export_webdav">离线导出WebDav</string> <string name="webdav_cache_backup">离线缓存书籍备份</string>
<string name="export_webdav_s">默认导出到legado文件夹下exports目录</string> <string name="webdav_cache_backup_s">导出本地同时备份到legado文件夹下exports目录</string>
<string name="backup_path">备份路径</string> <string name="backup_path">备份路径</string>
<string name="select_backup_path">请选择备份路径</string> <string name="select_backup_path">请选择备份路径</string>
<string name="menu_import_old_version">导入旧版数据</string> <string name="menu_import_old_version">导入旧版数据</string>
@ -575,6 +575,7 @@
<string name="export_selection">导出所选</string> <string name="export_selection">导出所选</string>
<string name="export">导出</string> <string name="export">导出</string>
<string name="load_toc">加载目录</string> <string name="load_toc">加载目录</string>
<string name="load_info">加载详情页</string>
<string name="tts">TTS</string> <string name="tts">TTS</string>
<string name="web_dav_pw">WebDav 密码</string> <string name="web_dav_pw">WebDav 密码</string>
<string name="web_dav_pw_s">输入你的WebDav授权密码</string> <string name="web_dav_pw_s">输入你的WebDav授权密码</string>

@ -10,8 +10,8 @@
<string name="menu_import_old">Import Legado data</string> <string name="menu_import_old">Import Legado data</string>
<string name="mkdirs">Create a subfolder</string> <string name="mkdirs">Create a subfolder</string>
<string name="mkdirs_description">Create a folder named Legado as the backup folder.</string> <string name="mkdirs_description">Create a folder named Legado as the backup folder.</string>
<string name="export_webdav">Export Webdav</string> <string name="webdav_cache_backup">Offline cache book backup</string>
<string name="export_webdav_s">Default export to the exports directory under the legado folder</string> <string name="webdav_cache_backup_s">Export to local and back up to the exports directory under the legado folder</string>
<string name="backup_path">Backup to</string> <string name="backup_path">Backup to</string>
<string name="select_backup_path">Please select a backup path.</string> <string name="select_backup_path">Please select a backup path.</string>
<string name="menu_import_old_version">Import legacy data</string> <string name="menu_import_old_version">Import legacy data</string>
@ -577,6 +577,7 @@
<string name="export_selection">Export selected</string> <string name="export_selection">Export selected</string>
<string name="export">Export</string> <string name="export">Export</string>
<string name="load_toc">Load chapters</string> <string name="load_toc">Load chapters</string>
<string name="load_info">Load book detail</string>
<string name="tts">TTS</string> <string name="tts">TTS</string>
<string name="web_dav_pw">WebDav password</string> <string name="web_dav_pw">WebDav password</string>
<string name="web_dav_pw_s">Input you WebDav authorized password</string> <string name="web_dav_pw_s">Input you WebDav authorized password</string>

@ -39,8 +39,8 @@
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:key="webDavExport" android:key="webDavExport"
android:defaultValue="false" android:defaultValue="false"
android:title="@string/export_webdav" android:title="@string/webdav_cache_backup"
android:summary="@string/export_webdav_s" android:summary="@string/webdav_cache_backup_s"
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

Loading…
Cancel
Save