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") @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> 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") @Query("update book_sources set enabled = 1 where bookSourceUrl in (:sourceUrls)")
fun enableAllSearch(searchKey: String = "", enable: String = "1") 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") @Query("select * from book_sources where enabledExplore = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource> 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.activity_book_source.*
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 kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
@ -72,22 +70,16 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_import_book_source_qr -> { R.id.menu_import_book_source_qr -> {
this.startActivityForResult<QrCodeActivity>(qrRequestCode) 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( R.id.menu_group_manage -> GroupManageDialog().show(
supportFragmentManager, supportFragmentManager,
"groupManage" "groupManage"
) )
R.id.menu_import_book_source_local -> Restore.importYueDuData(this) 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) { if (item.groupId == R.id.source_group) {
search_view.setQuery(item.title, true) search_view.setQuery(item.title, true)
@ -179,7 +171,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
viewModel.upOrder() viewModel.upOrder()
} }
override fun topSource(bookSource: BookSource) { override fun toTop(bookSource: BookSource) {
viewModel.topSource(bookSource) viewModel.topSource(bookSource)
} }

@ -1,6 +1,8 @@
package io.legado.app.ui.booksource package io.legado.app.ui.booksource
import android.content.Context import android.content.Context
import android.view.Menu
import android.widget.PopupMenu
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter 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), SimpleRecyclerAdapter<BookSource>(context, R.layout.item_book_source),
OnItemTouchCallbackListener { 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) { override fun onSwiped(adapterPosition: Int) {
} }
@ -48,9 +80,21 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
item.enabled = cb_book_source.isChecked item.enabled = cb_book_source.isChecked
callBack.update(item) callBack.update(item)
} }
iv_edit_source.onClick { callBack.edit(item) } iv_edit.onClick { callBack.edit(item) }
iv_top_source.onClick { callBack.topSource(item) } iv_menu_more.onClick {
iv_del_source.onClick { callBack.del(item) } 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 del(bookSource: BookSource)
fun edit(bookSource: BookSource) fun edit(bookSource: BookSource)
fun update(vararg bookSource: BookSource) fun update(vararg bookSource: BookSource)
fun topSource(bookSource: BookSource) fun toTop(bookSource: BookSource)
fun upOrder() fun upOrder()
} }
} }

@ -9,7 +9,6 @@ import io.legado.app.utils.splitNotBlank
class BookSourceViewModel(application: Application) : BaseViewModel(application) { class BookSourceViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) { fun topSource(bookSource: BookSource) {
execute { execute {
val minXh = App.db.bookSourceDao().minOrder 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) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.bookSourceDao().noGroup val sources = App.db.bookSourceDao().noGroup

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
@ -18,8 +18,17 @@
android:text="" android:text=""
android:textColor="@color/tv_text_default" /> 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 <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit_source" android:id="@+id/iv_edit"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_gravity="center" android:layout_gravity="center"
@ -27,28 +36,16 @@
android:contentDescription="@string/edit" android:contentDescription="@string/edit"
android:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_edit" android:src="@drawable/ic_edit"
app:tint="@color/tv_text_default" /> android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_top_source" android:id="@+id/iv_menu_more"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_gravity="center" android:background="?attr/selectableItemBackgroundBorderless"
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:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_clear_all" android:src="@drawable/ic_more_vert"
app:tint="@color/tv_text_default" /> android:tint="@color/tv_text_default"
tools:ignore="RtlHardcoded" />
</LinearLayout> </LinearLayout>

@ -4,11 +4,42 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<item <item
android:id="@+id/menu_select_all" android:id="@+id/menu_select_action"
android:icon="@drawable/ic_select_all" android:icon="@drawable/ic_select_all"
android:title="@string/select_all" android:title="@string/select_action"
app:showAsAction="always" 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 <item
android:id="@+id/menu_group" android:id="@+id/menu_group"
@ -83,18 +114,6 @@
android:title="@string/import_by_qr_code" android:title="@string/import_by_qr_code"
app:showAsAction="never" /> 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 <item
android:id="@+id/menu_check_book_source" android:id="@+id/menu_check_book_source"
android:icon="@drawable/ic_check_source" android:icon="@drawable/ic_check_source"

Loading…
Cancel
Save