edit BookGroupDao.kt GroupManageDialog.kt item_book_group_manage.xml item_group_manage.xml

pull/840/head
gedoor 4 years ago
parent 41942086e4
commit 2dabed561b
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  3. 29
      app/src/main/res/layout/item_book_group_manage.xml
  4. 6
      app/src/main/res/layout/item_group_manage.xml

@ -19,7 +19,7 @@ interface BookGroupDao {
@Query(
"""
SELECT * FROM book_groups where groupId >= 0
SELECT * FROM book_groups where (groupId >= 0 and show > 0)
or (groupId = -4 and show > 0 and (select count(bookUrl) from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0) > 0)
or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0)
or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0)

@ -8,7 +8,6 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.core.view.isGone
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -20,7 +19,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemGroupManageBinding
import io.legado.app.databinding.ItemBookGroupManageBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
@ -116,6 +115,11 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
editView.setHint(R.string.group_name)
editView.setText(bookGroup.groupName)
}
if (bookGroup.groupId >= 0) {
neutralButton(R.string.delete) {
deleteGroup(bookGroup)
}
}
customView = alertBinding.root
yesButton {
alertBinding.editView.text?.toString()?.let {
@ -136,18 +140,18 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
private inner class GroupAdapter(context: Context) :
RecyclerAdapter<BookGroup, ItemGroupManageBinding>(context),
RecyclerAdapter<BookGroup, ItemBookGroupManageBinding>(context),
ItemTouchCallback.Callback {
private var isMoved = false
override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding {
return ItemGroupManageBinding.inflate(inflater, parent, false)
override fun getViewBinding(parent: ViewGroup): ItemBookGroupManageBinding {
return ItemBookGroupManageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupManageBinding,
binding: ItemBookGroupManageBinding,
item: BookGroup,
payloads: MutableList<Any>
) {
@ -155,15 +159,12 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
root.setBackgroundColor(context.backgroundColor)
tvGroup.text = item.getManageName(context)
swShow.isChecked = item.show
tvDel.isGone = item.groupId < 0
swShow.isGone = item.groupId >= 0
}
}
override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) {
override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) {
with(binding) {
tvEdit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } }
tvDel.onClick { getItem(holder.layoutPosition)?.let { deleteGroup(it) } }
swShow.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed) {
getItem(holder.layoutPosition)?.let {

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="8dp"
android:text="@string/edit" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/sw_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

@ -29,10 +29,4 @@
android:padding="8dp"
android:text="@string/delete" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/sw_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
Loading…
Cancel
Save