From a9a8d720e60e41b0a2910496b9f7f928b5470b88 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 23 Aug 2019 11:36:56 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookActivity.kt | 4 ++- .../ui/readbook/config/MoreConfigDialog.kt | 34 ++++++++++++++++--- .../readbook/config/ReadPreferenceFragment.kt | 14 ++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt 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 6616805de..6c11b007a 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 @@ -19,6 +19,7 @@ import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity +import io.legado.app.ui.readbook.config.MoreConfigDialog import io.legado.app.ui.readbook.config.ReadStyleDialog import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.widget.page.ChapterProvider @@ -168,7 +169,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } override fun showMoreSetting() { - + runMenuOut() + MoreConfigDialog().show(supportFragmentManager, "moreConfig") } override fun toast(id: Int) { diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt index 9cbbe6270..8f52d65ef 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt @@ -1,15 +1,41 @@ package io.legado.app.ui.readbook.config import android.os.Bundle -import androidx.preference.PreferenceFragmentCompat +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 io.legado.app.R -class MoreConfigDialog : PreferenceFragmentCompat() { +class MoreConfigDialog : DialogFragment() { + private val readPreferTag = "readPreferenceFragment" - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.pref_config_read) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = LinearLayout(context) + view.id = R.id.tag1 + container?.addView(view) + return view } + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + var preferenceFragment = childFragmentManager.findFragmentByTag(readPreferTag) + if (preferenceFragment == null) preferenceFragment = ReadPreferenceFragment() + childFragmentManager.beginTransaction().replace(view.id, preferenceFragment, readPreferTag) + .commit() + } } \ No newline at end of file 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 new file mode 100644 index 000000000..d26bbf65a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt @@ -0,0 +1,14 @@ +package io.legado.app.ui.readbook.config + +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import io.legado.app.R + +class ReadPreferenceFragment : PreferenceFragmentCompat() { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_config_read) + } + + +} \ No newline at end of file