| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -21,10 +21,11 @@ import io.legado.app.ui.widget.recycler.VerticalDivider | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.utils.ColorUtils | 
					 | 
					 | 
					 | 
					import io.legado.app.utils.ColorUtils | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.utils.observeEvent | 
					 | 
					 | 
					 | 
					import io.legado.app.utils.observeEvent | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.utils.viewbindingdelegate.viewBinding | 
					 | 
					 | 
					 | 
					import io.legado.app.utils.viewbindingdelegate.viewBinding | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.* | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.CoroutineScope | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.Dispatchers.IO | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.Dispatchers.IO | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.Dispatchers.Main | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.Dispatchers.Main | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.flow.conflate | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.launch | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.withContext | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapter_list), | 
					 | 
					 | 
					 | 
					class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapter_list), | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ChapterListAdapter.Callback, | 
					 | 
					 | 
					 | 
					    ChapterListAdapter.Callback, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -34,10 +35,9 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) } | 
					 | 
					 | 
					 | 
					    private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val adapter by lazy { ChapterListAdapter(requireContext(), this) } | 
					 | 
					 | 
					 | 
					    private val adapter by lazy { ChapterListAdapter(requireContext(), this) } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var durChapterIndex = 0 | 
					 | 
					 | 
					 | 
					    private var durChapterIndex = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var tocFlowJob: Job? = null | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { | 
					 | 
					 | 
					 | 
					    override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        viewModel.chapterCallBack = this@ChapterListFragment | 
					 | 
					 | 
					 | 
					        viewModel.chapterListCallBack = this@ChapterListFragment | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val bbg = bottomBackground | 
					 | 
					 | 
					 | 
					        val bbg = bottomBackground | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg)) | 
					 | 
					 | 
					 | 
					        val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        llChapterBaseInfo.setBackgroundColor(bbg) | 
					 | 
					 | 
					 | 
					        llChapterBaseInfo.setBackgroundColor(bbg) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -103,17 +103,17 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    override fun upChapterList(searchKey: String?) { | 
					 | 
					 | 
					 | 
					    override fun upChapterList(searchKey: String?) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        tocFlowJob?.cancel() | 
					 | 
					 | 
					 | 
					        launch { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        tocFlowJob = launch { | 
					 | 
					 | 
					 | 
					            withContext(IO) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            when { | 
					 | 
					 | 
					 | 
					                when { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) | 
					 | 
					 | 
					 | 
					                    searchKey.isNullOrBlank() -> appDb.bookChapterDao.getChapterList(viewModel.bookUrl) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) | 
					 | 
					 | 
					 | 
					                    else -> appDb.bookChapterDao.search(viewModel.bookUrl, searchKey) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            }.conflate().collect { | 
					 | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            }.let { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                adapter.setItems(it) | 
					 | 
					 | 
					 | 
					                adapter.setItems(it) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if (searchKey.isNullOrBlank() && mLayoutManager.findFirstVisibleItemPosition() < 0) { | 
					 | 
					 | 
					 | 
					                if (searchKey.isNullOrBlank() && mLayoutManager.findFirstVisibleItemPosition() < 0) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) | 
					 | 
					 | 
					 | 
					                    mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                delay(100) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |