| | |
| | | package com.sinata.xqmuse.ui.course |
| | | |
| | | import android.annotation.SuppressLint |
| | | import android.content.Intent |
| | | import android.os.CountDownTimer |
| | | import android.util.TypedValue |
| | | import android.webkit.WebChromeClient |
| | | import android.webkit.WebSettings |
| | | import android.webkit.WebViewClient |
| | | import androidx.core.widget.NestedScrollView |
| | | import androidx.recyclerview.widget.GridLayoutManager |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.* |
| | | import cn.sinata.xldutils.utils.SpanBuilder |
| | | import cn.sinata.xldutils.utils.showAllowingStateLoss |
| | | import cn.sinata.xldutils.visible |
| | | import com.github.zackratos.ultimatebar.UltimateBar |
| | | import com.google.android.material.appbar.AppBarLayout |
| | | import com.share.utils.ShareUtils |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.dialog.RiskDialog |
| | | import com.sinata.xqmuse.dialog.SendConfirmDialog |
| | | import com.sinata.xqmuse.dialog.ShareDialog |
| | | import com.sinata.xqmuse.network.Apis |
| | | import com.sinata.xqmuse.network.HttpManager |
| | | import com.sinata.xqmuse.network.entity.Course |
| | | import com.sinata.xqmuse.network.entity.Chapter |
| | | import com.sinata.xqmuse.network.entity.CourseBean |
| | | import com.sinata.xqmuse.network.entity.CourseDetail |
| | | import com.sinata.xqmuse.network.entity.VideoBean |
| | | import com.sinata.xqmuse.network.request |
| | | import com.sinata.xqmuse.ui.TransparentStatusBarActivity |
| | | import com.sinata.xqmuse.ui.course.adapter.RecommendAdapter |
| | | import com.sinata.xqmuse.ui.course.adapter.VideoNameAdapter |
| | | import com.sinata.xqmuse.utils.extention.clickDelay |
| | | import com.sinata.xqmuse.ui.course.adapter.ChapterAdapter |
| | | import com.sinata.xqmuse.ui.course.adapter.CourseGridAdapter |
| | | import com.sinata.xqmuse.utils.AppBarStateChangeListener |
| | | import com.sinata.xqmuse.utils.Const |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import com.umeng.socialize.bean.SHARE_MEDIA |
| | | import kotlinx.android.synthetic.main.activity_course_deatil.* |
| | | import org.jetbrains.anko.imageResource |
| | | import org.jetbrains.anko.startActivity |
| | | import kotlinx.android.synthetic.main.activity_course_deatil.iv_back |
| | | import kotlinx.android.synthetic.main.activity_course_deatil.webView |
| | | import kotlinx.android.synthetic.main.activity_level.* |
| | | import org.jetbrains.anko.* |
| | | |
| | | class CourseDetailActivity : TransparentStatusBarActivity() { |
| | | override fun setContentView() = R.layout.activity_course_deatil |
| | | |
| | | private val id by lazy { intent.getStringExtra("id")?:"" } |
| | | private val data by lazy { intent.getParcelableExtra<CourseDetail>("data") } |
| | | |
| | | private var course: CourseDetail? = null |
| | | private val chapterList = arrayListOf<Chapter>() |
| | | private val chapterAdapter = ChapterAdapter(chapterList) |
| | | private val courseList = arrayListOf<CourseBean>() |
| | | private val courseAdapter = CourseGridAdapter(courseList) |
| | | |
| | | private val videoList = arrayListOf<VideoBean>() |
| | | private val videoAdapter = VideoNameAdapter(videoList) |
| | | |
| | | private val courseList = arrayListOf<Course>() |
| | | private val courseAdapter = RecommendAdapter(courseList) |
| | | |
| | | var scrollByTab = false //true:点击tab滑动,不触发滑动回调,防止回环 |
| | | private val SCROLL_DURATION = 500 //滑动时长 |
| | | private var timer: CountDownTimer? = null |
| | | |
| | | override fun initClick() { |
| | | iv_back.setOnClickListener { finish() } |
| | | courseAdapter.setOnItemClickListener { view, position -> |
| | | startActivity<CourseDetailActivity>("id" to courseList[position].id) |
| | | |
| | | tv_send.setOnClickListener { |
| | | getData(true) |
| | | } |
| | | |
| | | tv_action.setOnClickListener { |
| | | startActivity<JoinCourseActivity>("id" to id) |
| | | if (tv_action.text == "立即学习"){ |
| | | if (data?.list?.isNullOrEmpty() == true) |
| | | toast("该课程暂未添加章节") |
| | | else |
| | | startActivity<StudyActivity>("id" to data?.list?.firstOrNull()?.id) |
| | | } else |
| | | getData(false) |
| | | } |
| | | iv_collected.setOnClickListener { |
| | | iv_collected.isEnabled = false |
| | | HttpManager.collectCourse(id).request(this,success = {_,data-> |
| | | iv_collected.isEnabled = true |
| | | course?.isCollect = if (course?.isCollect == "1") "0" else "1" |
| | | iv_collected.imageResource = if (course?.isCollect == "1") R.mipmap.star_red else R.mipmap.star_empty |
| | | }){_,_-> |
| | | iv_collected.isEnabled = true |
| | | iv_collect.setOnClickListener { |
| | | HttpManager.collectCourse(data?.id?:"").request(this){_,_-> |
| | | data?.isCollect = if (data?.isCollect == 1) 2 else 1 |
| | | iv_collect.setImageResource(if (data?.isCollect == 1) R.mipmap.collected else R.mipmap.uncollect) |
| | | toast(if (data?.isCollect == 1) "收藏成功" else "已取消收藏") |
| | | } |
| | | } |
| | | tv_start.clickDelay { |
| | | HttpManager.riskInfo().request(this){_,data-> |
| | | if (data?.state == 1){ |
| | | RiskDialog.show(supportFragmentManager,data.riskInfo,object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | startVideo() |
| | | } |
| | | }) |
| | | }else |
| | | startVideo() |
| | | iv_share.setOnClickListener { |
| | | val shareDialog = ShareDialog() |
| | | shareDialog.callback = object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | if (rst == "wx"){ |
| | | ShareUtils.share(this@CourseDetailActivity, |
| | | SHARE_MEDIA.WEIXIN,data?.courseTitle, Const.SHARE.SHARE_COURSE_TITLE, |
| | | Apis.SHARE_COURSE.format(data?.id),null,"") |
| | | }else{ |
| | | ShareUtils.share(this@CourseDetailActivity, |
| | | SHARE_MEDIA.WEIXIN_CIRCLE,data?.courseTitle,Const.SHARE.SHARE_COURSE_TITLE, |
| | | Apis.SHARE_COURSE.format(data?.id),null,"") |
| | | } |
| | | } |
| | | } |
| | | shareDialog.showAllowingStateLoss(supportFragmentManager,"share") |
| | | } |
| | | cb_intro.setOnClickListener { |
| | | scroll2Position(0) |
| | | checkTab(0) |
| | | } |
| | | cb_chapter.setOnClickListener { |
| | | scroll2Position(1) |
| | | checkTab(1) |
| | | } |
| | | cb_push.setOnClickListener { |
| | | scroll2Position(2) |
| | | checkTab(2) |
| | | } |
| | | scrollView.setOnScrollChangeListener { _: NestedScrollView?, _: Int, scrollY: Int, _: Int, _: Int -> |
| | | if (!scrollByTab) |
| | | when { |
| | | scrollY>=tv_2.top -> checkTab(2) |
| | | scrollY>=tv_1.top -> checkTab(1) |
| | | else -> checkTab(0) |
| | | } |
| | | } |
| | | chapterAdapter.setOnItemClickListener { _, position -> |
| | | if (tv_action.text == "立即学习") |
| | | startActivity<StudyActivity>("id" to data?.list?.get(position)?.id,"index" to position) |
| | | else |
| | | getData(false) |
| | | } |
| | | courseAdapter.setOnItemClickListener { _, position -> |
| | | showDialog() |
| | | HttpManager.getPayCourseInfoById(courseList[position].id?:"").request(this,success = { _, data-> |
| | | dismissDialog() |
| | | data?.goDetail(this) |
| | | }){_,_-> |
| | | dismissDialog() |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun initView() { |
| | | UltimateBar.with(this) |
| | | .statusDark(false) |
| | | .create().immersionBar() //沉浸状态栏 |
| | | titleBar.gone() |
| | | rv_list.layoutManager = LinearLayoutManager(this) |
| | | rv_list.adapter = videoAdapter |
| | | rv_course.layoutManager = LinearLayoutManager(this) |
| | | rv_course.adapter = courseAdapter |
| | | getDetail() |
| | | val settings = webView.settings |
| | | settings.javaScriptEnabled = true |
| | | settings.javaScriptCanOpenWindowsAutomatically = true |
| | | settings.defaultTextEncodingName = "utf-8" |
| | | settings.domStorageEnabled = true |
| | | settings.setSupportZoom(true) |
| | | // settings.textZoom = 200 |
| | | settings.useWideViewPort = true |
| | | settings.loadWithOverviewMode = true |
| | | settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING |
| | | webView.webChromeClient = object : WebChromeClient() {} |
| | | webView.webViewClient = object : WebViewClient() {} |
| | | rv_chapter.layoutManager = LinearLayoutManager(this) |
| | | rv_chapter.adapter = chapterAdapter |
| | | rv_push.layoutManager = GridLayoutManager(this,2) |
| | | rv_push.adapter = courseAdapter |
| | | webView.backgroundColor = 0 |
| | | webView.background.alpha = 0 |
| | | appbar.addOnOffsetChangedListener(object : AppBarStateChangeListener() { |
| | | override fun onStateChanged(appBarLayout: AppBarLayout?, state: State?, ratio:Double) { |
| | | bg.alpha = if(ratio<0.2) 0f else ((ratio-0.2)/0.8).toFloat() |
| | | when (state) { |
| | | State.EXPANDED -> { |
| | | //展开状态 |
| | | iv_back.imageResource = R.mipmap.icon_back_white |
| | | iv_share.imageResource = R.mipmap.ic_share |
| | | if (data?.isCollect!=1) |
| | | iv_collect.imageResource = R.mipmap.uncollect |
| | | tvTitle.textColorResource = R.color.white |
| | | } |
| | | State.COLLAPSED -> { |
| | | //折叠状态 |
| | | iv_back.imageResource = R.mipmap.back |
| | | iv_share.imageResource = R.mipmap.ic_share_black |
| | | if (data?.isCollect!=1) |
| | | iv_collect.imageResource = R.mipmap.uncollect_b |
| | | tvTitle.textColorResource = R.color.textColor |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | |
| | | data?.apply { |
| | | iv_collect.setImageResource(if (data?.isCollect == 1) R.mipmap.collected else R.mipmap.uncollect) |
| | | iv_cover.setImageURI(detailUrl) |
| | | tv_name.text = courseTitle |
| | | tv_teacher.text = "导师 ${tutor}" |
| | | tv_count.text = "${count}人已加入学习" |
| | | val sHead = |
| | | "<html><head><meta name=\"viewport\" content=\"width=device-width, " + "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />" + "<style>img{max-width:100% !important;height:auto !important;}</style>" + "<style>body{max-width:100% !important;}</style>" + "</head><body>" |
| | | webView!!.loadDataWithBaseURL( |
| | | null, |
| | | sHead + briefIntroduction, |
| | | "text/html", |
| | | "utf-8", |
| | | null |
| | | ) |
| | | chapterList.addAll(list) |
| | | chapterAdapter.notifyDataSetChanged() |
| | | courseList.addAll(list2) |
| | | courseAdapter.notifyDataSetChanged() |
| | | if (chargeType == 3) |
| | | tv_send.visible() |
| | | if (chargeType == 1||isBuy == 1||(chargeType == 2&&isVip == 1)){ |
| | | tv_action.text = "立即学习" |
| | | }else{ |
| | | val s = "¥ %s 立即购买".format(generalPrice!!) |
| | | tv_action.text = SpanBuilder(s).size(0,1,12).size(2,generalPrice.length+2,21).build() |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private fun startVideo(){ |
| | | showDialog() |
| | | HttpManager.startTrain(id).request(this){_,data-> |
| | | startActivity<PreLoadActivity>("course" to data) |
| | | // startActivity<VideoDetailActivity>("course" to data) |
| | | private fun scroll2Position(position:Int){ |
| | | scrollByTab = true |
| | | timer?.cancel() |
| | | when(position){ |
| | | 0->{ |
| | | scrollView.smoothScrollTo(0,0,SCROLL_DURATION) |
| | | } |
| | | 1->{ |
| | | scrollView.smoothScrollTo(0,tv_1.top,SCROLL_DURATION) |
| | | } |
| | | 2->{ |
| | | scrollView.smoothScrollTo(0,tv_2.top,SCROLL_DURATION) |
| | | } |
| | | } |
| | | timer = object :CountDownTimer(SCROLL_DURATION.toLong(),SCROLL_DURATION.toLong()){ |
| | | override fun onTick(p0: Long) { |
| | | } |
| | | |
| | | override fun onFinish() { |
| | | scrollByTab = false |
| | | } |
| | | }.start() |
| | | } |
| | | |
| | | private fun checkTab(i: Int){ |
| | | when (i) { |
| | | 0 -> { |
| | | cb_intro.textColorResource = R.color.textColor |
| | | cb_intro.setTextSize(TypedValue.COMPLEX_UNIT_SP,21f) |
| | | iv_tab_1.visible() |
| | | cb_chapter.textColorResource = R.color.textColor99 |
| | | cb_chapter.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_2.gone() |
| | | cb_push.textColorResource = R.color.textColor99 |
| | | cb_push.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_3.gone() |
| | | } |
| | | 1 -> { |
| | | cb_chapter.textColorResource = R.color.textColor |
| | | cb_chapter.setTextSize(TypedValue.COMPLEX_UNIT_SP,21f) |
| | | iv_tab_2.visible() |
| | | cb_intro.textColorResource = R.color.textColor99 |
| | | cb_intro.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_1.gone() |
| | | cb_push.textColorResource = R.color.textColor99 |
| | | cb_push.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_3.gone() |
| | | } |
| | | else -> { |
| | | cb_push.textColorResource = R.color.textColor |
| | | cb_push.setTextSize(TypedValue.COMPLEX_UNIT_SP,21f) |
| | | iv_tab_3.visible() |
| | | cb_intro.textColorResource = R.color.textColor99 |
| | | cb_intro.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_1.gone() |
| | | cb_chapter.textColorResource = R.color.textColor99 |
| | | cb_chapter.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f) |
| | | iv_tab_2.gone() |
| | | } |
| | | } |
| | | } |
| | | |
| | | @SuppressLint("SetTextI18n") |
| | | private fun getDetail() { |
| | | HttpManager.queryCourseInfo(id) |
| | | .request(this) { _, data -> |
| | | course = data |
| | | data?.apply { |
| | | banner.setImageURI(coverImg) |
| | | tv_name.text = courseName |
| | | iv_collected.imageResource = if (isCollect == "1") R.mipmap.star_red else R.mipmap.star_empty |
| | | tv_time.text = "${time}|H${difficulty}" |
| | | tv_type.text = typeName |
| | | tv_info.text = introduce |
| | | |
| | | if (isFree == 1||isBuy == 1){ |
| | | tv_start.visible() |
| | | }else{ |
| | | tv_tip.visible() |
| | | tv_tip.text = "购买后“${typeName}”相关课程均可查看;\n长期有效,我们将持续为您更新。" |
| | | ll_bottom_1.visible() |
| | | tv_price.text = SpanBuilder("¥%.2f".format(price.toDouble())).size(0,1,18).build() |
| | | private fun getData(isSend:Boolean) { |
| | | HttpManager.confirmOrder(data?.id?:"").request(this){_,data-> |
| | | if (isSend){ |
| | | SendConfirmDialog.show(supportFragmentManager,data?.generalPrice?:"0.0",object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | startActivity<BuyCourseActivity>("isSend" to isSend,"data" to data) |
| | | } |
| | | videoList.clear() |
| | | videoList.addAll(videos) |
| | | videoAdapter.notifyDataSetChanged() |
| | | |
| | | courseList.clear() |
| | | courseList.addAll(recommendCourse) |
| | | courseAdapter.notifyDataSetChanged() |
| | | if (courseList.isNullOrEmpty()) |
| | | tv_2.gone() |
| | | } |
| | | } |
| | | }) |
| | | }else |
| | | startActivityForResult<BuyCourseActivity>(1,"isSend" to isSend,"data" to data) |
| | | } |
| | | } |
| | | |
| | | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
| | | super.onActivityResult(requestCode, resultCode, data) |
| | | if (resultCode == RESULT_OK){ |
| | | this.data?.isBuy = 1 |
| | | tv_action.text = "立即学习" |
| | | } |
| | | } |
| | | } |