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()
|
}
|
|
}
|
}
|
}
|