pull/1194/head
gedoor 3 years ago
parent 38e262393e
commit 94d4d15e7d
  1. 6
      app/src/main/java/io/legado/app/service/WebService.kt
  2. 35
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  3. 25
      app/src/main/java/io/legado/app/service/help/CacheBook.kt
  4. 14
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  5. 16
      app/src/main/java/io/legado/app/service/help/Download.kt
  6. 4
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -28,9 +28,9 @@ class WebService : BaseService() {
fun stop(context: Context) {
if (isRun) {
val intent = Intent(context, WebService::class.java)
intent.action = IntentAction.stop
context.startService(intent)
context.startService<WebService> {
action = IntentAction.stop
}
}
}

@ -13,6 +13,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.AudioPlayService
import io.legado.app.utils.postEvent
import io.legado.app.utils.startService
object AudioPlay {
var titleData = MutableLiveData<String>()
@ -52,43 +53,43 @@ object AudioPlay {
fun pause(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = IntentAction.pause
context.startService(intent)
context.startService<AudioPlayService> {
action = IntentAction.pause
}
}
}
fun resume(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = IntentAction.resume
context.startService(intent)
context.startService<AudioPlayService> {
action = IntentAction.resume
}
}
}
fun stop(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = IntentAction.stop
context.startService(intent)
context.startService<AudioPlayService> {
action = IntentAction.stop
}
}
}
fun adjustSpeed(context: Context, adjust: Float) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = IntentAction.adjustSpeed
intent.putExtra("adjust", adjust)
context.startService(intent)
context.startService<AudioPlayService> {
action = IntentAction.adjustSpeed
putExtra("adjust", adjust)
}
}
}
fun adjustProgress(context: Context, position: Int) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = IntentAction.adjustProgress
intent.putExtra("position", position)
context.startService(intent)
context.startService<AudioPlayService> {
action = IntentAction.adjustProgress
putExtra("position", position)
}
}
}

@ -1,7 +1,6 @@
package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.R
import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.Book
@ -9,6 +8,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.CacheBookService
import io.legado.app.utils.msg
import io.legado.app.utils.startService
import kotlinx.coroutines.CoroutineScope
import splitties.init.appCtx
import java.util.concurrent.ConcurrentHashMap
@ -29,27 +29,24 @@ object CacheBook {
}
fun start(context: Context, bookUrl: String, start: Int, end: Int) {
Intent(context, CacheBookService::class.java).let {
it.action = IntentAction.start
it.putExtra("bookUrl", bookUrl)
it.putExtra("start", start)
it.putExtra("end", end)
context.startService(it)
context.startService<CacheBookService> {
action = IntentAction.start
putExtra("bookUrl", bookUrl)
putExtra("start", start)
putExtra("end", end)
}
}
fun remove(context: Context, bookUrl: String) {
Intent(context, CacheBookService::class.java).let {
it.action = IntentAction.remove
it.putExtra("bookUrl", bookUrl)
context.startService(it)
context.startService<CacheBookService> {
action = IntentAction.remove
putExtra("bookUrl", bookUrl)
}
}
fun stop(context: Context) {
Intent(context, CacheBookService::class.java).let {
it.action = IntentAction.stop
context.startService(it)
context.startService<CacheBookService> {
action = IntentAction.stop
}
}

@ -1,11 +1,11 @@
package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.R
import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.BookSource
import io.legado.app.service.CheckSourceService
import io.legado.app.utils.startService
import io.legado.app.utils.toastOnUi
object CheckSource {
@ -20,17 +20,15 @@ object CheckSource {
sources.map {
selectedIds.add(it.bookSourceUrl)
}
Intent(context, CheckSourceService::class.java).let {
it.action = IntentAction.start
it.putExtra("selectIds", selectedIds)
context.startService(it)
context.startService<CheckSourceService> {
action = IntentAction.start
putExtra("selectIds", selectedIds)
}
}
fun stop(context: Context) {
Intent(context, CheckSourceService::class.java).let {
it.action = IntentAction.stop
context.startService(it)
context.startService<CheckSourceService> {
action = IntentAction.stop
}
}
}

@ -1,25 +1,23 @@
package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.constant.IntentAction
import io.legado.app.service.DownloadService
import io.legado.app.utils.startService
object Download {
fun start(context: Context, downloadId: Long, fileName: String) {
Intent(context, DownloadService::class.java).let {
it.action = IntentAction.start
it.putExtra("downloadId", downloadId)
it.putExtra("fileName", fileName)
context.startService(it)
context.startService<DownloadService> {
action = IntentAction.start
putExtra("downloadId", downloadId)
putExtra("fileName", fileName)
}
}
fun stop(context: Context) {
Intent(context, DownloadService::class.java).let {
it.action = IntentAction.stop
context.startService(it)
context.startService<DownloadService> {
action = IntentAction.stop
}
}

@ -38,6 +38,10 @@ inline fun <reified T : Service> Context.startService(configIntent: Intent.() ->
startService(Intent(this, T::class.java).apply(configIntent))
}
inline fun <reified T : Service> Context.stopService() {
stopService(Intent(this, T::class.java))
}
fun Context.toastOnUi(message: Int) {
runOnUI {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()

Loading…
Cancel
Save