feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 1827288eca
commit d50682e340
  1. 17
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 10
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  4. 9
      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,12 +230,13 @@ 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))
item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) .map {
if (it == selectedGroup) { item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
item?.isChecked = true if (it == selectedGroup) {
item?.isChecked = true
}
} }
}
menu?.setGroupCheckable(R.id.source_group, true, true) menu?.setGroupCheckable(R.id.source_group, true, 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,9 +198,10 @@ 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))
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) .map {
} groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")

@ -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,9 +120,10 @@ 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))
subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it) .forEach {
} 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,9 +192,10 @@ 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))
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) .map {
} groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
} }
private fun initLiveDataSource(key: String? = null) { private fun initLiveDataSource(key: String? = null) {

@ -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