| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.track 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.app.Dialog 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.os.Bundle 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.view.LayoutInflater 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.view.View 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import androidx.core.os.bundleOf 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import androidx.core.view.isInvisible 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,10 +14,8 @@ import eu.kanade.tachiyomi.data.database.models.Track 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import eu.kanade.tachiyomi.data.track.TrackManager 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import eu.kanade.tachiyomi.data.track.TrackService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import eu.kanade.tachiyomi.data.track.model.TrackSearch 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import eu.kanade.tachiyomi.databinding.TrackSearchDialogBinding 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import eu.kanade.tachiyomi.ui.base.controller.DialogController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import kotlinx.android.synthetic.main.track_search_dialog.view.progress 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import kotlinx.android.synthetic.main.track_search_dialog.view.track_search 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import kotlinx.android.synthetic.main.track_search_dialog.view.track_search_list 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kotlinx.coroutines.flow.debounce 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kotlinx.coroutines.flow.filter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kotlinx.coroutines.flow.launchIn 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -29,7 +28,7 @@ import java.util.concurrent.TimeUnit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class TrackSearchDialog : DialogController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private var dialogView: View? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var binding: TrackSearchDialogBinding? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private var adapter: TrackSearchAdapter? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -53,13 +52,13 @@ class TrackSearchDialog : DialogController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     override fun onCreateDialog(savedViewState: Bundle?): Dialog { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding = TrackSearchDialogBinding.inflate(LayoutInflater.from(activity!!)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val dialog = MaterialDialog(activity!!) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .customView(R.layout.track_search_dialog) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .customView(view = binding!!.root) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .positiveButton(android.R.string.ok) { onPositiveButtonClick() } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .negativeButton(android.R.string.cancel) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .neutralButton(R.string.action_remove) { onRemoveButtonClick() } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        dialogView = dialog.view 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         onViewCreated(dialog.view, savedViewState) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return dialog 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -69,12 +68,12 @@ class TrackSearchDialog : DialogController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Create adapter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         val adapter = TrackSearchAdapter(view.context) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.adapter = adapter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.track_search_list.adapter = adapter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding!!.trackSearchList.adapter = adapter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Set listeners 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         selectedItem = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.track_search_list.itemClicks() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding!!.trackSearchList.itemClicks() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .onEach { position -> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 selectedItem = adapter.getItem(position) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -83,20 +82,20 @@ class TrackSearchDialog : DialogController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Do an initial search based on the manga's title 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (savedState == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             val title = trackController.presenter.manga.title 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            view.track_search.append(title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            binding!!.trackSearch.append(title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             search(title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     override fun onDestroyView(view: View) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         super.onDestroyView(view) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        dialogView = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         adapter = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     override fun onAttach(view: View) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         super.onAttach(view) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        dialogView!!.track_search.textChanges() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding!!.trackSearch.textChanges() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .debounce(TimeUnit.SECONDS.toMillis(1)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .filter { it.isNotBlank() } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .onEach { search(it.toString()) } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -104,24 +103,24 @@ class TrackSearchDialog : DialogController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private fun search(query: String) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val view = dialogView ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.progress.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.track_search_list.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val binding = binding ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.progress.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.trackSearchList.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         trackController.presenter.search(query, service) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fun onSearchResults(results: List<TrackSearch>) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         selectedItem = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val view = dialogView ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.progress.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.track_search_list.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val binding = binding ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.progress.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.trackSearchList.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         adapter?.setItems(results) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fun onSearchResultsError() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        val view = dialogView ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.progress.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        view.track_search_list.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val binding = binding ?: return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.progress.isVisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        binding.trackSearchList.isInvisible = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         adapter?.setItems(emptyList()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |