viewBinding

pull/517/head
gedoor 4 years ago
parent 8a57fe3b28
commit da5622d298
  1. 2
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 13
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  3. 5
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  5. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  6. 69
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  7. 5
      app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt
  8. 5
      app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt
  9. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  10. 5
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  12. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  13. 5
      app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt
  14. 113
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  15. 4
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  16. 5
      app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt
  17. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  18. 4
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  19. 4
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  20. 5
      app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt
  21. 5
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  22. 5
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  23. 5
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  24. 5
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt
  25. 61
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  26. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  27. 5
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt
  28. 4
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  29. 5
      app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt
  30. 5
      app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt
  31. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  32. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  33. 5
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  34. 5
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  35. 4
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  36. 5
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  37. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt
  38. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt
  39. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt
  40. 5
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt
  41. 6
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt
  42. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  43. 61
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  44. 4
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt
  45. 4
      app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt
  46. 5
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt
  47. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt

@ -35,12 +35,12 @@ abstract class BaseActivity<VB : ViewBinding>(
) : AppCompatActivity(),
CoroutineScope by MainScope() {
@Suppress("UNCHECKED_CAST")
protected val binding: VB by lazy {
//使用反射得到viewBinding的class
val type = javaClass.genericSuperclass as ParameterizedType
val aClass = type.actualTypeArguments[0] as Class<*>
val method = aClass.getDeclaredMethod("inflate", LayoutInflater::class.java)
@Suppress("UNCHECKED_CAST")
method.invoke(null, layoutInflater) as VB
}

@ -8,7 +8,6 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import java.lang.reflect.ParameterizedType
import java.util.*
/**
@ -313,8 +312,7 @@ abstract class CommonRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
else -> {
//使用反射得到viewBinding的class
val holder = ItemViewHolder(getViewBinding(parent, viewType))
val holder = ItemViewHolder(getViewBinding(parent))
@Suppress("UNCHECKED_CAST")
itemDelegates.getValue(viewType)
@ -340,14 +338,7 @@ abstract class CommonRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
}
private fun getViewBinding(parent: ViewGroup, viewType: Int): ViewBinding {
//使用反射得到viewBinding的class
val type = javaClass.genericSuperclass as ParameterizedType
val aClass = type.actualTypeArguments[0] as Class<*>
val method = aClass.getDeclaredMethod("inflate", LayoutInflater::class.java)
@Suppress("UNCHECKED_CAST")
return method.invoke(null, inflater, parent, false) as VB
}
protected abstract fun getViewBinding(parent: ViewGroup): VB
final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {}

@ -2,6 +2,7 @@ package io.legado.app.ui.about
import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
@ -57,6 +58,10 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
inner class RecordAdapter(context: Context) :
SimpleRecyclerAdapter<ReadRecordShow, ItemReadRecordBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemReadRecordBinding {
return ItemReadRecordBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemReadRecordBinding,

@ -132,6 +132,10 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
inner class SourcesAdapter(context: Context) :
SimpleRecyclerAdapter<BookSource, ItemSourceImportBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemSourceImportBinding {
return ItemSourceImportBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemSourceImportBinding,

@ -132,6 +132,10 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
inner class SourcesAdapter(context: Context) :
SimpleRecyclerAdapter<RssSource, ItemSourceImportBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemSourceImportBinding {
return ItemSourceImportBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemSourceImportBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.book.arrange
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.base.adapter.ItemViewHolder
@ -23,38 +24,8 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
private val selectedBooks: HashSet<Book> = hashSetOf()
var actionItem: Book? = null
fun selectAll(selectAll: Boolean) {
if (selectAll) {
getItems().forEach {
selectedBooks.add(it)
}
} else {
selectedBooks.clear()
}
notifyDataSetChanged()
callBack.upSelectCount()
}
fun revertSelection() {
getItems().forEach {
if (selectedBooks.contains(it)) {
selectedBooks.remove(it)
} else {
selectedBooks.add(it)
}
}
notifyDataSetChanged()
callBack.upSelectCount()
}
fun selectedBooks(): Array<Book> {
val books = arrayListOf<Book>()
selectedBooks.forEach {
if (getItems().contains(it)) {
books.add(it)
}
}
return books.toTypedArray()
override fun getViewBinding(parent: ViewGroup): ItemArrangeBookBinding {
return ItemArrangeBookBinding.inflate(inflater, parent, false)
}
override fun convert(
@ -113,6 +84,40 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
}
}
fun selectAll(selectAll: Boolean) {
if (selectAll) {
getItems().forEach {
selectedBooks.add(it)
}
} else {
selectedBooks.clear()
}
notifyDataSetChanged()
callBack.upSelectCount()
}
fun revertSelection() {
getItems().forEach {
if (selectedBooks.contains(it)) {
selectedBooks.remove(it)
} else {
selectedBooks.add(it)
}
}
notifyDataSetChanged()
callBack.upSelectCount()
}
fun selectedBooks(): Array<Book> {
val books = arrayListOf<Book>()
selectedBooks.forEach {
if (getItems().contains(it)) {
books.add(it)
}
}
return books.toTypedArray()
}
private fun getGroupList(groupId: Long): List<String> {
val groupNames = arrayListOf<String>()
callBack.groupList.forEach {

@ -1,6 +1,7 @@
package io.legado.app.ui.book.cache
import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
@ -20,6 +21,10 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
val cacheChapters = hashMapOf<String, HashSet<String>>()
var downloadMap: ConcurrentHashMap<String, CopyOnWriteArraySet<BookChapter>>? = null
override fun getViewBinding(parent: ViewGroup): ItemDownloadBinding {
return ItemDownloadBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemDownloadBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.changecover
import android.content.Context
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook
@ -10,6 +11,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class CoverAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchBook, ItemCoverBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemCoverBinding {
return ItemCoverBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemCoverBinding,

@ -3,6 +3,7 @@ package io.legado.app.ui.book.changesource
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
@ -18,6 +19,10 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemChangeSourceBinding {
return ItemChangeSourceBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemChangeSourceBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.explore
import android.content.Context
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -14,6 +15,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class ExploreShowAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchBook, ItemSearchBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemSearchBinding {
return ItemSearchBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemSearchBinding,

@ -178,6 +178,10 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private var isMoved = false
override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding {
return ItemGroupManageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupManageBinding,

@ -162,6 +162,10 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private var isMoved: Boolean = false
override fun getViewBinding(parent: ViewGroup): ItemGroupSelectBinding {
return ItemGroupSelectBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupSelectBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.info
import android.content.Context
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -13,6 +14,10 @@ import org.jetbrains.anko.textColorResource
class ChapterListAdapter(context: Context, var callBack: CallBack) :
SimpleRecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding {
return ItemChapterListBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemChapterListBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.book.local
import android.content.Context
import android.net.Uri
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -17,6 +18,64 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
var checkableCount = 0
private var bookFileNames = arrayListOf<String>()
override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
return ItemImportBookBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemImportBookBinding,
item: DocItem,
payloads: MutableList<Any>
) {
with(binding) {
if (payloads.isEmpty()) {
if (item.isDir) {
ivIcon.setImageResource(R.drawable.ic_folder)
ivIcon.visible()
cbSelect.invisible()
llBrief.gone()
cbSelect.isChecked = false
} else {
if (bookFileNames.contains(item.name)) {
ivIcon.setImageResource(R.drawable.ic_book_has)
ivIcon.visible()
cbSelect.invisible()
} else {
ivIcon.invisible()
cbSelect.visible()
}
llBrief.visible()
tvTag.text = item.name.substringAfterLast(".")
tvSize.text = StringUtils.toSize(item.size)
tvDate.text = AppConst.dateFormat.format(item.date)
cbSelect.isChecked = selectedUris.contains(item.uri.toString())
}
tvName.text = item.name
} else {
cbSelect.isChecked = selectedUris.contains(item.uri.toString())
}
}
}
override fun registerListener(holder: ItemViewHolder, binding: ItemImportBookBinding) {
holder.itemView.onClick {
getItem(holder.layoutPosition)?.let {
if (it.isDir) {
callBack.nextDoc(it.uri)
} else if (!bookFileNames.contains(it.name)) {
if (!selectedUris.contains(it.uri.toString())) {
selectedUris.add(it.uri.toString())
} else {
selectedUris.remove(it.uri.toString())
}
notifyItemChanged(holder.layoutPosition, true)
callBack.upCountView()
}
}
}
}
fun upBookHas(bookUrls: List<String>) {
bookFileNames.clear()
bookUrls.forEach {
@ -77,60 +136,6 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
}
}
override fun convert(
holder: ItemViewHolder,
binding: ItemImportBookBinding,
item: DocItem,
payloads: MutableList<Any>
) {
with(binding) {
if (payloads.isEmpty()) {
if (item.isDir) {
ivIcon.setImageResource(R.drawable.ic_folder)
ivIcon.visible()
cbSelect.invisible()
llBrief.gone()
cbSelect.isChecked = false
} else {
if (bookFileNames.contains(item.name)) {
ivIcon.setImageResource(R.drawable.ic_book_has)
ivIcon.visible()
cbSelect.invisible()
} else {
ivIcon.invisible()
cbSelect.visible()
}
llBrief.visible()
tvTag.text = item.name.substringAfterLast(".")
tvSize.text = StringUtils.toSize(item.size)
tvDate.text = AppConst.dateFormat.format(item.date)
cbSelect.isChecked = selectedUris.contains(item.uri.toString())
}
tvName.text = item.name
} else {
cbSelect.isChecked = selectedUris.contains(item.uri.toString())
}
}
}
override fun registerListener(holder: ItemViewHolder, binding: ItemImportBookBinding) {
holder.itemView.onClick {
getItem(holder.layoutPosition)?.let {
if (it.isDir) {
callBack.nextDoc(it.uri)
} else if (!bookFileNames.contains(it.name)) {
if (!selectedUris.contains(it.uri.toString())) {
selectedUris.add(it.uri.toString())
} else {
selectedUris.remove(it.uri.toString())
}
notifyItemChanged(holder.layoutPosition, true)
callBack.upCountView()
}
}
}
}
interface CallBack {
fun nextDoc(uri: Uri)
fun upCountView()

@ -89,6 +89,10 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<MenuItemImpl, ItemTextBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
return ItemTextBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemTextBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.read.config
import android.content.Context
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.EventBus
@ -14,6 +15,10 @@ import java.io.File
class BgAdapter(context: Context, val textColor: Int) :
SimpleRecyclerAdapter<String, ItemBgImageBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemBgImageBinding {
return ItemBgImageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemBgImageBinding,

@ -208,6 +208,10 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
inner class StyleAdapter :
SimpleRecyclerAdapter<ReadBookConfig.Config, ItemReadStyleBinding>(requireContext()) {
override fun getViewBinding(parent: ViewGroup): ItemReadStyleBinding {
return ItemReadStyleBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemReadStyleBinding,

@ -131,6 +131,10 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<HttpTTS, ItemHttpTtsBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemHttpTtsBinding {
return ItemHttpTtsBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemHttpTtsBinding,

@ -192,6 +192,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
SimpleRecyclerAdapter<TxtTocRule, ItemTocRegexBinding>(context),
ItemTouchCallback.Callback {
override fun getViewBinding(parent: ViewGroup): ItemTocRegexBinding {
return ItemTocRegexBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemTocRegexBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.search
import android.content.Context
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book
@ -10,6 +11,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class BookAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<Book, ItemFilletTextBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFilletTextBinding,

@ -1,5 +1,6 @@
package io.legado.app.ui.book.search
import android.view.ViewGroup
import io.legado.app.App
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -18,6 +19,10 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
private val explosionField = ExplosionField.attach2Window(activity)
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFilletTextBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.book.search
import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -14,6 +15,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchBook, ItemSearchBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemSearchBinding {
return ItemSearchBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemSearchBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.searchContent
import android.content.Context
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -17,6 +18,10 @@ class SearchContentAdapter(context: Context, val callback: Callback) :
val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2)
val accentColor = context.accentColor.hexString.substring(2)
override fun getViewBinding(parent: ViewGroup): ItemSearchListBinding {
return ItemSearchListBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemSearchListBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.book.source.debug
import android.content.Context
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -10,6 +11,10 @@ import io.legado.app.databinding.ItemLogBinding
class BookSourceDebugAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemLogBinding {
return ItemLogBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemLogBinding,

@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.PopupMenu
import androidx.core.os.bundleOf
@ -27,34 +28,8 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
private val selected = linkedSetOf<BookSource>()
fun selectAll() {
getItems().forEach {
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun revertSelection() {
getItems().forEach {
if (selected.contains(it)) {
selected.remove(it)
} else {
selected.add(it)
}
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun getSelection(): List<BookSource> {
val selection = arrayListOf<BookSource>()
getItems().map {
if (selected.contains(it)) {
selection.add(it)
}
}
return selection.sortedBy { it.customOrder }
override fun getViewBinding(parent: ViewGroup): ItemBookSourceBinding {
return ItemBookSourceBinding.inflate(inflater, parent, false)
}
override fun convert(
@ -171,6 +146,36 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
}
fun selectAll() {
getItems().forEach {
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun revertSelection() {
getItems().forEach {
if (selected.contains(it)) {
selected.remove(it)
} else {
selected.add(it)
}
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun getSelection(): List<BookSource> {
val selection = arrayListOf<BookSource>()
getItems().map {
if (selected.contains(it)) {
selection.add(it)
}
}
return selection.sortedBy { it.customOrder }
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
val srcItem = getItem(srcPosition)
val targetItem = getItem(targetPosition)

@ -111,6 +111,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private inner class GroupAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemGroupManageBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding {
return ItemGroupManageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupManageBinding,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.toc
import android.content.Context
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -16,6 +17,10 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
val cacheFileNames = hashSetOf<String>()
override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding {
return ItemChapterListBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemChapterListBinding,

@ -98,6 +98,10 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
inner class Adapter :
SimpleRecyclerAdapter<ThemeConfig.Config, ItemThemeConfigBinding>(requireContext()) {
override fun getViewBinding(parent: ViewGroup): ItemThemeConfigBinding {
return ItemThemeConfigBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemThemeConfigBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.filepicker.adapter
import android.content.Context
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemFileFilepickerBinding
@ -85,6 +86,10 @@ class FileAdapter(context: Context, val callBack: CallBack) :
}
override fun getViewBinding(parent: ViewGroup): ItemFileFilepickerBinding {
return ItemFileFilepickerBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFileFilepickerBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.filepicker.adapter
import android.content.Context
import android.os.Environment
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemPathFilepickerBinding
@ -43,6 +44,10 @@ class PathAdapter(context: Context, val callBack: CallBack) :
setItems(paths)
}
override fun getViewBinding(parent: ViewGroup): ItemPathFilepickerBinding {
return ItemPathFilepickerBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemPathFilepickerBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
@ -14,6 +15,10 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfGridBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemBookshelfGridBinding {
return ItemBookshelfGridBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemBookshelfGridBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
@ -14,6 +15,10 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapterList(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfListBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemBookshelfListBinding {
return ItemBookshelfListBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemBookshelfListBinding,

@ -3,6 +3,7 @@ package io.legado.app.ui.main.explore
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import io.legado.app.App
import io.legado.app.R
@ -27,6 +28,10 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
private var exIndex = -1
private var scrollTo = -1
override fun getViewBinding(parent: ViewGroup): ItemFindBookBinding {
return ItemFindBookBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFindBookBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.main.rss
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
@ -15,6 +16,10 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class RssAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssSource, ItemRssBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemRssBinding {
return ItemRssBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemRssBinding,

@ -116,6 +116,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private inner class GroupAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemGroupManageBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding {
return ItemGroupManageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupManageBinding,

@ -3,6 +3,7 @@ package io.legado.app.ui.replace
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
@ -54,6 +55,10 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
return selection
}
override fun getViewBinding(parent: ViewGroup): ItemReplaceRuleBinding {
return ItemReplaceRuleBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemReplaceRuleBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.rss.article
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@ -19,6 +20,10 @@ import org.jetbrains.anko.textColorResource
class RssArticlesAdapter(context: Context, callBack: CallBack) :
BaseRssArticlesAdapter<ItemRssArticleBinding>(context, callBack) {
override fun getViewBinding(parent: ViewGroup): ItemRssArticleBinding {
return ItemRssArticleBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemRssArticleBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.rss.article
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@ -19,6 +20,10 @@ import org.jetbrains.anko.textColorResource
class RssArticlesAdapter1(context: Context, callBack: CallBack) :
BaseRssArticlesAdapter<ItemRssArticle1Binding>(context, callBack) {
override fun getViewBinding(parent: ViewGroup): ItemRssArticle1Binding {
return ItemRssArticle1Binding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemRssArticle1Binding,

@ -2,6 +2,7 @@ package io.legado.app.ui.rss.article
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@ -19,6 +20,10 @@ import org.jetbrains.anko.textColorResource
class RssArticlesAdapter2(context: Context, callBack: CallBack) :
BaseRssArticlesAdapter<ItemRssArticle2Binding>(context, callBack) {
override fun getViewBinding(parent: ViewGroup): ItemRssArticle2Binding {
return ItemRssArticle2Binding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemRssArticle2Binding,

@ -2,6 +2,7 @@ package io.legado.app.ui.rss.favorites
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@ -18,6 +19,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class RssFavoritesAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssStar, ItemRssArticleBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemRssArticleBinding {
return ItemRssArticleBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemRssArticleBinding,

@ -2,6 +2,7 @@ package io.legado.app.ui.rss.source.debug
import android.content.Context
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -9,6 +10,11 @@ import io.legado.app.databinding.ItemLogBinding
class RssSourceDebugAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemLogBinding {
return ItemLogBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemLogBinding,

@ -115,6 +115,10 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private inner class GroupAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemGroupManageBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding {
return ItemGroupManageBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemGroupManageBinding,

@ -3,6 +3,7 @@ package io.legado.app.ui.rss.source.manage
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
@ -23,34 +24,8 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
private val selected = linkedSetOf<RssSource>()
fun selectAll() {
getItems().forEach {
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun revertSelection() {
getItems().forEach {
if (selected.contains(it)) {
selected.remove(it)
} else {
selected.add(it)
}
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun getSelection(): List<RssSource> {
val selection = arrayListOf<RssSource>()
getItems().forEach {
if (selected.contains(it)) {
selection.add(it)
}
}
return selection.sortedBy { it.customOrder }
override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding {
return ItemRssSourceBinding.inflate(inflater, parent, false)
}
override fun convert(
@ -122,6 +97,36 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
}
}
fun selectAll() {
getItems().forEach {
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun revertSelection() {
getItems().forEach {
if (selected.contains(it)) {
selected.remove(it)
} else {
selected.add(it)
}
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun getSelection(): List<RssSource> {
val selection = arrayListOf<RssSource>()
getItems().forEach {
if (selected.contains(it)) {
selection.add(it)
}
}
return selection.sortedBy { it.customOrder }
}
private fun showMenu(view: View, position: Int) {
val source = getItem(position) ?: return
val popupMenu = PopupMenu(context, view)

@ -42,6 +42,10 @@ class KeyboardToolPop(
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<String, ItemFilletTextBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFilletTextBinding,

@ -61,6 +61,10 @@ class TextListDialog : BaseDialogFragment() {
class TextAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemLogBinding {
return ItemLogBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemLogBinding,

@ -3,6 +3,7 @@ package io.legado.app.ui.widget.font
import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemFontBinding
@ -17,6 +18,10 @@ import java.io.File
class FontAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<DocItem, ItemFontBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemFontBinding {
return ItemFontBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemFontBinding,

@ -158,6 +158,10 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<CharSequence, ItemIconPreferenceBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemIconPreferenceBinding {
return ItemIconPreferenceBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemIconPreferenceBinding,

Loading…
Cancel
Save