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 package io.legado.app.constant
object Bus { object EventBus {
const val MEDIA_BUTTON = "mediaButton" const val MEDIA_BUTTON = "mediaButton"
const val RECREATE = "RECREATE" const val RECREATE = "RECREATE"
const val UP_BOOK = "sourceDebugLog" const val UP_BOOK = "sourceDebugLog"

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

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

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

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

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

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

@ -2,7 +2,7 @@ package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.media.MediaPlayer 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.constant.PreferKey
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
@ -98,7 +98,7 @@ class HttpReadAloudService : BaseReadAloudService(),
mediaPlayer.reset() mediaPlayer.reset()
mediaPlayer.setDataSource(fd) mediaPlayer.setDataSource(fd)
mediaPlayer.prepareAsync() mediaPlayer.prepareAsync()
postEvent(Bus.TTS_START, readAloudNumber + 1) postEvent(EventBus.TTS_START, readAloudNumber + 1)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
@ -187,7 +187,7 @@ class HttpReadAloudService : BaseReadAloudService(),
ReadBook.moveToNextPage() ReadBook.moveToNextPage()
} }
} }
postEvent(Bus.TTS_START, readAloudNumber + 1) postEvent(EventBus.TTS_START, readAloudNumber + 1)
} }
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { 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 android.speech.tts.UtteranceProgressListener
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst 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.IntentHelp
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
@ -152,7 +152,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
ReadBook.moveToNextPage() ReadBook.moveToNextPage()
} }
} }
postEvent(Bus.TTS_START, readAloudNumber + 1) postEvent(EventBus.TTS_START, readAloudNumber + 1)
} }
override fun onDone(s: String) { override fun onDone(s: String) {
@ -169,7 +169,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++ pageIndex++
ReadBook.moveToNextPage() 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.App
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.Action import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst 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.IntentHelp
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
@ -32,7 +32,7 @@ class WebService : BaseService() {
fun stop(context: Context) { fun stop(context: Context) {
if (isRun) { if (isRun) {
val intent = Intent(context, WebService::class.java) val intent = Intent(context, WebService::class.java)
intent.action = Action.stop intent.action = IntentAction.stop
context.startService(intent) context.startService(intent)
} }
} }
@ -56,12 +56,12 @@ class WebService : BaseService() {
if (webSocketServer?.isAlive == true) { if (webSocketServer?.isAlive == true) {
webSocketServer?.stop() webSocketServer?.stop()
} }
postEvent(Bus.WEB_SERVICE_STOP, true) postEvent(EventBus.WEB_SERVICE_STOP, true)
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
when (intent?.action) { when (intent?.action) {
Action.stop -> stopSelf() IntentAction.stop -> stopSelf()
else -> upWebServer() else -> upWebServer()
} }
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
@ -115,7 +115,7 @@ class WebService : BaseService() {
builder.addAction( builder.addAction(
R.drawable.ic_stop_black_24dp, R.drawable.ic_stop_black_24dp,
getString(R.string.cancel), getString(R.string.cancel),
IntentHelp.servicePendingIntent<WebService>(this, Action.stop) IntentHelp.servicePendingIntent<WebService>(this, IntentAction.stop)
) )
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build() val notification = builder.build()

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

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

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

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

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

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

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

@ -8,7 +8,7 @@ import android.view.ViewGroup
import android.widget.SeekBar import android.widget.SeekBar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R 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.help.ReadBookConfig
import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.Help
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -61,35 +61,35 @@ class PaddingConfigDialog : DialogFragment() {
private fun initView() = with(ReadBookConfig.getConfig()) { private fun initView() = with(ReadBookConfig.getConfig()) {
iv_padding_top_add.onClick { iv_padding_top_add.onClick {
seek_padding_top.progressAdd(1) seek_padding_top.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_top_remove.onClick { iv_padding_top_remove.onClick {
seek_padding_top.progressAdd(-1) seek_padding_top.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_bottom_add.onClick { iv_padding_bottom_add.onClick {
seek_padding_bottom.progressAdd(1) seek_padding_bottom.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_bottom_remove.onClick { iv_padding_bottom_remove.onClick {
seek_padding_bottom.progressAdd(-1) seek_padding_bottom.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_left_add.onClick { iv_padding_left_add.onClick {
seek_padding_left.progressAdd(1) seek_padding_left.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_left_remove.onClick { iv_padding_left_remove.onClick {
seek_padding_left.progressAdd(-1) seek_padding_left.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_right_add.onClick { iv_padding_right_add.onClick {
seek_padding_right.progressAdd(1) seek_padding_right.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_padding_right_remove.onClick { iv_padding_right_remove.onClick {
seek_padding_right.progressAdd(-1) seek_padding_right.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
seek_padding_top.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_padding_top.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -101,7 +101,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
seek_padding_bottom.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_padding_bottom.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -113,7 +113,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
seek_padding_left.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_padding_left.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -125,7 +125,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
seek_padding_right.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_padding_right.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
@ -137,7 +137,7 @@ class PaddingConfigDialog : DialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { 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.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R 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.constant.PreferKey
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -89,7 +89,7 @@ class ReadAloudConfigDialog : DialogFragment() {
when (key) { when (key) {
PreferKey.readAloudByPage -> { PreferKey.readAloudByPage -> {
if (BaseReadAloudService.isRun) { if (BaseReadAloudService.isRun) {
postEvent(Bus.MEDIA_BUTTON, false) postEvent(EventBus.MEDIA_BUTTON, false)
} }
} }
PreferKey.readAloudOnLine -> { PreferKey.readAloudOnLine -> {

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

@ -10,7 +10,7 @@ import android.widget.SeekBar
import androidx.core.view.get import androidx.core.view.get
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R 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.constant.PreferKey
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
@ -83,7 +83,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
textBold = !textBold textBold = !textBold
tv_text_bold.isSelected = textBold tv_text_bold.isSelected = textBold
} }
postEvent(Bus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
tv_text_font.onClick { tv_text_font.onClick {
FontSelectDialog().show(childFragmentManager, "fontSelectDialog") FontSelectDialog().show(childFragmentManager, "fontSelectDialog")
@ -94,7 +94,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
items = resources.getStringArray(R.array.indent).toList() items = resources.getStringArray(R.array.indent).toList()
) { _, index -> ) { _, index ->
putPrefInt("textIndent", index) putPrefInt("textIndent", index)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
tv_padding.onClick { tv_padding.onClick {
@ -112,16 +112,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
iv_text_size_add.onClick { iv_text_size_add.onClick {
seek_text_size.progressAdd(1) seek_text_size.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_text_size_remove.onClick { iv_text_size_remove.onClick {
seek_text_size.progressAdd(-1) seek_text_size.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
seek_text_letter_spacing.setOnSeekBarChangeListener(object : seek_text_letter_spacing.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener { SeekBar.OnSeekBarChangeListener {
@ -134,16 +134,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
iv_text_letter_spacing_add.onClick { iv_text_letter_spacing_add.onClick {
seek_text_letter_spacing.progressAdd(1) seek_text_letter_spacing.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_text_letter_spacing_remove.onClick { iv_text_letter_spacing_remove.onClick {
seek_text_letter_spacing.progressAdd(-1) seek_text_letter_spacing.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
seek_line_size.setOnSeekBarChangeListener(object : seek_line_size.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener { SeekBar.OnSeekBarChangeListener {
@ -156,16 +156,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
}) })
iv_line_size_add.onClick { iv_line_size_add.onClick {
seek_line_size.progressAdd(1) seek_line_size.progressAdd(1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
iv_line_size_remove.onClick { iv_line_size_remove.onClick {
seek_line_size.progressAdd(-1) seek_line_size.progressAdd(-1)
postEvent(Bus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
rg_page_anim.onCheckedChange { _, checkedId -> rg_page_anim.onCheckedChange { _, checkedId ->
for (i in 0 until rg_page_anim.childCount) { for (i in 0 until rg_page_anim.childCount) {
@ -197,7 +197,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
ReadBookConfig.upBg() ReadBookConfig.upBg()
upStyle() upStyle()
upBg() 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) { override fun selectFile(path: String) {
requireContext().putPrefString(PreferKey.readBookFont, path) 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 android.widget.TextView
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.EventBus
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
class ContentSelectActionCallback(private val textView: TextView) : ActionMode.Callback { class ContentSelectActionCallback(private val textView: TextView) : ActionMode.Callback {
@ -15,7 +15,7 @@ class ContentSelectActionCallback(private val textView: TextView) : ActionMode.C
when (item?.itemId) { when (item?.itemId) {
R.id.menu_replace -> { R.id.menu_replace -> {
val text = textView.text.substring(textView.selectionStart, textView.selectionEnd) val text = textView.text.substring(textView.selectionStart, textView.selectionEnd)
postEvent(Bus.REPLACE, text) postEvent(EventBus.REPLACE, text)
mode?.finish() mode?.finish()
return true return true
} }

@ -12,7 +12,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
import io.legado.app.R 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.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -90,7 +90,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
PreferKey.processText -> sharedPreferences?.let { PreferKey.processText -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean("process_text", true)) 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 androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
import io.legado.app.R 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.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
@ -180,7 +180,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
} }
private fun recreateActivities() { private fun recreateActivities() {
postEvent(Bus.RECREATE, "") postEvent(EventBus.RECREATE, "")
Handler().postDelayed({ activity?.recreate() }, 100L) Handler().postDelayed({ activity?.recreate() }, 100L)
} }

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

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

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

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

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

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

Loading…
Cancel
Save