pull/517/head
gedoor 4 years ago
parent efb880484b
commit 3a55d1af75
  1. 11
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 106
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt
  4. 19
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  5. 40
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  6. 9
      app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt
  7. 19
      app/src/main/java/io/legado/app/ui/widget/seekbar/SeekBarChangeListener.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 {

@ -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()
}

@ -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

@ -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)
}
})

@ -51,17 +51,17 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
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<ActivityMainBinding, MainViewModel>(),
}, 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<ActivityMainBinding, MainViewModel>(),
}
}
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
}
}
}

@ -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)
}

@ -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) {
}
}
Loading…
Cancel
Save