lmw
2024-06-18 1f45a54dc8e149548d3a61d1228741627aa4f23e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.dollearn.student.dialog
 
import android.view.Gravity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.MainActivity
import com.dollearn.student.R
import com.dollearn.student.utils.Const
import com.dollearn.student.utils.event.EmptyEvent
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_confirm_shop.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.support.v4.startActivity
 
class ConfirmShopDialog : BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_confirm_shop
 
    private val type by lazy { arguments?.getInt("type",0)?:0 } //作用是根据上级页面显示不同标题
 
    var callback: StringCallback? = null
 
    override fun setGravity() = Gravity.CENTER
 
    override fun initView() {
        when(type){
            TYPE_PLACE->{
                tv_title.text = "请确认预约门店"
            }
            TYPE_WORLD->{
                tv_title.text = "请确认参与赛点"
                tv_change_shop.text = "更换赛点"
            }
        }
        iv_shop.setImageURI(arguments?.getString("img"))
        tv_name.text = arguments?.getString("name")
        tv_address.text = arguments?.getString("address")
        val distance = arguments?.getString("distance")
        tv_distance.text = if (distance.isNullOrEmpty()) "" else "距你${distance}"
        tv_change_shop.setOnClickListener {
            dismissAllowingStateLoss()
            startActivity<MainActivity>()
            EventBus.getDefault().post(EmptyEvent(Const.EventCode.SHOW_CHANGE_SHOP_DIALOG))
        }
        tv_cancel.setOnClickListener { dismissAllowingStateLoss() }
        tv_action.setOnClickListener {
            callback?.onResult("")
            dismissAllowingStateLoss()
        }
    }
 
    companion object {
        const val TYPE_PLACE = 1 //场地报名
        const val TYPE_WORLD = 2 //世界杯报名
 
        fun show(
            fm: FragmentManager,
            img: String,
            name: String,
            address: String,
            distance: String,
            callback: StringCallback,
            type:Int = 0
        ) {
            val confirmShopDialog = ConfirmShopDialog()
            confirmShopDialog.callback = callback
            confirmShopDialog.arguments = bundleOf("img" to img,"name" to name,"address" to address,"distance" to distance,"type" to type)
            confirmShopDialog.showAllowingStateLoss(fm,"confirm")
        }
    }
}