From c3e7e3af6f00c1e86bf331f7bb173098c3246c65 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 16 Feb 2020 13:31:51 +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 --- .../legado/app/base/adapter/CommonRecyclerAdapter.kt | 2 +- .../io/legado/app/base/adapter/ItemViewDelegate.kt | 2 +- .../legado/app/base/adapter/SimpleRecyclerAdapter.kt | 6 +++--- .../legado/app/ui/book/arrange/ArrangeBookAdapter.kt | 10 +++++----- .../io/legado/app/ui/book/group/GroupManageDialog.kt | 6 +++--- .../io/legado/app/ui/book/group/GroupSelectDialog.kt | 6 +++--- .../io/legado/app/ui/book/info/ChapterListAdapter.kt | 4 ++-- .../app/ui/book/read/config/BgTextConfigDialog.kt | 4 ++-- .../java/io/legado/app/ui/book/search/BookAdapter.kt | 4 ++-- .../io/legado/app/ui/book/search/HistoryKeyAdapter.kt | 6 +++--- .../java/io/legado/app/ui/book/search/SearchAdapter.kt | 4 ++-- .../app/ui/book/source/debug/BookSourceDebugAdapter.kt | 2 +- .../app/ui/book/source/manage/BookSourceAdapter.kt | 10 +++++----- .../app/ui/book/source/manage/GroupManageDialog.kt | 8 +++++--- .../java/io/legado/app/ui/changecover/CoverAdapter.kt | 4 ++-- .../legado/app/ui/changesource/ChangeSourceAdapter.kt | 4 ++-- .../io/legado/app/ui/chapterlist/ChapterListAdapter.kt | 4 ++-- .../java/io/legado/app/ui/download/DownloadAdapter.kt | 2 +- .../io/legado/app/ui/explore/ExploreShowAdapter.kt | 4 ++-- .../legado/app/ui/filechooser/adapter/FileAdapter.kt | 4 ++-- .../legado/app/ui/filechooser/adapter/PathAdapter.kt | 4 ++-- .../io/legado/app/ui/importbook/ImportBookAdapter.kt | 6 +++--- .../app/ui/main/bookshelf/books/BooksAdapterGrid.kt | 6 +++--- .../app/ui/main/bookshelf/books/BooksAdapterList.kt | 6 +++--- .../io/legado/app/ui/main/explore/ExploreAdapter.kt | 10 +++++----- .../main/java/io/legado/app/ui/main/rss/RssAdapter.kt | 4 ++-- .../io/legado/app/ui/replacerule/GroupManageDialog.kt | 8 +++++--- .../io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt | 8 ++++---- .../io/legado/app/ui/rss/article/RssArticlesAdapter.kt | 4 ++-- .../legado/app/ui/rss/favorites/RssFavoritesAdapter.kt | 4 ++-- .../app/ui/rss/source/debug/RssSourceDebugAdapter.kt | 2 +- .../app/ui/rss/source/manage/GroupManageDialog.kt | 6 +++--- .../app/ui/rss/source/manage/RssSourceAdapter.kt | 2 +- .../java/io/legado/app/ui/widget/KeyboardToolPop.kt | 4 ++-- .../java/io/legado/app/ui/widget/font/FontAdapter.kt | 4 ++-- .../legado/app/ui/widget/prefs/IconListPreference.kt | 4 ++-- 36 files changed, 91 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt index 5560c4cbd..a638b87f6 100644 --- a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt @@ -376,7 +376,7 @@ abstract class CommonRecyclerAdapter(protected val context: Context) : } if (payloads.isEmpty()) { itemDelegates.getValue(getItemViewType(holder.layoutPosition)) - .registerListener(holder, position) + .registerListener(holder) } } } diff --git a/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt b/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt index aefe1f3d8..866a53b6f 100644 --- a/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt +++ b/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt @@ -20,6 +20,6 @@ abstract class ItemViewDelegate(protected val context: Context, val layout /** * 注册事件 */ - abstract fun registerListener(holder: ItemViewHolder, position: Int) + abstract fun registerListener(holder: ItemViewHolder) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt index 47289b477..81c831ff4 100644 --- a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt @@ -15,8 +15,8 @@ abstract class SimpleRecyclerAdapter(context: Context, private val layoutI this@SimpleRecyclerAdapter.convert(holder, item, payloads) } - override fun registerListener(holder: ItemViewHolder, position: Int) { - this@SimpleRecyclerAdapter.registerListener(holder, position) + override fun registerListener(holder: ItemViewHolder) { + this@SimpleRecyclerAdapter.registerListener(holder) } }) } @@ -30,5 +30,5 @@ abstract class SimpleRecyclerAdapter(context: Context, private val layoutI /** * 注册事件 */ - abstract fun registerListener(holder: ItemViewHolder, position: Int) + abstract fun registerListener(holder: ItemViewHolder) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 1c8457073..66eff5706 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -52,10 +52,10 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { checkbox.setOnCheckedChangeListener { buttonView, isChecked -> - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (buttonView.isPressed) { if (isChecked) { selectedBooks.add(it) @@ -68,7 +68,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } } onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { checkbox.isChecked = !checkbox.isChecked if (checkbox.isChecked) { selectedBooks.add(it) @@ -79,12 +79,12 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } } tv_delete.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.deleteBook(it) } } tv_group.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { actionItem = it callBack.selectGroup(it.group, groupRequestCode) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 3c321f14e..e982cbbe0 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -186,10 +186,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { - tv_edit.onClick { getItem(position)?.let { editGroup(it) } } - tv_del.onClick { getItem(position)?.let { viewModel.delGroup(it) } } + tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } + tv_del.onClick { getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 7a39980fb..2d90a82e2 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -179,10 +179,10 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { cb_group.setOnCheckedChangeListener { buttonView, isChecked -> - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (buttonView.isPressed) { groupId = if (isChecked) { groupId + it.groupId @@ -192,7 +192,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } } - tv_edit.onClick { getItem(position)?.let { editGroup(it) } } + tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt index f37410765..4af4e96fa 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt @@ -25,10 +25,10 @@ class ChapterListAdapter(context: Context, var callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { this.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.openChapter(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 04abaa4a7..2ad61a9b5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -152,10 +152,10 @@ class BgTextConfigDialog : DialogFragment() { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { this.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { ReadBookConfig.getConfig().setBg(1, it) ReadBookConfig.upBg() postEvent(EventBus.UP_CONFIG, false) diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index 1e835d3a5..070837520 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -17,10 +17,10 @@ class BookAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 2a27aa695..cfe7699a8 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -25,10 +25,10 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.searchHistory(it.word) } } @@ -36,7 +36,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : it?.let { explosionField.explode(it, true) } - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { GlobalScope.launch(IO) { App.db.searchKeywordDao().delete(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 348a583ae..fbdcb99cf 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -26,10 +26,10 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it.name, it.author) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt index 77e496191..718b0a231 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt @@ -27,7 +27,7 @@ class BookSourceDebugAdapter(context: Context) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { //nothing } } \ No newline at end of file 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 78adb2ad2..5d5872638 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 @@ -88,10 +88,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { swt_enabled.setOnCheckedChangeListener { view, checked -> - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (view.isPressed) { it.enabled = checked callBack.update(it) @@ -99,7 +99,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } cb_book_source.setOnCheckedChangeListener { view, checked -> - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (view.isPressed) { if (checked) { selected.add(it) @@ -111,12 +111,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } iv_edit.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.edit(it) } } iv_menu_more.onClick { - showMenu(iv_menu_more, position) + showMenu(iv_menu_more, holder.layoutPosition) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 265afced0..314b45d08 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -128,14 +128,16 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { tv_edit.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { editGroup(it) } } - tv_del.onClick { getItem(position)?.let { viewModel.delGroup(it) } } + tv_del.onClick { + getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 9d4864f41..eae791b2c 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -18,10 +18,10 @@ class CoverAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.changeTo(it.coverUrl ?: "") } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt index 0f0b67f86..1fa9284c1 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt @@ -37,9 +37,9 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.changeTo(it) } } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt index da18ff7a7..08b222970 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt @@ -45,9 +45,9 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callback.openChapter(it) } } diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt index 7f3ddeab8..2015c614a 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt @@ -34,7 +34,7 @@ class DownloadAdapter(context: Context) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.tv_export.onClick { } diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt index 7bf4ef06c..2204dae03 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt @@ -38,9 +38,9 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it.toBook()) } } diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt index d40d43368..4ade6da7f 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt @@ -113,9 +113,9 @@ class FileAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - callBack.onFileClick(position) + callBack.onFileClick(holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt index 1697b8a45..3d2323495 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt @@ -53,9 +53,9 @@ class PathAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - callBack.onPathClick(position) + callBack.onPathClick(holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index a3e9ccee1..2f4c317e5 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -101,9 +101,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (it.isDir) { callBack.nextDoc(DocumentFile.fromSingleUri(context, it.uri)!!) } else if (!bookshelf.contains(it.uri.toString())) { @@ -115,7 +115,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : callBack.upCountView() } } - notifyItemChanged(position, true) + notifyItemChanged(holder.layoutPosition, true) callBack.upCountView() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index fa031ae8a..d647afd3b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -51,16 +51,16 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.open(it) } } onLongClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } true diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index 2b4af6b7d..f4faaa5c1 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -55,16 +55,16 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.open(it) } } onLongClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } true diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index a1bce6b2b..9bd403e33 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -68,19 +68,19 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { ll_title.onClick { val oldEx = exIndex - exIndex = if (exIndex == position) -1 else position + exIndex = if (exIndex == holder.layoutPosition) -1 else holder.layoutPosition notifyItemChanged(oldEx, false) if (exIndex != -1) { - notifyItemChanged(position, false) + notifyItemChanged(holder.layoutPosition, false) } - callBack.scrollTo(position) + callBack.scrollTo(holder.layoutPosition) } ll_title.onLongClick { - showMenu(ll_title, position) + showMenu(ll_title, holder.layoutPosition) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index 38a6b5509..d58f7587e 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -23,9 +23,9 @@ class RssAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.openRss(it) } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index ca7322ba4..6f9a61f4c 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -128,15 +128,17 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { tv_edit.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { editGroup(it) } } - tv_del.onClick { getItem(position)?.let { viewModel.delGroup(it) } } + tv_del.onClick { + getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index 1c911b5f5..dd51d31d0 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -84,21 +84,21 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { swt_enabled.setOnCheckedChangeListener { _, isChecked -> - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { it.isEnabled = isChecked callBack.update(it) } } iv_edit.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.edit(it) } } cb_name.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { if (cb_name.isChecked) { selected.add(it) } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index b26291b02..00b296359 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -62,9 +62,9 @@ class RssArticlesAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.readRss(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt index 8263571cf..6077d5db9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt @@ -55,9 +55,9 @@ class RssFavoritesAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.readRss(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt index 95001a035..3d5262db4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt @@ -27,7 +27,7 @@ class RssSourceDebugAdapter(context: Context) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { //nothing } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 3b7500fad..1ba2a567b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -128,16 +128,16 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { tv_edit.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { editGroup(it) } } tv_del.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } } 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 9ef43925f..165d9bd0c 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 @@ -71,7 +71,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { swt_enabled.setOnCheckedChangeListener { view, checked -> getItem(holder.layoutPosition)?.let { diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index ce47e007d..01d36ca4a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -48,10 +48,10 @@ class KeyboardToolPop( } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack?.sendText(it) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index e376277cc..f7c73030a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -28,9 +28,9 @@ class FontAdapter(context: Context, val callBack: CallBack) : } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { callBack.onClick(it) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index 292a02fbd..ecad8d5c1 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -175,9 +175,9 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference } } - override fun registerListener(holder: ItemViewHolder, position: Int) { + override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { - getItem(position)?.let { + getItem(holder.layoutPosition)?.let { onChanged?.invoke(it.toString()) } }