From bffbf0e46bae1933bcd42b7fd23e436f6e8e503b Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Mon, 14 Sep 2020 21:33:52 -0400 Subject: [PATCH 01/48] revert log --- .../main/java/io/legado/app/service/help/ReadBook.kt | 11 +++++++++++ .../io/legado/app/ui/book/read/ReadBookActivity.kt | 5 +++++ .../app/ui/book/searchContent/SearchListFragment.kt | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 2e96221f3..dfa337ae7 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -339,9 +339,11 @@ object ReadBook { index = content.indexOf(query, index + 1); count += 1 } + Log.d("h11128", "new index $index") val contentPosition = index var pageIndex = 0 var length = pages[pageIndex].text.length + Log.d("h11128", "page size ${pages.size}") while (length < contentPosition){ pageIndex += 1 if (pageIndex >pages.size){ @@ -349,12 +351,16 @@ object ReadBook { break } length += pages[pageIndex].text.length + Log.d("h11128", "to next page , add length change to $length") } + Log.d("h11128", "at pageindex $pageIndex") + // calculate search result's lineIndex val currentPage = pages[pageIndex] var lineIndex = 0 length = length - currentPage.text.length + currentPage.textLines[lineIndex].text.length + Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") while (length < contentPosition){ lineIndex += 1 if (lineIndex >currentPage.textLines.size){ @@ -362,12 +368,17 @@ object ReadBook { break } length += currentPage.textLines[lineIndex].text.length + Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") } // charIndex + Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") + Log.d("h11128", "currentLength $length") val currentLine = currentPage.textLines[lineIndex] length -= currentLine.text.length + Log.d("h11128", "currentLength $length") val charIndex = contentPosition - length + Log.d("h11128", "contentLength $contentPosition") return arrayOf(pageIndex, lineIndex, charIndex) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7120e047a..7abcdfc3a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -780,13 +780,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0) val query = data.getStringExtra("query") viewModel.openChapter(index) + // block until load correct chapter and pages var pages = ReadBook.curTextChapter?.pages while (ReadBook.durChapterIndex != index || pages == null ){ delay(100L) pages = ReadBook.curTextChapter?.pages } + Log.d("h11128", "Current chapter pages ${pages.size}") val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!) + Log.d("h11128", positions[0].toString()) + Log.d("h11128", positions[1].toString()) + Log.d("h11128", positions[2].toString()) //todo: show selected text val job1 = async(Main){ ReadBook.skipToPage(positions[0]) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt index 38ac013df..646153b6c 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt @@ -121,12 +121,15 @@ class SearchListFragment : VMBaseFragment(R.layout.fragment val job = async(IO){ if (isLocalBook || adapter.cacheFileNames.contains(BookHelp.formatChapterName(chapter))) { searchResults = searchChapter(newText, chapter) + //Log.d("h11128", "find ${searchResults.size} results in chapter ${chapter.title}") } } job.await() if (searchResults.isNotEmpty()){ + //Log.d("h11128", "load ${searchResults.size} results in chapter ${chapter.title}") searchResultList.addAll(searchResults) tv_current_search_info.text = "搜索结果:$searchResultCounts" + //Log.d("h11128", "searchResultList size ${searchResultList.size}") adapter.addItems(searchResults) searchResults = listOf() } @@ -226,6 +229,7 @@ class SearchListFragment : VMBaseFragment(R.layout.fragment searchData.putExtra("contentPosition", searchResult.contentPosition) searchData.putExtra("query", searchResult.query) searchData.putExtra("indexWithinChapter", searchResult.indexWithinChapter) + Log.d("h11128","current chapter index ${searchResult.chapterIndex}") activity?.setResult(RESULT_OK, searchData) activity?.finish() From 48e7d49ae7b6835576cfad7fc904d624ad8807cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Wed, 16 Sep 2020 09:14:30 +0800 Subject: [PATCH 02/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/explore/ExploreShowAdapter.kt | 6 +++++- .../app/ui/book/search/SearchAdapter.kt | 19 ++++++++++++++++--- .../app/ui/main/explore/ExploreAdapter.kt | 11 ++++------- app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index 322e4a7a3..1118eb8cc 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -26,7 +26,11 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : tv_lasted.text = context.getString(R.string.lasted_show, item.latestChapterTitle) tv_lasted.visible() } - tv_introduce.text = context.getString(R.string.intro_show, item.intro) + if (item.intro.isNullOrEmpty()) { + tv_introduce.text = context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = context.getString(R.string.intro_show, item.intro) + } val kinds = item.getKindList() if (kinds.isEmpty()) { ll_kind.gone() diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index a96244113..4370e9697 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -42,7 +42,13 @@ class SearchAdapter(context: Context, val callBack: CallBack) : tv_author.text = context.getString(R.string.author_show, searchBook.author) bv_originCount.setBadgeCount(searchBook.origins.size) upLasted(itemView, searchBook.latestChapterTitle) - tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) + if (searchBook.intro.isNullOrEmpty()) { + tv_introduce.text = + context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) + } upKind(itemView, searchBook.getKindList()) iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) @@ -58,8 +64,15 @@ class SearchAdapter(context: Context, val callBack: CallBack) : context.getString(R.string.author_show, searchBook.author) "origins" -> bv_originCount.setBadgeCount(searchBook.origins.size) "last" -> upLasted(itemView, searchBook.latestChapterTitle) - "intro" -> tv_introduce.text = - context.getString(R.string.intro_show, searchBook.intro) + "intro" -> { + if (searchBook.intro.isNullOrEmpty()) { + tv_introduce.text = + context.getString(R.string.intro_show_null) + } else { + tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) + } + } "kind" -> upKind(itemView, searchBook.getKindList()) "cover" -> iv_cover.load( searchBook.coverUrl, diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index ccfa5bf82..0fdfa373f 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -11,10 +11,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.ACache -import io.legado.app.utils.dp -import io.legado.app.utils.gone -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.coroutines.CoroutineScope @@ -55,12 +52,12 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca .inflate(R.layout.item_fillet_text, gl_child, false) gl_child.addView(tv) tv.text_view.text = kind.title - tv.text_view.onClick { - kind.url?.let { kindUrl -> + if (!kind.url.isNullOrEmpty()) { + tv.text_view.onClick { callBack.openExplore( item.bookSourceUrl, kind.title, - kindUrl + kind.url.toString() ) } } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index c585ffb97..7eb76aee8 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -223,6 +223,7 @@ 載入失敗,點擊重試 內容簡介 簡介: %s + 簡介: 暫無簡介 打開外部書籍 來源: %s 本地導入 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 006b4ff45..11101e7eb 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -223,6 +223,7 @@ 載入失敗,點擊重試 內容簡介 簡介:%s + 簡介: 暫無簡介 打開外部書籍 來源: %s 本機匯入 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 78487a2be..6052fe4f5 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -225,6 +225,7 @@ 加载失败,点击重试 内容简介 简介:%s + 简介: 暂无简介 打开外部书籍 来源: %s 本地导入 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 893230b30..89c65602e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -225,6 +225,7 @@ Load failed, tap to retry Book description Description:%s + Description: no introduction Open external book Origin: %s Import local rules From 24c026f77e553df69eb1d27ef7e8c01c70bae197 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 16 Sep 2020 10:07:06 +0800 Subject: [PATCH 03/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadMenu.kt | 13 +++-- .../app/ui/book/searchContent/SearchResult.kt | 13 +++-- app/src/main/res/layout/view_read_menu.xml | 58 +++++++------------ 3 files changed, 35 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 26423e701..e56a47066 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -170,6 +170,13 @@ class ReadMenu : FrameLayout { } }) + //搜索 + fabSearch.onClick { + runMenuOut { + callBack?.openSearchList() + } + } + //自动翻页 fabAutoPage.onClick { runMenuOut { @@ -200,12 +207,6 @@ class ReadMenu : FrameLayout { } } - ll_search.onClick { - runMenuOut { - callBack?.openSearchList() - } - } - //朗读 ll_read_aloud.onClick { runMenuOut { diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt index 3a629839b..2de16020b 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt @@ -4,6 +4,7 @@ import android.text.Spanned import androidx.core.text.HtmlCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.hexString @@ -19,18 +20,20 @@ data class SearchResult( var newPosition: Int = 0, var contentPosition: Int =0 ) { + val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString + val accentColor = App.INSTANCE.accentColor.hexString + val presentText: String - get(){ + get() { return colorPresentText(newPosition, query, text) + - "($chapterTitle)" + "($chapterTitle)" } - fun colorPresentText(position: Int, center: String, targetText: String): String { + private fun colorPresentText(position: Int, center: String, targetText: String): String { val sub1 = text.substring(0, position) val sub2 = text.substring(position + center.length, targetText.length) - val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString return "$sub1" + - "$center" + + "$center" + "$sub2" } diff --git a/app/src/main/res/layout/view_read_menu.xml b/app/src/main/res/layout/view_read_menu.xml index b63fba1ff..d48221169 100644 --- a/app/src/main/res/layout/view_read_menu.xml +++ b/app/src/main/res/layout/view_read_menu.xml @@ -92,6 +92,26 @@ android:paddingStart="32dp" android:paddingEnd="32dp"> + + + + - - - - - - - - - Date: Wed, 16 Sep 2020 10:18:49 +0800 Subject: [PATCH 04/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index e56a47066..bef8898ee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -65,6 +65,8 @@ class ReadMenu : FrameLayout { brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) ll_brightness.background = brightnessBackground ll_bottom_bg.setBackgroundColor(bgColor) + fabSearch.backgroundTintList = bottomBackgroundList + fabSearch.setColorFilter(textColor) fabAutoPage.backgroundTintList = bottomBackgroundList fabAutoPage.setColorFilter(textColor) fabReplaceRule.backgroundTintList = bottomBackgroundList From 24e87036632c7312393116b6b37a41146c149712 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 16 Sep 2020 14:15:28 +0800 Subject: [PATCH 05/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/searchContent/SearchListAdapter.kt | 19 +++--------- .../app/ui/book/searchContent/SearchResult.kt | 31 +++++++------------ 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt index d2c98b955..d68eb85ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt @@ -1,21 +1,12 @@ package io.legado.app.ui.book.searchContent import android.content.Context -import android.os.Build -import android.text.Html -import android.util.Log -import android.view.View -import androidx.annotation.RequiresApi -import androidx.core.text.HtmlCompat import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter -import io.legado.app.data.entities.BookChapter -import io.legado.app.help.BookHelp import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor -import io.legado.app.utils.visible -import kotlinx.android.synthetic.main.item_bookmark.view.* +import io.legado.app.utils.hexString import kotlinx.android.synthetic.main.item_search_list.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -23,15 +14,15 @@ class SearchListAdapter(context: Context, val callback: Callback) : SimpleRecyclerAdapter(context, R.layout.item_search_list) { val cacheFileNames = hashSetOf() + val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2) + val accentColor = context.accentColor.hexString.substring(2) override fun convert(holder: ItemViewHolder, item: SearchResult, payloads: MutableList) { with(holder.itemView) { val isDur = callback.durChapterIndex() == item.chapterIndex if (payloads.isEmpty()) { - tv_search_result.text = item.parseText(item.presentText) - if (isDur){ - tv_search_result.paint.isFakeBoldText = true - } + tv_search_result.text = item.getHtmlCompat(textColor, accentColor) + tv_search_result.paint.isFakeBoldText = isDur } } } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt index 2de16020b..482afab30 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt @@ -2,11 +2,6 @@ package io.legado.app.ui.book.searchContent import android.text.Spanned import androidx.core.text.HtmlCompat -import io.legado.app.App -import io.legado.app.R -import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.getCompatColor -import io.legado.app.utils.hexString data class SearchResult( var index: Int = 0, @@ -20,16 +15,20 @@ data class SearchResult( var newPosition: Int = 0, var contentPosition: Int =0 ) { - val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString - val accentColor = App.INSTANCE.accentColor.hexString - val presentText: String - get() { - return colorPresentText(newPosition, query, text) + - "($chapterTitle)" - } + fun getHtmlCompat(textColor: String, accentColor: String): Spanned { + val html = colorPresentText(newPosition, query, text, textColor, accentColor) + + "($chapterTitle)" + return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) + } - private fun colorPresentText(position: Int, center: String, targetText: String): String { + private fun colorPresentText( + position: Int, + center: String, + targetText: String, + textColor: String, + accentColor: String + ): String { val sub1 = text.substring(0, position) val sub2 = text.substring(position + center.length, targetText.length) return "$sub1" + @@ -37,10 +36,4 @@ data class SearchResult( "$sub2" } - fun parseText(targetText: String): Spanned { - return HtmlCompat.fromHtml(targetText, HtmlCompat.FROM_HTML_MODE_LEGACY) - } - - - } \ No newline at end of file From 06164384025067dd5ca314b52d566f2a22b7b61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Wed, 16 Sep 2020 14:43:10 +0800 Subject: [PATCH 06/48] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/EventBus.kt | 3 +++ .../main/java/io/legado/app/help/AppConfig.kt | 3 +++ .../legado/app/service/CheckSourceService.kt | 26 ++++++++++++++----- .../book/source/manage/BookSourceActivity.kt | 25 ++++++++++++++++++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/pref_key_value.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_config_other.xml | 7 +++++ 10 files changed, 67 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 6fe8b5cea..53ec7d778 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -20,4 +20,7 @@ object EventBus { const val WEB_SERVICE_STOP = "webServiceStop" const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" + const val CHECK_INIT = "checkInit" + const val CHECK_UP_PROGRESS = "checkProgress" + const val CHECK_DONE = "checkDone" } \ No newline at end of file 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 e2538e902..eddc4f428 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -58,6 +58,9 @@ object AppConfig { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } + val backgroundVerification: Boolean + get() = App.INSTANCE.getPrefBoolean(R.string.pk_background_verification) + val autoRefreshBook: Boolean get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 09900d0d0..4ce08ff07 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -6,12 +6,15 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst +import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig +import io.legado.app.help.AppConfig.backgroundVerification import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.manage.BookSourceActivity +import io.legado.app.utils.postEvent import kotlinx.coroutines.asCoroutineDispatcher import org.jetbrains.anko.toast import java.util.concurrent.Executors @@ -42,7 +45,9 @@ class CheckSourceService : BaseService() { override fun onCreate() { super.onCreate() - updateNotification(0, getString(R.string.start)) + if (backgroundVerification) { + updateNotification(0, getString(R.string.start)) + } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -59,6 +64,7 @@ class CheckSourceService : BaseService() { super.onDestroy() tasks.clear() searchPool.close() + postEvent(EventBus.CHECK_DONE, 0) } private fun check(ids: List) { @@ -72,7 +78,11 @@ class CheckSourceService : BaseService() { allIds.addAll(ids) processIndex = 0 threadCount = min(allIds.size, threadCount) - updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + if (backgroundVerification) { + updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + } else { + postEvent(EventBus.CHECK_INIT, allIds.size) + } for (i in 0 until threadCount) { check() } @@ -106,10 +116,14 @@ class CheckSourceService : BaseService() { synchronized(this) { check() checkedIds.add(sourceUrl) - updateNotification( - checkedIds.size, - getString(R.string.progress_show, checkedIds.size, allIds.size) - ) + if (backgroundVerification) { + updateNotification( + checkedIds.size, + getString(R.string.progress_show, checkedIds.size, allIds.size) + ) + } else { + postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) + } if (processIndex >= allIds.size + threadCount - 1) { stopSelf() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 07f959719..33edb5624 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern +import io.legado.app.constant.EventBus import io.legado.app.data.entities.BookSource import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.* @@ -65,6 +66,12 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var sort = 0 private var sortAscending = 0 + private val progressDialogBuilder by lazy { + progressDialog("校验书源") { + setCancelable(false) + } + } + override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() @@ -263,6 +270,24 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } + override fun observeLiveBus() { + observeEvent(EventBus.CHECK_INIT) { max-> + progressDialogBuilder.max = max + progressDialogBuilder.show() + } + observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> + progressDialogBuilder.progress = progress + } + observeEvent(EventBus.CHECK_DONE) { + if (progressDialogBuilder.isShowing) { + progressDialogBuilder.progress = it + progressDialogBuilder.max = it + progressDialogBuilder.dismiss() + } + toast("校验完成") + } + } + override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7eb76aee8..649f57d1a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -94,6 +94,8 @@ 閲讀3.0下載地址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release Version %s + 後臺校驗書源 + 打開后可以在校驗書源時自由操作 自動刷新 打開程式時自動更新書輯 自動下載最新章節 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 11101e7eb..17cc16af4 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -94,6 +94,8 @@ 閱讀3.0下載網址:\nhttps://play.google.com/store/apps/details?id=io.legado.play.release Version %s + 後臺校驗書源 + 打開后可以在校驗書源時自由操作 自動重新整理 打開軟體時自動更新書籍 自動下載最新章節 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6052fe4f5..2a5645ab8 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -96,6 +96,8 @@ 阅读3.0下载地址:\nhttps://www.coolapk.com/apk/256030 Version %s + 后台校验书源 + 打开后可以在校验书源时自由操作 自动刷新 打开软件时自动更新书籍 自动下载最新章节 diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 42058ce0c..7ce2f7f13 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -1,5 +1,6 @@ + background_verification auto_refresh list_screen_direction full_screen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 89c65602e..8ae687184 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,6 +96,8 @@ Legado (YueDu 3.0) download link:\n https://play.google.com/store/apps/details?id=io.legado.play.release Version %s + Background-verification + you can operate freely when verifying the book source Auto-refresh Update books automatically when opening the software Auto-download diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0e3930546..f4f28ca94 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -51,6 +51,13 @@ app:iconSpaceReserved="false" app:layout="@layout/view_preference_category"> + + Date: Wed, 16 Sep 2020 14:55:25 +0800 Subject: [PATCH 07/48] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E5=A4=B1=E6=95=88=E4=B9=A6=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/source/manage/BookSourceActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 33edb5624..e0eff84e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -284,7 +284,14 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity progressDialogBuilder.max = it progressDialogBuilder.dismiss() } - toast("校验完成") + groups.map { group-> + if (group.indexOf("失效") != -1) { + search_view.setQuery("失效", true) + toast("校验完成,发现有失效书源,已为您自动筛选!") + } else { + toast("校验完成") + } + } } } From 2cff6b4f86c71df6047f3ad988d80e2254b558e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Wed, 16 Sep 2020 15:10:22 +0800 Subject: [PATCH 08/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/source/manage/BookSourceActivity.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index e0eff84e8..d6f1aab3f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -284,12 +284,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity progressDialogBuilder.max = it progressDialogBuilder.dismiss() } + toast("校验完成!") groups.map { group-> - if (group.indexOf("失效") != -1) { + if (group.contains("失效")) { search_view.setQuery("失效", true) - toast("校验完成,发现有失效书源,已为您自动筛选!") - } else { - toast("校验完成") + toast("发现有失效书源,已为您自动筛选!") } } } From c622ed579d4b47102dba77261a87df6016297a02 Mon Sep 17 00:00:00 2001 From: 10bits Date: Wed, 16 Sep 2020 17:58:11 +0800 Subject: [PATCH 09/48] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E4=B9=A6=E7=B1=8D=E5=AF=BC=E5=87=BA=E5=88=B0?= =?UTF-8?q?webdav?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/WebDavHelp.kt | 25 ++++++++++++++++--- .../app/ui/book/cache/CacheViewModel.kt | 20 ++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index e728c28de..327ed5fda 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -10,10 +10,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.selector import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth -import io.legado.app.utils.FileUtils -import io.legado.app.utils.ZipUtils -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefString +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext @@ -125,4 +122,24 @@ object WebDavHelp { } } } + fun exportWebDav(path: String, fileName: String) { + try { + if (initWebDav()) { + //默认导出到legado文件夹下exports目录 + val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/" + //在legado文件夹创建exports目录,如果不存在的话 + WebDav(exportsWebDavUrl).makeAsDir() + val file = File("${path}${File.separator}${fileName}") + //如果导出的本地文件存在,开始上传 + if(file.exists()){ + val putUrl = exportsWebDavUrl + fileName + WebDav(putUrl).upload("${path}${File.separator}${fileName}") + } + } + } catch (e: Exception) { + Handler(Looper.getMainLooper()).post { + App.INSTANCE.toast("WebDav导出\n${e.localizedMessage}") + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 0673aaaab..e0c67bd6b 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp +import io.legado.app.help.storage.WebDavHelp import io.legado.app.utils.* import java.io.File @@ -34,8 +35,19 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(doc: DocumentFile, book: Book) { - DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") - ?.writeText(context, getAllContents(book)) + val filename = "${book.name} 作者:${book.author}.txt" + val content = getAllContents(book) + DocumentUtils.createFileIfNotExist(doc, filename) + ?.writeText(context, content) + //写出文件到cache目录 + FileUtils.createFileIfNotExist( + File(FileUtils.getCachePath()), + filename + ).writeText(content) + //导出到webdav + WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) + //上传完删除cache文件 + FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> @@ -61,8 +73,10 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(file: File, book: Book) { - FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") + val filename = "${book.name} 作者:${book.author}.txt" + FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) + WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> From 1bde9f77ab805a11f7a185987267d26986ea35cc Mon Sep 17 00:00:00 2001 From: 10bits Date: Wed, 16 Sep 2020 20:59:26 +0800 Subject: [PATCH 10/48] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E5=AF=B9windows=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8F=8B=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/cache/CacheViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index e0c67bd6b..4fa6a27a0 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -35,7 +35,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(doc: DocumentFile, book: Book) { - val filename = "${book.name} 作者:${book.author}.txt" + val filename = "${book.name} by ${book.author}.txt" val content = getAllContents(book) DocumentUtils.createFileIfNotExist(doc, filename) ?.writeText(context, content) @@ -73,7 +73,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(file: File, book: Book) { - val filename = "${book.name} 作者:${book.author}.txt" + val filename = "${book.name} by ${book.author}.txt" FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav From 0ab2f07960df8ae2c8ecf322169a6a4abe5cf31c Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 17 Sep 2020 11:19:19 +0800 Subject: [PATCH 11/48] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E4=B9=9F=E5=9C=A8=E5=AD=97=E4=BD=93=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/font/FontSelectDialog.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 0fa7bea7d..ca932932a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -123,6 +123,26 @@ class FontSelectDialog : BaseDialogFragment(), } } + private fun getLocalFonts(): ArrayList { + val fontItems = arrayListOf() + val fontDir = + FileUtils.createFolderIfNotExist(requireContext().externalFilesDir, "font") + fontDir.listFiles { pathName -> + pathName.name.toLowerCase(Locale.getDefault()).matches(fontRegex) + }?.forEach { + fontItems.add( + DocItem( + it.name, + it.extension, + it.length(), + Date(it.lastModified()), + Uri.parse(it.absolutePath) + ) + ) + } + return fontItems + } + private fun loadFontFiles(doc: DocumentFile) { execute { val fontItems = arrayListOf() @@ -132,6 +152,7 @@ class FontSelectDialog : BaseDialogFragment(), fontItems.add(item) } } + fontItems.addAll(getLocalFonts()) fontItems.sortedBy { it.name } }.onSuccess { adapter?.setItems(it) @@ -167,6 +188,7 @@ class FontSelectDialog : BaseDialogFragment(), ) ) } + fontItems.addAll(getLocalFonts()) fontItems.sortedBy { it.name } }.onSuccess { adapter?.setItems(it) From e65ccf2dd25697dfb3a474a167de281b906bd411 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 17 Sep 2020 11:42:47 +0800 Subject: [PATCH 12/48] update log --- app/src/main/assets/updateLog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 40348af60..c964cd83e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,12 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/17** +* 优化正文搜索文字颜色 +* 优化书源校验 by KKL369 +* 缓存导出到webDav by 10bits +* 导入的字体在字体选择界面显示 + **2020/09/15** * 修复导入排版字体重复报错的bug * 添加正文搜索 by [h11128](https://github.com/h11128) From bb33743a215fd524e50618faa401be093fea3df2 Mon Sep 17 00:00:00 2001 From: 10bits Date: Thu, 17 Sep 2020 13:02:48 +0800 Subject: [PATCH 13/48] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E5=AF=BC=E5=87=BAWebDav=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../app/ui/book/cache/CacheViewModel.kt | 25 +++++++++++-------- app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_config_backup.xml | 9 +++++++ 7 files changed, 33 insertions(+), 10 deletions(-) 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 c6e222849..3e89dd2e2 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -33,6 +33,7 @@ object PreferKey { const val webDavAccount = "web_dav_account" const val webDavPassword = "web_dav_password" const val webDavCreateDir = "webDavCreateDir" + const val webDavExport = "webDavExport" const val changeSourceLoadToc = "changeSourceLoadToc" const val chineseConverterType = "chineseConverterType" const val launcherIcon = "launcherIcon" diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 4fa6a27a0..afc78bc37 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern +import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp import io.legado.app.help.storage.WebDavHelp @@ -39,15 +40,17 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val content = getAllContents(book) DocumentUtils.createFileIfNotExist(doc, filename) ?.writeText(context, content) - //写出文件到cache目录 - FileUtils.createFileIfNotExist( - File(FileUtils.getCachePath()), - filename - ).writeText(content) - //导出到webdav - WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) - //上传完删除cache文件 - FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") + if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { + //写出文件到cache目录 + FileUtils.createFileIfNotExist( + File(FileUtils.getCachePath()), + filename + ).writeText(content) + //导出到webdav + WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) + //上传完删除cache文件 + FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") + } App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> @@ -76,7 +79,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val filename = "${book.name} by ${book.author}.txt" FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) - WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav + if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { + WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav + } App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 649f57d1a..eac3f655b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -10,6 +10,8 @@ 導入閲讀數據 創建子文件夾 創建 legado 文件夾作爲備份路徑 + 離線導出WebDav + 默認導出到legado文件夾下exports目錄 備份路徑 導入舊版數據 導入 Github 數據 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 17cc16af4..25fe6e740 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -10,6 +10,8 @@ 匯入閱讀資料 建立子資料夾 建立legado資料夾作為備份資料夾 + 離線導出WebDav + 默認導出到legado文件夾下exports目錄 備份路徑 匯入舊版資料 匯入Github資料 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 2a5645ab8..8981f1707 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -10,6 +10,8 @@ 导入阅读数据 创建子文件夹 创建legado文件夹作为备份文件夹 + 离线导出WebDav + 默认导出到legado文件夹下exports目录 备份路径 请选择备份路径 导入旧版数据 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8ae687184..be20fce1e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,8 @@ Import Legado data Create a subfolder Create a folder named Legado as the backup folder. + Export Webdav + Default export to the exports directory under the legado folder Backup to Please select a backup path. Import legacy data diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index b16c6f32b..1d0ee0a9d 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -36,6 +36,15 @@ app:allowDividerBelow="false" app:iconSpaceReserved="false" /> + + Date: Thu, 17 Sep 2020 17:08:55 +0800 Subject: [PATCH 14/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index f9ed9230f..74160e71d 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -343,7 +343,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } evalMatcher.appendTail(stringBuffer) - val replaceRegex = stringBuffer.toString() + val replaceRegex = Pattern.quote(stringBuffer.toString()) if (replaceRegex.isNotEmpty()) { vResult = if (rule.replaceFirst) { val pattern = Pattern.compile(replaceRegex) @@ -466,15 +466,8 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { //分离put rule = splitPutRule(rule, putMap) //分离正则表达式 - val index = rule.indexOf("}}") - var rule1 = "" - var rule2 = rule - if (index > 0) { - rule1 = rule.substring(0, index) - rule2 = rule.substring(index) - } - val ruleStrS = rule2.trim { it <= ' ' }.split("##") - rule = rule1 + ruleStrS[0] + val ruleStrS = rule.trim { it <= ' ' }.split("##") + rule = ruleStrS[0] if (ruleStrS.size > 1) { replaceRegex = ruleStrS[1] } From 09a39b0b2d656024a67e287e4804636be6f66314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Thu, 17 Sep 2020 21:31:18 +0800 Subject: [PATCH 15/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B1=E7=94=A8?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E9=85=8D=E7=BD=AE=E4=B8=8D=E8=83=BD=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ReadBookConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 4353e2fe1..5cceab22d 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -75,7 +75,7 @@ object ReadBookConfig { } fun initShareConfig() { - val configFile = File(configFilePath) + val configFile = File(shareConfigFilePath) var c: Config? = null if (configFile.exists()) { try { From c2e54e1efd951757f711e8354d3228fa897d6f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Fri, 18 Sep 2020 00:52:09 +0800 Subject: [PATCH 16/48] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=BA=90=E5=88=86=E7=BB=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/README.md | 1 + .../association/ImportBookSourceActivity.kt | 26 +++++++++++++++++++ app/src/main/res/menu/import_source.xml | 6 +++++ app/src/main/res/values-zh/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 3 +++ 5 files changed, 39 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/README.md b/app/src/main/java/io/legado/app/ui/README.md index ef44bed69..102071a0c 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -1,6 +1,7 @@ ## 放置与界面有关的类 * about 关于界面 +* association 导入书源界面 * audio 音频播放界面 * book\arrange 书架整理界面 * book\info 书籍信息查看 diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 07b6451da..c045d0e33 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -20,16 +20,21 @@ import io.legado.app.data.entities.BookSource import io.legado.app.help.IntentDataHelp import io.legado.app.help.SourceHelp import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton +import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_translucence.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_source_import.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast + class ImportBookSourceActivity : VMBaseActivity( R.layout.activity_translucence, theme = Theme.Transparent @@ -112,6 +117,7 @@ class ImportBookSourceActivity : VMBaseActivity( class SourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { lateinit var adapter: SourcesAdapter + private var _groupName: String? = null override fun onStart() { super.onStart() @@ -165,6 +171,23 @@ class ImportBookSourceActivity : VMBaseActivity( override fun onMenuItemClick(item: MenuItem): Boolean { when (item.itemId) { + R.id.menu_new_group -> { + alert(R.string.diy_edit_source_group) { + var editText: AutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + } + } + okButton { + editText?.text?.toString()?.let { group -> + _groupName = group + item.title = getString(R.string.diy_edit_source_group_title, _groupName) + } + } + noButton { } + }.show().applyTint() + } R.id.menu_select_all -> { adapter.selectStatus.forEachIndexed { index, b -> if (!b) { @@ -193,6 +216,9 @@ class ImportBookSourceActivity : VMBaseActivity( private fun importSelect() { val selectSource = arrayListOf() adapter.selectStatus.forEachIndexed { index, b -> + if (_groupName != null) { + adapter.getItem(index)!!.bookSourceGroup = _groupName + } if (b) { selectSource.add(adapter.getItem(index)!!) } diff --git a/app/src/main/res/menu/import_source.xml b/app/src/main/res/menu/import_source.xml index 37c34f4de..8a2971e3f 100644 --- a/app/src/main/res/menu/import_source.xml +++ b/app/src/main/res/menu/import_source.xml @@ -3,6 +3,12 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> + + 源名称(sourceName) 源URL(sourceUrl) 源分组(sourceGroup) + 自定义源分组 + 输入自定义源分组名称 + 【%s】 分类Url 登录URL(loginUrl) 源注释(sourceComment) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be20fce1e..46e2c5304 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -389,6 +389,9 @@ 源名称(sourceName) 源URL(sourceUrl) 源分组(sourceGroup) + 自定义源分组 + 输入自定义源分组名称 + 【%s】 分类Url 登录URL(loginUrl) 源注释(sourceComment) From 11a51f3cd54b8bef1830fae8d4008050017e33e1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 18 Sep 2020 09:18:32 +0800 Subject: [PATCH 17/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 74160e71d..3077cbf51 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -335,15 +335,15 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } ?: "" if (jsEval is String) { - evalMatcher.appendReplacement(stringBuffer, jsEval) + evalMatcher.appendReplacement(stringBuffer, Pattern.quote(jsEval)) } else if (jsEval is Double && jsEval % 1.0 == 0.0) { evalMatcher.appendReplacement(stringBuffer, String.format("%.0f", jsEval)) } else { - evalMatcher.appendReplacement(stringBuffer, jsEval.toString()) + evalMatcher.appendReplacement(stringBuffer, Pattern.quote(jsEval.toString())) } } evalMatcher.appendTail(stringBuffer) - val replaceRegex = Pattern.quote(stringBuffer.toString()) + val replaceRegex = stringBuffer.toString() if (replaceRegex.isNotEmpty()) { vResult = if (rule.replaceFirst) { val pattern = Pattern.compile(replaceRegex) From deed97f761c9ef4dff8b4bcde82500a1f76c90ad Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 18 Sep 2020 09:37:42 +0800 Subject: [PATCH 18/48] update log --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c964cd83e..185160f78 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/18** +* 修复共用布局配置不能读取的问题 +* 添加自定义源分组功能 + **2020/09/17** * 优化正文搜索文字颜色 * 优化书源校验 by KKL369 From f607f0eb25b95c8cdc0f6e18b25f6541c6fd734c Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 18 Sep 2020 09:47:12 +0800 Subject: [PATCH 19/48] up ReaderProvider.kt --- .../java/io/legado/app/api/ReaderProvider.kt | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/ReaderProvider.kt b/app/src/main/java/io/legado/app/api/ReaderProvider.kt index fcf50aa9c..3ae8c7963 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -7,10 +7,7 @@ import android.content.ContentProvider import android.content.ContentResolver import android.content.ContentValues import android.content.UriMatcher -import android.database.CharArrayBuffer -import android.database.ContentObserver -import android.database.Cursor -import android.database.DataSetObserver +import android.database.* import android.net.Uri import android.os.Bundle import com.google.gson.Gson @@ -109,40 +106,22 @@ class ReaderProvider : ContentProvider() { uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array? ) = throw UnsupportedOperationException("Not yet implemented") - + /** * Simple inner class to deliver json callback data. * * Only getString() makes sense. */ - private class SimpleCursor(data: ReturnData?) : Cursor { + private class SimpleCursor(data: ReturnData?) : MatrixCursor(arrayOf("result"), 1) { private val mData: String = Gson().toJson(data) - override fun getCount() = 1 - - override fun getPosition() = 0 - - override fun move(i: Int) = true - - override fun moveToPosition(i: Int) = true - - override fun moveToFirst() = true - - override fun moveToLast() = true - - override fun moveToNext() = true - - override fun moveToPrevious() = true - - override fun isFirst() = true - - override fun isLast() = true - - override fun isBeforeFirst() = true + init { + addRow(arrayOf(mData)) + } - override fun isAfterLast() = true + override fun getCount() = 1 override fun getColumnIndex(s: String) = 0 From 2dbbdfe9f3f41eca5bc8a8f84486369c51ea6000 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 18 Sep 2020 10:05:11 +0800 Subject: [PATCH 20/48] update log --- app/src/main/assets/updateLog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 185160f78..da210dc26 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,8 +4,10 @@ - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 **2020/09/18** +* 解决正文替换{{title}}问题 * 修复共用布局配置不能读取的问题 -* 添加自定义源分组功能 +* 添加自定义源分组功能 by KKL369 +* 解决跨进程调用ReaderProvider出现CursorIndexOutOfBoundsException问题 **2020/09/17** * 优化正文搜索文字颜色 From 7b4d9b34d1515b8f8162a80c8f68e71e0a393b8b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Sep 2020 19:24:22 +0800 Subject: [PATCH 21/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/searchContent/SearchListActivity.kt | 270 ++++++++++++++---- .../book/searchContent/SearchListFragment.kt | 239 ---------------- .../main/res/layout/activity_search_list.xml | 83 +++++- .../main/res/layout/fragment_search_list.xml | 66 ----- 4 files changed, 289 insertions(+), 369 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt delete mode 100644 app/src/main/res/layout/fragment_search_list.xml diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt index ec1cbc0c7..c21f3ce75 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt @@ -1,93 +1,263 @@ package io.legado.app.ui.book.searchContent +import android.annotation.SuppressLint +import android.content.Intent import android.os.Bundle -import android.view.Menu import androidx.appcompat.widget.SearchView -import androidx.core.view.isGone -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentPagerAdapter +import com.hankcs.hanlp.HanLP +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.EventBus +import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookChapter +import io.legado.app.help.AppConfig +import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.theme.bottomBackground +import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.ui.widget.recycler.UpLinearLayoutManager +import io.legado.app.ui.widget.recycler.VerticalDivider +import io.legado.app.utils.ColorUtils import io.legado.app.utils.getViewModel -import io.legado.app.utils.gone -import io.legado.app.utils.visible -import kotlinx.android.synthetic.main.activity_chapter_list.* -import kotlinx.android.synthetic.main.view_tab_layout.* +import io.legado.app.utils.observeEvent +import kotlinx.android.synthetic.main.activity_search_list.* +import kotlinx.android.synthetic.main.view_search.* +import kotlinx.coroutines.* +import org.jetbrains.anko.sdk27.listeners.onClick -class SearchListActivity : VMBaseActivity(R.layout.activity_search_list) { - // todo: 完善搜索界面UI +class SearchListActivity : VMBaseActivity(R.layout.activity_search_list), + SearchListAdapter.Callback, + SearchListViewModel.SearchListCallBack { + override val viewModel: SearchListViewModel get() = getViewModel(SearchListViewModel::class.java) - private var searchView: SearchView? = null + lateinit var adapter: SearchListAdapter + private lateinit var mLayoutManager: UpLinearLayoutManager + private var searchResultCounts = 0 + private var durChapterIndex = 0 + private var searchResultList: MutableList = mutableListOf() override fun onActivityCreated(savedInstanceState: Bundle?) { - tab_layout.isTabIndicatorFullWidth = false - tab_layout.setSelectedTabIndicatorColor(accentColor) + viewModel.searchCallBack = this + val bbg = bottomBackground + val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg)) + ll_search_base_info.setBackgroundColor(bbg) + tv_current_search_info.setTextColor(btc) + iv_search_content_top.setColorFilter(btc) + iv_search_content_bottom.setColorFilter(btc) + initSearchView() + initRecyclerView() + initView() intent.getStringExtra("bookUrl")?.let { viewModel.initBook(it) { - view_pager.adapter = TabFragmentPageAdapter(supportFragmentManager) - tab_layout.setupWithViewPager(view_pager) + initBook() } } } - override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { - menuInflater.inflate(R.menu.search_view, menu) - val search = menu.findItem(R.id.menu_search) - searchView = search.actionView as SearchView - ATH.setTint(searchView!!, primaryTextColor) - searchView?.maxWidth = resources.displayMetrics.widthPixels - searchView?.onActionViewCollapsed() - searchView?.setOnCloseListener { - tab_layout.visible() - //to do clean - false - } - searchView?.setOnSearchClickListener { tab_layout.gone() } - searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + private fun initSearchView() { + ATH.setTint(search_view, primaryTextColor) + search_view.onActionViewExpanded() + search_view.isSubmitButtonEnabled = true + search_view.queryHint = getString(R.string.search) + search_view.clearFocus() + search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { - if (viewModel.lastQuery != query){ + if (viewModel.lastQuery != query) { viewModel.startContentSearch(query) } - return false + return true } - override fun onQueryTextChange(newText: String): Boolean { - + override fun onQueryTextChange(newText: String?): Boolean { return false } }) - return super.onCompatCreateOptionsMenu(menu) } - private inner class TabFragmentPageAdapter(fm: FragmentManager) : - FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { - override fun getItem(position: Int): Fragment { - return SearchListFragment() + private fun initRecyclerView() { + adapter = SearchListAdapter(this, this) + mLayoutManager = UpLinearLayoutManager(this) + recycler_view.layoutManager = mLayoutManager + recycler_view.addItemDecoration(VerticalDivider(this)) + recycler_view.adapter = adapter + } + + private fun initView() { + iv_search_content_top.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } + iv_search_content_bottom.onClick { + if (adapter.itemCount > 0) { + mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) + } + } + } + + @SuppressLint("SetTextI18n") + private fun initBook() { + launch { + tv_current_search_info.text = "搜索结果:$searchResultCounts" + viewModel.book?.let { + initCacheFileNames(it) + durChapterIndex = it.durChapterIndex + } + } + } + + private fun initCacheFileNames(book: Book) { + launch(Dispatchers.IO) { + adapter.cacheFileNames.addAll(BookHelp.getChapterFiles(book)) + withContext(Dispatchers.Main) { + adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true) + } + } + } + + override fun observeLiveBus() { + observeEvent(EventBus.SAVE_CONTENT) { chapter -> + viewModel.book?.bookUrl?.let { bookUrl -> + if (chapter.bookUrl == bookUrl) { + adapter.cacheFileNames.add(BookHelp.formatChapterName(chapter)) + adapter.notifyItemChanged(chapter.index, true) + } + } } + } - override fun getCount(): Int { - return 1 + @SuppressLint("SetTextI18n") + override fun startContentSearch(newText: String) { + // 按章节搜索内容 + if (!newText.isBlank()) { + adapter.clearItems() + searchResultList.clear() + searchResultCounts = 0 + viewModel.lastQuery = newText + var searchResults = listOf() + launch(Dispatchers.Main) { + App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map { chapter -> + val job = async(Dispatchers.IO) { + if (isLocalBook || adapter.cacheFileNames.contains( + BookHelp.formatChapterName( + chapter + ) + ) + ) { + searchResults = searchChapter(newText, chapter) + } + } + job.await() + if (searchResults.isNotEmpty()) { + searchResultList.addAll(searchResults) + tv_current_search_info.text = "搜索结果:$searchResultCounts" + adapter.addItems(searchResults) + searchResults = listOf() + } + } + } } + } - override fun getPageTitle(position: Int): CharSequence? { - return "Search" + private suspend fun searchChapter(query: String, chapter: BookChapter?): List { + val searchResults: MutableList = mutableListOf() + var positions: List + var replaceContents: List? = null + var totalContents: String + if (chapter != null) { + viewModel.book?.let { bookSource -> + val bookContent = BookHelp.getContent(bookSource, chapter) + if (bookContent != null) { + //搜索替换后的正文 + val job = async(Dispatchers.IO) { + chapter.title = when (AppConfig.chineseConverterType) { + 1 -> HanLP.convertToSimplifiedChinese(chapter.title) + 2 -> HanLP.convertToTraditionalChinese(chapter.title) + else -> chapter.title + } + replaceContents = BookHelp.disposeContent( + chapter.title, + bookSource.name, + bookSource.bookUrl, + bookContent, + bookSource.useReplaceRule + ) + } + job.await() + while (replaceContents == null) { + delay(100L) + } + totalContents = replaceContents!!.joinToString("") + positions = searchPosition(totalContents, query) + var count = 1 + positions.map { + val construct = constructText(totalContents, it, query) + val result = SearchResult( + index = searchResultCounts, + indexWithinChapter = count, + text = construct[1] as String, + chapterTitle = chapter.title, + query = query, + chapterIndex = chapter.index, + newPosition = construct[0] as Int, + contentPosition = it + ) + count += 1 + searchResultCounts += 1 + searchResults.add(result) + } + } + } } + return searchResults + } + private fun searchPosition(content: String, pattern: String): List { + val position: MutableList = mutableListOf() + var index = content.indexOf(pattern) + while (index >= 0) { + position.add(index) + index = content.indexOf(pattern, index + 1) + } + return position } - override fun onBackPressed() { - if (tab_layout.isGone) { - searchView?.onActionViewCollapsed() - tab_layout.visible() - } else { - super.onBackPressed() + private fun constructText(content: String, position: Int, query: String): Array { + // 构建关键词周边文字,在搜索结果里显示 + // todo: 判断段落,只在关键词所在段落内分割 + // todo: 利用标点符号分割完整的句 + // todo: length和设置结合,自由调整周边文字长度 + val length = 20 + var po1 = position - length + var po2 = position + query.length + length + if (po1 < 0) { + po1 = 0 + } + if (po2 > content.length) { + po2 = content.length } + val newPosition = position - po1 + val newText = content.substring(po1, po2) + return arrayOf(newPosition, newText) } + + val isLocalBook: Boolean + get() = viewModel.book?.isLocalBook() == true + + override fun openSearchResult(searchResult: SearchResult) { + + val searchData = Intent() + searchData.putExtra("index", searchResult.chapterIndex) + searchData.putExtra("contentPosition", searchResult.contentPosition) + searchData.putExtra("query", searchResult.query) + searchData.putExtra("indexWithinChapter", searchResult.indexWithinChapter) + setResult(RESULT_OK, searchData) + finish() + } + + override fun durChapterIndex(): Int { + return durChapterIndex + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt deleted file mode 100644 index 38ac013df..000000000 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt +++ /dev/null @@ -1,239 +0,0 @@ -package io.legado.app.ui.book.searchContent - -import android.annotation.SuppressLint -import android.app.Activity.RESULT_OK -import android.content.Intent -import android.os.Bundle -import android.util.Log -import android.view.View -import androidx.lifecycle.LiveData -import com.hankcs.hanlp.HanLP -import io.legado.app.App -import io.legado.app.R -import io.legado.app.base.VMBaseFragment -import io.legado.app.constant.EventBus -import io.legado.app.data.entities.Book -import io.legado.app.data.entities.BookChapter -import io.legado.app.help.AppConfig -import io.legado.app.help.BookHelp -import io.legado.app.lib.theme.bottomBackground -import io.legado.app.lib.theme.getPrimaryTextColor -import io.legado.app.service.help.ReadBook -import io.legado.app.ui.book.read.page.entities.TextPage -import io.legado.app.ui.book.read.page.provider.ChapterProvider -import io.legado.app.ui.widget.recycler.UpLinearLayoutManager -import io.legado.app.ui.widget.recycler.VerticalDivider -import io.legado.app.utils.ColorUtils -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.observeEvent -import kotlinx.android.synthetic.main.fragment_search_list.* -import kotlinx.coroutines.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main -import org.jetbrains.anko.sdk27.listeners.onClick -import java.util.regex.Pattern - -class SearchListFragment : VMBaseFragment(R.layout.fragment_search_list), - SearchListAdapter.Callback, - SearchListViewModel.SearchListCallBack{ - override val viewModel: SearchListViewModel - get() = getViewModelOfActivity(SearchListViewModel::class.java) - - lateinit var adapter: SearchListAdapter - private lateinit var mLayoutManager: UpLinearLayoutManager - private var searchResultCounts = 0 - private var durChapterIndex = 0 - private var searchResultList: MutableList = mutableListOf() - - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - viewModel.searchCallBack = this - val bbg = bottomBackground - val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg)) - ll_search_base_info.setBackgroundColor(bbg) - tv_current_search_info.setTextColor(btc) - iv_search_content_top.setColorFilter(btc) - iv_search_content_bottom.setColorFilter(btc) - initRecyclerView() - initView() - initBook() - } - - private fun initRecyclerView() { - adapter = SearchListAdapter(requireContext(), this) - mLayoutManager = UpLinearLayoutManager(requireContext()) - recycler_view.layoutManager = mLayoutManager - recycler_view.addItemDecoration(VerticalDivider(requireContext())) - recycler_view.adapter = adapter - } - - private fun initView() { - iv_search_content_top.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } - iv_search_content_bottom.onClick { - if (adapter.itemCount > 0) { - mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) - } - } - } - - @SuppressLint("SetTextI18n") - private fun initBook() { - launch { - - tv_current_search_info.text = "搜索结果:$searchResultCounts" - viewModel.book?.let { - initCacheFileNames(it) - durChapterIndex = it.durChapterIndex - } - } - } - - private fun initCacheFileNames(book: Book) { - launch(IO) { - adapter.cacheFileNames.addAll(BookHelp.getChapterFiles(book)) - withContext(Main) { - adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true) - } - } - } - - override fun observeLiveBus() { - observeEvent(EventBus.SAVE_CONTENT) { chapter -> - viewModel.book?.bookUrl?.let { bookUrl -> - if (chapter.bookUrl == bookUrl) { - adapter.cacheFileNames.add(BookHelp.formatChapterName(chapter)) - adapter.notifyItemChanged(chapter.index, true) - } - } - } - } - - @SuppressLint("SetTextI18n") - override fun startContentSearch(newText: String) { - // 按章节搜索内容 - if (!newText.isBlank()) { - adapter.clearItems() - searchResultList.clear() - searchResultCounts = 0 - viewModel.lastQuery = newText - var searchResults = listOf() - launch(Main){ - App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map{ chapter -> - val job = async(IO){ - if (isLocalBook || adapter.cacheFileNames.contains(BookHelp.formatChapterName(chapter))) { - searchResults = searchChapter(newText, chapter) - } - } - job.await() - if (searchResults.isNotEmpty()){ - searchResultList.addAll(searchResults) - tv_current_search_info.text = "搜索结果:$searchResultCounts" - adapter.addItems(searchResults) - searchResults = listOf() - } - } - } - } - } - - private suspend fun searchChapter(query: String, chapter: BookChapter?): List { - val searchResults: MutableList = mutableListOf() - var positions : List = listOf() - var replaceContents: List? = null - var totalContents = "" - if (chapter != null){ - viewModel.book?.let { bookSource -> - val bookContent = BookHelp.getContent(bookSource, chapter) - if (bookContent != null){ - //搜索替换后的正文 - val job = async(IO) { - chapter.title = when (AppConfig.chineseConverterType) { - 1 -> HanLP.convertToSimplifiedChinese(chapter.title) - 2 -> HanLP.convertToTraditionalChinese(chapter.title) - else -> chapter.title - } - replaceContents = BookHelp.disposeContent( - chapter.title, - bookSource.name, - bookSource.bookUrl, - bookContent, - bookSource.useReplaceRule - ) - } - job.await() - while (replaceContents == null){ - delay(100L) - } - totalContents = replaceContents!!.joinToString("") - positions = searchPosition(totalContents, query) - var count = 1 - positions.map{ - val construct = constructText(totalContents, it, query) - val result = SearchResult(index = searchResultCounts, - indexWithinChapter = count, - text = construct[1] as String, - chapterTitle = chapter.title, - query = query, - chapterIndex = chapter.index, - newPosition = construct[0] as Int, - contentPosition = it - ) - count += 1 - searchResultCounts += 1 - searchResults.add(result) - } - } - } - } - return searchResults - } - - private fun searchPosition(content: String, pattern: String): List { - val position : MutableList = mutableListOf() - var index = content.indexOf(pattern) - while(index >= 0){ - position.add(index) - index = content.indexOf(pattern, index + 1); - } - return position - } - - private fun constructText(content: String, position: Int, query: String): Array{ - // 构建关键词周边文字,在搜索结果里显示 - // todo: 判断段落,只在关键词所在段落内分割 - // todo: 利用标点符号分割完整的句 - // todo: length和设置结合,自由调整周边文字长度 - val length = 20 - var po1 = position - length - var po2 = position + query.length + length - if (po1 <0) { - po1 = 0 - } - if (po2 > content.length){ - po2 = content.length - } - val newPosition = position - po1 - val newText = content.substring(po1, po2) - return arrayOf(newPosition, newText) - } - - val isLocalBook: Boolean - get() = viewModel.book?.isLocalBook() == true - - override fun openSearchResult(searchResult: SearchResult) { - - val searchData = Intent() - searchData.putExtra("index", searchResult.chapterIndex) - searchData.putExtra("contentPosition", searchResult.contentPosition) - searchData.putExtra("query", searchResult.query) - searchData.putExtra("indexWithinChapter", searchResult.indexWithinChapter) - activity?.setResult(RESULT_OK, searchData) - activity?.finish() - - - } - - override fun durChapterIndex(): Int { - return durChapterIndex - } - -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search_list.xml b/app/src/main/res/layout/activity_search_list.xml index 159f77324..ce7e57b93 100644 --- a/app/src/main/res/layout/activity_search_list.xml +++ b/app/src/main/res/layout/activity_search_list.xml @@ -1,19 +1,74 @@ - + + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:contentLayout="@layout/view_search" + app:contentInsetRight="24dp" + app:layout_constraintTop_toTopOf="parent" /> - + - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search_list.xml b/app/src/main/res/layout/fragment_search_list.xml deleted file mode 100644 index 79fefe11f..000000000 --- a/app/src/main/res/layout/fragment_search_list.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file From b3ef1812b580f60480e5c47c09b23796f5570727 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Sep 2020 19:26:49 +0800 Subject: [PATCH 22/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/searchContent/SearchListActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt index c21f3ce75..12079695d 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt @@ -70,7 +70,7 @@ class SearchListActivity : VMBaseActivity(R.layout.activity if (viewModel.lastQuery != query) { viewModel.startContentSearch(query) } - return true + return false } override fun onQueryTextChange(newText: String?): Boolean { From 3c4bd308ed7de63065a87b108e790784c2aefa1d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Sep 2020 20:00:42 +0800 Subject: [PATCH 23/48] =?UTF-8?q?=E9=98=85=E8=AF=BB=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B9=A6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ReadTipConfig.kt | 1 + app/src/main/res/values-zh-rHK/arrays.xml | 11 +++++++++++ app/src/main/res/values-zh-rTW/arrays.xml | 1 + app/src/main/res/values-zh/arrays.xml | 1 + app/src/main/res/values/arrays.xml | 1 + 5 files changed, 15 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt index eb37a10e1..204851aee 100644 --- a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt @@ -12,6 +12,7 @@ object ReadTipConfig { const val page = 4 const val totalProgress = 5 const val pageAndTotal = 6 + const val bookName = 7 val tipHeaderLeftStr: String get() = tipArray.getOrElse(tipHeaderLeft) { tipArray[none] } val tipHeaderMiddleStr: String get() = tipArray.getOrElse(tipHeaderMiddle) { tipArray[none] } diff --git a/app/src/main/res/values-zh-rHK/arrays.xml b/app/src/main/res/values-zh-rHK/arrays.xml index 4e75577e4..6e2446f65 100644 --- a/app/src/main/res/values-zh-rHK/arrays.xml +++ b/app/src/main/res/values-zh-rHK/arrays.xml @@ -35,6 +35,17 @@ 系統等寬字體 + + + 标题 + 时间 + 电量 + 页数 + 进度 + 页数及进度 + 書名 + + 正常 粗體 diff --git a/app/src/main/res/values-zh-rTW/arrays.xml b/app/src/main/res/values-zh-rTW/arrays.xml index 23909ad85..35192b3a1 100644 --- a/app/src/main/res/values-zh-rTW/arrays.xml +++ b/app/src/main/res/values-zh-rTW/arrays.xml @@ -89,6 +89,7 @@ 頁數 進度 頁數及進度 + 書名 diff --git a/app/src/main/res/values-zh/arrays.xml b/app/src/main/res/values-zh/arrays.xml index 5fdf42b1d..26baaa668 100644 --- a/app/src/main/res/values-zh/arrays.xml +++ b/app/src/main/res/values-zh/arrays.xml @@ -89,6 +89,7 @@ 页数 进度 页数及进度 + 书名 diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 5847f7765..9a0410c81 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -89,6 +89,7 @@ Pages Progress Pages and progress + Book name From edfb3d007209a3e2c512cb4f75812d9d6915dd7b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 20 Sep 2020 16:26:36 +0800 Subject: [PATCH 24/48] =?UTF-8?q?=E9=98=85=E8=AF=BB=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B9=A6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentView.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index e89ee5ae8..166a9b731 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -11,6 +11,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.constant.AppConst.timeFormat import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadTipConfig +import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.widget.BatteryView @@ -29,6 +30,7 @@ class ContentView(context: Context) : FrameLayout(context) { private var tvPage: BatteryView? = null private var tvTotalProgress: BatteryView? = null private var tvPageAndTotal: BatteryView? = null + private var tvBookName: BatteryView? = null val headerHeight: Int get() = if (ReadBookConfig.hideStatusBar) { @@ -185,6 +187,19 @@ class ContentView(context: Context) : FrameLayout(context) { isBattery = false textSize = 12f } + tvBookName = when (ReadTipConfig.bookName) { + ReadTipConfig.tipHeaderLeft -> bv_header_left + ReadTipConfig.tipHeaderMiddle -> tv_header_middle + ReadTipConfig.tipHeaderRight -> tv_header_right + ReadTipConfig.tipFooterLeft -> bv_footer_left + ReadTipConfig.tipFooterMiddle -> tv_footer_middle + ReadTipConfig.tipFooterRight -> tv_footer_right + else -> null + } + tvBookName?.apply { + isBattery = false + textSize = 12f + } } fun setBg(bg: Drawable?) { @@ -213,8 +228,8 @@ class ContentView(context: Context) : FrameLayout(context) { @SuppressLint("SetTextI18n") fun setProgress(textPage: TextPage) = textPage.apply { - val title = textPage.title - tvTitle?.text = title + tvBookName?.text = ReadBook.book?.name + tvTitle?.text = textPage.title tvPage?.text = "${index.plus(1)}/$pageSize" tvTotalProgress?.text = readProgress tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress" From d092e82a5a7598c0fa8cd7f5413141677cb9a290 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 20 Sep 2020 16:30:05 +0800 Subject: [PATCH 25/48] update log --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index da210dc26..c59e8a3ad 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/20** +* 优化正文搜索 +* 阅读界面信息添加书名 + **2020/09/18** * 解决正文替换{{title}}问题 * 修复共用布局配置不能读取的问题 From 60b5b536bf7a0c61b492d2828ba3d276ea92baf2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 20 Sep 2020 19:29:38 +0800 Subject: [PATCH 26/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 12 +++++++----- .../main/java/io/legado/app/ui/book/read/ReadMenu.kt | 4 ++-- .../app/ui/book/searchContent/SearchListActivity.kt | 11 ++++++----- .../app/ui/book/searchContent/SearchListViewModel.kt | 10 ---------- app/src/main/res/menu/content_select_action.xml | 4 ++++ app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 3 +-- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 23 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7120e047a..53a549425 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.os.Handler -import android.util.Log import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.core.view.get @@ -49,7 +48,6 @@ import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.searchContent.SearchListActivity -import io.legado.app.ui.book.searchContent.SearchResult import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.replacerule.ReplaceRuleActivity @@ -496,6 +494,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ) return true } + R.id.menu_search_content -> { + openSearchActivity(selectedText) + return true + } } return false } @@ -680,12 +682,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 打开搜索界面 */ - //todo: change request code - override fun openSearchList() { + override fun openSearchActivity(searchWord: String?) { ReadBook.book?.let { startActivityForResult( requestCodeSearchResult, - Pair("bookUrl", it.bookUrl) + Pair("bookUrl", it.bookUrl), + Pair("searchWord", searchWord) ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index bef8898ee..a532bac2a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -175,7 +175,7 @@ class ReadMenu : FrameLayout { //搜索 fabSearch.onClick { runMenuOut { - callBack?.openSearchList() + callBack?.openSearchActivity(null) } } @@ -300,7 +300,7 @@ class ReadMenu : FrameLayout { fun autoPage() fun openReplaceRule() fun openChapterList() - fun openSearchList() + fun openSearchActivity(searchWord: String?) fun showReadStyle() fun showMoreSetting() fun showReadAloudDialog() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt index 12079695d..6c01801c3 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt @@ -29,8 +29,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class SearchListActivity : VMBaseActivity(R.layout.activity_search_list), - SearchListAdapter.Callback, - SearchListViewModel.SearchListCallBack { + SearchListAdapter.Callback { override val viewModel: SearchListViewModel get() = getViewModel(SearchListViewModel::class.java) @@ -42,7 +41,6 @@ class SearchListActivity : VMBaseActivity(R.layout.activity private var searchResultList: MutableList = mutableListOf() override fun onActivityCreated(savedInstanceState: Bundle?) { - viewModel.searchCallBack = this val bbg = bottomBackground val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg)) ll_search_base_info.setBackgroundColor(bbg) @@ -68,7 +66,7 @@ class SearchListActivity : VMBaseActivity(R.layout.activity search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { if (viewModel.lastQuery != query) { - viewModel.startContentSearch(query) + startContentSearch(query) } return false } @@ -103,6 +101,9 @@ class SearchListActivity : VMBaseActivity(R.layout.activity viewModel.book?.let { initCacheFileNames(it) durChapterIndex = it.durChapterIndex + intent.getStringExtra("searchWord")?.let { searchWord -> + search_view.setQuery(searchWord, true) + } } } } @@ -128,7 +129,7 @@ class SearchListActivity : VMBaseActivity(R.layout.activity } @SuppressLint("SetTextI18n") - override fun startContentSearch(newText: String) { + fun startContentSearch(newText: String) { // 按章节搜索内容 if (!newText.isBlank()) { adapter.clearItems() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt index 060d74067..0b8cd1259 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt @@ -9,7 +9,6 @@ import io.legado.app.data.entities.Book class SearchListViewModel(application: Application) : BaseViewModel(application) { var bookUrl: String = "" var book: Book? = null - var searchCallBack: SearchListCallBack? = null var lastQuery: String = "" fun initBook(bookUrl: String, success: () -> Unit) { @@ -21,13 +20,4 @@ class SearchListViewModel(application: Application) : BaseViewModel(application) } } - fun startContentSearch(newText: String) { - searchCallBack?.startContentSearch(newText) - } - - - interface SearchListCallBack { - fun startContentSearch(newText: String) - } - } \ No newline at end of file diff --git a/app/src/main/res/menu/content_select_action.xml b/app/src/main/res/menu/content_select_action.xml index ff83efd96..692f1092f 100644 --- a/app/src/main/res/menu/content_select_action.xml +++ b/app/src/main/res/menu/content_select_action.xml @@ -13,6 +13,10 @@ android:id="@+id/menu_aloud" android:title="@string/read_aloud" /> + + diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index eac3f655b..2e7d44236 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -766,6 +766,6 @@ 切換默認主題 分享選中書源 時間排序 - 搜索 + 全文搜索 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 25fe6e740..d7d39b40c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -766,7 +766,6 @@ 切換默認主題 分享選中書源 時間排序 - 搜索 - + 全文搜索 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3da57c6c5..8e4821f0a 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -769,6 +769,6 @@ 使用保存主题,导入,分享主题 切换默认主题 时间排序 - 搜索 + 全文搜索 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46e2c5304..77e490b8c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -771,6 +771,6 @@ Save, Import, Share theme Share selected sources Sort by update time - Search + Search content \ No newline at end of file From 1b46547040068595c48d945ef6082e6071181bd6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 07:57:06 +0800 Subject: [PATCH 27/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index d1437ce7c..5f944db99 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -53,6 +53,7 @@ object Backup { suspend fun backup(context: Context, path: String, isAuto: Boolean = false) { context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) withContext(IO) { + FileUtils.deleteFile(backupPath) synchronized(this@Backup) { writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) writeListToJson(App.db.bookmarkDao().all, "bookmark.json", backupPath) From 91b94943e0f50472df3b18671e4d9d66445afc1e Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 07:58:08 +0800 Subject: [PATCH 28/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 5f944db99..6e6cb6791 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -53,8 +53,8 @@ object Backup { suspend fun backup(context: Context, path: String, isAuto: Boolean = false) { context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) withContext(IO) { - FileUtils.deleteFile(backupPath) synchronized(this@Backup) { + FileUtils.deleteFile(backupPath) writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) writeListToJson(App.db.bookmarkDao().all, "bookmark.json", backupPath) writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) From 8a0ff325c5550959f210811fcdb8261b5bb1b44f Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 13:57:07 +0800 Subject: [PATCH 29/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeRule.kt | 53 ++++++------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 3077cbf51..b72bcded3 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -238,6 +238,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { if (ruleList.isNotEmpty()) result = o for (sourceRule in ruleList) { putRule(sourceRule.putMap) + sourceRule.makeUpRule(result) result?.let { result = when (sourceRule.mode) { Mode.Regex -> AnalyzeByRegex.getElement( @@ -324,37 +325,17 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { */ private fun replaceRegex(result: String, rule: SourceRule): String { var vResult = result - val stringBuffer = StringBuffer() - val evalMatcher = replacePattern.matcher(rule.replaceRegex) - while (evalMatcher.find()) { - val jsEval = evalMatcher.group().let { - if (it.startsWith("@get:", true)) { - get(it.substring(6, it.lastIndex)) - } else { - evalJS(it.substring(2, it.length - 2), result) - } - } ?: "" - if (jsEval is String) { - evalMatcher.appendReplacement(stringBuffer, Pattern.quote(jsEval)) - } else if (jsEval is Double && jsEval % 1.0 == 0.0) { - evalMatcher.appendReplacement(stringBuffer, String.format("%.0f", jsEval)) - } else { - evalMatcher.appendReplacement(stringBuffer, Pattern.quote(jsEval.toString())) - } - } - evalMatcher.appendTail(stringBuffer) - val replaceRegex = stringBuffer.toString() - if (replaceRegex.isNotEmpty()) { + if (rule.replaceRegex.isNotEmpty()) { vResult = if (rule.replaceFirst) { - val pattern = Pattern.compile(replaceRegex) + val pattern = Pattern.compile(rule.replaceRegex) val matcher = pattern.matcher(vResult) if (matcher.find()) { - matcher.group(0)!!.replaceFirst(replaceRegex.toRegex(), rule.replacement) + matcher.group(0)!!.replaceFirst(rule.replaceRegex.toRegex(), rule.replacement) } else { "" } } else { - vResult.replace(replaceRegex.toRegex(), rule.replacement) + vResult.replace(rule.replaceRegex.toRegex(), rule.replacement) } } return vResult @@ -465,18 +446,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } //分离put rule = splitPutRule(rule, putMap) - //分离正则表达式 - val ruleStrS = rule.trim { it <= ' ' }.split("##") - rule = ruleStrS[0] - if (ruleStrS.size > 1) { - replaceRegex = ruleStrS[1] - } - if (ruleStrS.size > 2) { - replacement = ruleStrS[2] - } - if (ruleStrS.size > 3) { - replaceFirst = true - } //@get,{{ }},$1, 拆分 var start = 0 var tmp: String @@ -566,6 +535,18 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } rule = infoVal.toString() + //分离正则表达式 + val ruleStrS = rule.trim { it <= ' ' }.split("##") + rule = ruleStrS[0] + if (ruleStrS.size > 1) { + replaceRegex = ruleStrS[1] + } + if (ruleStrS.size > 2) { + replacement = ruleStrS[2] + } + if (ruleStrS.size > 3) { + replaceFirst = true + } } } From 1bc6c95d52af6970de34b9225ee000818bb45ec2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 13:57:57 +0800 Subject: [PATCH 30/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c59e8a3ad..0e4cfb8b6 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/21** +* 修复规则解析bug + **2020/09/20** * 优化正文搜索 * 阅读界面信息添加书名 From 796c217fa15be58f0e49ba495d01728106af161b Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 14:15:18 +0800 Subject: [PATCH 31/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeRule.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index b72bcded3..a205d3893 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -535,18 +535,18 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } rule = infoVal.toString() - //分离正则表达式 - val ruleStrS = rule.trim { it <= ' ' }.split("##") - rule = ruleStrS[0] - if (ruleStrS.size > 1) { - replaceRegex = ruleStrS[1] - } - if (ruleStrS.size > 2) { - replacement = ruleStrS[2] - } - if (ruleStrS.size > 3) { - replaceFirst = true - } + } + //分离正则表达式 + val ruleStrS = rule.trim { it <= ' ' }.split("##") + rule = ruleStrS[0] + if (ruleStrS.size > 1) { + replaceRegex = ruleStrS[1] + } + if (ruleStrS.size > 2) { + replacement = ruleStrS[2] + } + if (ruleStrS.size > 3) { + replaceFirst = true } } From dc5c7f2a3eed9d36cdd379140052ed33159cc9f8 Mon Sep 17 00:00:00 2001 From: 10bits Date: Mon, 21 Sep 2020 20:58:15 +0800 Subject: [PATCH 32/48] =?UTF-8?q?=E4=BC=98=E5=8C=96webdav=E5=A4=87?= =?UTF-8?q?=E4=BB=BD=E7=A6=BB=E7=BA=BF=E7=BC=93=E5=AD=98=E4=B9=A6=E7=B1=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/constant/PreferKey.kt | 2 +- .../java/io/legado/app/help/storage/WebDavHelp.kt | 8 ++++---- .../io/legado/app/ui/book/cache/CacheViewModel.kt | 13 ++++++------- app/src/main/res/values-zh-rHK/strings.xml | 4 ++-- app/src/main/res/values-zh-rTW/strings.xml | 4 ++-- app/src/main/res/values-zh/strings.xml | 4 ++-- app/src/main/res/values/strings.xml | 4 ++-- app/src/main/res/xml/pref_config_backup.xml | 4 ++-- 8 files changed, 21 insertions(+), 22 deletions(-) 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 3e89dd2e2..f40091b0f 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -33,7 +33,7 @@ object PreferKey { const val webDavAccount = "web_dav_account" const val webDavPassword = "web_dav_password" const val webDavCreateDir = "webDavCreateDir" - const val webDavExport = "webDavExport" + const val webDavCacheBackup = "webDavCacheBackup" const val changeSourceLoadToc = "changeSourceLoadToc" const val chineseConverterType = "chineseConverterType" const val launcherIcon = "launcherIcon" diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 327ed5fda..407bcf2c5 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -125,13 +125,13 @@ object WebDavHelp { fun exportWebDav(path: String, fileName: String) { try { if (initWebDav()) { - //默认导出到legado文件夹下exports目录 + // 默认导出到legado文件夹下exports目录 val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/" - //在legado文件夹创建exports目录,如果不存在的话 + // 在legado文件夹创建exports目录,如果不存在的话 WebDav(exportsWebDavUrl).makeAsDir() val file = File("${path}${File.separator}${fileName}") - //如果导出的本地文件存在,开始上传 - if(file.exists()){ + // 如果导出的本地文件存在,开始上传 + if(file.exists()) { val putUrl = exportsWebDavUrl + fileName WebDav(putUrl).upload("${path}${File.separator}${fileName}") } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index afc78bc37..52e26862c 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -40,15 +40,14 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val content = getAllContents(book) DocumentUtils.createFileIfNotExist(doc, filename) ?.writeText(context, content) - if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { - //写出文件到cache目录 + if(App.INSTANCE.getPrefBoolean(PreferKey.webDavCacheBackup,false)) { FileUtils.createFileIfNotExist( File(FileUtils.getCachePath()), filename - ).writeText(content) - //导出到webdav + ).writeText(content) // 写出文件到cache目录 + // 导出到webdav WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) - //上传完删除cache文件 + // 上传完删除cache文件 FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") } 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" FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) - if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { - WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav + if(App.INSTANCE.getPrefBoolean(PreferKey.webDavCacheBackup,false)) { + WebDavHelp.exportWebDav(file.absolutePath, filename) // 导出到webdav } App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index eac3f655b..8ad97bc38 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -10,8 +10,8 @@ 導入閲讀數據 創建子文件夾 創建 legado 文件夾作爲備份路徑 - 離線導出WebDav - 默認導出到legado文件夾下exports目錄 + 離線緩存書籍備份 + 導出本地同時備份到legado文件夾下exports目錄 備份路徑 導入舊版數據 導入 Github 數據 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 25fe6e740..d83bd8552 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -10,8 +10,8 @@ 匯入閱讀資料 建立子資料夾 建立legado資料夾作為備份資料夾 - 離線導出WebDav - 默認導出到legado文件夾下exports目錄 + 離線緩存書籍備份 + 導出本地同時備份到legado文件夾下exports目錄 備份路徑 匯入舊版資料 匯入Github資料 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8981f1707..8f0068f33 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -10,8 +10,8 @@ 导入阅读数据 创建子文件夹 创建legado文件夹作为备份文件夹 - 离线导出WebDav - 默认导出到legado文件夹下exports目录 + 离线缓存书籍备份 + 导出本地同时备份到legado文件夹下exports目录 备份路径 请选择备份路径 导入旧版数据 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be20fce1e..adbda6a61 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,8 +10,8 @@ Import Legado data Create a subfolder Create a folder named Legado as the backup folder. - Export Webdav - Default export to the exports directory under the legado folder + Offline cache book backup + Export to local and back up to the exports directory under the legado folder Backup to Please select a backup path. Import legacy data diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index 1d0ee0a9d..dc5ec4f37 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -39,8 +39,8 @@ From c02c35a4c9c19af4aa247734b2f7904f4ea11194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Mon, 21 Sep 2020 23:31:46 +0800 Subject: [PATCH 33/48] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E4=B9=A6=E6=BA=90=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/EventBus.kt | 1 + .../legado/app/service/CheckSourceService.kt | 13 +-- .../book/source/manage/BookSourceActivity.kt | 101 ++++++++++++------ .../res/layout/dialog_progressbar_view.xml | 36 +++++++ app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 8 files changed, 116 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/layout/dialog_progressbar_view.xml diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 53ec7d778..8ea4122b9 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -22,5 +22,6 @@ object EventBus { const val SAVE_CONTENT = "saveContent" const val CHECK_INIT = "checkInit" const val CHECK_UP_PROGRESS = "checkProgress" + const val CHECK_UP_PROGRESS_STRING = "checkProgressTxt" const val CHECK_DONE = "checkDone" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 4ce08ff07..705ff19c9 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -79,7 +79,7 @@ class CheckSourceService : BaseService() { processIndex = 0 threadCount = min(allIds.size, threadCount) if (backgroundVerification) { - updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + updateNotification(0, getString(R.string.progress_show, "", 0, allIds.size)) } else { postEvent(EventBus.CHECK_INIT, allIds.size) } @@ -101,28 +101,29 @@ class CheckSourceService : BaseService() { val sourceUrl = allIds[index] App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> if (source.searchUrl.isNullOrEmpty()) { - onNext(sourceUrl) + onNext(sourceUrl, source.bookSourceName) } else { CheckSource(source).check(this, searchPool) { - onNext(it) + onNext(it, source.bookSourceName) } } - } ?: onNext(sourceUrl) + } ?: onNext(sourceUrl, "") } } } - private fun onNext(sourceUrl: String) { + private fun onNext(sourceUrl: String, sourceName: String) { synchronized(this) { check() checkedIds.add(sourceUrl) if (backgroundVerification) { updateNotification( checkedIds.size, - getString(R.string.progress_show, checkedIds.size, allIds.size) + getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) ) } else { postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) + postEvent(EventBus.CHECK_UP_PROGRESS_STRING, getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size)) } if (processIndex >= allIds.size + threadCount - 1) { stopSelf() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index d6f1aab3f..c461797dd 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -5,9 +5,8 @@ import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import android.view.SubMenu +import android.util.DisplayMetrics +import android.view.* import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.content.FileProvider @@ -19,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.BuildConfig import io.legado.app.R +import io.legado.app.base.BaseDialogFragment import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus @@ -40,8 +40,12 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* +import kotlinx.android.synthetic.main.activity_book_source.recycler_view import kotlinx.android.synthetic.main.dialog_edit_text.view.* +import kotlinx.android.synthetic.main.dialog_progressbar_view.* +import kotlinx.android.synthetic.main.dialog_progressbar_view.tv_footer_left import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -66,12 +70,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var sort = 0 private var sortAscending = 0 - private val progressDialogBuilder by lazy { - progressDialog("校验书源") { - setCancelable(false) - } - } - override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() @@ -270,30 +268,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } - override fun observeLiveBus() { - observeEvent(EventBus.CHECK_INIT) { max-> - progressDialogBuilder.max = max - progressDialogBuilder.show() - } - observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> - progressDialogBuilder.progress = progress - } - observeEvent(EventBus.CHECK_DONE) { - if (progressDialogBuilder.isShowing) { - progressDialogBuilder.progress = it - progressDialogBuilder.max = it - progressDialogBuilder.dismiss() - } - toast("校验完成!") - groups.map { group-> - if (group.contains("失效")) { - search_view.setQuery("失效", true) - toast("发现有失效书源,已为您自动筛选!") - } - } - } - } - override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) @@ -415,6 +389,24 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }.show().applyTint() } + override fun observeLiveBus() { + observeEvent(EventBus.CHECK_INIT) { max-> + val bundle = Bundle() + bundle.putInt("maxProgress", max) + CheckSourceDialog().apply { + arguments = bundle + }.show(supportFragmentManager, "CheckDialog") + } + observeEvent(EventBus.CHECK_DONE) { + groups.map { group-> + if (group.contains("失效")) { + search_view.setQuery("失效", true) + toast("发现有失效书源,已为您自动筛选!") + } + } + } + } + override fun upCountView() { select_action_bar.upCountView(adapter.getSelection().size, adapter.getActualItemCount()) } @@ -509,4 +501,47 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity search_view.setQuery("", true) } } + + class CheckSourceDialog : BaseDialogFragment() { + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout( + (dm.widthPixels * 0.9).toInt(), + (dm.heightPixels * 0.14).toInt() + ) + dialog?.setCancelable(false) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_progressbar_view, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + arguments?.let { bundle -> + val maxProgress = bundle.getInt("maxProgress") + ck_progress_text.text = getString(R.string.progress_show, "", 0, maxProgress) + ck_progress.max = maxProgress + observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> + ck_progress.progress = progress + } + observeEvent(EventBus.CHECK_UP_PROGRESS_STRING) { + ck_progress_text.text = it + } + observeEvent(EventBus.CHECK_DONE) { + dismiss() + } + tv_footer_left.onClick { + CheckSource.stop(requireContext()).apply { + dismiss() + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_progressbar_view.xml b/app/src/main/res/layout/dialog_progressbar_view.xml new file mode 100644 index 000000000..f310c9ced --- /dev/null +++ b/app/src/main/res/layout/dialog_progressbar_view.xml @@ -0,0 +1,36 @@ + + + + + + + + + \ 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 2e7d44236..5990fc38a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -293,7 +293,7 @@ 右邊距 校驗書源 校驗所選 - 進度 %1$d/%2$d + %1$s 進度 %2$d/%3$d 請安裝並選擇中文 TTS! TTS 初始化失敗! 簡繁轉換 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d7d39b40c..bab0077cc 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -293,7 +293,7 @@ 右邊距 校驗書源 校驗所選 - 進度 %1$d/%2$d + %1$s 進度 %2$d/%3$d 請安裝並選擇中文TTS! TTS初始化失敗! 簡繁轉換 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8e4821f0a..edabcafce 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -295,7 +295,7 @@ 右边距 校验书源 校验所选 - 进度 %1$d/%2$d + %1$s 进度 %2$d/%3$d 请安装并选择中文TTS! TTS初始化失败! 简繁转换 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 77e490b8c..515c117b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -295,7 +295,7 @@ Padding right Check book sources Check the selected source - Progress %1$d/%2$d + %1$s Progress %2$d/%3$d Please install and select Chinese TTS! TTS initialization failed! Simplified conversion From eee6a69cc7dc4ec31f36a843b774970e070aed86 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Sep 2020 23:59:16 +0800 Subject: [PATCH 34/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index a205d3893..81dfe2f61 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -451,9 +451,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var tmp: String val evalMatcher = evalPattern.matcher(rule) while (evalMatcher.find()) { - if (mode != Mode.Js) { - mode = Mode.Regex - } if (evalMatcher.start() > start) { tmp = rule.substring(start, evalMatcher.start()) ruleType.add(0) @@ -461,7 +458,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } tmp = evalMatcher.group() when { - tmp.startsWith("$") -> { + tmp.startsWith("$") && !rule.contains("##") -> { ruleType.add(tmp.substring(1).toInt()) ruleParam.add(tmp) } From 8c377c2ba50c55f4b558c8a84b124c0dc01528c7 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Mon, 21 Sep 2020 20:59:10 -0400 Subject: [PATCH 35/48] =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 16 ++++++++-- .../app/ui/book/read/ReadBookActivity.kt | 32 +++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index dfa337ae7..c52f75afe 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -378,8 +378,20 @@ object ReadBook { length -= currentLine.text.length Log.d("h11128", "currentLength $length") val charIndex = contentPosition - length - Log.d("h11128", "contentLength $contentPosition") - 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 + } + Log.d("h11128", "charIndex2 $charIndex $addLine $charIndex2") + return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2) } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index b6bb4503c..8ea3cd1c6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.os.Handler +import android.util.Log import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.core.view.get @@ -56,16 +57,14 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.view_read_menu.* -import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO 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.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast +import java.lang.Runnable class ReadBookActivity : VMBaseActivity(R.layout.activity_book_read), View.OnTouchListener, @@ -794,14 +793,29 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo Log.d("h11128", positions[0].toString()) Log.d("h11128", positions[1].toString()) Log.d("h11128", positions[2].toString()) - //todo: show selected text - val job1 = async(Main){ + Log.d("h11128", positions[3].toString()) + + while (ReadBook.durPageIndex != positions[0]){ + delay(100L) 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){ + Log.d("h11128", "currentpage ${ReadBook.durPageIndex}") + Log.d("h11128", "currentpage ${page_view.pageFactory.currentPage.index}") + Log.d("h11128", "${positions[0]} ${positions[1]} ${positions[2]}") + + 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 + delay(100L) + Log.d("h11128", "asdasd $selectedText") } - job1.await() } } requestCodeReplace -> onReplaceRuleSave() From 65b7bb3d41eaed371d1aebd1001f4baf18bd1e17 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Mon, 21 Sep 2020 21:04:28 -0400 Subject: [PATCH 36/48] clean log --- .../main/java/io/legado/app/service/help/ReadBook.kt | 11 ----------- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 12 ------------ 2 files changed, 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index c52f75afe..479850620 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -339,11 +339,9 @@ object ReadBook { index = content.indexOf(query, index + 1); count += 1 } - Log.d("h11128", "new index $index") val contentPosition = index var pageIndex = 0 var length = pages[pageIndex].text.length - Log.d("h11128", "page size ${pages.size}") while (length < contentPosition){ pageIndex += 1 if (pageIndex >pages.size){ @@ -351,16 +349,12 @@ object ReadBook { break } length += pages[pageIndex].text.length - Log.d("h11128", "to next page , add length change to $length") } - Log.d("h11128", "at pageindex $pageIndex") - // calculate search result's lineIndex val currentPage = pages[pageIndex] var lineIndex = 0 length = length - currentPage.text.length + currentPage.textLines[lineIndex].text.length - Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") while (length < contentPosition){ lineIndex += 1 if (lineIndex >currentPage.textLines.size){ @@ -368,15 +362,11 @@ object ReadBook { break } length += currentPage.textLines[lineIndex].text.length - Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") } // charIndex - Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}") - Log.d("h11128", "currentLength $length") val currentLine = currentPage.textLines[lineIndex] length -= currentLine.text.length - Log.d("h11128", "currentLength $length") val charIndex = contentPosition - length var addLine = 0 var charIndex2 = 0 @@ -390,7 +380,6 @@ object ReadBook { addLine = -1 charIndex2 = charIndex + query.length - currentLine.text.length - 1 } - Log.d("h11128", "charIndex2 $charIndex $addLine $charIndex2") return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 8ea3cd1c6..92df11f6a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -781,29 +781,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0) val query = data.getStringExtra("query") viewModel.openChapter(index) - // block until load correct chapter and pages var pages = ReadBook.curTextChapter?.pages while (ReadBook.durChapterIndex != index || pages == null ){ delay(100L) pages = ReadBook.curTextChapter?.pages } - Log.d("h11128", "Current chapter pages ${pages.size}") val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!) - Log.d("h11128", positions[0].toString()) - Log.d("h11128", positions[1].toString()) - Log.d("h11128", positions[2].toString()) - Log.d("h11128", positions[3].toString()) - while (ReadBook.durPageIndex != positions[0]){ delay(100L) ReadBook.skipToPage(positions[0]) } withContext(Main){ - Log.d("h11128", "currentpage ${ReadBook.durPageIndex}") - Log.d("h11128", "currentpage ${page_view.pageFactory.currentPage.index}") - Log.d("h11128", "${positions[0]} ${positions[1]} ${positions[2]}") - page_view.curPage.selectStartMoveIndex(0, positions[1], positions[2]) delay(20L) when (positions[3]){ @@ -814,7 +803,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } page_view.isTextSelected = true delay(100L) - Log.d("h11128", "asdasd $selectedText") } } } From 5584a22637d8e7d63192b7e8f300ddfe158f8b11 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 22 Sep 2020 11:00:31 +0800 Subject: [PATCH 37/48] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=AB=A0=E8=8A=82=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E8=AF=A6=E6=83=85=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/changesource/ChangeSourceViewModel.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index ec423c3dd..581ad9f41 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -120,12 +120,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio .onSuccess(IO) { it.forEach { searchBook -> if (searchBook.name == name && searchBook.author == author) { - if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { - if (searchBook.tocUrl.isEmpty()) { - loadBookInfo(searchBook.toBook()) - } else { - loadChapter(searchBook.toBook()) - } + if (searchBook.latestChapterTitle.isNullOrEmpty()) { + loadBookInfo(searchBook.toBook()) } else { searchFinish(searchBook) } @@ -156,7 +152,14 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> WebBook(bookSource).getBookInfo(book, this) .onSuccess { - loadChapter(it) + if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { + loadChapter(it) + } else { + //从详情页里获取最新章节 + book.latestChapterTitle = it.latestChapterTitle + val searchBook = book.toSearchBook() + searchFinish(searchBook) + } }.onError { debug { context.getString(R.string.error_get_book_info) } } From 273d465e080304e49922bbdc0ce9f3ac7a023a2f Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 22 Sep 2020 12:31:23 +0800 Subject: [PATCH 38/48] add options --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + .../legado/app/ui/book/changesource/ChangeSourceDialog.kt | 6 ++++++ .../app/ui/book/changesource/ChangeSourceViewModel.kt | 4 +++- app/src/main/res/menu/change_source.xml | 6 ++++++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 20 insertions(+), 1 deletion(-) 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 f40091b0f..7ef56460e 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -35,6 +35,7 @@ object PreferKey { const val webDavCreateDir = "webDavCreateDir" const val webDavCacheBackup = "webDavCacheBackup" const val changeSourceLoadToc = "changeSourceLoadToc" + const val changeSourceLoadInfo = "changeSourceLoadInfo" const val chineseConverterType = "chineseConverterType" const val launcherIcon = "launcherIcon" const val textSelectAble = "selectText" diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index bbd627466..e73b443a6 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -88,6 +88,8 @@ class ChangeSourceDialog : BaseDialogFragment(), tool_bar.setOnMenuItemClickListener(this) tool_bar.menu.findItem(R.id.menu_load_toc)?.isChecked = getPrefBoolean(PreferKey.changeSourceLoadToc) + tool_bar.menu.findItem(R.id.menu_load_info)?.isChecked = + getPrefBoolean(PreferKey.changeSourceLoadInfo) } private fun initRecyclerView() { @@ -159,6 +161,10 @@ class ChangeSourceDialog : BaseDialogFragment(), putPrefBoolean(PreferKey.changeSourceLoadToc, !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() } return false diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 581ad9f41..6633a889d 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -121,7 +121,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio it.forEach { searchBook -> if (searchBook.name == name && searchBook.author == author) { if (searchBook.latestChapterTitle.isNullOrEmpty()) { - loadBookInfo(searchBook.toBook()) + if (context.getPrefBoolean(PreferKey.changeSourceLoadInfo)) { + loadBookInfo(searchBook.toBook()) + } } else { searchFinish(searchBook) } diff --git a/app/src/main/res/menu/change_source.xml b/app/src/main/res/menu/change_source.xml index ab2bfee4c..dd2deae1b 100644 --- a/app/src/main/res/menu/change_source.xml +++ b/app/src/main/res/menu/change_source.xml @@ -24,4 +24,10 @@ android:checkable="true" app:showAsAction="never" /> + + \ 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 72b0eaa2f..4d38941b5 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -568,6 +568,7 @@ 導出所選 導出 加載目錄 + 加載詳情頁 TTS WebDav 密碼 輸入你的 WebDav 授權密碼 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 69c410eaa..6335186ca 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -569,6 +569,7 @@ 匯出所選 匯出 載入目錄 + 載入詳情頁 TTS WebDav 密碼 輸入你的WebDav授權密碼 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 76b0b02c1..92977d3f5 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -575,6 +575,7 @@ 导出所选 导出 加载目录 + 加载详情页 TTS WebDav 密码 输入你的WebDav授权密码 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4343ffa11..4779b5909 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -577,6 +577,7 @@ Export selected Export Load chapters + Load book detail TTS WebDav password Input you WebDav authorized password From be931db1a0cb84719c2652ec11ecff5e821d3928 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 22 Sep 2020 12:49:28 +0800 Subject: [PATCH 39/48] update --- app/src/main/assets/updateLog.md | 1 + .../legado/app/ui/book/changesource/ChangeSourceViewModel.kt | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0e4cfb8b6..6b5ff9e46 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/09/21** * 修复规则解析bug +* 换源时无最新章节信息时可加载详情页来获取(默认关闭) **2020/09/20** * 优化正文搜索 diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 6633a889d..0cbc1e2ee 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -121,8 +121,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio it.forEach { searchBook -> if (searchBook.name == name && searchBook.author == author) { if (searchBook.latestChapterTitle.isNullOrEmpty()) { - if (context.getPrefBoolean(PreferKey.changeSourceLoadInfo)) { + if (context.getPrefBoolean(PreferKey.changeSourceLoadInfo) || context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { loadBookInfo(searchBook.toBook()) + } else { + searchFinish(searchBook) } } else { searchFinish(searchBook) From 6219ab8774e455a6fb24e7c95acba838b895674b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 22 Sep 2020 14:27:51 +0800 Subject: [PATCH 40/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 81dfe2f61..29c0f5473 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -458,7 +458,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } tmp = evalMatcher.group() when { - tmp.startsWith("$") && !rule.contains("##") -> { + tmp.startsWith("$") -> { ruleType.add(tmp.substring(1).toInt()) ruleParam.add(tmp) } From b37e6bdadc510eb3e50d3c3cba2682d8282bae22 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 22 Sep 2020 23:35:04 +0800 Subject: [PATCH 41/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeRule.kt | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 29c0f5473..8b82d4151 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -446,22 +446,17 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } //分离put rule = splitPutRule(rule, putMap) - //@get,{{ }},$1, 拆分 + //@get,{{ }}, 拆分 var start = 0 var tmp: String val evalMatcher = evalPattern.matcher(rule) while (evalMatcher.find()) { if (evalMatcher.start() > start) { tmp = rule.substring(start, evalMatcher.start()) - ruleType.add(0) - ruleParam.add(tmp) + splitRegex(tmp) } tmp = evalMatcher.group() when { - tmp.startsWith("$") -> { - ruleType.add(tmp.substring(1).toInt()) - ruleParam.add(tmp) - } tmp.startsWith("@get:", true) -> { ruleType.add(-2) ruleParam.add(tmp.substring(6, tmp.lastIndex)) @@ -471,21 +466,45 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { ruleParam.add(tmp.substring(2, tmp.length - 2)) } else -> { - ruleType.add(0) - ruleParam.add(tmp) + splitRegex(tmp) } } start = evalMatcher.end() } if (rule.length > start) { tmp = rule.substring(start) + splitRegex(tmp) + } + } + + private fun splitRegex(ruleStr: String) { + var start = 0 + var tmp: String + val ruleStrArray = ruleStr.split("##") + val regexMatcher = regexPattern.matcher(ruleStrArray[0]) + while (regexMatcher.find()) { + if (mode != Mode.Js) { + mode = Mode.Regex + } + if (regexMatcher.start() > start) { + tmp = rule.substring(start, regexMatcher.start()) + ruleType.add(0) + ruleParam.add(tmp) + } + tmp = regexMatcher.group() + ruleType.add(tmp.substring(1).toInt()) + ruleParam.add(tmp) + start = regexMatcher.end() + } + if (ruleStr.length > start) { + tmp = ruleStr.substring(start) ruleType.add(0) ruleParam.add(tmp) } } /** - * 替换@get,{{ }},$1, + * 替换@get,{{ }} */ fun makeUpRule(result: Any?) { val infoVal = StringBuilder() @@ -631,14 +650,9 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { companion object { private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) - private val evalPattern = Pattern.compile( - "@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}|\\$\\d{1,2}", - Pattern.CASE_INSENSITIVE - ) - private val replacePattern = Pattern.compile( - "@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", - Pattern.CASE_INSENSITIVE - ) + private val evalPattern = + Pattern.compile("@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) + private val regexPattern = Pattern.compile("\\\$\\d{1,2}") } } From 1c0cb183aa04a7e98792b7d161e3ae02086cdd2b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 22 Sep 2020 23:38:08 +0800 Subject: [PATCH 42/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 6b5ff9e46..d8696bcce 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/22** +* 修复规则解析bug + **2020/09/21** * 修复规则解析bug * 换源时无最新章节信息时可加载详情页来获取(默认关闭) From 0ea41c3f4fb97e3a81cabd31060e25bdf64d2582 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 00:07:37 +0800 Subject: [PATCH 43/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 8b82d4151..530dcb33b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -487,7 +487,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { mode = Mode.Regex } if (regexMatcher.start() > start) { - tmp = rule.substring(start, regexMatcher.start()) + tmp = ruleStr.substring(start, regexMatcher.start()) ruleType.add(0) ruleParam.add(tmp) } From 9cae96fe2e07f68dca830a368cb2a856de6a7506 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 00:07:56 +0800 Subject: [PATCH 44/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index d8696bcce..db5123e54 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,7 +3,7 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/09/22** +**2020/09/23** * 修复规则解析bug **2020/09/21** From 98de63b04c031b78fde46d46bb882d7fbf123417 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 07:57:17 +0800 Subject: [PATCH 45/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 530dcb33b..d7555c951 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -451,6 +451,9 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var tmp: String val evalMatcher = evalPattern.matcher(rule) while (evalMatcher.find()) { + if (mode != Mode.Js) { + mode = Mode.Regex + } if (evalMatcher.start() > start) { tmp = rule.substring(start, evalMatcher.start()) splitRegex(tmp) @@ -483,9 +486,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { val ruleStrArray = ruleStr.split("##") val regexMatcher = regexPattern.matcher(ruleStrArray[0]) while (regexMatcher.find()) { - if (mode != Mode.Js) { - mode = Mode.Regex - } if (regexMatcher.start() > start) { tmp = ruleStr.substring(start, regexMatcher.start()) ruleType.add(0) From c06c26a36fc17f0895282c356ec9641589598493 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 08:14:59 +0800 Subject: [PATCH 46/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index d7555c951..55e028134 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -480,12 +480,18 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } + /** + * 拆分\$\d{1,2} + */ private fun splitRegex(ruleStr: String) { var start = 0 var tmp: String val ruleStrArray = ruleStr.split("##") val regexMatcher = regexPattern.matcher(ruleStrArray[0]) while (regexMatcher.find()) { + if (mode != Mode.Js) { + mode = Mode.Regex + } if (regexMatcher.start() > start) { tmp = ruleStr.substring(start, regexMatcher.start()) ruleType.add(0) @@ -652,7 +658,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) private val evalPattern = Pattern.compile("@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) - private val regexPattern = Pattern.compile("\\\$\\d{1,2}") + private val regexPattern = Pattern.compile("\\$\\d{1,2}") } } From 6b6a39e07dcb96cd2e2b0a24fe9ac7f343be618e Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 08:33:46 +0800 Subject: [PATCH 47/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 55e028134..d43abdfcd 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -451,11 +451,11 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var tmp: String val evalMatcher = evalPattern.matcher(rule) while (evalMatcher.find()) { - if (mode != Mode.Js) { - mode = Mode.Regex - } if (evalMatcher.start() > start) { tmp = rule.substring(start, evalMatcher.start()) + if (start == 0 && !tmp.contains("##") && mode != Mode.Js) { + mode = Mode.Regex + } splitRegex(tmp) } tmp = evalMatcher.group() From 487524182acff8023e32e32385aadc835f703cd6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 08:41:05 +0800 Subject: [PATCH 48/48] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index d43abdfcd..1b77cdd1a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -406,6 +406,9 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { internal val putMap = HashMap() private val ruleParam = ArrayList() private val ruleType = ArrayList() + private val getRuleType = -2 + private val jsRuleType = -1 + private val defaultRuleType = 0 init { this.mode = mainMode @@ -461,11 +464,11 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { tmp = evalMatcher.group() when { tmp.startsWith("@get:", true) -> { - ruleType.add(-2) + ruleType.add(getRuleType) ruleParam.add(tmp.substring(6, tmp.lastIndex)) } tmp.startsWith("{{") -> { - ruleType.add(-1) + ruleType.add(jsRuleType) ruleParam.add(tmp.substring(2, tmp.length - 2)) } else -> { @@ -494,7 +497,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } if (regexMatcher.start() > start) { tmp = ruleStr.substring(start, regexMatcher.start()) - ruleType.add(0) + ruleType.add(defaultRuleType) ruleParam.add(tmp) } tmp = regexMatcher.group() @@ -504,7 +507,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } if (ruleStr.length > start) { tmp = ruleStr.substring(start) - ruleType.add(0) + ruleType.add(defaultRuleType) ruleParam.add(tmp) } } @@ -519,7 +522,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { while (index-- > 0) { val regType = ruleType[index] when { - regType > 0 -> { + regType > defaultRuleType -> { @Suppress("UNCHECKED_CAST") val resultList = result as? List if (resultList != null) { @@ -532,7 +535,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { infoVal.insert(0, ruleParam[index]) } } - regType == -1 -> { + regType == jsRuleType -> { if (isRule(ruleParam[index])) { getString(arrayListOf(SourceRule(ruleParam[index]))).let { infoVal.insert(0, it) @@ -550,7 +553,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } } - regType == -2 -> { + regType == getRuleType -> { infoVal.insert(0, get(ruleParam[index])) } else -> infoVal.insert(0, ruleParam[index])