Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Jul 22, 2023
1 parent d592122 commit 01bc753
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/src/main/java/io/legado/app/service/ExportBookService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.activityPendingIntent
import io.legado.app.utils.buildMainHandler
import io.legado.app.utils.cnCompare
import io.legado.app.utils.createFolderIfNotExist
import io.legado.app.utils.isContentScheme
Expand All @@ -45,12 +46,10 @@ import io.legado.app.utils.toastOnUi
import io.legado.app.utils.writeBytes
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.ag2s.epublib.domain.Author
import me.ag2s.epublib.domain.Date
import me.ag2s.epublib.domain.EpubBook
Expand Down Expand Up @@ -86,6 +85,7 @@ class ExportBookService : BaseService() {
val epubScope: String? = null
)

private val handler = buildMainHandler()
private val waitExportBooks = linkedMapOf<String, ExportConfig>()
private var exportJob: Job? = null

Expand Down Expand Up @@ -124,14 +124,21 @@ class ExportBookService : BaseService() {
override fun upNotification() {
val notification = NotificationCompat.Builder(this, AppConst.channelIdDownload)
.setSmallIcon(R.drawable.ic_export)
.setOngoing(true)
.setContentTitle(getString(R.string.export))
.setContentIntent(activityPendingIntent<CacheActivity>("cacheActivity"))
notification.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
servicePendingIntent<ExportBookService>(IntentAction.stop)
)
if (exportJob?.isActive == true) {
notification.setOngoing(true)
notification.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
servicePendingIntent<ExportBookService>(IntentAction.stop)
)
} else {
notification.setOngoing(false)
notification.setDeleteIntent(
servicePendingIntent<ExportBookService>(IntentAction.stop)
)
}
notification.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
notification.setContentText(notificationContent)
startForeground(AppConst.notificationIdCache, notification.build())
Expand Down Expand Up @@ -175,7 +182,7 @@ class ExportBookService : BaseService() {
exportProgress.remove(bookUrl)
postEvent(EventBus.EXPORT_BOOK, bookUrl)
}
withContext(Main) {
handler.post {
export()
}
}
Expand Down

0 comments on commit 01bc753

Please sign in to comment.