From 1e185b0ee939889fc917e9e5d8a68ca0b0f6b596 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 18:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/constant/{Bus.kt => EventBus.kt} | 2 +- .../constant/{Action.kt => IntentAction.kt} | 2 +- .../app/receiver/MediaButtonReceiver.kt | 6 +- .../app/receiver/TimeElectricityReceiver.kt | 6 +- .../io/legado/app/service/AudioPlayService.kt | 56 +++++++++---------- .../app/service/BaseReadAloudService.kt | 34 +++++------ .../legado/app/service/CheckSourceService.kt | 25 ++++++++- .../io/legado/app/service/DownloadService.kt | 14 ++--- .../app/service/HttpReadAloudService.kt | 6 +- .../legado/app/service/TTSReadAloudService.kt | 6 +- .../java/io/legado/app/service/WebService.kt | 12 ++-- .../io/legado/app/service/help/AudioPlay.kt | 18 +++--- .../io/legado/app/service/help/Download.kt | 4 +- .../io/legado/app/service/help/ReadAloud.kt | 18 +++--- .../legado/app/ui/audio/AudioPlayActivity.kt | 14 ++--- .../app/ui/book/read/ReadBookActivity.kt | 22 ++++---- .../ui/book/read/config/BgTextConfigDialog.kt | 8 +-- .../ui/book/read/config/MoreConfigDialog.kt | 6 +- .../book/read/config/PaddingConfigDialog.kt | 26 ++++----- .../book/read/config/ReadAloudConfigDialog.kt | 4 +- .../ui/book/read/config/ReadAloudDialog.kt | 6 +- .../ui/book/read/config/ReadStyleDialog.kt | 28 +++++----- .../read/page/ContentSelectActionCallback.kt | 4 +- .../app/ui/config/OtherConfigFragment.kt | 4 +- .../app/ui/config/ThemeConfigFragment.kt | 4 +- .../app/ui/download/DownloadActivity.kt | 4 +- .../io/legado/app/ui/main/MainActivity.kt | 6 +- .../io/legado/app/ui/main/MainViewModel.kt | 8 +-- .../ui/main/bookshelf/BookshelfFragment.kt | 4 +- .../ui/main/bookshelf/books/BooksFragment.kt | 4 +- .../io/legado/app/ui/main/my/MyFragment.kt | 4 +- 31 files changed, 192 insertions(+), 173 deletions(-) rename app/src/main/java/io/legado/app/constant/{Bus.kt => EventBus.kt} (97%) rename app/src/main/java/io/legado/app/constant/{Action.kt => IntentAction.kt} (96%) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt similarity index 97% rename from app/src/main/java/io/legado/app/constant/Bus.kt rename to app/src/main/java/io/legado/app/constant/EventBus.kt index eb1dd14dd..3fc80e3ac 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.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" diff --git a/app/src/main/java/io/legado/app/constant/Action.kt b/app/src/main/java/io/legado/app/constant/IntentAction.kt similarity index 96% rename from app/src/main/java/io/legado/app/constant/Action.kt rename to app/src/main/java/io/legado/app/constant/IntentAction.kt index a13a8cca3..0dffe87a1 100644 --- a/app/src/main/java/io/legado/app/constant/Action.kt +++ b/app/src/main/java/io/legado/app/constant/IntentAction.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 5cc36a680..12083c652 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt index 613db4fe4..765d05b3e 100644 --- a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index ef2638c29..c165f3142 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 5603da72c..cb946d145 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index ba36d1e8b..6507cb219 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -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) { + 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? = 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(this, Action.stop) + IntentHelp.servicePendingIntent(this, IntentAction.stop) ) sourceList?.let { builder.setProgress(it.size, state, false) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 9c2e7a2f3..df49e24d9 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -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(this, Action.stop) + IntentHelp.servicePendingIntent(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) } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index f8048af54..1cf40fc8c 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 977e8b0ac..4c5357ce6 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 25f2b6822..e9d223956 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -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(this, Action.stop) + IntentHelp.servicePendingIntent(this, IntentAction.stop) ) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index add1a3fab..7c8d120b3 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/service/help/Download.kt b/app/src/main/java/io/legado/app/service/help/Download.kt index 1c17a7ee1..86accbceb 100644 --- a/app/src/main/java/io/legado/app/service/help/Download.kt +++ b/app/src/main/java/io/legado/app/service/help/Download.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt index 49285eeff..b5c12a965 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index a348b6e1e..dffd6a50f 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -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(Bus.MEDIA_BUTTON) { + observeEvent(EventBus.MEDIA_BUTTON) { if (it) { playButton() } } - observeEventSticky(Bus.AUDIO_STATE) { + observeEventSticky(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(Bus.AUDIO_SUB_TITLE) { + observeEventSticky(EventBus.AUDIO_SUB_TITLE) { tv_sub_title.text = it } - observeEventSticky(Bus.AUDIO_SIZE) { + observeEventSticky(EventBus.AUDIO_SIZE) { player_progress.max = it tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") } - observeEventSticky(Bus.AUDIO_PROGRESS) { + observeEventSticky(EventBus.AUDIO_PROGRESS) { AudioPlay.durPageIndex = it if (!adjustProgress) player_progress.progress = it tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") } - observeEventSticky(Bus.AUDIO_SPEED) { + observeEventSticky(EventBus.AUDIO_SPEED) { tv_speed.text = String.format("%.1fX", it) tv_speed.visible() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 60057a622..e35a50a9e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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(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(R.layout.activity_boo override fun observeLiveBus() { super.observeLiveBus() - observeEvent(Bus.ALOUD_STATE) { + observeEvent(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(R.layout.activity_boo } } } - observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } - observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } - observeEvent(Bus.OPEN_CHAPTER) { + observeEvent(EventBus.TIME_CHANGED) { page_view.upTime() } + observeEvent(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) } + observeEvent(EventBus.OPEN_CHAPTER) { viewModel.openChapter(it.index, ReadBook.durPageIndex) page_view.upContent() } - observeEvent(Bus.MEDIA_BUTTON) { + observeEvent(EventBus.MEDIA_BUTTON) { if (it) { onClickReadAloud() } else { ReadBook.readAloud(!BaseReadAloudService.pause) } } - observeEvent(Bus.UP_CONFIG) { + observeEvent(EventBus.UP_CONFIG) { upSystemUiVisibility() content_view.upStyle() page_view.upBg() @@ -585,7 +585,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo page_view.upContent() } } - observeEventSticky(Bus.TTS_START) { chapterStart -> + observeEventSticky(EventBus.TTS_START) { chapterStart -> launch(IO) { if (BaseReadAloudService.isPlay()) { ReadBook.curTextChapter?.let { @@ -598,7 +598,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } } - observeEvent(Bus.REPLACE) { + observeEvent(EventBus.REPLACE) { ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog") } observeEvent(PreferKey.keepLight) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 5d61aefe1..289658f80 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index e18f32c0b..ecb7df170 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 19ce7e100..c1a9e5e8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -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) } }) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 14f5c0b9b..0cc2a1336 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -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 -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index f464d99b2..deeef204b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -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(Bus.ALOUD_STATE) { upPlayState() } - observeEvent(Bus.TTS_DS) { seek_timer.progress = it } + observeEvent(EventBus.ALOUD_STATE) { upPlayState() } + observeEvent(EventBus.TTS_DS) { seek_timer.progress = it } upPlayState() seek_timer.progress = BaseReadAloudService.timeMinute tv_timer.text = diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 8a1327a85..10d3d3433 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -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) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt index cfce5f27b..f274b2744 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index ccfc88116..8f3a7e244 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -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") } } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 2ee2f6621..856e6cbb3 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt index a2ff5d99e..dfa5f5b3d 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt @@ -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(Bus.UP_DOWNLOAD) { + observeEvent(EventBus.UP_DOWNLOAD) { if (it) { menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) menu?.applyTint(this) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 5d9fee452..9fda82311 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -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(R.layout.activity_main), } override fun observeLiveBus() { - observeEvent(Bus.RECREATE) { + observeEvent(EventBus.RECREATE) { recreate() } - observeEvent(Bus.SHOW_RSS) { + observeEvent(EventBus.SHOW_RSS) { bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS upFragmentList() view_pager_main.adapter?.notifyDataSetChanged() diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 960f860c1..6af83db54 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 237e73567..a5fbb8bd5 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(R.layout.fragment_b TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position -> tab.text = bookGroups[position].groupName }.attach() - observeEvent(Bus.UP_TABS) { + observeEvent(EventBus.UP_TABS) { tab_layout.getTabAt(it)?.select() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 2b92d361b..d7ffd7a34 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -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(Bus.UP_BOOK) { + observeEvent(EventBus.UP_BOOK) { booksAdapter.notification(it) } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 2c515dbb7..035ca4d26 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -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(PreferKey.webService) - observeEvent(Bus.WEB_SERVICE_STOP) { + observeEvent(EventBus.WEB_SERVICE_STOP) { webServicePre?.isChecked = false } }