Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.61 KB | None | 0 0
  1.  interface LoadingModalListener {
  2.     fun onLoadingStop()
  3. }
  4. class LoadingModal: androidx.fragment.app.DialogFragment() {
  5.  
  6.     private var listener: LoadingModalListener? = null
  7.  
  8.     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
  9.         val dialog = Dialog(activity, R.style.LoadingDialogStyle)
  10.         dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
  11.         dialog.window!!.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN)
  12.         dialog.window!!.statusBarColor = ContextCompat.getColor(context!!, R.color.white)
  13.         dialog.setContentView(R.layout.layout_loading)
  14.  
  15.         dialog.setCanceledOnTouchOutside(false)
  16.         /*if (!BuildConfig.DEBUG) {
  17.             dialog.setCancelable(false)
  18.         }*/
  19.  
  20.         return dialog
  21.     }
  22.  
  23.     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  24.         val v = inflater.inflate(R.layout.layout_loading, container, false)
  25.  
  26.         dialog.setCanceledOnTouchOutside(false)
  27.         /*if (!BuildConfig.DEBUG) {
  28.             isCancelable = false
  29.         }*/
  30.  
  31.         return v
  32.     }
  33.  
  34.     fun setDialogListener(dialogListener: LoadingModalListener) {
  35.         this.listener = dialogListener
  36.     }
  37.  
  38.     override fun onDismiss(dialog: DialogInterface?) {
  39.         super.onDismiss(dialog)
  40.         listener?.onLoadingStop()
  41.     }
  42.  
  43.     override fun dismiss() {
  44.         dismissAllowingStateLoss()
  45.     }
  46.  
  47.     companion object {
  48.         fun newInstance(): LoadingModal {
  49.             return LoadingModal()
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement