package com.bc_chat.im

import android.net.Uri
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.bc_base.view.MenuDialogFragment
import com.bc_chat.im.chat.MConversationListFragment
import com.bc_chat.im.databinding.FragmentChatBinding
import com.zhaohaoting.framework.abs.AbsV4Fragment
import com.zhaohaoting.framework.abs.contract.BaseContract
import io.rong.imlib.model.Conversation
import kotlinx.android.synthetic.main.header_msgs_conversation.view.*

/**
 * author：Created by zhaohaoting on 2019/2/20
 * email：526309416@qq.com
 * desc：消息 10
 */
@Route(path = RouteConfig.CHAT_FRAGMENT)
class ChatFragment : AbsV4Fragment<BaseContract.BasePresenter>() {

    private val binding by lazy {
        rootDataBinding as FragmentChatBinding
    }

    override fun initialize() {
        val uri = Uri.parse("rong://" + context?.packageName).buildUpon()
                .appendPath("conversationlist")
                .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false") //设置私聊会话是否聚合显示
                .appendQueryParameter(Conversation.ConversationType.GROUP.getName(), "false")//群组
                .appendQueryParameter(Conversation.ConversationType.PUBLIC_SERVICE.getName(), "false")//公共服务号
                .appendQueryParameter(Conversation.ConversationType.APP_PUBLIC_SERVICE.getName(), "false")//订阅号
                .appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "false")//系统
                .build()
        val fragment = MConversationListFragment()
        fragment.uri = uri
        addFragment(fragment, R.id.fl_chat_container)
        binding.ivAddFriend.setOnClickListener {
            MenuDialogFragment().show(getFragmentManager())
        }
//        binding.headLayout?.rl_sys_message!!.setOnClickListener {
//            //系统消息
//            ARouter.getInstance().navigation(ImRongService::class.java).startConversation(context!!, sysMessageConversation.conversationType!!, sysMessageConversation.targetId!!, Const.SERVICE_NAME, null)
//        }
//        headerView?.rl_sys_notice!!.setOnClickListener {
//            //系统消息
//            ARouter.getInstance().navigation(ImRongService::class.java).startConversation(context!!, noticeMessageConversation.conversationType!!, noticeMessageConversation.targetId!!, Const.SERVICE_NOTICE_NAME, null)
//        }
        binding.headLayout.rl_search!!.setOnClickListener {
            ARouter.getInstance().build(RouteConfig.SEARCH_CONVERSATION_ACTIVITY).navigation()
        }
    }

    override fun initPresenter(): BaseContract.BasePresenter? = null

    override fun getLayoutResId(): Int = R.layout.fragment_chat
}
