pull/1440/head
gedoor 3 years ago
parent 2e19bf6978
commit fa98d8c5bb
  1. 22
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  2. 19
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt
  3. 3
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  4. 19
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt

@ -20,22 +20,20 @@ class ChangeSourceAdapter(
context: Context, context: Context,
val viewModel: ChangeSourceViewModel, val viewModel: ChangeSourceViewModel,
val callBack: CallBack val callBack: CallBack
) : ) : DiffRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) {
DiffRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) {
override val diffItemCallback: DiffUtil.ItemCallback<SearchBook> override val diffItemCallback = object : DiffUtil.ItemCallback<SearchBook>() {
get() = object : DiffUtil.ItemCallback<SearchBook>() { override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean {
override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { return oldItem.bookUrl == newItem.bookUrl
return oldItem.bookUrl == newItem.bookUrl }
}
override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean {
return oldItem.originName == newItem.originName
&& oldItem.getDisplayLastChapterTitle() == newItem.getDisplayLastChapterTitle()
}
override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean {
return oldItem.originName == newItem.originName
&& oldItem.getDisplayLastChapterTitle() == newItem.getDisplayLastChapterTitle()
} }
}
override fun getViewBinding(parent: ViewGroup): ItemChangeSourceBinding { override fun getViewBinding(parent: ViewGroup): ItemChangeSourceBinding {
return ItemChangeSourceBinding.inflate(inflater, parent, false) return ItemChangeSourceBinding.inflate(inflater, parent, false)
} }

@ -11,18 +11,17 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
val callBack: CallBack val callBack: CallBack
) : RecyclerView.Adapter<VH>() { ) : RecyclerView.Adapter<VH>() {
val diffItemCallback: DiffUtil.ItemCallback<Book> val diffItemCallback = object : DiffUtil.ItemCallback<Book>() {
get() = object : DiffUtil.ItemCallback<Book>() {
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean {
return oldItem.name == newItem.name return oldItem.name == newItem.name
&& oldItem.author == newItem.author && oldItem.author == newItem.author
} }
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean { override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean {
return when { return when {
oldItem.durChapterTime != newItem.durChapterTime -> false oldItem.durChapterTime != newItem.durChapterTime -> false
oldItem.name != newItem.name -> false oldItem.name != newItem.name -> false
oldItem.author != newItem.author -> false oldItem.author != newItem.author -> false
oldItem.durChapterTitle != newItem.durChapterTitle -> false oldItem.durChapterTitle != newItem.durChapterTitle -> false
oldItem.latestChapterTitle != newItem.latestChapterTitle -> false oldItem.latestChapterTitle != newItem.latestChapterTitle -> false

@ -40,6 +40,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
private val searchView: SearchView by lazy { private val searchView: SearchView by lazy {
binding.titleBar.findViewById(R.id.search_view) binding.titleBar.findViewById(R.id.search_view)
} }
private val diffItemCallBack = ExploreDiffItemCallBack()
private val groups = linkedSetOf<String>() private val groups = linkedSetOf<String>()
private var exploreFlowJob: Job? = null private var exploreFlowJob: Job? = null
private var groupsMenu: SubMenu? = null private var groupsMenu: SubMenu? = null
@ -127,7 +128,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
} }
exploreFlow.collect { exploreFlow.collect {
binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty() binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty()
adapter.setItems(it, ExploreDiffItemCallBack()) adapter.setItems(it, diffItemCallBack)
} }
} }
} }

@ -36,18 +36,17 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
return selection.sortedBy { it.customOrder } return selection.sortedBy { it.customOrder }
} }
val diffItemCallback: DiffUtil.ItemCallback<RssSource> val diffItemCallback = object : DiffUtil.ItemCallback<RssSource>() {
get() = object : DiffUtil.ItemCallback<RssSource>() {
override fun areItemsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { override fun areItemsTheSame(oldItem: RssSource, newItem: RssSource): Boolean {
return oldItem.sourceUrl == newItem.sourceUrl return oldItem.sourceUrl == newItem.sourceUrl
} }
override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean {
return oldItem.sourceName == newItem.sourceName return oldItem.sourceName == newItem.sourceName
&& oldItem.sourceGroup == newItem.sourceGroup && oldItem.sourceGroup == newItem.sourceGroup
&& oldItem.enabled == newItem.enabled && oldItem.enabled == newItem.enabled
} }
override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? { override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? {
val payload = Bundle() val payload = Bundle()

Loading…
Cancel
Save