feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 1827288eca
commit d50682e340
  1. 9
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  4. 5
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  5. 1
      app/src/main/res/layout/item_search.xml

@ -32,6 +32,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import java.text.Collator
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_search), class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_search),
@ -50,7 +51,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var bookData: LiveData<List<Book>>? = null private var bookData: LiveData<List<Book>>? = null
private var menu: Menu? = null private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null private var precisionSearchMenuItem: MenuItem? = null
private var groups = hashSetOf<String>() private var groups = linkedSetOf<String>()
private var refreshTime = System.currentTimeMillis() private var refreshTime = System.currentTimeMillis()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -229,7 +230,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
if (selectedGroup == "") { if (selectedGroup == "") {
item?.isChecked = true item?.isChecked = true
} }
groups.map { groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE))
.map {
item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
if (it == selectedGroup) { if (it == selectedGroup) {
item?.isChecked = true item?.isChecked = true
@ -266,7 +268,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
} else { } else {
App.db.searchKeywordDao().liveDataSearch(key) App.db.searchKeywordDao().liveDataSearch(key)
} }
historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) historyData?.observe(this, Observer {
historyKeyAdapter.setItems(it)
if (it.isEmpty()) { if (it.isEmpty()) {
tv_clear_history.invisible() tv_clear_history.invisible()
} else { } else {

@ -40,6 +40,7 @@ import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.text.Collator
class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source), class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
@ -197,7 +198,8 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private fun upGroupMenu() { private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group) groupMenu?.removeGroup(R.id.source_group)
groups.map { groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE))
.map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
} }
} }

@ -17,14 +17,15 @@ import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor 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.explore.ExploreShowActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.fragment_find_book.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import java.text.Collator
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_book), class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_book),
@ -119,7 +120,8 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_
private fun upGroupsMenu() { private fun upGroupsMenu() {
groupsMenu?.let { subMenu -> groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text) subMenu.removeGroup(R.id.menu_group_text)
groups.forEach { groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE))
.forEach {
subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it) subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it)
} }
} }

@ -39,6 +39,8 @@ import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.text.Collator
import java.util.*
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source),
@ -190,7 +192,8 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
private fun upGroupMenu() { private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group) groupMenu?.removeGroup(R.id.source_group)
groups.map { groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE))
.map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
} }
} }

@ -35,6 +35,7 @@
android:singleLine="true" android:singleLine="true"
android:text="@string/app_name" android:text="@string/app_name"
android:textColor="@color/tv_text_default" android:textColor="@color/tv_text_default"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@id/bv_originCount" app:layout_constraintEnd_toStartOf="@id/bv_originCount"
app:layout_constraintStart_toEndOf="@+id/iv_cover" app:layout_constraintStart_toEndOf="@+id/iv_cover"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

Loading…
Cancel
Save