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 org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
import java.text.Collator
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 menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null
private var groups = hashSetOf<String>()
private var groups = linkedSetOf<String>()
private var refreshTime = System.currentTimeMillis()
override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -229,12 +230,13 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(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<SearchViewModel>(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 {

@ -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<BookSourceViewModel>(R.layout.activity_book_source),
PopupMenu.OnMenuItemClickListener,
@ -197,9 +198,10 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(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")

@ -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<ExploreViewModel>(R.layout.fragment_find_book),
@ -119,9 +120,10 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(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)
}
}
}

@ -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<RssSourceViewModel>(R.layout.activity_rss_source),
@ -190,9 +192,10 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(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) {

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

Loading…
Cancel
Save