mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
Compare commits
8 Commits
186fa9e40d
...
0a27482394
Author | SHA1 | Date | |
---|---|---|---|
|
0a27482394 | ||
|
72ff30b1ea | ||
|
b30ef00307 | ||
|
0cfd6ea46d | ||
|
96c76d74ba | ||
|
ed6f8e5e43 | ||
|
9247d56cbd | ||
|
d774b2df7c |
@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.base
|
package io.legado.app.base
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
@ -83,9 +84,11 @@ abstract class BaseService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.request()
|
.request()
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
PermissionsCompat.Builder()
|
PermissionsCompat.Builder()
|
||||||
.addPermissions(Permissions.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
.addPermissions(Permissions.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||||
.rationale(R.string.ignore_battery_permission_rationale)
|
.rationale(R.string.ignore_battery_permission_rationale)
|
||||||
.request()
|
.request()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -168,6 +168,7 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
abandonFocus()
|
abandonFocus()
|
||||||
unregisterReceiver(broadcastReceiver)
|
unregisterReceiver(broadcastReceiver)
|
||||||
postEvent(EventBus.ALOUD_STATE, Status.STOP)
|
postEvent(EventBus.ALOUD_STATE, Status.STOP)
|
||||||
|
notificationManager.cancel(NotificationId.ReadAloudService)
|
||||||
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
|
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
|
||||||
mediaSessionCompat.release()
|
mediaSessionCompat.release()
|
||||||
ReadBook.uploadProgress()
|
ReadBook.uploadProgress()
|
||||||
@ -496,6 +497,8 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
nSubtitle = getString(R.string.read_aloud_s)
|
nSubtitle = getString(R.string.read_aloud_s)
|
||||||
val builder = NotificationCompat
|
val builder = NotificationCompat
|
||||||
.Builder(this@BaseReadAloudService, AppConst.channelIdReadAloud)
|
.Builder(this@BaseReadAloudService, AppConst.channelIdReadAloud)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
|
||||||
.setSmallIcon(R.drawable.ic_volume_up)
|
.setSmallIcon(R.drawable.ic_volume_up)
|
||||||
.setSubText(getString(R.string.read_aloud))
|
.setSubText(getString(R.string.read_aloud))
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
@ -535,7 +538,7 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
androidx.media.app.NotificationCompat.MediaStyle()
|
androidx.media.app.NotificationCompat.MediaStyle()
|
||||||
.setShowActionsInCompactView(0, 1, 2)
|
.setShowActionsInCompactView(0, 1, 2)
|
||||||
)
|
)
|
||||||
return builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
return builder
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ import io.legado.app.help.book.BookHelp
|
|||||||
import io.legado.app.help.book.ContentProcessor
|
import io.legado.app.help.book.ContentProcessor
|
||||||
import io.legado.app.help.book.getExportFileName
|
import io.legado.app.help.book.getExportFileName
|
||||||
import io.legado.app.help.book.isLocal
|
import io.legado.app.help.book.isLocal
|
||||||
|
import io.legado.app.help.book.isLocalModified
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.model.localBook.LocalBook
|
import io.legado.app.model.localBook.LocalBook
|
||||||
import io.legado.app.ui.book.cache.CacheActivity
|
import io.legado.app.ui.book.cache.CacheActivity
|
||||||
@ -57,6 +58,7 @@ import kotlinx.coroutines.coroutineScope
|
|||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.flow.collectIndexed
|
import kotlinx.coroutines.flow.collectIndexed
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.ag2s.epublib.domain.Author
|
import me.ag2s.epublib.domain.Author
|
||||||
import me.ag2s.epublib.domain.Date
|
import me.ag2s.epublib.domain.Date
|
||||||
@ -121,7 +123,10 @@ class ExportBookService : BaseService() {
|
|||||||
toastOnUi(it.localizedMessage)
|
toastOnUi(it.localizedMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
IntentAction.stop -> stopSelf()
|
IntentAction.stop -> {
|
||||||
|
notificationManager.cancel(NotificationId.ExportBook)
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
}
|
}
|
||||||
@ -130,6 +135,9 @@ class ExportBookService : BaseService() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
exportProgress.clear()
|
exportProgress.clear()
|
||||||
exportMsg.clear()
|
exportMsg.clear()
|
||||||
|
waitExportBooks.keys.forEach {
|
||||||
|
postEvent(EventBus.EXPORT_BOOK, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@ -168,7 +176,7 @@ class ExportBookService : BaseService() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
exportJob = lifecycleScope.launch(IO) {
|
exportJob = lifecycleScope.launch(IO) {
|
||||||
while (true) {
|
while (isActive) {
|
||||||
val (bookUrl, exportConfig) = waitExportBooks.entries.firstOrNull() ?: let {
|
val (bookUrl, exportConfig) = waitExportBooks.entries.firstOrNull() ?: let {
|
||||||
notificationContentText = "导出完成"
|
notificationContentText = "导出完成"
|
||||||
upExportNotification(true)
|
upExportNotification(true)
|
||||||
@ -200,6 +208,7 @@ class ExportBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
exportMsg[book.bookUrl] = getString(R.string.export_success)
|
exportMsg[book.bookUrl] = getString(R.string.export_success)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
ensureActive()
|
||||||
exportMsg[bookUrl] = e.localizedMessage ?: "ERROR"
|
exportMsg[bookUrl] = e.localizedMessage ?: "ERROR"
|
||||||
AppLog.put("导出书籍<${book?.name ?: bookUrl}>出错", e)
|
AppLog.put("导出书籍<${book?.name ?: bookUrl}>出错", e)
|
||||||
} finally {
|
} finally {
|
||||||
@ -211,10 +220,7 @@ class ExportBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshChapterList(book: Book) {
|
private fun refreshChapterList(book: Book) {
|
||||||
if (!book.isLocal) {
|
if (!book.isLocal || !book.isLocalModified()) {
|
||||||
return
|
|
||||||
}
|
|
||||||
if (LocalBook.getLastModified(book).getOrDefault(0L) < book.latestChapterTime) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
|
Loading…
Reference in New Issue
Block a user