Merge remote-tracking branch 'upstream/master' into h11128dev

pull/374/head
Jason Yao 4 years ago
commit 1e94325f80
  1. 1
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/assets/updateLog.md
  3. 2
      app/src/main/java/io/legado/app/App.kt
  4. 2
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  5. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  6. 4
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  7. 10
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  8. 2
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  9. 35
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  10. 46
      app/src/main/java/io/legado/app/service/DownloadService.kt
  11. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  12. 1
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt

@ -358,6 +358,7 @@
<service android:name=".service.TTSReadAloudService" />
<service android:name=".service.HttpReadAloudService" />
<service android:name=".service.AudioPlayService" />
<service android:name=".service.DownloadService" />
<receiver android:name=".receiver.MediaButtonReceiver">
<intent-filter>

@ -6,7 +6,7 @@
**2020/09/12**
* web看书同步最新章
* web写源增加图片样式等规则
* 正文规则可以使用@get{title}获取目录标题,js里使用title
* 正文规则可以使用@get:{title}获取目录标题,js里使用title
**2020/09/11**
* 修复一些bug

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

@ -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<String, String>
var kind: String?

@ -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(书源获取)

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

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

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

@ -24,6 +24,21 @@ class CheckSourceService : BaseService() {
private val allIds = ArrayList<String>()
private val checkedIds = ArrayList<String>()
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<BookSourceActivity>(this, "activity")
)
.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<CheckSourceService>(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<BookSourceActivity>(this, "activity")
)
.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<CheckSourceService>(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())
}
}

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

@ -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<BookSourceViewModel>(R.layout.activity
else -> data.reversed()
}
}
recycler_view.scrollToPosition(0)
val diffResult = DiffUtil
.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), sourceList))
adapter.setItems(sourceList, diffResult)

@ -160,6 +160,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(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

Loading…
Cancel
Save