feat: 优化

pull/226/head
gedoor 5 years ago
parent 4d1cbda379
commit f5733bbf3e
  1. 37
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 16
      app/src/main/res/menu/book_source.xml
  3. 1
      app/src/main/res/values-zh-rHK/strings.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -57,6 +57,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private var bookSourceLiveDate: LiveData<List<BookSource>>? = null private var bookSourceLiveDate: LiveData<List<BookSource>>? = null
private var groups = linkedSetOf<String>() private var groups = linkedSetOf<String>()
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private var sort = 0
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initUriScheme() initUriScheme()
@ -92,6 +93,22 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) )
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()
R.id.menu_sort_manual -> {
item.isChecked = true
sort = 0
}
R.id.menu_sort_auto -> {
item.isChecked = true
sort = 2
}
R.id.menu_sort_pin_yin -> {
item.isChecked = true
sort = 3
}
R.id.menu_sort_url -> {
item.isChecked = true
sort = 4
}
} }
if (item.groupId == R.id.source_group) { if (item.groupId == R.id.source_group) {
search_view.setQuery(item.title, true) search_view.setQuery(item.title, true)
@ -104,14 +121,14 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
when (it.path) { when (it.path) {
"/importonline" -> it.getQueryParameter("src")?.let { url -> "/importonline" -> it.getQueryParameter("src")?.let { url ->
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show()
if (url.startsWith("http", false)){ if (url.startsWith("http", false)) {
viewModel.importSource(url) { msg -> viewModel.importSource(url) { msg ->
title_bar.snackbar(msg) title_bar.snackbar(msg)
} }
} else {
viewModel.importSourceFromFilePath(url) { msg ->
title_bar.snackbar(msg)
} }
else{
viewModel.importSourceFromFilePath(url){msg ->
title_bar.snackbar(msg)}
} }
} }
else -> { else -> {
@ -148,10 +165,16 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} else { } else {
App.db.bookSourceDao().liveDataSearch("%$searchKey%") App.db.bookSourceDao().liveDataSearch("%$searchKey%")
} }
bookSourceLiveDate?.observe(this, Observer { bookSourceLiveDate?.observe(this, Observer { data ->
val sourceList = when (sort) {
1 -> data.sortedBy { it.weight }
2 -> data.sortedBy { it.bookSourceName }
3 -> data.sortedBy { it.bookSourceUrl }
else -> data
}
val diffResult = DiffUtil val diffResult = DiffUtil
.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it)) .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), sourceList))
adapter.setItems(it, diffResult) adapter.setItems(sourceList, diffResult)
upCountView() upCountView()
}) })
} }

@ -23,23 +23,31 @@
<menu> <menu>
<group <group
android:id="@+id/menu_group_sort" android:id="@+id/menu_group_sort"
android:checkableBehavior="single" /> android:checkableBehavior="single">
<item <item
android:id="@+id/sort_manual" android:id="@+id/menu_sort_manual"
android:checkable="true" android:checkable="true"
android:checked="true"
android:title="@string/sort_manual" /> android:title="@string/sort_manual" />
<item <item
android:id="@+id/sort_auto" android:id="@+id/menu_sort_auto"
android:checkable="true" android:checkable="true"
android:title="@string/sort_auto" /> android:title="@string/sort_auto" />
<item <item
android:id="@+id/sort_pin_yin" android:id="@+id/menu_sort_pin_yin"
android:checkable="true" android:checkable="true"
android:title="@string/sort_pin_yin" /> android:title="@string/sort_pin_yin" />
<item
android:id="@+id/menu_sort_url"
android:checkable="true"
android:title="@string/sort_by_url" />
</group>
</menu> </menu>
</item> </item>

@ -693,4 +693,5 @@
<string name="to_bottom">置底</string> <string name="to_bottom">置底</string>
<string name="text_full_justify">文字兩端對齊</string> <string name="text_full_justify">文字兩端對齊</string>
<string name="auto_page_speed">自動翻頁速度</string> <string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</string>
</resources> </resources>

@ -695,5 +695,6 @@
<string name="auto_change_source">自动换源</string> <string name="auto_change_source">自动换源</string>
<string name="text_full_justify">文字两端对齐</string> <string name="text_full_justify">文字两端对齐</string>
<string name="auto_page_speed">自动翻页速度</string> <string name="auto_page_speed">自动翻页速度</string>
<string name="sort_by_url">地址排序</string>
</resources> </resources>

Loading…
Cancel
Save