From 2ebdf5e1e63f844f1d15b45eecba8a15d7ce4678 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 23 Aug 2019 22:34:30 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookActivity.kt | 47 ++++++++++--------- .../app/ui/readbook/ReadBookViewModel.kt | 8 ++++ .../readbook/config/ReadPreferenceFragment.kt | 27 ++++++++++- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 1701f36c6..351d38967 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -65,6 +65,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun onResume() { super.onResume() + upBar() timeElectricityReceiver = TimeElectricityReceiver.register(this) } @@ -74,6 +75,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea unregisterReceiver(it) timeElectricityReceiver = null } + upBar() } private fun initView() { @@ -264,6 +266,30 @@ class ReadBookActivity : VMBaseActivity(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(Bus.ALOUD_STATE) { readAloudStatus = it } @@ -288,25 +314,4 @@ class ReadBookActivity : VMBaseActivity(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 -> { - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index ba3c9b845..b69f3c3d8 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt index d26bbf65a..f66d7e222 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt @@ -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" -> { + } + } + } } \ No newline at end of file