pull/32/head
kunfei 5 years ago
parent c0fa0821a1
commit a3ff57aa44
  1. 10
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 20
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  3. 52
      app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt
  4. 19
      app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt
  5. 37
      app/src/main/res/layout/item_book_source.xml
  6. 49
      app/src/main/res/menu/book_source.xml

@ -23,8 +23,14 @@ interface BookSourceDao {
@Query("select distinct enabled from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey")
fun searchIsEnable(searchKey: String = ""): List<Boolean>
@Query("UPDATE book_sources SET enabled = :enable where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey")
fun enableAllSearch(searchKey: String = "", enable: String = "1")
@Query("update book_sources set enabled = 1 where bookSourceUrl in (:sourceUrls)")
fun enableSection(vararg sourceUrls: String)
@Query("update book_sources set enabled = 0 where bookSourceUrl in (:sourceUrls)")
fun disableSection(vararg sourceUrls: String)
@Query("delete from book_sources where bookSourceUrl in (:sourceUrls)")
fun delSection(vararg sourceUrls: String)
@Query("select * from book_sources where enabledExplore = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource>

@ -28,8 +28,6 @@ import io.legado.app.utils.splitNotBlank
import kotlinx.android.synthetic.main.activity_book_source.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
@ -72,22 +70,16 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_import_book_source_qr -> {
this.startActivityForResult<QrCodeActivity>(qrRequestCode)
}
R.id.menu_select_all -> {
launch(IO) {
val isEnableList =
App.db.bookSourceDao().searchIsEnable("%${search_view.query}%")
if (isEnableList.contains(false)) {
App.db.bookSourceDao().enableAllSearch("%${search_view.query}%", "1")
} else {
App.db.bookSourceDao().enableAllSearch("%${search_view.query}%", "0")
}
}
}
R.id.menu_group_manage -> GroupManageDialog().show(
supportFragmentManager,
"groupManage"
)
R.id.menu_import_book_source_local -> Restore.importYueDuData(this)
R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
}
if (item.groupId == R.id.source_group) {
search_view.setQuery(item.title, true)
@ -179,7 +171,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
viewModel.upOrder()
}
override fun topSource(bookSource: BookSource) {
override fun toTop(bookSource: BookSource) {
viewModel.topSource(bookSource)
}

@ -1,6 +1,8 @@
package io.legado.app.ui.booksource
import android.content.Context
import android.view.Menu
import android.widget.PopupMenu
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -14,6 +16,36 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<BookSource>(context, R.layout.item_book_source),
OnItemTouchCallbackListener {
private val selectedIds = linkedSetOf<String>()
fun selectAll() {
getItems().forEach {
selectedIds.add(it.bookSourceUrl)
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun revertSelection() {
getItems().forEach {
if (selectedIds.contains(it.bookSourceUrl)) {
selectedIds.remove(it.bookSourceUrl)
} else {
selectedIds.add(it.bookSourceUrl)
}
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun getSelectionIds(): LinkedHashSet<String> {
val selection = linkedSetOf<String>()
getItems().map {
if (selectedIds.contains(it.bookSourceUrl)) {
selection.add(it.bookSourceUrl)
}
}
return selection
}
override fun onSwiped(adapterPosition: Int) {
}
@ -48,9 +80,21 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
item.enabled = cb_book_source.isChecked
callBack.update(item)
}
iv_edit_source.onClick { callBack.edit(item) }
iv_top_source.onClick { callBack.topSource(item) }
iv_del_source.onClick { callBack.del(item) }
iv_edit.onClick { callBack.edit(item) }
iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it)
popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item)
R.id.menu_del -> callBack.del(item)
}
true
}
popupMenu.show()
}
}
}
@ -58,7 +102,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
fun del(bookSource: BookSource)
fun edit(bookSource: BookSource)
fun update(vararg bookSource: BookSource)
fun topSource(bookSource: BookSource)
fun toTop(bookSource: BookSource)
fun upOrder()
}
}

@ -9,7 +9,6 @@ import io.legado.app.utils.splitNotBlank
class BookSourceViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao().minOrder
@ -36,6 +35,24 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}
}
fun enableSelection(ids: LinkedHashSet<String>) {
execute {
App.db.bookSourceDao().enableSection(*ids.toTypedArray())
}
}
fun disableSelection(ids: LinkedHashSet<String>) {
execute {
App.db.bookSourceDao().disableSection(*ids.toTypedArray())
}
}
fun delSelection(ids: LinkedHashSet<String>) {
execute {
App.db.bookSourceDao().delSection(*ids.toTypedArray())
}
}
fun addGroup(group: String) {
execute {
val sources = App.db.bookSourceDao().noGroup

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
@ -18,8 +18,17 @@
android:text=""
android:textColor="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/swt_enabled"
android:name="@string/enable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
tools:ignore="RtlSymmetry" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit_source"
android:id="@+id/iv_edit"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
@ -27,28 +36,16 @@
android:contentDescription="@string/edit"
android:padding="6dp"
android:src="@drawable/ic_edit"
app:tint="@color/tv_text_default" />
android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_top_source"
android:id="@+id/iv_menu_more"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/to_top"
android:padding="6dp"
android:src="@drawable/ic_top_source"
app:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_del_source"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/delete"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="6dp"
android:src="@drawable/ic_clear_all"
app:tint="@color/tv_text_default" />
android:src="@drawable/ic_more_vert"
android:tint="@color/tv_text_default"
tools:ignore="RtlHardcoded" />
</LinearLayout>

@ -4,11 +4,42 @@
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/menu_select_all"
android:id="@+id/menu_select_action"
android:icon="@drawable/ic_select_all"
android:title="@string/select_all"
android:title="@string/select_action"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
tools:ignore="AlwaysShowAction">
<menu>
<item
android:id="@+id/menu_select_all"
android:title="@string/select_all"
app:showAsAction="never" />
<item
android:id="@+id/menu_revert_selection"
android:title="@string/revert_selection"
app:showAsAction="never" />
<item
android:id="@+id/menu_enable_selection"
android:title="@string/enable_selection"
app:showAsAction="never" />
<item
android:id="@+id/menu_disable_selection"
android:title="@string/disable_selection"
app:showAsAction="never" />
<item
android:id="@+id/menu_del_selection"
android:title="@string/del_select"
app:showAsAction="never" />
</menu>
</item>
<item
android:id="@+id/menu_group"
@ -83,18 +114,6 @@
android:title="@string/import_by_qr_code"
app:showAsAction="never" />
<item
android:id="@+id/menu_revert_selection"
android:icon="@drawable/ic_swap_outline_24dp"
android:title="@string/revert_selection"
app:showAsAction="never" />
<item
android:id="@+id/menu_del_select"
android:icon="@drawable/ic_clear_all"
android:title="@string/del_select"
app:showAsAction="never" />
<item
android:id="@+id/menu_check_book_source"
android:icon="@drawable/ic_check_source"

Loading…
Cancel
Save