From c2cff4ce1ad8359a54aa03447afed02976815158 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Sep 2020 21:53:05 +0800 Subject: [PATCH 1/4] update log --- 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 7e7454cef..e9ab31cb0 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,7 +6,7 @@ **2020/09/12** * web看书同步最新章 * web写源增加图片样式等规则 -* 正文规则可以使用@get{title}获取目录标题,js里使用title +* 正文规则可以使用@get:{title}获取目录标题,js里使用title **2020/09/11** * 修复一些bug From 6b8e92ea8abbdc4830657db35e507fcf5452f1b2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 13 Sep 2020 16:53:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?@get:{bookName}=E5=8F=AF=E4=BB=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B9=A6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/entities/BaseBook.kt | 2 ++ app/src/main/java/io/legado/app/data/entities/Book.kt | 4 ++-- .../java/io/legado/app/data/entities/SearchBook.kt | 4 ++-- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 10 +++++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt index 31346a50c..e52f9e185 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt @@ -3,6 +3,8 @@ package io.legado.app.data.entities import io.legado.app.utils.splitNotBlank interface BaseBook { + var name: String + var author: String var bookUrl: String val variableMap: HashMap var kind: String? diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 7996e3ea9..62926b3b4 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -29,8 +29,8 @@ data class Book( var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) var originName: String = "", //书源名称 or 本地书籍文件名 - var name: String = "", // 书籍名称(书源获取) - var author: String = "", // 作者名称(书源获取) + override var name: String = "", // 书籍名称(书源获取) + override var author: String = "", // 作者名称(书源获取) override var kind: String? = null, // 分类信息(书源获取) var customTag: String? = null, // 分类信息(用户修改) var coverUrl: String? = null, // 封面Url(书源获取) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index 71bd9016f..62635219c 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -25,8 +25,8 @@ data class SearchBook( var origin: String = "", // 书源规则 var originName: String = "", var type: Int = 0, // @BookType - var name: String = "", - var author: String = "", + override var name: String = "", + override var author: String = "", override var kind: String? = null, var coverUrl: String? = null, var intro: String? = null, 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 84673215c..d196e18fa 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 @@ -580,9 +580,13 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } fun get(key: String): String { - val chapter = chapter - if (chapter != null && key == "title") { - return chapter.title + when (key) { + "bookName" -> book?.let { + return it.name + } + "title" -> chapter?.let { + return it.title + } } return chapter?.variableMap?.get(key) ?: book?.variableMap?.get(key) From f8572d2a4216085a7eb6c0990a03440da73dbf84 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 13 Sep 2020 17:39:38 +0800 Subject: [PATCH 3/4] =?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/model/webBook/BookContent.kt | 2 +- app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 040ee91a4..c2ae45071 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -97,7 +97,7 @@ object BookContent { val replaceRegex = bookSource.ruleContent?.replaceRegex if (!replaceRegex.isNullOrEmpty()) { val analyzeRule = AnalyzeRule(book) - analyzeRule.setContent(body, baseUrl) + analyzeRule.setContent(contentStr, baseUrl) analyzeRule.chapter = bookChapter contentStr = analyzeRule.getString(replaceRegex) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 3e48c3ebf..e2834e456 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -160,6 +160,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r request.setAllowedOverRoaming(true) // 允许下载的网路类型 request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI) + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) // 设置下载文件保存的路径和文件名 request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) val downloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager From cd8615075cc14cd89c316d3ba81212663e927235 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 13 Sep 2020 20:06:56 +0800 Subject: [PATCH 4/4] =?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/AndroidManifest.xml | 1 + app/src/main/java/io/legado/app/App.kt | 2 +- .../legado/app/service/CheckSourceService.kt | 35 +++++++------- .../io/legado/app/service/DownloadService.kt | 46 +++++++++++++++++++ .../book/source/manage/BookSourceActivity.kt | 5 -- 5 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/io/legado/app/service/DownloadService.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 34c57bb7b..ca5b1e976 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -354,6 +354,7 @@ + diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 98f255c72..37aea552d 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -156,7 +156,7 @@ class App : MultiDexApplication() { //用唯一的ID创建渠道对象 val downloadChannel = NotificationChannel( channelIdDownload, - getString(R.string.offline_cache), + getString(R.string.action_download), NotificationManager.IMPORTANCE_LOW ) //初始化channel 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 e6cbb5966..09900d0d0 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -24,6 +24,21 @@ class CheckSourceService : BaseService() { private val allIds = ArrayList() private val checkedIds = ArrayList() private var processIndex = 0 + private val notificationBuilder by lazy { + NotificationCompat.Builder(this, AppConst.channelIdReadAloud) + .setSmallIcon(R.drawable.ic_network_check) + .setOngoing(true) + .setContentTitle(getString(R.string.check_book_source)) + .setContentIntent( + IntentHelp.activityPendingIntent(this, "activity") + ) + .addAction( + R.drawable.ic_stop_black_24dp, + getString(R.string.cancel), + IntentHelp.servicePendingIntent(this, IntentAction.stop) + ) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + } override fun onCreate() { super.onCreate() @@ -105,23 +120,9 @@ class CheckSourceService : BaseService() { * 更新通知 */ private fun updateNotification(state: Int, msg: String) { - val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) - .setSmallIcon(R.drawable.ic_network_check) - .setOngoing(true) - .setContentTitle(getString(R.string.check_book_source)) - .setContentText(msg) - .setContentIntent( - IntentHelp.activityPendingIntent(this, "activity") - ) - .addAction( - R.drawable.ic_stop_black_24dp, - getString(R.string.cancel), - IntentHelp.servicePendingIntent(this, IntentAction.stop) - ) - builder.setProgress(allIds.size, state, false) - builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - val notification = builder.build() - startForeground(112202, notification) + notificationBuilder.setContentText(msg) + notificationBuilder.setProgress(allIds.size, state, false) + startForeground(112202, notificationBuilder.build()) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt new file mode 100644 index 000000000..7a77bb7a5 --- /dev/null +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -0,0 +1,46 @@ +package io.legado.app.service + +import android.content.Intent +import androidx.core.app.NotificationCompat +import io.legado.app.R +import io.legado.app.base.BaseService +import io.legado.app.constant.AppConst +import io.legado.app.constant.IntentAction +import io.legado.app.help.IntentHelp + +class DownloadService : BaseService() { + + private val notificationBuilder by lazy { + val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) + .setSmallIcon(R.drawable.ic_download) + .setOngoing(true) + .setContentTitle(getString(R.string.action_download)) + builder.addAction( + R.drawable.ic_stop_black_24dp, + getString(R.string.cancel), + IntentHelp.servicePendingIntent(this, IntentAction.stop) + ) + builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + } + + override fun onCreate() { + super.onCreate() + updateNotification("准备下载") + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + when (intent?.action) { + + } + return super.onStartCommand(intent, flags, startId) + } + + /** + * 更新通知 + */ + private fun updateNotification(content: String) { + notificationBuilder.setContentText(content) + val notification = notificationBuilder.build() + startForeground(AppConst.notificationIdDownload, notification) + } +} \ No newline at end of file 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 59422c186..07f959719 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 @@ -24,9 +24,6 @@ import io.legado.app.constant.AppPattern import io.legado.app.data.entities.BookSource import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.* -import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.service.help.CheckSource @@ -47,7 +44,6 @@ import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast - import java.io.File import java.text.Collator @@ -212,7 +208,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity else -> data.reversed() } } - recycler_view.scrollToPosition(0) val diffResult = DiffUtil .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), sourceList)) adapter.setItems(sourceList, diffResult)