|  |  | @ -9,14 +9,15 @@ import io.legado.app.lib.theme.primaryColor | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.widget.code.addJsPattern |  |  |  | import io.legado.app.ui.widget.code.addJsPattern | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.widget.code.addJsonPattern |  |  |  | import io.legado.app.ui.widget.code.addJsonPattern | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.widget.code.addLegadoPattern |  |  |  | import io.legado.app.ui.widget.code.addLegadoPattern | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import io.legado.app.utils.disableEdit | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.utils.setLayout |  |  |  | import io.legado.app.utils.setLayout | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.utils.viewbindingdelegate.viewBinding |  |  |  | import io.legado.app.utils.viewbindingdelegate.viewBinding | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { |  |  |  | class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     constructor(code: String) : this() { |  |  |  |     constructor(code: String, disableEdit: Boolean = true) : this() { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         arguments = Bundle().apply { |  |  |  |         arguments = Bundle().apply { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |             putBoolean("disableEdit", disableEdit) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             putString("code", code) |  |  |  |             putString("code", code) | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | @ -30,6 +31,11 @@ class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |  |  |  |     override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.toolBar.setBackgroundColor(primaryColor) |  |  |  |         binding.toolBar.setBackgroundColor(primaryColor) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (arguments?.getBoolean("disableEdit") == true) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             binding.codeView.disableEdit() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             initMenu() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.codeView.addLegadoPattern() |  |  |  |         binding.codeView.addLegadoPattern() | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.codeView.addJsonPattern() |  |  |  |         binding.codeView.addJsonPattern() | 
			
		
	
		
		
			
				
					
					|  |  |  |         binding.codeView.addJsPattern() |  |  |  |         binding.codeView.addJsPattern() | 
			
		
	
	
		
		
			
				
					|  |  | @ -38,4 +44,24 @@ class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private fun initMenu() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.toolBar.inflateMenu(R.menu.code_edit) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         binding.toolBar.setOnMenuItemClickListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             when (it.itemId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 R.id.menu_save -> binding.codeView.text?.toString()?.let { code -> | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     (parentFragment as? Callback)?.saveCode(code) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         ?: (activity as? Callback)?.saveCode(code) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return@setOnMenuItemClickListener true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     interface Callback { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         fun saveCode(code: String) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } |