From a32834f4842a46251e2023399a616c9c515f6f5f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Feb 2020 09:51:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceAdapter.kt | 32 ++++++---- .../ui/rss/source/manage/RssSourceAdapter.kt | 58 ++++++++++++------- 2 files changed, 60 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 6e66704b8..343b8a7d5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -68,20 +68,32 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) } swt_enabled.isChecked = item.enabled - swt_enabled.onClick { - item.enabled = swt_enabled.isChecked - callBack.update(item) + swt_enabled.setOnCheckedChangeListener { view, checked -> + getItem(holder.layoutPosition)?.let { + if (view.isPressed) { + it.enabled = checked + callBack.update(it) + } + } } cb_book_source.isChecked = selected.contains(item) - cb_book_source.setOnClickListener { - if (cb_book_source.isChecked) { - selected.add(item) - } else { - selected.remove(item) + cb_book_source.setOnCheckedChangeListener { view, checked -> + getItem(holder.layoutPosition)?.let { + if (view.isPressed) { + if (checked) { + selected.add(it) + } else { + selected.remove(it) + } + callBack.upCountView() + } + } + } + iv_edit.onClick { + getItem(holder.layoutPosition)?.let { + callBack.edit(it) } - callBack.upCountView() } - iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { showMenu(iv_menu_more, getItem(holder.layoutPosition)) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index e388ffbc1..11beabe5c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.rss.source.manage import android.content.Context +import android.view.View import android.widget.PopupMenu import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -60,31 +61,34 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : String.format("%s (%s)", item.sourceName, item.sourceGroup) } swt_enabled.isChecked = item.enabled - swt_enabled.onClick { - item.enabled = swt_enabled.isChecked - callBack.update(item) + swt_enabled.setOnCheckedChangeListener { view, checked -> + getItem(holder.layoutPosition)?.let { + if (view.isPressed) { + it.enabled = checked + callBack.update(it) + } + } } cb_source.isChecked = selected.contains(item) - cb_source.setOnClickListener { - if (cb_source.isChecked) { - selected.add(item) - } else { - selected.remove(item) + cb_source.setOnCheckedChangeListener { view, checked -> + getItem(holder.layoutPosition)?.let { + if (view.isPressed) { + if (checked) { + selected.add(it) + } else { + selected.remove(it) + } + callBack.upCountView() + } } - callBack.upCountView() } - iv_edit.onClick { callBack.edit(item) } - iv_menu_more.onClick { - val popupMenu = PopupMenu(context, it) - popupMenu.inflate(R.menu.rss_source_item) - popupMenu.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.menu_top -> callBack.toTop(item) - R.id.menu_del -> callBack.del(item) - } - true + iv_edit.onClick { + getItem(holder.layoutPosition)?.let { + callBack.edit(it) } - popupMenu.show() + } + iv_menu_more.onClick { + showMenu(iv_menu_more, getItem(holder.layoutPosition)) } } else { when (payloads[0]) { @@ -95,6 +99,20 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } + private fun showMenu(view: View, source: RssSource?) { + if (source == null) return + val popupMenu = PopupMenu(context, view) + popupMenu.inflate(R.menu.rss_source_item) + popupMenu.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.menu_top -> callBack.toTop(source) + R.id.menu_del -> callBack.del(source) + } + true + } + popupMenu.show() + } + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition)