From 7ce3e670bd294ad525badd923dbe8e588eec75ed Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 22:07:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../ui/book/read/config/ReadStyleDialog.kt | 25 ++--- .../ui/main/bookshelf/BookshelfFragment.kt | 46 ++++++-- .../io/legado/app/utils/ViewExtensions.kt | 24 ++++ .../res/layout/dialog_bookshelf_config.xml | 105 ++++++++++++++++++ .../main/res/layout/dialog_number_picker.xml | 3 +- app/src/main/res/values/arrays.xml | 20 ---- app/src/main/res/values/strings.xml | 19 ++-- 8 files changed, 186 insertions(+), 57 deletions(-) create mode 100644 app/src/main/res/layout/dialog_bookshelf_config.xml diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 6be087f05..225154a97 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -16,6 +16,7 @@ object PreferKey { const val nextKey = "nextKeyCode" const val showRss = "showRss" const val bookshelfLayout = "bookshelfLayout" + const val bookshelfSort = "bookshelfSort" const val recordLog = "recordLog" const val processText = "process_text" const val cleanCache = "cleanCache" diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index b7a0a330b..a6482caed 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -19,6 +19,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog +import io.legado.app.utils.getIndexById import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent import io.legado.app.utils.putPrefString @@ -30,6 +31,8 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { + val callBack = activity as? ReadBookActivity + override fun onStart() { super.onStart() val dm = DisplayMetrics() @@ -120,11 +123,8 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { } } tv_padding.onClick { - val activity = activity dismiss() - if (activity is ReadBookActivity) { - activity.showPaddingConfig() - } + callBack?.showPaddingConfig() } dsb_text_size.onChanged = { ReadBookConfig.textSize = it + 5 @@ -143,15 +143,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } rg_page_anim.onCheckedChange { _, checkedId -> - for (i in 0 until rg_page_anim.childCount) { - if (checkedId == rg_page_anim[i].id) { - ReadBookConfig.pageAnim = i - val activity = activity - if (activity is ReadBookActivity) { - activity.page_view.upPageAnim() - } - break - } + rg_page_anim.getIndexById(checkedId).let { + ReadBookConfig.pageAnim = it + callBack?.page_view?.upPageAnim() } } cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> @@ -186,10 +180,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun showBgTextConfig(index: Int): Boolean { dismiss() changeBg(index) - val activity = activity - if (activity is ReadBookActivity) { - activity.showBgTextConfig() - } + callBack?.showBgTextConfig() return true } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 16b7b286f..cd4d40a72 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf import android.annotation.SuppressLint import android.os.Bundle +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View @@ -17,7 +18,10 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup -import io.legado.app.lib.dialogs.* +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.book.arrange.ArrangeBookActivity @@ -27,6 +31,7 @@ import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* +import kotlinx.android.synthetic.main.dialog_bookshelf_config.view.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* @@ -61,7 +66,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b super.onCompatOptionsItemSelected(item) when (item.itemId) { R.id.menu_search -> startActivity() - R.id.menu_bookshelf_layout -> selectBookshelfLayout() + R.id.menu_bookshelf_layout -> configBookshelf() R.id.menu_group_manage -> GroupManageDialog() .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> startActivity() @@ -145,14 +150,35 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } } - private fun selectBookshelfLayout() { - selector( - title = "选择书架布局", - items = resources.getStringArray(R.array.bookshelf_layout).toList() - ) { _, index -> - putPrefInt(PreferKey.bookshelfLayout, index) - activity?.recreate() - } + @SuppressLint("InflateParams") + private fun configBookshelf() { + requireContext().alert(titleResource = R.string.bookshelf_layout) { + val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout) + val bookshelfSort = getPrefInt(PreferKey.bookshelfSort) + val root = LayoutInflater.from(requireContext()) + .inflate(R.layout.dialog_bookshelf_config, null).apply { + rg_layout.checkByIndex(bookshelfLayout) + rg_sort.checkByIndex(bookshelfSort) + } + customView = root + okButton { + root.apply { + var changed = false + if (bookshelfLayout != rg_layout.getCheckedIndex()) { + putPrefInt(PreferKey.bookshelfLayout, rg_layout.getCheckedIndex()) + changed = true + } + if (bookshelfSort != rg_sort.getCheckedIndex()) { + putPrefInt(PreferKey.bookshelfLayout, rg_sort.getCheckedIndex()) + changed = true + } + if (changed) { + activity?.recreate() + } + } + } + noButton() + }.show().applyTint() } @SuppressLint("InflateParams") diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 8eb3cb1f6..b8a457325 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -7,8 +7,10 @@ import android.os.Build import android.view.View import android.view.View.* import android.view.inputmethod.InputMethodManager +import android.widget.RadioGroup import android.widget.SeekBar import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.get import io.legado.app.App @@ -69,4 +71,26 @@ fun View.screenshot(): Bitmap? { fun SeekBar.progressAdd(int: Int) { progress += int +} + +fun RadioGroup.getIndexById(id: Int): Int { + for (i in 0 until this.childCount) { + if (id == get(i).id) { + return i + } + } + return 0 +} + +fun RadioGroup.getCheckedIndex(): Int { + for (i in 0 until this.childCount) { + if (checkedRadioButtonId == get(i).id) { + return i + } + } + return 0 +} + +fun RadioGroup.checkByIndex(index: Int) { + check(get(index).id) } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_bookshelf_config.xml b/app/src/main/res/layout/dialog_bookshelf_config.xml new file mode 100644 index 000000000..944913f4c --- /dev/null +++ b/app/src/main/res/layout/dialog_bookshelf_config.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_number_picker.xml b/app/src/main/res/layout/dialog_number_picker.xml index 5a471be84..f54fd0a00 100644 --- a/app/src/main/res/layout/dialog_number_picker.xml +++ b/app/src/main/res/layout/dialog_number_picker.xml @@ -7,6 +7,7 @@ android:id="@+id/number_picker" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:scrollbars="none" /> \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index ff1fc875c..f46e94565 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -35,14 +35,6 @@ 9 - - @string/layout_list - @string/layout_grid3 - @string/layout_grid4 - @string/layout_grid5 - @string/layout_grid6 - - @string/indent_0 @string/indent_1 @@ -111,18 +103,6 @@ @string/screen_sensor - - @string/bookshelf_px_0 - @string/bookshelf_px_1 - @string/bookshelf_px_2 - - - - 0 - 1 - 2 - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8da65e500..7e9540a2f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -47,12 +47,13 @@ 书架还空着,先去添加吧! 搜索 下载 - 列表视图 - 网格视图三列 - 网格视图四列 - 网格视图五列 - 网格视图六列 + 列表 + 网格三列 + 网格四列 + 网格五列 + 网格六列 书架布局 + 视图 书城 添加本地 书源 @@ -226,11 +227,11 @@ 来源:%s 本地导入 网络导入 - 书架排序 检查更新间隔 - 按阅读时间排序 - 按更新时间排序 - 手动排序 + 按阅读时间 + 按更新时间 + 按书名 + 手动排序 阅读方式 删除所选 是否确认删除?