|
|
@ -6,8 +6,8 @@ import android.content.Intent |
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.KeyEvent |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
|
|
|
import io.legado.app.help.ActivityHelp |
|
|
|
import io.legado.app.help.ActivityHelp |
|
|
|
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.service.AudioPlayService |
|
|
|
import io.legado.app.service.AudioPlayService |
|
|
|
import io.legado.app.service.BaseReadAloudService |
|
|
|
import io.legado.app.service.BaseReadAloudService |
|
|
|
import io.legado.app.service.help.AudioPlay |
|
|
|
import io.legado.app.service.help.AudioPlay |
|
|
@ -15,13 +15,7 @@ import io.legado.app.service.help.ReadAloud |
|
|
|
import io.legado.app.ui.audio.AudioPlayActivity |
|
|
|
import io.legado.app.ui.audio.AudioPlayActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.main.MainActivity |
|
|
|
import io.legado.app.ui.main.MainActivity |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -61,7 +55,7 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun readAloud(context: Context) { |
|
|
|
fun readAloud(context: Context, isMediaKey: Boolean = true) { |
|
|
|
when { |
|
|
|
when { |
|
|
|
BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { |
|
|
|
BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { |
|
|
|
ReadAloud.pause(context) |
|
|
|
ReadAloud.pause(context) |
|
|
@ -79,12 +73,8 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
ActivityHelp.isExist(AudioPlayActivity::class.java) -> |
|
|
|
ActivityHelp.isExist(AudioPlayActivity::class.java) -> |
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) { |
|
|
|
else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) { |
|
|
|
GlobalScope.launch(Main) { |
|
|
|
appDb.bookDao.lastReadBook?.let { |
|
|
|
val lastBook: Book? = withContext(IO) { |
|
|
|
|
|
|
|
appDb.bookDao.lastReadBook |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastBook?.let { |
|
|
|
|
|
|
|
if (!ActivityHelp.isExist(MainActivity::class.java)) { |
|
|
|
if (!ActivityHelp.isExist(MainActivity::class.java)) { |
|
|
|
Intent(context, MainActivity::class.java).let { |
|
|
|
Intent(context, MainActivity::class.java).let { |
|
|
|
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
@ -101,6 +91,5 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|