|
|
@ -16,7 +16,6 @@ import androidx.media.AudioFocusRequestCompat |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseService |
|
|
|
import io.legado.app.base.BaseService |
|
|
|
import io.legado.app.constant.* |
|
|
|
import io.legado.app.constant.* |
|
|
|
import io.legado.app.help.IntentDataHelp |
|
|
|
|
|
|
|
import io.legado.app.help.MediaHelp |
|
|
|
import io.legado.app.help.MediaHelp |
|
|
|
import io.legado.app.model.ReadAloud |
|
|
|
import io.legado.app.model.ReadAloud |
|
|
|
import io.legado.app.model.ReadBook |
|
|
|
import io.legado.app.model.ReadBook |
|
|
@ -46,8 +45,6 @@ abstract class BaseReadAloudService : BaseService(), |
|
|
|
private var mFocusRequest: AudioFocusRequestCompat? = null |
|
|
|
private var mFocusRequest: AudioFocusRequestCompat? = null |
|
|
|
private var broadcastReceiver: BroadcastReceiver? = null |
|
|
|
private var broadcastReceiver: BroadcastReceiver? = null |
|
|
|
private lateinit var mediaSessionCompat: MediaSessionCompat |
|
|
|
private lateinit var mediaSessionCompat: MediaSessionCompat |
|
|
|
private var title: String = "" |
|
|
|
|
|
|
|
private var subtitle: String = "" |
|
|
|
|
|
|
|
internal val contentList = arrayListOf<String>() |
|
|
|
internal val contentList = arrayListOf<String>() |
|
|
|
internal var nowSpeak: Int = 0 |
|
|
|
internal var nowSpeak: Int = 0 |
|
|
|
internal var readAloudNumber: Int = 0 |
|
|
|
internal var readAloudNumber: Int = 0 |
|
|
@ -84,11 +81,9 @@ abstract class BaseReadAloudService : BaseService(), |
|
|
|
intent?.action?.let { action -> |
|
|
|
intent?.action?.let { action -> |
|
|
|
when (action) { |
|
|
|
when (action) { |
|
|
|
IntentAction.play -> { |
|
|
|
IntentAction.play -> { |
|
|
|
title = intent.getStringExtra("title") ?: "" |
|
|
|
pageIndex = ReadBook.durPageIndex() |
|
|
|
subtitle = intent.getStringExtra("subtitle") ?: "" |
|
|
|
|
|
|
|
pageIndex = intent.getIntExtra("pageIndex", 0) |
|
|
|
|
|
|
|
newReadAloud( |
|
|
|
newReadAloud( |
|
|
|
intent.getStringExtra("dataKey"), |
|
|
|
ReadBook.curTextChapter, |
|
|
|
intent.getBooleanExtra("play", true) |
|
|
|
intent.getBooleanExtra("play", true) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -106,29 +101,26 @@ abstract class BaseReadAloudService : BaseService(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@CallSuper |
|
|
|
@CallSuper |
|
|
|
open fun newReadAloud(dataKey: String?, play: Boolean) { |
|
|
|
open fun newReadAloud(textChapter: TextChapter?, play: Boolean) { |
|
|
|
dataKey?.let { |
|
|
|
textChapter?.let { |
|
|
|
textChapter = IntentDataHelp.getData<TextChapter>(dataKey) |
|
|
|
nowSpeak = 0 |
|
|
|
textChapter?.let { textChapter -> |
|
|
|
readAloudNumber = textChapter.getReadLength(pageIndex) |
|
|
|
nowSpeak = 0 |
|
|
|
contentList.clear() |
|
|
|
readAloudNumber = textChapter.getReadLength(pageIndex) |
|
|
|
if (getPrefBoolean(PreferKey.readAloudByPage)) { |
|
|
|
contentList.clear() |
|
|
|
for (index in pageIndex..textChapter.lastIndex) { |
|
|
|
if (getPrefBoolean(PreferKey.readAloudByPage)) { |
|
|
|
textChapter.page(index)?.text?.split("\n")?.let { |
|
|
|
for (index in pageIndex..textChapter.lastIndex) { |
|
|
|
contentList.addAll(it) |
|
|
|
textChapter.page(index)?.text?.split("\n")?.let { |
|
|
|
|
|
|
|
contentList.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
textChapter.getUnRead(pageIndex).split("\n").forEach { |
|
|
|
} else { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
textChapter.getUnRead(pageIndex).split("\n").forEach { |
|
|
|
contentList.add(it) |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
} |
|
|
|
contentList.add(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (play) play() |
|
|
|
} |
|
|
|
} ?: stopSelf() |
|
|
|
if (play) play() |
|
|
|
} ?: stopSelf() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun play() { |
|
|
|
open fun play() { |
|
|
@ -307,9 +299,9 @@ abstract class BaseReadAloudService : BaseService(), |
|
|
|
) |
|
|
|
) |
|
|
|
else -> getString(R.string.read_aloud_t) |
|
|
|
else -> getString(R.string.read_aloud_t) |
|
|
|
} |
|
|
|
} |
|
|
|
nTitle += ": $title" |
|
|
|
nTitle += ": ${ReadBook.book?.name}" |
|
|
|
var nSubtitle = subtitle |
|
|
|
var nSubtitle = ReadBook.curTextChapter?.title |
|
|
|
if (subtitle.isEmpty()) |
|
|
|
if (nSubtitle.isNullOrBlank()) |
|
|
|
nSubtitle = getString(R.string.read_aloud_s) |
|
|
|
nSubtitle = getString(R.string.read_aloud_s) |
|
|
|
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) |
|
|
|
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud) |
|
|
|
.setSmallIcon(R.drawable.ic_volume_up) |
|
|
|
.setSmallIcon(R.drawable.ic_volume_up) |
|
|
|