在书源管理增加启用发现和禁用发现

调试log修改
关于完善了一点
pull/44/head
Celeter 5 years ago
parent 55fa2a5688
commit 66e7500000
  1. 6
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 4
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  3. 11
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  4. 12
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt
  5. 15
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 16
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  8. 10
      app/src/main/res/menu/book_source.xml
  9. 4
      app/src/main/res/values/pref_key_value.xml
  10. 12
      app/src/main/res/values/strings.xml
  11. 14
      app/src/main/res/xml/about.xml

@ -35,6 +35,12 @@ interface BookSourceDao {
@Query("update book_sources set enabled = 0 where bookSourceUrl = :sourceUrl") @Query("update book_sources set enabled = 0 where bookSourceUrl = :sourceUrl")
fun disableSection(sourceUrl: String) fun disableSection(sourceUrl: String)
@Query("update book_sources set enabledExplore = 1 where bookSourceUrl = :sourceUrl")
fun enableSectionExplore(sourceUrl: String)
@Query("update book_sources set enabledExplore = 0 where bookSourceUrl = :sourceUrl")
fun disableSectionExplore(sourceUrl: String)
@Query("delete from book_sources where bookSourceUrl = :sourceUrl") @Query("delete from book_sources where bookSourceUrl = :sourceUrl")
fun delSection(sourceUrl: String) fun delSection(sourceUrl: String)

@ -69,7 +69,7 @@ object BookChapterList {
} }
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "目录总页数:${nextUrlList.size}") SourceDebug.printLog(bookSource.bookSourceUrl, "目录总页数:${nextUrlList.size}")
} else if (chapterData.nextUrl.size > 1) { } else if (chapterData.nextUrl.size > 1) {
val chapterDataList = arrayListOf<ChapterData<String>>() val chapterDataList = arrayListOf<ChapterData<String>>()
for (item in chapterData.nextUrl) { for (item in chapterData.nextUrl) {
@ -145,7 +145,7 @@ object BookChapterList {
} }
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, bookSource.bookSourceUrl,
"" + TextUtils.join(",\n", nextUrlList), "" + TextUtils.join("\n", nextUrlList),
printLog printLog
) )
} }

@ -62,7 +62,7 @@ object BookContent {
content.append(contentData.content) content.append(contentData.content)
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "本章总页数:${nextUrlList.size}") SourceDebug.printLog(bookSource.bookSourceUrl, "本章总页数:${nextUrlList.size}")
} else if (contentData.nextUrl.size > 1) { } else if (contentData.nextUrl.size > 1) {
val contentDataList = arrayListOf<ContentData<String>>() val contentDataList = arrayListOf<ContentData<String>>()
for (item in contentData.nextUrl) { for (item in contentData.nextUrl) {
@ -95,11 +95,12 @@ object BookContent {
} }
} }
if (content.isNotEmpty()) { if (content.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取章节名称")
SourceDebug.printLog(bookSource.bookSourceUrl, "${bookChapter.title}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取正文内容")
if (!content[0].toString().startsWith(bookChapter.title)) { if (!content[0].toString().startsWith(bookChapter.title)) {
content content
.insert(0, "\n") .insert(0, "\n")
.insert(0, "\n》正文内容:")
.insert(0, "》章节名称:${bookChapter.title}")
} }
} }
return content.toString() return content.toString()
@ -123,7 +124,7 @@ object BookContent {
analyzeRule.getStringList(nextUrlRule, true)?.let { analyzeRule.getStringList(nextUrlRule, true)?.let {
nextUrlList.addAll(it) nextUrlList.addAll(it)
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(","), printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog)
} }
val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: ""
return ContentData(content, nextUrlList) return ContentData(content, nextUrlList)

@ -65,15 +65,16 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
val book = Book() val book = Book()
book.origin = webBook.sourceUrl book.origin = webBook.sourceUrl
book.bookUrl = key book.bookUrl = key
printLog(webBook.sourceUrl, "开始访问:$key") printLog(webBook.sourceUrl, "开始访问:$key")
infoDebug(book) infoDebug(book)
} else { } else {
printLog(webBook.sourceUrl, "开始搜索关键字:$key") printLog(webBook.sourceUrl, "开始搜索关键字:$key")
searchDebug(key) searchDebug(key)
} }
} }
private fun searchDebug(key: String) { private fun searchDebug(key: String) {
printLog(debugSource, "︾开始解析搜索页")
val search = webBook.searchBook(key, 1) val search = webBook.searchBook(key, 1)
.onSuccess { searchBooks -> .onSuccess { searchBooks ->
searchBooks?.let { searchBooks?.let {
@ -93,7 +94,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
} }
private fun infoDebug(book: Book) { private fun infoDebug(book: Book) {
printLog(debugSource, "︾开始获取详情页") printLog(debugSource, "︾开始解析详情页")
val info = webBook.getBookInfo(book) val info = webBook.getBookInfo(book)
.onSuccess { .onSuccess {
printLog(debugSource, "︽详情页解析完成") printLog(debugSource, "︽详情页解析完成")
@ -107,7 +108,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
} }
private fun tocDebug(book: Book) { private fun tocDebug(book: Book) {
printLog(debugSource, "︾开始获取目录页") printLog(debugSource, "︾开始解析目录页")
val chapterList = webBook.getChapterList(book) val chapterList = webBook.getChapterList(book)
.onSuccess { chapterList -> .onSuccess { chapterList ->
chapterList?.let { chapterList?.let {
@ -128,12 +129,13 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
} }
private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) { private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) {
printLog(debugSource, "︾开始获取正文") printLog(debugSource, "︾开始解析正文页")
val content = webBook.getContent(book, bookChapter, nextChapterUrl) val content = webBook.getContent(book, bookChapter, nextChapterUrl)
.onSuccess { content -> .onSuccess { content ->
content?.let { content?.let {
printLog(debugSource, it, state = 1000) printLog(debugSource, it, state = 1000)
} }
printLog(debugSource, "︽正文页解析完成")
} }
.onError { .onError {
printLog(debugSource, it.localizedMessage, state = -1) printLog(debugSource, it.localizedMessage, state = -1)

@ -13,7 +13,7 @@ import io.legado.app.utils.toast
class AboutFragment : PreferenceFragmentCompat() { class AboutFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.about) addPreferencesFromResource(R.xml.about)
findPreference<Preference>("version")?.summary = App.INSTANCE.versionName findPreference<Preference>("check_update")?.summary = getString(R.string.version) + " " + App.INSTANCE.versionName
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -23,8 +23,11 @@ class AboutFragment : PreferenceFragmentCompat() {
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"check_update" -> openIntent(Intent.ACTION_VIEW, getString(R.string.latest_release_url))
"mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com") "mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com")
"git" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)) "git" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))
"home_page" -> openIntent(Intent.ACTION_VIEW, getString(R.string.home_page_url))
"share_app" -> shareText("App Share",getString(R.string.app_share_description))
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
@ -37,6 +40,16 @@ class AboutFragment : PreferenceFragmentCompat() {
} catch (e: Exception) { } catch (e: Exception) {
toast(R.string.can_not_open) toast(R.string.can_not_open)
} }
}
private fun shareText(title: String, text: String) {
try {
val textIntent = Intent(Intent.ACTION_SEND)
textIntent.setType("text/plain")
textIntent.putExtra(Intent.EXTRA_TEXT, text)
startActivity(Intent.createChooser(textIntent, title))
} catch (e: Exception) {
toast(R.string.can_not_share)
}
} }
} }

@ -86,6 +86,8 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelectionIds())
R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
R.id.menu_check_source -> R.id.menu_check_source ->
startService<CheckSourceService>(Pair("data", adapter.getSelectionIds())) startService<CheckSourceService>(Pair("data", adapter.getSelectionIds()))

@ -56,6 +56,22 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun enableSelectExplore(ids: LinkedHashSet<String>) {
execute {
ids.forEach {
App.db.bookSourceDao().enableSectionExplore(it)
}
}
}
fun disableSelectExplore(ids: LinkedHashSet<String>) {
execute {
ids.forEach {
App.db.bookSourceDao().disableSectionExplore(it)
}
}
}
fun delSelection(ids: LinkedHashSet<String>) { fun delSelection(ids: LinkedHashSet<String>) {
execute { execute {
ids.forEach { ids.forEach {

@ -32,6 +32,16 @@
android:title="@string/disable_selection" android:title="@string/disable_selection"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_enable_explore"
android:title="@string/enable_explore"
app:showAsAction="never" />
<item
android:id="@+id/menu_disable_explore"
android:title="@string/disable_explore"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_del_selection" android:id="@+id/menu_del_selection"
android:title="@string/del_select" android:title="@string/del_select"

@ -22,6 +22,6 @@
<string name="this_github_url">https://github.com/gedoor/legado</string> <string name="this_github_url">https://github.com/gedoor/legado</string>
<string name="disclaimer_url">https://gedoor.github.io/MyBookshelf/disclaimer.html</string> <string name="disclaimer_url">https://gedoor.github.io/MyBookshelf/disclaimer.html</string>
<string name="home_page_url">https://gedoor.github.io/MyBookshelf/</string> <string name="home_page_url">https://gedoor.github.io/MyBookshelf/</string>
<string name="latest_release_url">https://github.com/gedoor/MyBookshelf/releases/latest</string> <string name="latest_release_url">https://github.com/gedoor/legado/releases/latest</string>
<string name="latest_release_api">https://api.github.com/repos/gedoor/MyBookshelf/releases/latest</string> <string name="latest_release_api">https://api.github.com/repos/gedoor/legado/releases/latest</string>
</resources> </resources>

@ -83,6 +83,9 @@
<string name="about_description"> <string name="about_description">
\u3000\u3000这是一款开源的阅读软件,你可以fork我们的代码自己编译APK。欢迎提交代码帮助改善应用。\n\u3000\u3000公众号[开源阅读软件]! \u3000\u3000这是一款开源的阅读软件,你可以fork我们的代码自己编译APK。欢迎提交代码帮助改善应用。\n\u3000\u3000公众号[开源阅读软件]!
</string> </string>
<string name="app_share_description">
阅读3.0下载地址:\nhttps://play.google.com/store/apps/details?id=io.legado.app
</string>
<string name="version_name">Version %s</string> <string name="version_name">Version %s</string>
<string name="pt_auto_refresh">自动刷新</string> <string name="pt_auto_refresh">自动刷新</string>
<string name="ps_auto_refresh">打开软件时自动更新书籍</string> <string name="ps_auto_refresh">打开软件时自动更新书籍</string>
@ -138,6 +141,7 @@
<string name="scoring">评分</string> <string name="scoring">评分</string>
<string name="send_mail">发送邮件</string> <string name="send_mail">发送邮件</string>
<string name="can_not_open">无法打开</string> <string name="can_not_open">无法打开</string>
<string name="can_not_share">分享失败</string>
<string name="no_chapter">无章节</string> <string name="no_chapter">无章节</string>
<string name="add_url">添加网址</string> <string name="add_url">添加网址</string>
<string name="add_book_url">添加书籍网址</string> <string name="add_book_url">添加书籍网址</string>
@ -361,7 +365,7 @@
<string name="rule_find_url">发现地址规则(url)</string> <string name="rule_find_url">发现地址规则(url)</string>
<string name="rule_book_list">书籍列表规则(bookList)</string> <string name="rule_book_list">书籍列表规则(bookList)</string>
<string name="rule_book_name">书名规则(name)</string> <string name="rule_book_name">书名规则(name)</string>
<string name="rule_book_url">书籍url规则(bookUrl)</string> <string name="rule_book_url">详情页url规则(bookUrl)</string>
<string name="rule_book_author">作者规则(author)</string> <string name="rule_book_author">作者规则(author)</string>
<string name="rule_book_kind">分类规则(kind)</string> <string name="rule_book_kind">分类规则(kind)</string>
<string name="rule_book_intro">简介规则(intro)</string> <string name="rule_book_intro">简介规则(intro)</string>
@ -412,7 +416,7 @@
<string name="net_error_10003">数据解析失败</string> <string name="net_error_10003">数据解析失败</string>
<!--error string end--> <!--error string end-->
<string name="source_http_header">header</string> <string name="source_http_header">请求头(header)</string>
<string name="debug_source">调试源</string> <string name="debug_source">调试源</string>
<string name="import_by_qr_code">二维码导入</string> <string name="import_by_qr_code">二维码导入</string>
<string name="scan_qr_code">扫描二维码</string> <string name="scan_qr_code">扫描二维码</string>
@ -482,7 +486,7 @@
<string name="source_tab_find">发现</string> <string name="source_tab_find">发现</string>
<string name="source_tab_info">详情</string> <string name="source_tab_info">详情</string>
<string name="source_tab_toc">目录</string> <string name="source_tab_toc">目录</string>
<string name="source_tab_content">内容</string> <string name="source_tab_content">正文</string>
<string name="e_ink_mode">E-Ink 模式</string> <string name="e_ink_mode">E-Ink 模式</string>
<string name="e_ink_mode_detail">去除动画,优化电纸书使用体验</string> <string name="e_ink_mode_detail">去除动画,优化电纸书使用体验</string>
@ -523,6 +527,8 @@
<string name="add_group">添加分组</string> <string name="add_group">添加分组</string>
<string name="add_replace_rule">新建替换</string> <string name="add_replace_rule">新建替换</string>
<string name="group">分组</string> <string name="group">分组</string>
<string name="enable_explore">启用发现</string>
<string name="disable_explore">禁用发现</string>
<string name="enable_selection">启用所选</string> <string name="enable_selection">启用所选</string>
<string name="disable_selection">禁用所选</string> <string name="disable_selection">禁用所选</string>
<string name="tts">TTS</string> <string name="tts">TTS</string>

@ -9,8 +9,8 @@
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference
android:key="version" android:key="check_update"
android:title="@string/version" android:title="@string/check_update"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference
@ -18,11 +18,6 @@
android:title="@string/update_log" android:title="@string/update_log"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="check_update"
android:title="@string/check_update"
app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference
android:key="qq" android:key="qq"
android:title="@string/join_qq_group" android:title="@string/join_qq_group"
@ -43,6 +38,11 @@
android:title="@string/home_page" android:title="@string/home_page"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="share_app"
android:title="@string/share_app"
app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference
android:key="disclaimer" android:key="disclaimer"
android:title="@string/disclaimer" android:title="@string/disclaimer"

Loading…
Cancel
Save