package com.renrenliao.im.ui.activity

import android.content.Intent
import com.renrenliao.im.R
import com.renrenliao.im.base.BaseVMActivity
import com.renrenliao.im.bean.UserInfo
import com.renrenliao.im.viewmodel.FriendAddViewModel
import kotlinx.android.synthetic.main.activity_friendadd.*
import org.koin.androidx.viewmodel.ext.android.getViewModel

/**
 **@ClassName FriendAddActivity
 **@Description
 **@Author gan
 **@Date 2022/6/14 18:05
 **/
class FriendAddActivity:BaseVMActivity<FriendAddViewModel>() {


    override fun initVM(): FriendAddViewModel = getViewModel()

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

    override fun initView() {
        val userInfo = intent.getParcelableExtra<UserInfo>("userinfo")

        tool_bar.setOnBackListener { onBackPressed() }
        submit.setOnClickListener {
            addFriend(userInfo.userUid)
        }
    }

    private fun addFriend(friendId:String){
        val say = et_say.text.toString().trim()
        val beizhu = et_beizhu.text.toString().trim()

        mViewModel.addFriend(friendId,say,beizhu)
    }

    override fun initData() {

    }

    override fun startObserve() {
        mViewModel.addFriendLiveData.observe(this){
            if (it){
                val intent = Intent()
                intent.putExtra("data","add")
                setResult(RESULT_OK,intent)
                finish()
            }
        }
    }
}