pull/32/head
gedoor 5 years ago
parent ffda2a35f9
commit 397e64a84a
  1. 67
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt
  2. 7
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  3. 39
      app/src/main/res/layout/item_book_source.xml

@ -1,10 +1,8 @@
package io.legado.app.ui.main.booksource
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.paging.PagedList
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
@ -34,7 +32,6 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
var callBack: CallBack? = null
private val checkedList = HashSet<String>()
val itemTouchCallbackListener = object : OnItemTouchCallbackListener {
override fun onSwiped(adapterPosition: Int) {
@ -57,24 +54,6 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
}
fun clearSelect() {
checkedList.clear()
}
fun selectAll() {
currentList?.let {
if (checkedList.size == it.size) {
checkedList.clear()
notifyDataSetChanged()
} else {
for (item in it) {
item?.let { checkedList.add(item.origin) }
}
notifyDataSetChanged()
}
}
}
override fun onCurrentListChanged(previousList: PagedList<BookSource>?, currentList: PagedList<BookSource>?) {
super.onCurrentListChanged(previousList, currentList)
callBack?.upCount(itemCount)
@ -86,7 +65,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let { holder.bind(it, checkedList, callBack) }
getItem(position)?.let { holder.bind(it, callBack) }
}
@ -96,46 +75,16 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context))
}
fun bind(bookSource: BookSource, checkedList: HashSet<String>, callBack: CallBack?) = with(itemView) {
fun bind(bookSource: BookSource, callBack: CallBack?) = with(itemView) {
cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group)
cb_book_source.isChecked = checkedList.contains(bookSource.origin)
cb_book_source.onClick {
if (cb_book_source.isChecked) {
checkedList.add(bookSource.origin)
} else {
checkedList.remove(bookSource.origin)
}
}
sw_enabled.isChecked = bookSource.isEnabled
sw_enabled.setOnClickListener {
bookSource.isEnabled = sw_enabled.isChecked
cb_book_source.isChecked = bookSource.isEnabled
cb_book_source.setOnClickListener {
bookSource.isEnabled = cb_book_source.isChecked
callBack?.update(bookSource)
}
iv_more.onClick {
val popupMenu = PopupMenu(context, iv_more)
popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)
popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_edit -> {
callBack?.edit(bookSource)
true
}
R.id.menu_del -> {
callBack?.del(bookSource)
true
}
R.id.menu_top -> {
true
}
else -> {
false
}
}
}
popupMenu.show()
}
iv_edit_source.onClick { callBack?.edit(bookSource) }
iv_top_source.onClick { }
iv_del_source.onClick { callBack?.del(bookSource) }
}
}

@ -50,7 +50,11 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
R.id.action_import_book_source_qr -> {
context?.startActivity<QrCodeActivity>()
}
R.id.action_select_all -> adapter.selectAll()
R.id.action_select_all -> {
launch {
}
}
}
}
@ -92,7 +96,6 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
override fun onQueryTextChange(newText: String?): Boolean {
newText?.let {
adapter.clearSelect()
initDataObserve("%$it%")
}
return false

@ -18,19 +18,40 @@
android:text=""
android:textColor="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/sw_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit_source"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:contentDescription="@string/edit"
android:padding="8dp"
android:src="@drawable/ic_edit"
app:tint="@color/tv_text_default" />
<ImageView
android:id="@+id/iv_more"
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/iv_top_source"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:layout_margin="6dp"
android:contentDescription="@string/to_top"
android:src="@drawable/ic_more_vert"
android:padding="8dp"
android:src="@drawable/ic_top_source"
app:tint="@color/tv_text_default" />
<ImageView
android:id="@+id/iv_del_source"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:contentDescription="@string/delete"
android:padding="8dp"
android:src="@drawable/ic_clear_all"
app:tint="@color/tv_text_default" />
</LinearLayout>
Loading…
Cancel
Save