CourseCommentActivity.kt 4.18 KB
Newer Older
严久程 committed
1 2
package com.yidianling.course.coursePlay

严久程 committed
3
import android.annotation.SuppressLint
严久程 committed
4 5 6 7 8 9
import android.app.Activity
import android.content.Intent
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import com.alibaba.android.arouter.facade.annotation.Route
严久程 committed
10 11 12
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydlcommon.base.BaseActivity
konghaorui committed
13
import com.ydl.ydlcommon.bean.StatusBarOptions
严久程 committed
14
import com.ydl.ydlcommon.utils.log.LogHelper
严久程 committed
15 16 17
import com.yidianling.common.tools.ToastUtil
import com.yidianling.course.CourseConstants
import com.yidianling.course.R
严久程 committed
18
import com.yidianling.course.net.Command
严久程 committed
19
import com.yidianling.course.net.CourseRetrofitUtils
严久程 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_course_commeny.*

/**
 * @author jiucheng
 * @描述:课程写评价页面
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/7/2
 */
@Route(path = "/course/comment")
class CourseCommentActivity : BaseActivity() {
    private var courseId: String? = null

    companion object {
        private const val COURSE_ID = "course_id"
        fun startActivity(activity: Activity, courseId: String) {
            var intent = Intent(activity, CourseCommentActivity::class.java)
            intent.putExtra(COURSE_ID, courseId)
            activity.startActivity(intent)
        }
    }

konghaorui committed
44 45 46
    override fun getStatusViewOptions(): StatusBarOptions {
        return StatusBarOptions(true, statusBarDarkMode = true)
    }
严久程 committed
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
    override fun layoutResId(): Int {
        return R.layout.activity_course_commeny
    }

    override fun initDataAndEvent() {
        courseId = intent.getStringExtra(COURSE_ID)
        if (TextUtils.isEmpty(courseId)) {
            ToastUtil.toastShort("参数错误,请重试")
            return
        }
        iv_back.setOnClickListener {
            finish()
        }

        tv_left_menu.setOnClickListener {
            if (TextUtils.isEmpty(et_comment.text.toString())) {
                ToastUtil.toastShort("请输入评论内容")
                return@setOnClickListener
            }
            commitReply(et_comment.text.toString())
        }

        et_comment.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(s: Editable?) {
                if (TextUtils.isEmpty(s)) {
                    tv_input_length.text = "0"
严久程 committed
73
                    tv_input_length.setTextColor(resources.getColor(R.color.course_color_B3B3B3))
严久程 committed
74 75
                } else {
                    tv_input_length.text = s!!.length.toString()
严久程 committed
76
                    tv_input_length.setTextColor(resources.getColor(R.color.course_color_242424))
严久程 committed
77 78 79 80 81 82 83 84 85 86 87 88
                }
            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
        })
    }

    //提交评论
严久程 committed
89
    @SuppressLint("CheckResult")
严久程 committed
90 91 92
    private fun commitReply(content: String) {
        showProgressDialog(null)
        val cmd = Command.CourseCommitReply(courseId!!.toInt(), content)
严久程 committed
93
        CourseRetrofitUtils.commitCourseReply(cmd)
严久程 committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ resp ->
                    dismissProgressDialog()
                    if (resp.code == 200) {
                        ToastUtil.toastShort(resp.msg)

                        val h5Params = H5Params(CourseConstants.COURSE_COMMENT_H5 + courseId, "全部评价")
                        NewH5Activity.start(this@CourseCommentActivity, h5Params)

                        this@CourseCommentActivity.finish()
                    } else {
                        ToastUtil.toastShort(resp.msg)
                        LogHelper.getInstance().writeLogSync("提交评论失败:" + resp.msg)
                    }
                }, { t ->
                    dismissProgressDialog()
严久程 committed
111
                    CourseRetrofitUtils.handleError(this, t)
严久程 committed
112 113 114 115
                    LogHelper.getInstance().writeLogSync("提交评论失败:" + t.message)
                })
    }
}