package com.renrenliao.im.ui.activity

import com.renrenliao.im.R
import com.renrenliao.im.base.BaseVMActivity
import com.renrenliao.im.ext.click
import com.renrenliao.im.ext.toast
import com.renrenliao.im.viewmodel.FriendRemarkViewModel
import kotlinx.android.synthetic.main.activity_friendremark.*
import org.koin.androidx.viewmodel.ext.android.getViewModel

/**
 **@ClassName FriendRFemarkActivity
 **@Description
 **@Author gan
 **@Date 2022/6/15 13:13
 **/
class FriendRemarkActivity :BaseVMActivity<FriendRemarkViewModel>(){


    override fun initVM(): FriendRemarkViewModel = getViewModel()

    override fun getLayoutResId(): Int = R.layout.activity_friendremark

    override fun initView() {

        val friendId = intent.getStringExtra("friendId")
        val friendRemark = intent.getStringExtra("friendRemark")
        //先设置传递过来的remark
        et.setText(friendRemark)

        tool_bar.setOnBackListener { onBackPressed() }

        //点击确定提交修改备注
        submit.click {
            val remark = et.text.toString().trim()
            if (remark.isBlank()){
                toast("请输入备注信息")
                return@click
            }
            mViewModel.remark(friendId,remark)
        }
    }

    override fun initData() {

    }


    override fun startObserve() {
        mViewModel.remarkLiveData.observe(this){
            if (it){
                intent.putExtra("data","remark")
                intent.putExtra("buddyRemark",et.text.toString().trim())
                setResult(RESULT_OK,intent)
                finish()
            }
        }
    }
}