|
@@ -5,19 +5,19 @@ import android.content.Intent
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
import androidx.fragment.app.activityViewModels
|
|
import androidx.fragment.app.activityViewModels
|
|
|
-import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import io.legado.app.R
|
|
import io.legado.app.R
|
|
|
import io.legado.app.base.VMBaseFragment
|
|
import io.legado.app.base.VMBaseFragment
|
|
|
import io.legado.app.data.appDb
|
|
import io.legado.app.data.appDb
|
|
|
import io.legado.app.data.entities.Bookmark
|
|
import io.legado.app.data.entities.Bookmark
|
|
|
import io.legado.app.databinding.FragmentBookmarkBinding
|
|
import io.legado.app.databinding.FragmentBookmarkBinding
|
|
|
import io.legado.app.lib.theme.primaryColor
|
|
import io.legado.app.lib.theme.primaryColor
|
|
|
|
|
+import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
|
|
import io.legado.app.utils.setEdgeEffectColor
|
|
import io.legado.app.utils.setEdgeEffectColor
|
|
|
import io.legado.app.utils.showDialogFragment
|
|
import io.legado.app.utils.showDialogFragment
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
-import kotlinx.coroutines.delay
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
|
|
@@ -27,19 +27,22 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
|
|
|
TocViewModel.BookmarkCallBack {
|
|
TocViewModel.BookmarkCallBack {
|
|
|
override val viewModel by activityViewModels<TocViewModel>()
|
|
override val viewModel by activityViewModels<TocViewModel>()
|
|
|
private val binding by viewBinding(FragmentBookmarkBinding::bind)
|
|
private val binding by viewBinding(FragmentBookmarkBinding::bind)
|
|
|
|
|
+ private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) }
|
|
|
private val adapter by lazy { BookmarkAdapter(requireContext(), this) }
|
|
private val adapter by lazy { BookmarkAdapter(requireContext(), this) }
|
|
|
|
|
+ private var durChapterIndex = 0
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
viewModel.bookMarkCallBack = this
|
|
viewModel.bookMarkCallBack = this
|
|
|
initRecyclerView()
|
|
initRecyclerView()
|
|
|
viewModel.bookData.observe(this) {
|
|
viewModel.bookData.observe(this) {
|
|
|
|
|
+ durChapterIndex = it.durChapterIndex
|
|
|
upBookmark(null)
|
|
upBookmark(null)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun initRecyclerView() {
|
|
private fun initRecyclerView() {
|
|
|
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
|
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
|
|
- binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
|
|
|
|
|
|
+ binding.recyclerView.layoutManager = mLayoutManager
|
|
|
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
|
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
|
|
binding.recyclerView.adapter = adapter
|
|
binding.recyclerView.adapter = adapter
|
|
|
}
|
|
}
|
|
@@ -54,7 +57,16 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
|
|
|
}
|
|
}
|
|
|
}.let {
|
|
}.let {
|
|
|
adapter.setItems(it)
|
|
adapter.setItems(it)
|
|
|
- delay(100)
|
|
|
|
|
|
|
+ var scrollPos = 0
|
|
|
|
|
+ withContext(Dispatchers.Default) {
|
|
|
|
|
+ adapter.getItems().forEachIndexed { index, bookmark ->
|
|
|
|
|
+ if (bookmark.chapterIndex >= durChapterIndex) {
|
|
|
|
|
+ return@withContext
|
|
|
|
|
+ }
|
|
|
|
|
+ scrollPos = index
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mLayoutManager.scrollToPositionWithOffset(scrollPos, 0)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|