|
|
@ -4,8 +4,8 @@ import android.content.Context |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.base.adapter.DiffRecyclerAdapter |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter |
|
|
|
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.databinding.ItemChapterListBinding |
|
|
|
import io.legado.app.databinding.ItemChapterListBinding |
|
|
@ -22,21 +22,23 @@ import kotlinx.coroutines.isActive |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
|
|
|
|
|
|
|
|
class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) { |
|
|
|
DiffRecyclerAdapter<BookChapter, ItemChapterListBinding>(context) { |
|
|
|
|
|
|
|
|
|
|
|
val cacheFileNames = hashSetOf<String>() |
|
|
|
val cacheFileNames = hashSetOf<String>() |
|
|
|
val displayTileMap = ConcurrentHashMap<Int, String>() |
|
|
|
val displayTileMap = ConcurrentHashMap<Int, String>() |
|
|
|
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun areItemsTheSame( |
|
|
|
override val diffItemCallback: DiffUtil.ItemCallback<BookChapter> |
|
|
|
oldItem: BookChapter, |
|
|
|
get() = object : DiffUtil.ItemCallback<BookChapter>() { |
|
|
|
newItem: BookChapter |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
override fun areItemsTheSame( |
|
|
|
return oldItem.index == newItem.index |
|
|
|
oldItem: BookChapter, |
|
|
|
} |
|
|
|
newItem: BookChapter |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
|
|
|
|
return oldItem.index == newItem.index |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame( |
|
|
|
override fun areContentsTheSame( |
|
|
|
oldItem: BookChapter, |
|
|
|
oldItem: BookChapter, |
|
|
|
newItem: BookChapter |
|
|
|
newItem: BookChapter |
|
|
|
): Boolean { |
|
|
|
): Boolean { |
|
|
|
return oldItem.bookUrl == newItem.bookUrl |
|
|
|
return oldItem.bookUrl == newItem.bookUrl |
|
|
@ -48,7 +50,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
&& oldItem.isVolume == newItem.isVolume |
|
|
|
&& oldItem.isVolume == newItem.isVolume |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val replaceRules |
|
|
|
private val replaceRules |
|
|
|
get() = callback.book?.let { |
|
|
|
get() = callback.book?.let { |
|
|
@ -58,6 +60,11 @@ class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
get() = AppConfig.tocUiUseReplace && callback.book?.getUseReplaceRule() == true |
|
|
|
get() = AppConfig.tocUiUseReplace && callback.book?.getUseReplaceRule() == true |
|
|
|
private var upDisplayTileJob: Coroutine<*>? = null |
|
|
|
private var upDisplayTileJob: Coroutine<*>? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCurrentListChanged() { |
|
|
|
|
|
|
|
super.onCurrentListChanged() |
|
|
|
|
|
|
|
upDisplayTile() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun upDisplayTile() { |
|
|
|
fun upDisplayTile() { |
|
|
|
upDisplayTileJob?.cancel() |
|
|
|
upDisplayTileJob?.cancel() |
|
|
|
upDisplayTileJob = Coroutine.async(callback.scope) { |
|
|
|
upDisplayTileJob = Coroutine.async(callback.scope) { |
|
|
@ -151,4 +158,5 @@ class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
fun openChapter(bookChapter: BookChapter) |
|
|
|
fun openChapter(bookChapter: BookChapter) |
|
|
|
fun durChapterIndex(): Int |
|
|
|
fun durChapterIndex(): Int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |