From f6ad6b02424a3d0af967317eceb6bd27075b2640 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 8 Sep 2019 14:01:07 +0800 Subject: [PATCH] up --- .../app/ui/booksource/BookSourceAdapter.kt | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt index ac683d367..8152ba18a 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt @@ -68,41 +68,47 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList) { with(holder.itemView) { - this.setBackgroundColor(context.backgroundColor) - if (item.bookSourceGroup.isNullOrEmpty()) { - cb_book_source.text = item.bookSourceName - } else { - cb_book_source.text = - String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) - } - swt_enabled.isChecked = item.enabled - swt_enabled.onClick { - item.enabled = swt_enabled.isChecked - callBack.update(item) - } - cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) - cb_book_source.setOnClickListener { - if (cb_book_source.isChecked) { - selectedIds.add(item.bookSourceUrl) + if (payloads.isEmpty()) { + this.setBackgroundColor(context.backgroundColor) + if (item.bookSourceGroup.isNullOrEmpty()) { + cb_book_source.text = item.bookSourceName } else { - selectedIds.remove(item.bookSourceUrl) + cb_book_source.text = + String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) } - } - 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) + swt_enabled.isChecked = item.enabled + swt_enabled.onClick { + item.enabled = swt_enabled.isChecked + callBack.update(item) + } + cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) + cb_book_source.setOnClickListener { + if (cb_book_source.isChecked) { + selectedIds.add(item.bookSourceUrl) + } else { + selectedIds.remove(item.bookSourceUrl) } - true } - popupMenu.show() + 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() + } + } else { + when (payloads[0]) { + 1 -> cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) + 2 -> swt_enabled.isChecked = item.enabled + } } - } }