From d50682e34081f49845ad2850f1cdc8869eb7699d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 7 Mar 2020 19:12:18 +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 --- .../legado/app/ui/book/search/SearchActivity.kt | 17 ++++++++++------- .../ui/book/source/manage/BookSourceActivity.kt | 8 +++++--- .../app/ui/main/explore/ExploreFragment.kt | 10 ++++++---- .../ui/rss/source/manage/RssSourceActivity.kt | 9 ++++++--- app/src/main/res/layout/item_search.xml | 1 + 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 195a1c5e5..c86f96dba 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity +import java.text.Collator class SearchActivity : VMBaseActivity(R.layout.activity_book_search), @@ -50,7 +51,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private var bookData: LiveData>? = null private var menu: Menu? = null private var precisionSearchMenuItem: MenuItem? = null - private var groups = hashSetOf() + private var groups = linkedSetOf() private var refreshTime = System.currentTimeMillis() override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -229,12 +230,13 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se if (selectedGroup == "") { item?.isChecked = true } - groups.map { - item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - if (it == selectedGroup) { - item?.isChecked = true + groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) + .map { + item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) + if (it == selectedGroup) { + item?.isChecked = true + } } - } menu?.setGroupCheckable(R.id.source_group, true, true) } @@ -266,7 +268,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } else { App.db.searchKeywordDao().liveDataSearch(key) } - historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) + historyData?.observe(this, Observer { + historyKeyAdapter.setItems(it) if (it.isEmpty()) { tv_clear_history.invisible() } else { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 31b1c2028..eba5950f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -40,6 +40,7 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast import java.io.File +import java.text.Collator class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), PopupMenu.OnMenuItemClickListener, @@ -197,9 +198,10 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) - groups.map { - groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - } + groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) + .map { + groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) + } } @SuppressLint("InflateParams") diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index f4257732c..c8f93fc64 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -17,14 +17,15 @@ import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.BookSource import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor -import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.explore.ExploreShowActivity +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.splitNotBlank import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* +import java.text.Collator class ExploreFragment : VMBaseFragment(R.layout.fragment_find_book), @@ -119,9 +120,10 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ private fun upGroupsMenu() { groupsMenu?.let { subMenu -> subMenu.removeGroup(R.id.menu_group_text) - groups.forEach { - subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it) - } + groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) + .forEach { + subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it) + } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 35934e4d6..c60ddaa39 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -39,6 +39,8 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast import java.io.File +import java.text.Collator +import java.util.* class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), @@ -190,9 +192,10 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) - groups.map { - groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - } + groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) + .map { + groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) + } } private fun initLiveDataSource(key: String? = null) { diff --git a/app/src/main/res/layout/item_search.xml b/app/src/main/res/layout/item_search.xml index 2942b5db5..421082d13 100644 --- a/app/src/main/res/layout/item_search.xml +++ b/app/src/main/res/layout/item_search.xml @@ -35,6 +35,7 @@ android:singleLine="true" android:text="@string/app_name" android:textColor="@color/tv_text_default" + android:textSize="16sp" app:layout_constraintEnd_toStartOf="@id/bv_originCount" app:layout_constraintStart_toEndOf="@+id/iv_cover" app:layout_constraintTop_toTopOf="parent" />