package com.bc_chat.im.fragment

import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bc_chat.bc_base.utils.gone
import com.bc_chat.im.R
import com.bc_chat.im.adapter.MessageListAdapter
import com.bc_chat.im.adapter.TopMessageListAdapterEx
import com.bc_chat.im.view.SwipeRefreshRecyclerLayout
import io.rong.imkit.RongExtension

/**
 *群主消息
 */
class TopConversationFragmentEx : MyConversationFragment() {

    private var mTargetId: String? = null
    private var lordId: String? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        this.lordId = arguments?.getString("lordId")
        setHistoryMessageCount(100)
        setRemoteMessageCount(100)
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    override fun initFragment(uri: Uri?) {
        super.initFragment(uri)
        this.mTargetId = uri?.getQueryParameter("targetId")
        val mList = view?.findViewById(R.id.recycler_layout) as SwipeRefreshRecyclerLayout
        mList.setBackgroundColor(resources.getColor(R.color.white))
        val extension = view?.findViewById<RongExtension>(R.id.rc_extension)
        extension.gone()
        extension?.onDestroy()
        handler.postDelayed({
            val layoutManager = mList.mRecyclerView.layoutManager
            layoutManager?.scrollToPosition(layoutManager.itemCount - 1)
        }, 150)//延时150ms
    }

    override fun onResolveAdapter(context: Context): MessageListAdapter {
        return TopMessageListAdapterEx(context, lordId!!)
    }
}