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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.dollearn.student.ui.discovery
 
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.callPhone
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.dialog.MapTypeDialog
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.entity.Banner
import com.dollearn.student.network.entity.CourseVo
import com.dollearn.student.network.entity.ShopDetail
import com.dollearn.student.network.entity.Venue
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.course.CourseActivity
import com.dollearn.student.ui.course.CourseDetailActivity
import com.dollearn.student.ui.course.EvaluationActivity
import com.dollearn.student.ui.discovery.adapter.ShopCourseAdapter
import com.dollearn.student.ui.discovery.adapter.ShopPlaceAdapter
import com.dollearn.student.ui.home.FieldActivity
import com.dollearn.student.ui.home.adapter.HomeBannerAdapter
import com.dollearn.student.utils.ThirdPartyMapsGuide
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.activity_shop_detail.*
import org.jetbrains.anko.startActivity
 
class ShopDetailActivity:TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_shop_detail
 
    private val id by lazy { intent.getStringExtra("id")?:"" }
    private val bannerImg = arrayListOf<Banner>()
    private val bannerAdapter by lazy {
        HomeBannerAdapter(bannerImg, this)
    }
    private var shop:ShopDetail? = null
    private val placeList = arrayListOf<Venue>()
    private val placeAdapter = ShopPlaceAdapter(placeList)
    private val courseList = arrayListOf<CourseVo>()
    private val courseAdapter = ShopCourseAdapter(courseList)
 
    override fun initClick() {
        tv_evaluate.setOnClickListener {
            startActivity<EvaluateShopActivity>("id" to id)
        }
        tv_call.setOnClickListener {
            callPhone(shop?.phone)
        }
        tv_navi.setOnClickListener {
            if (shop?.lat != null){
                val mapTypeDialog = MapTypeDialog()
                mapTypeDialog.callback = object :StringCallback{
                    override fun onResult(rst: String) {
                        if(rst == "b"){
                            ThirdPartyMapsGuide.goToBaiduActivity(this@ShopDetailActivity,shop!!.storeName,shop!!.lon!!,shop!!.lat!!)
                        }else if (rst == "a"){
                            ThirdPartyMapsGuide.goToGaoDeMap(this@ShopDetailActivity,shop!!.storeName,shop!!.lon!!.toString(),shop!!.lat!!.toString())
                        }else{
                            ThirdPartyMapsGuide.goToTencentMap(this@ShopDetailActivity,shop!!.storeName,shop!!.lon!!,shop!!.lat!!)
                        }
                    }
                }
                mapTypeDialog.showAllowingStateLoss(supportFragmentManager,"map")
            }
        }
        tv_more_place.setOnClickListener {
            startActivity<FieldActivity>()
        }
        tv_more_course.setOnClickListener {
            startActivity<CourseActivity>()
        }
        courseAdapter.setOnItemClickListener { view, position ->
            startActivity<CourseDetailActivity>("id" to courseList[position].courseId)
        }
    }
 
    override fun initView() {
        banner.adapter = bannerAdapter
        rv_place.layoutManager = LinearLayoutManager(this)
        rv_place.adapter = placeAdapter
        rv_course.layoutManager = LinearLayoutManager(this)
        rv_course.adapter = courseAdapter
        getData()
    }
 
    private fun getData(){
        HttpManager.storeDetail(id).request(this){_,data->
            shop = data
            data?.apply {
                bannerImg.addAll((images?: arrayListOf()).map { Banner(url = it) })
                bannerAdapter.notifyDataSetChanged()
                banner.currentItem = 1
                tv_name.text = storeName
                tv_address.text = storeAddress
                tv_open_time.text = storeTime
                tv_introduce.text = storeInfo?:"暂无门店介绍"
                placeList.clear()
                placeList.addAll(venueList.take(3))
                placeAdapter.notifyDataSetChanged()
                courseList.clear()
                courseList.addAll(courseVoList.take(3))
                courseAdapter.notifyDataSetChanged()
            }
 
        }
    }
}