pull/90/head^2
kunfei 5 years ago
parent 232ca67c37
commit 1e185b0ee9
  1. 2
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 2
      app/src/main/java/io/legado/app/constant/IntentAction.kt
  3. 6
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  4. 6
      app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt
  5. 56
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  6. 34
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  7. 25
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  8. 14
      app/src/main/java/io/legado/app/service/DownloadService.kt
  9. 6
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  10. 6
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  11. 12
      app/src/main/java/io/legado/app/service/WebService.kt
  12. 18
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  13. 4
      app/src/main/java/io/legado/app/service/help/Download.kt
  14. 18
      app/src/main/java/io/legado/app/service/help/ReadAloud.kt
  15. 14
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  16. 22
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  17. 8
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  18. 6
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  19. 26
      app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt
  20. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  21. 6
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  22. 28
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  23. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt
  24. 4
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  25. 4
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  26. 4
      app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt
  27. 6
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  28. 8
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  29. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  30. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  31. 4
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt

@ -1,6 +1,6 @@
package io.legado.app.constant
object Bus {
object EventBus {
const val MEDIA_BUTTON = "mediaButton"
const val RECREATE = "RECREATE"
const val UP_BOOK = "sourceDebugLog"

@ -1,6 +1,6 @@
package io.legado.app.constant
object Action {
object IntentAction {
const val start = "start"
const val play = "play"
const val stop = "stop"

@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import io.legado.app.App
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp
import io.legado.app.ui.audio.AudioPlayActivity
@ -51,9 +51,9 @@ class MediaButtonReceiver : BroadcastReceiver() {
private fun readAloud(context: Context) {
when {
ActivityHelp.isExist(AudioPlayActivity::class.java) ->
postEvent(Bus.MEDIA_BUTTON, true)
postEvent(EventBus.MEDIA_BUTTON, true)
ActivityHelp.isExist(ReadBookActivity::class.java) ->
postEvent(Bus.MEDIA_BUTTON, true)
postEvent(EventBus.MEDIA_BUTTON, true)
else -> {
GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) {

@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.utils.postEvent
@ -28,11 +28,11 @@ class TimeElectricityReceiver : BroadcastReceiver() {
intent?.action?.let {
when (it) {
Intent.ACTION_TIME_TICK -> {
postEvent(Bus.TIME_CHANGED, "")
postEvent(EventBus.TIME_CHANGED, "")
}
Intent.ACTION_BATTERY_CHANGED -> {
val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
postEvent(Bus.BATTERY_CHANGED, level)
postEvent(EventBus.BATTERY_CHANGED, level)
}
}
}

@ -18,9 +18,9 @@ import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.Status
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
@ -81,21 +81,21 @@ class AudioPlayService : BaseService(),
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action ->
when (action) {
Action.play -> {
IntentAction.play -> {
AudioPlay.book?.let {
title = it.name
position = it.durChapterPos
loadContent(it.durChapterIndex)
}
}
Action.pause -> pause(true)
Action.resume -> resume()
Action.prev -> moveToPrev()
Action.next -> moveToNext()
Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
Action.addTimer -> addTimer()
Action.setTimer -> setTimer(intent.getIntExtra("minute", 0))
Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position))
IntentAction.pause -> pause(true)
IntentAction.resume -> resume()
IntentAction.prev -> moveToPrev()
IntentAction.next -> moveToNext()
IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
IntentAction.addTimer -> addTimer()
IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0))
IntentAction.adjustProgress -> adjustProgress(intent.getIntExtra("position", position))
else -> stopSelf()
}
}
@ -112,7 +112,7 @@ class AudioPlayService : BaseService(),
unregisterReceiver(broadcastReceiver)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
AudioPlay.status = Status.STOP
postEvent(Bus.AUDIO_STATE, Status.STOP)
postEvent(EventBus.AUDIO_STATE, Status.STOP)
}
private fun play() {
@ -120,7 +120,7 @@ class AudioPlayService : BaseService(),
if (requestFocus()) {
try {
AudioPlay.status = Status.PLAY
postEvent(Bus.AUDIO_STATE, Status.PLAY)
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
mediaPlayer.reset()
val analyzeUrl =
AnalyzeUrl(url, headerMapF = AudioPlay.headers(), useWebView = true)
@ -146,7 +146,7 @@ class AudioPlayService : BaseService(),
mediaPlayer.pause()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
AudioPlay.status = Status.PAUSE
postEvent(Bus.AUDIO_STATE, Status.PAUSE)
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
upNotification()
}
}
@ -159,7 +159,7 @@ class AudioPlayService : BaseService(),
handler.postDelayed(mpRunnable, 1000)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
AudioPlay.status = Status.PLAY
postEvent(Bus.AUDIO_STATE, Status.PLAY)
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
upNotification()
}
@ -178,7 +178,7 @@ class AudioPlayService : BaseService(),
if (isPlaying) {
playbackParams = playbackParams.apply { speed += adjust }
}
postEvent(Bus.AUDIO_SPEED, playbackParams.speed)
postEvent(EventBus.AUDIO_SPEED, playbackParams.speed)
}
}
}
@ -191,7 +191,7 @@ class AudioPlayService : BaseService(),
if (pause) return
mediaPlayer.start()
mediaPlayer.seekTo(position)
postEvent(Bus.AUDIO_SIZE, mediaPlayer.duration)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let {
it.end = mediaPlayer.duration.toLong()
}
@ -205,7 +205,7 @@ class AudioPlayService : BaseService(),
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
if (!mediaPlayer.isPlaying) {
AudioPlay.status = Status.STOP
postEvent(Bus.AUDIO_STATE, Status.STOP)
postEvent(EventBus.AUDIO_STATE, Status.STOP)
launch { toast("error: $what $extra $url") }
}
return true
@ -238,7 +238,7 @@ class AudioPlayService : BaseService(),
handler.removeCallbacks(dsRunnable)
handler.postDelayed(dsRunnable, 60000)
}
postEvent(Bus.TTS_DS, timeMinute)
postEvent(EventBus.TTS_DS, timeMinute)
upNotification()
}
@ -247,7 +247,7 @@ class AudioPlayService : BaseService(),
*/
private fun upPlayProgress() {
saveProgress()
postEvent(Bus.AUDIO_PROGRESS, mediaPlayer.currentPosition)
postEvent(EventBus.AUDIO_PROGRESS, mediaPlayer.currentPosition)
handler.postDelayed(mpRunnable, 1000)
}
@ -260,9 +260,9 @@ class AudioPlayService : BaseService(),
if (index == AudioPlay.durChapterIndex) {
bookChapter = chapter
subtitle = chapter.title
postEvent(Bus.AUDIO_SUB_TITLE, subtitle)
postEvent(Bus.AUDIO_SIZE, chapter.end?.toInt() ?: 0)
postEvent(Bus.AUDIO_PROGRESS, position)
postEvent(EventBus.AUDIO_SUB_TITLE, subtitle)
postEvent(EventBus.AUDIO_SIZE, chapter.end?.toInt() ?: 0)
postEvent(EventBus.AUDIO_PROGRESS, position)
}
loadContent(chapter)
} ?: removeLoading(index)
@ -376,7 +376,7 @@ class AudioPlayService : BaseService(),
handler.postDelayed(dsRunnable, 60000)
}
}
postEvent(Bus.TTS_DS, timeMinute)
postEvent(EventBus.TTS_DS, timeMinute)
upNotification()
}
@ -485,24 +485,24 @@ class AudioPlayService : BaseService(),
builder.addAction(
R.drawable.ic_play_24dp,
getString(R.string.resume),
thisPendingIntent(Action.resume)
thisPendingIntent(IntentAction.resume)
)
} else {
builder.addAction(
R.drawable.ic_pause_24dp,
getString(R.string.pause),
thisPendingIntent(Action.pause)
thisPendingIntent(IntentAction.pause)
)
}
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.stop),
thisPendingIntent(Action.stop)
thisPendingIntent(IntentAction.stop)
)
builder.addAction(
R.drawable.ic_time_add_24dp,
getString(R.string.set_timer),
thisPendingIntent(Action.addTimer)
thisPendingIntent(IntentAction.addTimer)
)
builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle()

@ -70,7 +70,7 @@ abstract class BaseReadAloudService : BaseService(),
isRun = false
pause = true
unregisterReceiver(broadcastReceiver)
postEvent(Bus.ALOUD_STATE, Status.STOP)
postEvent(EventBus.ALOUD_STATE, Status.STOP)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
mediaSessionCompat?.release()
}
@ -78,7 +78,7 @@ abstract class BaseReadAloudService : BaseService(),
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action ->
when (action) {
Action.play -> {
IntentAction.play -> {
title = intent.getStringExtra("title") ?: ""
subtitle = intent.getStringExtra("subtitle") ?: ""
pageIndex = intent.getIntExtra("pageIndex", 0)
@ -87,13 +87,13 @@ abstract class BaseReadAloudService : BaseService(),
intent.getBooleanExtra("play", true)
)
}
Action.pause -> pauseReadAloud(true)
Action.resume -> resumeReadAloud()
Action.upTtsSpeechRate -> upSpeechRate(true)
Action.prevParagraph -> prevP()
Action.nextParagraph -> nextP()
Action.addTimer -> addTimer()
Action.setTimer -> setTimer(intent.getIntExtra("minute", 0))
IntentAction.pause -> pauseReadAloud(true)
IntentAction.resume -> resumeReadAloud()
IntentAction.upTtsSpeechRate -> upSpeechRate(true)
IntentAction.prevParagraph -> prevP()
IntentAction.nextParagraph -> nextP()
IntentAction.addTimer -> addTimer()
IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0))
else -> stopSelf()
}
}
@ -124,13 +124,13 @@ abstract class BaseReadAloudService : BaseService(),
open fun play() {
pause = false
postEvent(Bus.ALOUD_STATE, Status.PLAY)
postEvent(EventBus.ALOUD_STATE, Status.PLAY)
upNotification()
}
@CallSuper
open fun pauseReadAloud(pause: Boolean) {
postEvent(Bus.ALOUD_STATE, Status.PAUSE)
postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
BaseReadAloudService.pause = pause
upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
@ -167,7 +167,7 @@ abstract class BaseReadAloudService : BaseService(),
handler.removeCallbacks(dsRunnable)
handler.postDelayed(dsRunnable, 60000)
}
postEvent(Bus.TTS_DS, timeMinute)
postEvent(EventBus.TTS_DS, timeMinute)
upNotification()
}
@ -183,7 +183,7 @@ abstract class BaseReadAloudService : BaseService(),
handler.postDelayed(dsRunnable, 60000)
}
}
postEvent(Bus.TTS_DS, timeMinute)
postEvent(EventBus.TTS_DS, timeMinute)
upNotification()
}
@ -298,24 +298,24 @@ abstract class BaseReadAloudService : BaseService(),
builder.addAction(
R.drawable.ic_play_24dp,
getString(R.string.resume),
aloudServicePendingIntent(Action.resume)
aloudServicePendingIntent(IntentAction.resume)
)
} else {
builder.addAction(
R.drawable.ic_pause_24dp,
getString(R.string.pause),
aloudServicePendingIntent(Action.pause)
aloudServicePendingIntent(IntentAction.pause)
)
}
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.stop),
aloudServicePendingIntent(Action.stop)
aloudServicePendingIntent(IntentAction.stop)
)
builder.addAction(
R.drawable.ic_time_add_24dp,
getString(R.string.set_timer),
aloudServicePendingIntent(Action.addTimer)
aloudServicePendingIntent(IntentAction.addTimer)
)
builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle()

@ -1,10 +1,11 @@
package io.legado.app.service
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst
import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig
@ -14,6 +15,24 @@ import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors
class CheckSourceService : BaseService() {
companion object{
fun start(context: Context, selectedIds: Array<String>) {
Intent(context, CheckSourceService::class.java).let {
it.action = IntentAction.start
it.putExtra("selectIds", selectedIds)
context.startService(it)
}
}
fun stop(context: Context) {
Intent(context, CheckSourceService::class.java).let {
it.action = IntentAction.stop
context.startService(it)
}
}
}
private var searchPool =
Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
private var sourceList: List<BookSource>? = null
@ -25,7 +44,7 @@ class CheckSourceService : BaseService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
when (intent?.action) {
Action.start -> {
IntentAction.start -> {
}
else -> stopSelf()
}
@ -52,7 +71,7 @@ class CheckSourceService : BaseService() {
.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<CheckSourceService>(this, Action.stop)
IntentHelp.servicePendingIntent<CheckSourceService>(this, IntentAction.stop)
)
sourceList?.let {
builder.setProgress(it.size, state, false)

@ -6,9 +6,9 @@ import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.help.IntentHelp
@ -34,7 +34,7 @@ class DownloadService : BaseService() {
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<DownloadService>(this, Action.stop)
IntentHelp.servicePendingIntent<DownloadService>(this, IntentAction.stop)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
}
@ -48,12 +48,12 @@ class DownloadService : BaseService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action ->
when (action) {
Action.start -> download(
IntentAction.start -> download(
intent.getStringExtra("bookUrl"),
intent.getIntExtra("start", 0),
intent.getIntExtra("end", 0)
)
Action.stop -> stopDownload()
IntentAction.stop -> stopDownload()
}
}
return super.onStartCommand(intent, flags, startId)
@ -64,7 +64,7 @@ class DownloadService : BaseService() {
searchPool.close()
handler.removeCallbacks(runnable)
super.onDestroy()
postEvent(Bus.UP_DOWNLOAD, false)
postEvent(EventBus.UP_DOWNLOAD, false)
}
private fun download(bookUrl: String?, start: Int, end: Int) {
@ -105,7 +105,7 @@ class DownloadService : BaseService() {
private fun upDownload() {
updateNotification(notificationContent)
postEvent(Bus.UP_DOWNLOAD, true)
postEvent(EventBus.UP_DOWNLOAD, true)
handler.removeCallbacks(runnable)
handler.postDelayed(runnable, 1000)
}

@ -2,7 +2,7 @@ package io.legado.app.service
import android.app.PendingIntent
import android.media.MediaPlayer
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.IntentHelp
import io.legado.app.help.http.HttpHelper
@ -98,7 +98,7 @@ class HttpReadAloudService : BaseReadAloudService(),
mediaPlayer.reset()
mediaPlayer.setDataSource(fd)
mediaPlayer.prepareAsync()
postEvent(Bus.TTS_START, readAloudNumber + 1)
postEvent(EventBus.TTS_START, readAloudNumber + 1)
} catch (e: Exception) {
e.printStackTrace()
}
@ -187,7 +187,7 @@ class HttpReadAloudService : BaseReadAloudService(),
ReadBook.moveToNextPage()
}
}
postEvent(Bus.TTS_START, readAloudNumber + 1)
postEvent(EventBus.TTS_START, readAloudNumber + 1)
}
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {

@ -6,7 +6,7 @@ import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp
import io.legado.app.service.help.ReadBook
@ -152,7 +152,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
ReadBook.moveToNextPage()
}
}
postEvent(Bus.TTS_START, readAloudNumber + 1)
postEvent(EventBus.TTS_START, readAloudNumber + 1)
}
override fun onDone(s: String) {
@ -169,7 +169,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++
ReadBook.moveToNextPage()
postEvent(Bus.TTS_START, readAloudNumber + start)
postEvent(EventBus.TTS_START, readAloudNumber + start)
}
}
}

@ -6,9 +6,9 @@ import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.IntentHelp
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getPrefInt
@ -32,7 +32,7 @@ class WebService : BaseService() {
fun stop(context: Context) {
if (isRun) {
val intent = Intent(context, WebService::class.java)
intent.action = Action.stop
intent.action = IntentAction.stop
context.startService(intent)
}
}
@ -56,12 +56,12 @@ class WebService : BaseService() {
if (webSocketServer?.isAlive == true) {
webSocketServer?.stop()
}
postEvent(Bus.WEB_SERVICE_STOP, true)
postEvent(EventBus.WEB_SERVICE_STOP, true)
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
when (intent?.action) {
Action.stop -> stopSelf()
IntentAction.stop -> stopSelf()
else -> upWebServer()
}
return super.onStartCommand(intent, flags, startId)
@ -115,7 +115,7 @@ class WebService : BaseService() {
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<WebService>(this, Action.stop)
IntentHelp.servicePendingIntent<WebService>(this, IntentAction.stop)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()

@ -3,7 +3,7 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book
import io.legado.app.model.WebBook
@ -27,14 +27,14 @@ object AudioPlay {
fun play(context: Context) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.play
intent.action = IntentAction.play
context.startService(intent)
}
fun pause(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.pause
intent.action = IntentAction.pause
context.startService(intent)
}
}
@ -42,7 +42,7 @@ object AudioPlay {
fun resume(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.resume
intent.action = IntentAction.resume
context.startService(intent)
}
}
@ -50,7 +50,7 @@ object AudioPlay {
fun stop(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.stop
intent.action = IntentAction.stop
context.startService(intent)
}
}
@ -58,7 +58,7 @@ object AudioPlay {
fun adjustSpeed(context: Context, adjust: Float) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.adjustSpeed
intent.action = IntentAction.adjustSpeed
intent.putExtra("adjust", adjust)
context.startService(intent)
}
@ -67,7 +67,7 @@ object AudioPlay {
fun adjustProgress(context: Context, position: Int) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.adjustProgress
intent.action = IntentAction.adjustProgress
intent.putExtra("position", position)
context.startService(intent)
}
@ -76,7 +76,7 @@ object AudioPlay {
fun prev(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.prev
intent.action = IntentAction.prev
context.startService(intent)
}
}
@ -84,7 +84,7 @@ object AudioPlay {
fun next(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.next
intent.action = IntentAction.next
context.startService(intent)
}
}

@ -2,14 +2,14 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.service.DownloadService
object Download {
fun start(context: Context, bookUrl: String, start: Int, end: Int) {
Intent(context, DownloadService::class.java).let {
it.action = Action.start
it.action = IntentAction.start
it.putExtra("bookUrl", bookUrl)
it.putExtra("start", start)
it.putExtra("end", end)

@ -3,7 +3,7 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.App
import io.legado.app.constant.Action
import io.legado.app.constant.IntentAction
import io.legado.app.constant.PreferKey
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.HttpReadAloudService
@ -30,7 +30,7 @@ object ReadAloud {
play: Boolean = true
) {
val intent = Intent(context, aloudClass)
intent.action = Action.play
intent.action = IntentAction.play
intent.putExtra("title", title)
intent.putExtra("subtitle", subtitle)
intent.putExtra("pageIndex", pageIndex)
@ -42,7 +42,7 @@ object ReadAloud {
fun pause(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.pause
intent.action = IntentAction.pause
context.startService(intent)
}
}
@ -50,7 +50,7 @@ object ReadAloud {
fun resume(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.resume
intent.action = IntentAction.resume
context.startService(intent)
}
}
@ -58,7 +58,7 @@ object ReadAloud {
fun stop(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.stop
intent.action = IntentAction.stop
context.startService(intent)
}
}
@ -66,7 +66,7 @@ object ReadAloud {
fun prevParagraph(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.prevParagraph
intent.action = IntentAction.prevParagraph
context.startService(intent)
}
}
@ -74,7 +74,7 @@ object ReadAloud {
fun nextParagraph(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.nextParagraph
intent.action = IntentAction.nextParagraph
context.startService(intent)
}
}
@ -82,7 +82,7 @@ object ReadAloud {
fun upTtsSpeechRate(context: Context) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.upTtsSpeechRate
intent.action = IntentAction.upTtsSpeechRate
context.startService(intent)
}
}
@ -90,7 +90,7 @@ object ReadAloud {
fun setTimer(context: Context, minute: Int) {
if (BaseReadAloudService.isRun) {
val intent = Intent(context, aloudClass)
intent.action = Action.setTimer
intent.action = IntentAction.setTimer
intent.putExtra("minute", minute)
context.startService(intent)
}

@ -14,7 +14,7 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.Status
import io.legado.app.constant.Theme
import io.legado.app.data.entities.Book
@ -193,12 +193,12 @@ class AudioPlayActivity :
}
override fun observeLiveBus() {
observeEvent<Boolean>(Bus.MEDIA_BUTTON) {
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
playButton()
}
}
observeEventSticky<Int>(Bus.AUDIO_STATE) {
observeEventSticky<Int>(EventBus.AUDIO_STATE) {
AudioPlay.status = it
if (it == Status.PLAY) {
fab_play_stop.setImageResource(R.drawable.ic_pause_24dp)
@ -206,19 +206,19 @@ class AudioPlayActivity :
fab_play_stop.setImageResource(R.drawable.ic_play_24dp)
}
}
observeEventSticky<String>(Bus.AUDIO_SUB_TITLE) {
observeEventSticky<String>(EventBus.AUDIO_SUB_TITLE) {
tv_sub_title.text = it
}
observeEventSticky<Int>(Bus.AUDIO_SIZE) {
observeEventSticky<Int>(EventBus.AUDIO_SIZE) {
player_progress.max = it
tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
}
observeEventSticky<Int>(Bus.AUDIO_PROGRESS) {
observeEventSticky<Int>(EventBus.AUDIO_PROGRESS) {
AudioPlay.durPageIndex = it
if (!adjustProgress) player_progress.progress = it
tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
}
observeEventSticky<Float>(Bus.AUDIO_SPEED) {
observeEventSticky<Float>(EventBus.AUDIO_SPEED) {
tv_speed.text = String.format("%.1fX", it)
tv_speed.visible()
}

@ -21,7 +21,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book
@ -498,12 +498,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
when (dialogId) {
TEXT_COLOR -> {
setTextColor(color)
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
BG_COLOR -> {
setBg(0, "#${color.hexString}")
ReadBookConfig.upBg()
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
}
}
@ -550,7 +550,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun observeLiveBus() {
super.observeLiveBus()
observeEvent<Int>(Bus.ALOUD_STATE) {
observeEvent<Int>(EventBus.ALOUD_STATE) {
if (it == Status.STOP || it == Status.PAUSE) {
ReadBook.curTextChapter?.let { textChapter ->
val page = textChapter.page(ReadBook.durPageIndex)
@ -561,20 +561,20 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
}
}
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) {
observeEvent<String>(EventBus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.index, ReadBook.durPageIndex)
page_view.upContent()
}
observeEvent<Boolean>(Bus.MEDIA_BUTTON) {
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
onClickReadAloud()
} else {
ReadBook.readAloud(!BaseReadAloudService.pause)
}
}
observeEvent<Boolean>(Bus.UP_CONFIG) {
observeEvent<Boolean>(EventBus.UP_CONFIG) {
upSystemUiVisibility()
content_view.upStyle()
page_view.upBg()
@ -585,7 +585,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
page_view.upContent()
}
}
observeEventSticky<Int>(Bus.TTS_START) { chapterStart ->
observeEventSticky<Int>(EventBus.TTS_START) { chapterStart ->
launch(IO) {
if (BaseReadAloudService.isPlay()) {
ReadBook.curTextChapter?.let {
@ -598,7 +598,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
}
}
observeEvent<String>(Bus.REPLACE) {
observeEvent<String>(EventBus.REPLACE) {
ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog")
}
observeEvent<Boolean>(PreferKey.keepLight) {

@ -20,7 +20,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialog
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.permission.Permissions
@ -154,7 +154,7 @@ class BgTextConfigDialog : DialogFragment() {
this.onClick {
ReadBookConfig.getConfig().setBg(1, item)
ReadBookConfig.upBg()
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
}
}
@ -178,7 +178,7 @@ class BgTextConfigDialog : DialogFragment() {
file.writeBytes(it)
ReadBookConfig.getConfig().setBg(2, file.absolutePath)
ReadBookConfig.upBg()
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
}
} else {
@ -192,7 +192,7 @@ class BgTextConfigDialog : DialogFragment() {
FileUtils.getPath(requireContext(), uri)?.let { path ->
ReadBookConfig.getConfig().setBg(2, path)
ReadBookConfig.upBg()
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
}
.request()

@ -12,7 +12,7 @@ import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.read.Help
@ -92,8 +92,8 @@ class MoreConfigDialog : DialogFragment() {
key: String?
) {
when (key) {
PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true)
PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true)
PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.keepLight -> postEvent(PreferKey.keepLight, true)
}
}

@ -8,7 +8,7 @@ import android.view.ViewGroup
import android.widget.SeekBar
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.postEvent
@ -61,35 +61,35 @@ class PaddingConfigDialog : DialogFragment() {
private fun initView() = with(ReadBookConfig.getConfig()) {
iv_padding_top_add.onClick {
seek_padding_top.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_top_remove.onClick {
seek_padding_top.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_bottom_add.onClick {
seek_padding_bottom.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_bottom_remove.onClick {
seek_padding_bottom.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_left_add.onClick {
seek_padding_left.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_left_remove.onClick {
seek_padding_left.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_right_add.onClick {
seek_padding_right.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_padding_right_remove.onClick {
seek_padding_right.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
seek_padding_top.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -101,7 +101,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
seek_padding_bottom.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -113,7 +113,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
seek_padding_left.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -125,7 +125,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
seek_padding_right.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -137,7 +137,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
}

@ -12,7 +12,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService
@ -89,7 +89,7 @@ class ReadAloudConfigDialog : DialogFragment() {
when (key) {
PreferKey.readAloudByPage -> {
if (BaseReadAloudService.isRun) {
postEvent(Bus.MEDIA_BUTTON, false)
postEvent(EventBus.MEDIA_BUTTON, false)
}
}
PreferKey.readAloudOnLine -> {

@ -9,7 +9,7 @@ import android.view.ViewGroup
import android.widget.SeekBar
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.service.help.ReadBook
@ -57,8 +57,8 @@ class ReadAloudDialog : DialogFragment() {
}
private fun initData() {
observeEvent<Int>(Bus.ALOUD_STATE) { upPlayState() }
observeEvent<Int>(Bus.TTS_DS) { seek_timer.progress = it }
observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() }
observeEvent<Int>(EventBus.TTS_DS) { seek_timer.progress = it }
upPlayState()
seek_timer.progress = BaseReadAloudService.timeMinute
tv_timer.text =

@ -10,7 +10,7 @@ import android.widget.SeekBar
import androidx.core.view.get
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
@ -83,7 +83,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
textBold = !textBold
tv_text_bold.isSelected = textBold
}
postEvent(Bus.UP_CONFIG, false)
postEvent(EventBus.UP_CONFIG, false)
}
tv_text_font.onClick {
FontSelectDialog().show(childFragmentManager, "fontSelectDialog")
@ -94,7 +94,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
items = resources.getStringArray(R.array.indent).toList()
) { _, index ->
putPrefInt("textIndent", index)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_padding.onClick {
@ -112,16 +112,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
iv_text_size_add.onClick {
seek_text_size.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_text_size_remove.onClick {
seek_text_size.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
seek_text_letter_spacing.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener {
@ -134,16 +134,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
iv_text_letter_spacing_add.onClick {
seek_text_letter_spacing.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_text_letter_spacing_remove.onClick {
seek_text_letter_spacing.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
seek_line_size.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener {
@ -156,16 +156,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
})
iv_line_size_add.onClick {
seek_line_size.progressAdd(1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
iv_line_size_remove.onClick {
seek_line_size.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
rg_page_anim.onCheckedChange { _, checkedId ->
for (i in 0 until rg_page_anim.childCount) {
@ -197,7 +197,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
ReadBookConfig.upBg()
upStyle()
upBg()
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
}
@ -266,6 +266,6 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun selectFile(path: String) {
requireContext().putPrefString(PreferKey.readBookFont, path)
postEvent(Bus.UP_CONFIG, true)
postEvent(EventBus.UP_CONFIG, true)
}
}

@ -6,7 +6,7 @@ import android.view.MenuItem
import android.widget.TextView
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.utils.postEvent
class ContentSelectActionCallback(private val textView: TextView) : ActionMode.Callback {
@ -15,7 +15,7 @@ class ContentSelectActionCallback(private val textView: TextView) : ActionMode.C
when (item?.itemId) {
R.id.menu_replace -> {
val text = textView.text.substring(textView.selectionStart, textView.selectionEnd)
postEvent(Bus.REPLACE, text)
postEvent(EventBus.REPLACE, text)
mode?.finish()
return true
}

@ -12,7 +12,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
@ -90,7 +90,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
PreferKey.processText -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean("process_text", true))
}
PreferKey.showRss -> postEvent(Bus.SHOW_RSS, "unused")
PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused")
}
}

@ -9,7 +9,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
@ -180,7 +180,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
}
private fun recreateActivities() {
postEvent(Bus.RECREATE, "")
postEvent(EventBus.RECREATE, "")
Handler().postDelayed({ activity?.recreate() }, 100L)
}

@ -9,7 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.service.help.Download
import io.legado.app.utils.applyTint
@ -67,7 +67,7 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) {
}
override fun observeLiveBus() {
observeEvent<Boolean>(Bus.UP_DOWNLOAD) {
observeEvent<Boolean>(EventBus.UP_DOWNLOAD) {
if (it) {
menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp)
menu?.applyTint(this)

@ -14,7 +14,7 @@ import io.legado.app.App
import io.legado.app.BuildConfig
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
@ -144,10 +144,10 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
}
override fun observeLiveBus() {
observeEvent<String>(Bus.RECREATE) {
observeEvent<String>(EventBus.RECREATE) {
recreate()
}
observeEvent<String>(Bus.SHOW_RSS) {
observeEvent<String>(EventBus.SHOW_RSS) {
bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS
upFragmentList()
view_pager_main.adapter?.notifyDataSetChanged()

@ -3,7 +3,7 @@ package io.legado.app.ui.main
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.RssSource
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.Restore
@ -24,14 +24,14 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
synchronized(this) {
updateList.add(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
WebBook(bookSource).getChapterList(book)
.timeout(300000)
.onSuccess(IO) {
synchronized(this) {
updateList.remove(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
it?.let {
App.db.bookDao().update(book)
@ -42,7 +42,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
.onError {
synchronized(this) {
updateList.remove(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
it.printStackTrace()
}

@ -14,7 +14,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.*
@ -87,7 +87,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position ->
tab.text = bookGroups[position].groupName
}.attach()
observeEvent<Int>(Bus.UP_TABS) {
observeEvent<Int>(EventBus.UP_TABS) {
tab_layout.getTabAt(it)?.select()
}
}

@ -11,7 +11,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseFragment
import io.legado.app.constant.BookType
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
import io.legado.app.help.IntentDataHelp
@ -56,7 +56,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
}
initRecyclerView()
upRecyclerData()
observeEvent<String>(Bus.UP_BOOK) {
observeEvent<String>(EventBus.UP_BOOK) {
booksAdapter.notification(it)
}
}

@ -14,7 +14,7 @@ import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseFragment
import io.legado.app.constant.Bus
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.BookHelp
import io.legado.app.help.permission.Permissions
@ -182,7 +182,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
}
addPreferencesFromResource(R.xml.pref_main)
val webServicePre = findPreference<ATESwitchPreference>(PreferKey.webService)
observeEvent<Boolean>(Bus.WEB_SERVICE_STOP) {
observeEvent<Boolean>(EventBus.WEB_SERVICE_STOP) {
webServicePre?.isChecked = false
}
}

Loading…
Cancel
Save