@@ -7,26 +7,51 @@ import android.graphics.drawable.ColorDrawable
77import android.os.Bundle
88import android.util.DisplayMetrics
99import android.view.ViewGroup
10+ import androidx.core.content.ContextCompat
11+ import com.ddd.attendance.check.R
12+ import com.ddd.attendance.check.vm.MainViewModel
1013import kotlinx.android.synthetic.main.dialog_ddd.*
1114
1215
13- class DDDDialog (context : Context , userType : UserType ) : Dialog(context) {
16+ class DDDDialog (context : Context , private val data : Pair < UserType , String > ) : Dialog(context) {
1417 private lateinit var dddDialogEventListener: DDDDialogEventListener
1518 override fun onCreate (savedInstanceState : Bundle ? ) {
1619 super .onCreate(savedInstanceState)
1720 window?.setBackgroundDrawable(ColorDrawable (Color .TRANSPARENT ))
1821 setContentView(com.ddd.attendance.check.R .layout.dialog_ddd)
19- val metrics = DisplayMetrics ()
20- window?.windowManager?.defaultDisplay?.getMetrics(metrics)
21- val width = (metrics.widthPixels * 0.8 ).toInt()
22- window?.setLayout(width, ViewGroup .LayoutParams .WRAP_CONTENT )
2322
23+ setInitView()
24+ setBackGround()
25+ setDialogMarkImg(data.second)
26+ tvMessage.text = data.second
2427 btnOK.setOnClickListener {
2528 dddDialogEventListener.onClick(this )
2629 dismiss()
2730 }
2831 }
2932
33+ private fun setDialogMarkImg (message : String ) {
34+ val background = ContextCompat .getDrawable(
35+ context,
36+ if (message == MainViewModel .MSG_ATTENDANCE_START ) R .drawable.check_icon else R .drawable.exclamation
37+ )
38+ imgMark.background = background
39+ }
40+
41+ private fun setInitView () {
42+ val metrics = DisplayMetrics ()
43+ window?.windowManager?.defaultDisplay?.getMetrics(metrics)
44+ val width = (metrics.widthPixels * 0.8 ).toInt()
45+ window?.setLayout(width, ViewGroup .LayoutParams .WRAP_CONTENT )
46+ }
47+
48+ private fun setBackGround () {
49+ linearDialog.background = ContextCompat .getDrawable(
50+ context,
51+ if (data.first == UserType .BASIC ) R .drawable.dialog_ddd_background else R .drawable.dialog_ddd_background_admin
52+ )
53+ }
54+
3055 fun setDialogListener (dddDialogEventListener : DDDDialogEventListener ): DDDDialog {
3156 this .dddDialogEventListener = dddDialogEventListener
3257 return this
0 commit comments