package com.bc_chat.contacts

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.entity.contact.Contacts
import com.bc_chat.bc_base.view.MenuDialogFragment
import com.bc_chat.contacts.databinding.FragmentContactBinding
import com.zhaohaoting.framework.abs.AbsV4Fragment
import com.zhaohaoting.framework.abs.contract.BaseContract

/**
 * author：Created by zhaohaoting on 2019/2/20
 * email：526309416@qq.com
 * desc： 20
 */
@Route(path = RouteConfig.CONTACTS_FRAGMENT)
class ContactFragment : AbsV4Fragment<BaseContract.BasePresenter>(), ContactListFragment.OnLoadDoneListener {

    private val contactsList: ArrayList<Contacts> = arrayListOf()

    override fun onloadDone(contactList: List<Contacts>) {
        this.contactsList.clear()
        this.contactsList.addAll(contactList)
    }

    private val binding by lazy {
        rootDataBinding as FragmentContactBinding
    }

    override fun initialize() {
        val contactListFragment = ContactListFragment()
        contactListFragment.setLoadDoneListener(this)
        addFragment(contactListFragment, R.id.fl_content)
        binding.ivAdd.setOnClickListener {
            MenuDialogFragment().show(fragmentManager)
        }
        binding.ivSearch.setOnClickListener {
            ARouter.getInstance().build(RouteConfig.CONTACT_SEARCH_ACTIVITY).withParcelableArrayList("contactsList", contactsList).navigation()
        }
    }

    override fun initPresenter(): BaseContract.BasePresenter? {
        return null
    }

    override fun getLayoutResId(): Int {
        return R.layout.fragment_contact
    }
}
