|
|
|
@ -3,9 +3,6 @@ package io.legado.app.receiver |
|
|
|
|
import android.content.BroadcastReceiver |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Handler |
|
|
|
|
import android.os.Looper |
|
|
|
|
import android.os.Message |
|
|
|
|
import android.view.KeyEvent |
|
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
|
import io.legado.app.data.appDb |
|
|
|
@ -19,8 +16,8 @@ import io.legado.app.service.help.ReadBook |
|
|
|
|
import io.legado.app.ui.book.audio.AudioPlayActivity |
|
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
|
import io.legado.app.ui.main.MainActivity |
|
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -37,21 +34,6 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
val handler = object : Handler(Looper.getMainLooper()) { |
|
|
|
|
|
|
|
|
|
override fun handleMessage(msg: Message) { |
|
|
|
|
when (msg.what) { |
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { |
|
|
|
|
ReadAloud.prevParagraph(appCtx) |
|
|
|
|
} |
|
|
|
|
KeyEvent.KEYCODE_MEDIA_NEXT -> { |
|
|
|
|
ReadAloud.nextParagraph(appCtx) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun handleIntent(context: Context, intent: Intent): Boolean { |
|
|
|
|
val intentAction = intent.action |
|
|
|
|
if (Intent.ACTION_MEDIA_BUTTON == intentAction) { |
|
|
|
@ -62,22 +44,17 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
|
if (action == KeyEvent.ACTION_DOWN) { |
|
|
|
|
when (keycode) { |
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { |
|
|
|
|
if (handler.hasMessages(KeyEvent.KEYCODE_MEDIA_PREVIOUS)) { |
|
|
|
|
handler.removeMessages(KeyEvent.KEYCODE_MEDIA_PREVIOUS) |
|
|
|
|
if (context.getPrefBoolean("mediaButtonPerNext", false)) { |
|
|
|
|
ReadBook.moveToPrevChapter(true) |
|
|
|
|
} else { |
|
|
|
|
handler.sendEmptyMessageDelayed( |
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PREVIOUS, |
|
|
|
|
500 |
|
|
|
|
) |
|
|
|
|
ReadAloud.prevParagraph(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
KeyEvent.KEYCODE_MEDIA_NEXT -> { |
|
|
|
|
if (handler.hasMessages(KeyEvent.KEYCODE_MEDIA_NEXT)) { |
|
|
|
|
handler.removeMessages(KeyEvent.KEYCODE_MEDIA_NEXT) |
|
|
|
|
if (context.getPrefBoolean("mediaButtonPerNext", false)) { |
|
|
|
|
ReadBook.moveToNextChapter(true) |
|
|
|
|
} else { |
|
|
|
|
handler.sendEmptyMessageDelayed(KeyEvent.KEYCODE_MEDIA_NEXT, 500) |
|
|
|
|
ReadAloud.nextParagraph(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> readAloud(context) |
|
|
|
|