pull/34/head
parent
d85db50d03
commit
2a9d537b6e
@ -0,0 +1,92 @@ |
||||
package io.legado.app.ui.readbook.config |
||||
|
||||
import android.content.SharedPreferences |
||||
import android.os.Bundle |
||||
import android.util.DisplayMetrics |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import android.widget.LinearLayout |
||||
import androidx.fragment.app.DialogFragment |
||||
import androidx.preference.PreferenceFragmentCompat |
||||
import io.legado.app.R |
||||
import io.legado.app.constant.Bus |
||||
import io.legado.app.lib.theme.ATH |
||||
import io.legado.app.ui.readbook.Help |
||||
import io.legado.app.utils.postEvent |
||||
|
||||
class ReadAloudConfigDialog : DialogFragment() { |
||||
private val readAloudPreferTag = "readAloudPreferTag" |
||||
|
||||
override fun onCreateView( |
||||
inflater: LayoutInflater, |
||||
container: ViewGroup?, |
||||
savedInstanceState: Bundle? |
||||
): View? { |
||||
val view = LinearLayout(context) |
||||
view.setBackgroundResource(R.color.background) |
||||
view.id = R.id.tag1 |
||||
container?.addView(view) |
||||
return view |
||||
} |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
val dm = DisplayMetrics() |
||||
activity?.let { |
||||
Help.upSystemUiVisibility(it) |
||||
it.windowManager?.defaultDisplay?.getMetrics(dm) |
||||
} |
||||
dialog?.window?.let { |
||||
it.setBackgroundDrawableResource(R.color.transparent) |
||||
it.decorView.setPadding(0, 0, 0, 0) |
||||
val attr = it.attributes |
||||
attr.dimAmount = 0.0f |
||||
it.attributes = attr |
||||
it.setLayout((dm.widthPixels * 0.9).toInt(), ViewGroup.LayoutParams.WRAP_CONTENT) |
||||
} |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
var preferenceFragment = childFragmentManager.findFragmentByTag(readAloudPreferTag) |
||||
if (preferenceFragment == null) preferenceFragment = ReadAloudPreferenceFragment() |
||||
childFragmentManager.beginTransaction() |
||||
.replace(view.id, preferenceFragment, readAloudPreferTag) |
||||
.commit() |
||||
} |
||||
|
||||
class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), |
||||
SharedPreferences.OnSharedPreferenceChangeListener { |
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
||||
addPreferencesFromResource(R.xml.pref_config_aloud) |
||||
} |
||||
|
||||
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) { |
||||
"readAloudByPage" -> postEvent(Bus.READ_ALOUD_BUTTON, false) |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -1,41 +0,0 @@ |
||||
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.constant.Bus |
||||
import io.legado.app.lib.theme.ATH |
||||
import io.legado.app.utils.postEvent |
||||
|
||||
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" -> postEvent(Bus.UP_CONFIG, true) |
||||
"hideNavigationBar" -> postEvent(Bus.UP_CONFIG, true) |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||
android:defaultValue="false" |
||||
android:title="@string/read_aloud_by_page" |
||||
android:key="readAloudByPage" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
|
||||
</androidx.preference.PreferenceScreen> |
Loading…
Reference in new issue