feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 8f8fc54d77
commit c3e7e3af6f
  1. 2
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt
  3. 6
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  5. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  6. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  9. 4
      app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt
  10. 6
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  12. 2
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt
  13. 10
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  14. 8
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  15. 4
      app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt
  16. 4
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt
  17. 4
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt
  18. 2
      app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt
  19. 4
      app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt
  20. 4
      app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt
  21. 4
      app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt
  22. 6
      app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt
  23. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  24. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  25. 10
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  26. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  27. 8
      app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt
  28. 8
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  29. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt
  30. 4
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt
  31. 2
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt
  32. 6
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  33. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  34. 4
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt
  35. 4
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt
  36. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt

@ -376,7 +376,7 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) :
}
if (payloads.isEmpty()) {
itemDelegates.getValue(getItemViewType(holder.layoutPosition))
.registerListener(holder, position)
.registerListener(holder)
}
}
}

@ -20,6 +20,6 @@ abstract class ItemViewDelegate<ITEM>(protected val context: Context, val layout
/**
* 注册事件
*/
abstract fun registerListener(holder: ItemViewHolder, position: Int)
abstract fun registerListener(holder: ItemViewHolder)
}

@ -15,8 +15,8 @@ abstract class SimpleRecyclerAdapter<ITEM>(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<ITEM>(context: Context, private val layoutI
/**
* 注册事件
*/
abstract fun registerListener(holder: ItemViewHolder, position: Int)
abstract fun registerListener(holder: ItemViewHolder)
}

@ -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)
}

@ -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) } }
}
}

@ -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) } }
}
}

@ -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)
}
}

@ -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)

@ -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)
}
}

@ -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)
}

@ -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)
}
}

@ -27,7 +27,7 @@ class BookSourceDebugAdapter(context: Context) :
}
}
override fun registerListener(holder: ItemViewHolder, position: Int) {
override fun registerListener(holder: ItemViewHolder) {
//nothing
}
}

@ -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)
}
}
}

@ -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) }
}
}
}
}

@ -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 ?: "")
}
}

@ -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)
}
}

@ -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)
}
}

@ -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 {
}

@ -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())
}
}

@ -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)
}
}

@ -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)
}
}

@ -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()
}
}

@ -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

@ -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

@ -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)
}
}
}

@ -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)
}
}

@ -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) }
}
}
}
}

@ -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 {

@ -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)
}
}

@ -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)
}
}

@ -27,7 +27,7 @@ class RssSourceDebugAdapter(context: Context) :
}
}
override fun registerListener(holder: ItemViewHolder, position: Int) {
override fun registerListener(holder: ItemViewHolder) {
//nothing
}
}

@ -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)
}
}

@ -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 {

@ -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)
}
}

@ -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)
}
}

@ -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())
}
}

Loading…
Cancel
Save