pull/32/head
kunfei 5 years ago
parent 1ccab90db4
commit 2ebdf5e1e6
  1. 47
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt
  3. 27
      app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt

@ -65,6 +65,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onResume() {
super.onResume()
upBar()
timeElectricityReceiver = TimeElectricityReceiver.register(this)
}
@ -74,6 +75,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
unregisterReceiver(it)
timeElectricityReceiver = null
}
upBar()
}
private fun initView() {
@ -264,6 +266,30 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
private fun setScreenBrightness(value: Int) {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (this.getPrefBoolean("brightnessAuto").not()) {
brightness = value.toFloat()
if (brightness < 1f) brightness = 1f
brightness = brightness * 1.0f / 255f
}
val params = window.attributes
params.screenBrightness = brightness
window.attributes = params
}
private fun upBar() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
requestCodeEditSource -> viewModel.upBookSource()
}
}
}
override fun observeLiveBus() {
super.observeLiveBus()
observeEvent<Int>(Bus.ALOUD_STATE) { readAloudStatus = it }
@ -288,25 +314,4 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
private fun setScreenBrightness(value: Int) {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (this.getPrefBoolean("brightnessAuto").not()) {
brightness = value.toFloat()
if (brightness < 1f) brightness = 1f
brightness = brightness * 1.0f / 255f
}
val params = window.attributes
params.screenBrightness = brightness
window.attributes = params
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
requestCodeEditSource -> {
}
}
}
}
}

@ -189,6 +189,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun upBookSource() {
execute {
bookData.value?.let {
bookSource = App.db.bookSourceDao().getBookSource(it.origin)
}
}
}
override fun onCleared() {
super.onCleared()
ReadAloudService.stop(context)

@ -1,14 +1,39 @@
package io.legado.app.ui.readbook.config
import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.lib.theme.ATH
class ReadPreferenceFragment : PreferenceFragmentCompat() {
class ReadPreferenceFragment : PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_read)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ATH.applyEdgeEffectColor(listView)
}
override fun onResume() {
super.onResume()
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
override fun onPause() {
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
super.onPause()
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
"hideStatusBar" -> {
}
}
}
}
Loading…
Cancel
Save