From 3a55d1af757eff82c58734ad958287f56a88502d Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 2 Dec 2020 19:36:28 +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 --- .../legado/app/ui/audio/AudioPlayActivity.kt | 11 +- .../io/legado/app/ui/book/read/ReadMenu.kt | 106 +++++++++--------- .../app/ui/book/read/config/AutoReadDialog.kt | 5 +- .../ui/book/read/config/ReadAloudDialog.kt | 19 ++-- .../io/legado/app/ui/main/MainActivity.kt | 40 +++---- .../io/legado/app/ui/widget/DetailSeekBar.kt | 9 +- .../widget/seekbar/SeekBarChangeListener.kt | 19 ++++ 7 files changed, 110 insertions(+), 99 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/seekbar/SeekBarChangeListener.kt 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 9d03b4e31..ff731e66f 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 @@ -25,6 +25,7 @@ import io.legado.app.service.help.AudioPlay import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.toc.ChapterListActivity import io.legado.app.ui.widget.image.CoverImageView +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import org.apache.commons.lang3.time.DateFormatUtils import org.jetbrains.anko.sdk27.listeners.onClick @@ -82,18 +83,18 @@ class AudioPlayActivity : binding.ivSkipPrevious.onClick { AudioPlay.prev(this) } - binding.playerProgress.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { binding.tvDurTime.text = DateFormatUtils.format(progress.toLong(), "mm:ss") } - override fun onStartTrackingTouch(seekBar: SeekBar?) { + override fun onStartTrackingTouch(seekBar: SeekBar) { adjustProgress = true } - override fun onStopTrackingTouch(seekBar: SeekBar?) { + override fun onStopTrackingTouch(seekBar: SeekBar) { adjustProgress = false - AudioPlay.adjustProgress(this@AudioPlayActivity, binding.playerProgress.progress) + AudioPlay.adjustProgress(this@AudioPlayActivity, seekBar.progress) } }) binding.ivChapter.onClick { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 46148718b..e598bce9d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -18,6 +18,7 @@ import io.legado.app.help.AppConfig import io.legado.app.help.LocalConfig import io.legado.app.lib.theme.* import io.legado.app.service.help.ReadBook +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick @@ -46,40 +47,44 @@ class ReadMenu @JvmOverloads constructor( val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true) init { + initView() + upBrightnessState() + bindEvent() + } + + private fun initView() = with(binding) { if (AppConfig.isNightTheme) { - binding.fabNightTheme.setImageResource(R.drawable.ic_daytime) + fabNightTheme.setImageResource(R.drawable.ic_daytime) } else { - binding.fabNightTheme.setImageResource(R.drawable.ic_brightness) + fabNightTheme.setImageResource(R.drawable.ic_brightness) } initAnimation() val brightnessBackground = GradientDrawable() brightnessBackground.cornerRadius = 5F.dp brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) - binding.llBrightness.background = brightnessBackground - binding.llBottomBg.setBackgroundColor(bgColor) - binding.fabSearch.backgroundTintList = bottomBackgroundList - binding.fabSearch.setColorFilter(textColor) - binding.fabAutoPage.backgroundTintList = bottomBackgroundList - binding.fabAutoPage.setColorFilter(textColor) - binding.fabReplaceRule.backgroundTintList = bottomBackgroundList - binding.fabReplaceRule.setColorFilter(textColor) - binding.fabNightTheme.backgroundTintList = bottomBackgroundList - binding.fabNightTheme.setColorFilter(textColor) - binding.tvPre.setTextColor(textColor) - binding.tvNext.setTextColor(textColor) - binding.ivCatalog.setColorFilter(textColor) - binding.tvCatalog.setTextColor(textColor) - binding.ivReadAloud.setColorFilter(textColor) - binding.tvReadAloud.setTextColor(textColor) - binding.ivFont.setColorFilter(textColor) - binding.tvFont.setTextColor(textColor) - binding.ivSetting.setColorFilter(textColor) - binding.tvSetting.setTextColor(textColor) - binding.vwBg.onClick { } - binding.vwNavigationBar.onClick { } - binding.seekBrightness.progress = context.getPrefInt("brightness", 100) - upBrightnessState() - bindEvent() + llBrightness.background = brightnessBackground + llBottomBg.setBackgroundColor(bgColor) + fabSearch.backgroundTintList = bottomBackgroundList + fabSearch.setColorFilter(textColor) + fabAutoPage.backgroundTintList = bottomBackgroundList + fabAutoPage.setColorFilter(textColor) + fabReplaceRule.backgroundTintList = bottomBackgroundList + fabReplaceRule.setColorFilter(textColor) + fabNightTheme.backgroundTintList = bottomBackgroundList + fabNightTheme.setColorFilter(textColor) + tvPre.setTextColor(textColor) + tvNext.setTextColor(textColor) + ivCatalog.setColorFilter(textColor) + tvCatalog.setTextColor(textColor) + ivReadAloud.setColorFilter(textColor) + tvReadAloud.setTextColor(textColor) + ivFont.setColorFilter(textColor) + tvFont.setTextColor(textColor) + ivSetting.setColorFilter(textColor) + tvSetting.setTextColor(textColor) + vwBg.onClick { } + vwNavigationBar.onClick { } + seekBrightness.progress = context.getPrefInt("brightness", 100) } fun upBrightnessState() { @@ -128,27 +133,24 @@ class ReadMenu @JvmOverloads constructor( return context.getPrefBoolean("brightnessAuto", true) || !showBrightnessView } - private fun bindEvent() { - binding.tvChapterName.onClick { + private fun bindEvent() = with(binding) { + tvChapterName.onClick { callBack.openSourceEditActivity() } - binding.tvChapterUrl.onClick { + tvChapterUrl.onClick { context.openUrl(binding.tvChapterUrl.text.toString()) } - binding.ivBrightnessAuto.onClick { + ivBrightnessAuto.onClick { context.putPrefBoolean("brightnessAuto", !brightnessAuto()) upBrightnessState() } //亮度调节 - binding.seekBrightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + seekBrightness.setOnSeekBarChangeListener(object : SeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { setScreenBrightness(progress) } - override fun onStartTrackingTouch(seekBar: SeekBar) { - - } - override fun onStopTrackingTouch(seekBar: SeekBar) { context.putPrefInt("brightness", seekBar.progress) } @@ -156,75 +158,69 @@ class ReadMenu @JvmOverloads constructor( }) //阅读进度 - binding.seekReadPage.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { - - } - - override fun onStartTrackingTouch(seekBar: SeekBar) { - - } + seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener { override fun onStopTrackingTouch(seekBar: SeekBar) { ReadBook.skipToPage(seekBar.progress) } + }) //搜索 - binding.fabSearch.onClick { + fabSearch.onClick { runMenuOut { callBack.openSearchActivity(null) } } //自动翻页 - binding.fabAutoPage.onClick { + fabAutoPage.onClick { runMenuOut { callBack.autoPage() } } //替换 - binding.fabReplaceRule.onClick { callBack.openReplaceRule() } + fabReplaceRule.onClick { callBack.openReplaceRule() } //夜间模式 - binding.fabNightTheme.onClick { + fabNightTheme.onClick { AppConfig.isNightTheme = !AppConfig.isNightTheme App.INSTANCE.applyDayNight() } //上一章 - binding.tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } + tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } //下一章 - binding.tvNext.onClick { ReadBook.moveToNextChapter(true) } + tvNext.onClick { ReadBook.moveToNextChapter(true) } //目录 - binding.llCatalog.onClick { + llCatalog.onClick { runMenuOut { callBack.openChapterList() } } //朗读 - binding.llReadAloud.onClick { + llReadAloud.onClick { runMenuOut { callBack.onClickReadAloud() } } - binding.llReadAloud.onLongClick { + llReadAloud.onLongClick { runMenuOut { callBack.showReadAloudDialog() } true } //界面 - binding.llFont.onClick { + llFont.onClick { runMenuOut { callBack.showReadStyle() } } //设置 - binding.llSetting.onClick { + llSetting.onClick { runMenuOut { callBack.showMoreSetting() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt index 9ee791297..67656c57e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt @@ -13,6 +13,7 @@ import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.ColorUtils import io.legado.app.utils.viewbindingdelegate.viewBinding import org.jetbrains.anko.sdk27.listeners.onClick @@ -78,14 +79,12 @@ class AutoReadDialog : BaseDialogFragment() { } private fun initOnChange() { - binding.seekAutoRead.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + binding.seekAutoRead.setOnSeekBarChangeListener(object : SeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { val speed = if (progress < 10) 10 else progress binding.tvReadSpeed.text = String.format("%ds", speed) } - override fun onStartTrackingTouch(seekBar: SeekBar) = Unit - override fun onStopTrackingTouch(seekBar: SeekBar) { ReadBookConfig.autoReadSpeed = if (binding.seekAutoRead.progress < 10) 10 else binding.seekAutoRead.progress 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 982f05d09..8fb2bbcea 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 @@ -15,6 +15,7 @@ import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.ColorUtils import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.observeEvent @@ -102,25 +103,19 @@ class ReadAloudDialog : BaseDialogFragment() { upTtsSpeechRate() } } - seekTtsSpeechRate.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit + seekTtsSpeechRate.setOnSeekBarChangeListener(object : SeekBarChangeListener { - override fun onStopTrackingTouch(seekBar: SeekBar?) { - AppConfig.ttsSpeechRate = seekTtsSpeechRate.progress + override fun onStopTrackingTouch(seekBar: SeekBar) { + AppConfig.ttsSpeechRate = seekBar.progress upTtsSpeechRate() } }) - seekTimer.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + seekTimer.setOnSeekBarChangeListener(object : SeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { upTimerText(progress) } - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit - - override fun onStopTrackingTouch(seekBar: SeekBar?) { + override fun onStopTrackingTouch(seekBar: SeekBar) { ReadAloud.setTimer(requireContext(), seekTimer.progress) } }) 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 af453d8e2..32794d127 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 @@ -51,17 +51,17 @@ class MainActivity : VMBaseActivity(), return ActivityMainBinding.inflate(layoutInflater) } - override fun onActivityCreated(savedInstanceState: Bundle?) { - ATH.applyEdgeEffectColor(binding.viewPagerMain) - ATH.applyBottomNavigationColor(binding.bottomNavigationView) - binding.viewPagerMain.offscreenPageLimit = 3 - binding.viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager) - binding.viewPagerMain.addOnPageChangeListener(this) - binding.bottomNavigationView.elevation = + override fun onActivityCreated(savedInstanceState: Bundle?) = with(binding) { + ATH.applyEdgeEffectColor(viewPagerMain) + ATH.applyBottomNavigationColor(bottomNavigationView) + viewPagerMain.offscreenPageLimit = 3 + viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager) + viewPagerMain.addOnPageChangeListener(this@MainActivity) + bottomNavigationView.elevation = if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat() - binding.bottomNavigationView.setOnNavigationItemSelectedListener(this) - binding.bottomNavigationView.setOnNavigationItemReselectedListener(this) - binding.bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS + bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity) + bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity) + bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS } override fun onPostCreate(savedInstanceState: Bundle?) { @@ -78,12 +78,12 @@ class MainActivity : VMBaseActivity(), }, 3000) } - override fun onNavigationItemSelected(item: MenuItem): Boolean { + override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { when (item.itemId) { - R.id.menu_bookshelf -> binding.viewPagerMain.setCurrentItem(0, false) - R.id.menu_explore -> binding.viewPagerMain.setCurrentItem(1, false) - R.id.menu_rss -> binding.viewPagerMain.setCurrentItem(2, false) - R.id.menu_my_config -> binding.viewPagerMain.setCurrentItem(3, false) + R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) + R.id.menu_explore -> viewPagerMain.setCurrentItem(1, false) + R.id.menu_rss -> viewPagerMain.setCurrentItem(2, false) + R.id.menu_my_config -> viewPagerMain.setCurrentItem(3, false) } return false } @@ -122,15 +122,15 @@ class MainActivity : VMBaseActivity(), } } - override fun onPageSelected(position: Int) { - binding.viewPagerMain.hideSoftInput() + override fun onPageSelected(position: Int) = with(binding) { + viewPagerMain.hideSoftInput() pagePosition = position when (position) { - 0, 1, 3 -> binding.bottomNavigationView.menu.getItem(position).isChecked = true + 0, 1, 3 -> bottomNavigationView.menu.getItem(position).isChecked = true 2 -> if (AppConfig.isShowRSS) { - binding.bottomNavigationView.menu.getItem(position).isChecked = true + bottomNavigationView.menu.getItem(position).isChecked = true } else { - binding.bottomNavigationView.menu.getItem(3).isChecked = true + bottomNavigationView.menu.getItem(3).isChecked = true } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index e120e4df7..b0a8115da 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -9,6 +9,7 @@ import io.legado.app.R import io.legado.app.databinding.ViewDetailSeekBarBinding import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.ColorUtils import io.legado.app.utils.progressAdd import org.jetbrains.anko.sdk27.listeners.onClick @@ -17,7 +18,7 @@ class DetailSeekBar @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : FrameLayout(context, attrs), - SeekBar.OnSeekBarChangeListener { + SeekBarChangeListener { private var binding: ViewDetailSeekBarBinding = ViewDetailSeekBarBinding.inflate(LayoutInflater.from(context), this, true) private val isBottomBackground: Boolean @@ -69,15 +70,15 @@ class DetailSeekBar @JvmOverloads constructor( } } - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { upValue(progress) } - override fun onStartTrackingTouch(seekBar: SeekBar?) { + override fun onStartTrackingTouch(seekBar: SeekBar) { } - override fun onStopTrackingTouch(seekBar: SeekBar?) { + override fun onStopTrackingTouch(seekBar: SeekBar) { onChanged?.invoke(binding.seekBar.progress) } diff --git a/app/src/main/java/io/legado/app/ui/widget/seekbar/SeekBarChangeListener.kt b/app/src/main/java/io/legado/app/ui/widget/seekbar/SeekBarChangeListener.kt new file mode 100644 index 000000000..eaa159029 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/seekbar/SeekBarChangeListener.kt @@ -0,0 +1,19 @@ +package io.legado.app.ui.widget.seekbar + +import android.widget.SeekBar + +interface SeekBarChangeListener : SeekBar.OnSeekBarChangeListener { + + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + + } + + override fun onStartTrackingTouch(seekBar: SeekBar) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + + } + +} \ No newline at end of file