pull/375/head
gedoor 4 years ago
parent f8572d2a42
commit cd8615075c
  1. 1
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/java/io/legado/app/App.kt
  3. 35
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  4. 46
      app/src/main/java/io/legado/app/service/DownloadService.kt
  5. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

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

@ -156,7 +156,7 @@ class App : MultiDexApplication() {
//用唯一的ID创建渠道对象 //用唯一的ID创建渠道对象
val downloadChannel = NotificationChannel( val downloadChannel = NotificationChannel(
channelIdDownload, channelIdDownload,
getString(R.string.offline_cache), getString(R.string.action_download),
NotificationManager.IMPORTANCE_LOW NotificationManager.IMPORTANCE_LOW
) )
//初始化channel //初始化channel

@ -24,6 +24,21 @@ class CheckSourceService : BaseService() {
private val allIds = ArrayList<String>() private val allIds = ArrayList<String>()
private val checkedIds = ArrayList<String>() private val checkedIds = ArrayList<String>()
private var processIndex = 0 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() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -105,23 +120,9 @@ class CheckSourceService : BaseService() {
* 更新通知 * 更新通知
*/ */
private fun updateNotification(state: Int, msg: String) { private fun updateNotification(state: Int, msg: String) {
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) notificationBuilder.setContentText(msg)
.setSmallIcon(R.drawable.ic_network_check) notificationBuilder.setProgress(allIds.size, state, false)
.setOngoing(true) startForeground(112202, notificationBuilder.build())
.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)
} }
} }

@ -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.data.entities.BookSource
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.* 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.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.service.help.CheckSource 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.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.text.Collator import java.text.Collator
@ -212,7 +208,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
else -> data.reversed() else -> data.reversed()
} }
} }
recycler_view.scrollToPosition(0)
val diffResult = DiffUtil val diffResult = DiffUtil
.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), sourceList)) .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), sourceList))
adapter.setItems(sourceList, diffResult) adapter.setItems(sourceList, diffResult)

Loading…
Cancel
Save