|  |  | @ -8,7 +8,6 @@ import androidx.appcompat.widget.SearchView | 
			
		
	
		
		
			
				
					
					|  |  |  | import androidx.appcompat.widget.Toolbar |  |  |  | import androidx.appcompat.widget.Toolbar | 
			
		
	
		
		
			
				
					
					|  |  |  | import androidx.core.os.bundleOf |  |  |  | import androidx.core.os.bundleOf | 
			
		
	
		
		
			
				
					
					|  |  |  | import androidx.fragment.app.viewModels |  |  |  | import androidx.fragment.app.viewModels | 
			
		
	
		
		
			
				
					
					|  |  |  | import androidx.recyclerview.widget.LinearLayoutManager |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import androidx.recyclerview.widget.RecyclerView |  |  |  | import androidx.recyclerview.widget.RecyclerView | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.R |  |  |  | import io.legado.app.R | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.base.BaseDialogFragment |  |  |  | import io.legado.app.base.BaseDialogFragment | 
			
		
	
	
		
		
			
				
					|  |  | @ -17,6 +16,7 @@ import io.legado.app.constant.EventBus | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.constant.PreferKey |  |  |  | import io.legado.app.constant.PreferKey | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.data.appDb |  |  |  | import io.legado.app.data.appDb | 
			
		
	
		
		
			
				
					
					|  |  |  | 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.BookSource |  |  |  | import io.legado.app.data.entities.BookSource | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.data.entities.SearchBook |  |  |  | import io.legado.app.data.entities.SearchBook | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.databinding.DialogChapterChangeSourceBinding |  |  |  | import io.legado.app.databinding.DialogChapterChangeSourceBinding | 
			
		
	
	
		
		
			
				
					|  |  | @ -33,7 +33,8 @@ import kotlinx.coroutines.launch | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source), |  |  |  | class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source), | 
			
		
	
		
		
			
				
					
					|  |  |  |     Toolbar.OnMenuItemClickListener, |  |  |  |     Toolbar.OnMenuItemClickListener, | 
			
		
	
		
		
			
				
					
					|  |  |  |     ChangeChapterSourceAdapter.CallBack { |  |  |  |     ChangeChapterSourceAdapter.CallBack, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     ChangeChapterTocAdapter.Callback { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     constructor(name: String, author: String, chapterIndex: Int, chapterTitle: String) : this() { |  |  |  |     constructor(name: String, author: String, chapterIndex: Int, chapterTitle: String) : this() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         arguments = Bundle().apply { |  |  |  |         arguments = Bundle().apply { | 
			
		
	
	
		
		
			
				
					|  |  | @ -48,11 +49,17 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val groups = linkedSetOf<String>() |  |  |  |     private val groups = linkedSetOf<String>() | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val callBack: CallBack? get() = activity as? CallBack |  |  |  |     private val callBack: CallBack? get() = activity as? CallBack | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val viewModel: ChangeChapterSourceViewModel by viewModels() |  |  |  |     private val viewModel: ChangeChapterSourceViewModel by viewModels() | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val adapter by lazy { ChangeChapterSourceAdapter(requireContext(), viewModel, this) } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val editSourceResult = |  |  |  |     private val editSourceResult = | 
			
		
	
		
		
			
				
					
					|  |  |  |         registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { |  |  |  |         registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             viewModel.startSearch() |  |  |  |             viewModel.startSearch() | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private val searchBookAdapter by lazy { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ChangeChapterSourceAdapter(requireContext(), viewModel, this) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private val tocAdapter by lazy { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ChangeChapterTocAdapter(requireContext(), this) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private var searchBook: SearchBook? = null | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     override fun onStart() { |  |  |  |     override fun onStart() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         super.onStart() |  |  |  |         super.onStart() | 
			
		
	
	
		
		
			
				
					|  |  | @ -64,14 +71,14 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |         viewModel.initData(arguments) |  |  |  |         viewModel.initData(arguments) | 
			
		
	
		
		
			
				
					
					|  |  |  |         showTitle() |  |  |  |         showTitle() | 
			
		
	
		
		
			
				
					
					|  |  |  |         initMenu() |  |  |  |         initMenu() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         initView() | 
			
		
	
		
		
			
				
					
					|  |  |  |         initRecyclerView() |  |  |  |         initRecyclerView() | 
			
		
	
		
		
			
				
					
					|  |  |  |         initSearchView() |  |  |  |         initSearchView() | 
			
		
	
		
		
			
				
					
					|  |  |  |         initLiveData() |  |  |  |         initLiveData() | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun showTitle() { |  |  |  |     private fun showTitle() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.toolBar.title = viewModel.name |  |  |  |         binding.toolBar.title = viewModel.chapterTitle | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         binding.toolBar.subtitle = viewModel.author |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun initMenu() { |  |  |  |     private fun initMenu() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -86,11 +93,16 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |             ?.isChecked = AppConfig.changeSourceLoadToc |  |  |  |             ?.isChecked = AppConfig.changeSourceLoadToc | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private fun initView() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.ivHideToc.setOnClickListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             binding.clToc.gone() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun initRecyclerView() { |  |  |  |     private fun initRecyclerView() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.recyclerView.layoutManager = LinearLayoutManager(context) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) |  |  |  |         binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.recyclerView.adapter = adapter |  |  |  |         binding.recyclerView.adapter = searchBookAdapter | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { |  |  |  |         searchBookAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { |  |  |  |             override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (positionStart == 0) { |  |  |  |                 if (positionStart == 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     binding.recyclerView.scrollToPosition(0) |  |  |  |                     binding.recyclerView.scrollToPosition(0) | 
			
		
	
	
		
		
			
				
					|  |  | @ -103,6 +115,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         }) |  |  |  |         }) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.recyclerViewToc.adapter = tocAdapter | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun initSearchView() { |  |  |  |     private fun initSearchView() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -147,7 +160,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |         launch { |  |  |  |         launch { | 
			
		
	
		
		
			
				
					
					|  |  |  |             viewModel.searchDataFlow |  |  |  |             viewModel.searchDataFlow | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .collect { |  |  |  |                 .collect { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     adapter.setItems(it) |  |  |  |                     searchBookAdapter.setItems(it) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     delay(1000) |  |  |  |                     delay(1000) | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | @ -198,8 +211,22 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |         return false |  |  |  |         return false | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private val tocSuccess: (toc: List<BookChapter>) -> Unit = { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tocAdapter.durChapterIndex = viewModel.chapterIndex | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.loadingToc.hide() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tocAdapter.setItems(it) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.recyclerViewToc.scrollToPosition(tocAdapter.durChapterIndex - 5) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     override fun openToc(searchBook: SearchBook) { |  |  |  |     override fun openToc(searchBook: SearchBook) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         this.searchBook = searchBook | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tocAdapter.setItems(null) | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.clToc.visible() |  |  |  |         binding.clToc.visible() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.loadingToc.show() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         viewModel.getToc(searchBook, tocSuccess) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             binding.clToc.gone() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             toastOnUi(it) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     override val bookUrl: String? |  |  |  |     override val bookUrl: String? | 
			
		
	
	
		
		
			
				
					|  |  | @ -232,6 +259,10 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     override fun clickChapter(bookChapter: BookChapter) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         TODO("Not yet implemented") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun changeSource(searchBook: SearchBook) { |  |  |  |     private fun changeSource(searchBook: SearchBook) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             val book = searchBook.toBook() |  |  |  |             val book = searchBook.toBook() | 
			
		
	
	
		
		
			
				
					|  |  | @ -272,9 +303,9 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     override fun observeLiveBus() { |  |  |  |     override fun observeLiveBus() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         observeEvent<String>(EventBus.SOURCE_CHANGED) { |  |  |  |         observeEvent<String>(EventBus.SOURCE_CHANGED) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             adapter.notifyItemRangeChanged( |  |  |  |             searchBookAdapter.notifyItemRangeChanged( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 0, |  |  |  |                 0, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 adapter.itemCount, |  |  |  |                 searchBookAdapter.itemCount, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 bundleOf(Pair("upCurSource", bookUrl)) |  |  |  |                 bundleOf(Pair("upCurSource", bookUrl)) | 
			
		
	
		
		
			
				
					
					|  |  |  |             ) |  |  |  |             ) | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |