本地书籍
This commit is contained in:
3 files changed
+28
-18
No files matched your search
@@ -14,6 +14,7 @@ import android.transition.TransitionManager
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -58,6 +59,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) }
|
||||
private val adapter by lazy { ChapterListAdapter(requireContext(), this) }
|
||||
private var durChapterIndex = 0
|
||||
private var swipeHelper: ItemTouchHelper? = null
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run {
|
||||
viewModel.chapterListCallBack = this@ChapterListFragment
|
||||
@@ -65,10 +67,32 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
initView()
|
||||
viewModel.bookData.observe(this@ChapterListFragment) {
|
||||
initBook(it)
|
||||
initSwipeIfNeed(it.isLocal)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
binding.recyclerView.layoutManager = mLayoutManager
|
||||
binding.recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
if (parent.getChildAdapterPosition(view) == state.itemCount - 1) {
|
||||
outRect.bottom = 80.dpToPx()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun initSwipeIfNeed(isLocalBook: Boolean) {
|
||||
binding.btnDownloadSelected.isEnabled = !isLocalBook
|
||||
swipeHelper?.attachToRecyclerView(null)
|
||||
if (!isLocalBook){
|
||||
val swipeCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
|
||||
|
||||
override fun onMove(
|
||||
@@ -151,27 +175,10 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val itemTouchHelper = ItemTouchHelper(swipeCallback)
|
||||
itemTouchHelper.attachToRecyclerView(binding.recyclerView)
|
||||
|
||||
binding.recyclerView.layoutManager = mLayoutManager
|
||||
|
||||
binding.recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
if (parent.getChildAdapterPosition(view) == state.itemCount - 1) {
|
||||
outRect.bottom = 80.dpToPx()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun initView() = binding.run {
|
||||
llBase.applyNavigationBarPadding()
|
||||
|
||||
@@ -31,6 +31,7 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.databinding.ActivityChapterListBinding
|
||||
import io.legado.app.databinding.DialogDownloadChoiceBinding
|
||||
import io.legado.app.help.book.isLocal
|
||||
import io.legado.app.help.book.isLocalTxt
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
@@ -64,6 +65,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
|
||||
private var menu: Menu? = null
|
||||
private var searchView: SearchView? = null
|
||||
private val waitDialog by lazy { WaitDialog(this) }
|
||||
private var isLocalBook : Boolean = false
|
||||
private val exportDir = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let { uri ->
|
||||
when (it.requestCode) {
|
||||
@@ -88,6 +90,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
|
||||
viewModel.bookData.observe(this) { book ->
|
||||
menu?.setGroupVisible(R.id.menu_group_text, book.isLocalTxt)
|
||||
supportActionBar?.title = book.name
|
||||
binding.topBar.menu.findItem(R.id.menu_download)?.isVisible = !book.isLocal
|
||||
}
|
||||
intent.getStringExtra("bookUrl")?.let {
|
||||
viewModel.initBook(it)
|
||||
|
||||
@@ -4,7 +4,7 @@ coreSplashscreen = "1.2.0-rc01"
|
||||
datastorePreferences = "1.1.7"
|
||||
kotlin = "2.2.20"
|
||||
ksp = "2.2.20-2.0.4"
|
||||
agp = "8.13.0"
|
||||
agp = "8.13.1"
|
||||
appcompat = "1.7.1"
|
||||
colorpicker = "1.1.0"
|
||||
commonsText = "1.14.0"
|
||||
|
||||
Reference in new issue
Block a user