package com.bc_chat.im.fragment

import android.net.Uri
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import com.bc_chat.bc_base.utils.Const
import com.bc_chat.bc_base.utils.gone
import com.bc_chat.im.R
import com.bc_chat.im.view.SwipeRefreshRecyclerLayout
import io.rong.imkit.RongExtension
import io.rong.imkit.RongIM
import io.rong.imlib.model.Conversation
import io.rong.imlib.model.Message
import java.util.*


/**
 *
 */
class ConversationFragmentEx : MyConversationFragment() {

    private var mTargetId: String? = null
    private var mConversationType: Conversation.ConversationType? = null

    override fun initFragment(uri: Uri?) {
        super.initFragment(uri)
        val typeStr = uri?.lastPathSegment?.toUpperCase(Locale.US)
        this.mConversationType = Conversation.ConversationType.valueOf(typeStr ?: "")
        this.mTargetId = uri?.getQueryParameter("targetId")
        if (mConversationType == Conversation.ConversationType.SYSTEM && Const.SERVICE_ID.contains(mTargetId!!)) {
            val extension = view?.findViewById<RongExtension>(R.id.rc_extension)
            extension.gone()
            extension?.onDestroy()
        }
        val mList = view?.findViewById(R.id.recycler_layout) as SwipeRefreshRecyclerLayout
        handler.postDelayed({
            val layoutManager = mList.mRecyclerView.layoutManager
            if (layoutManager != null) {
                layoutManager.scrollToPosition(layoutManager.itemCount - 1)
            }
        }, 150)//延时150ms
        if (arguments != null) {
        }
    }
//
//    fun refreshRongExtension() {
//        val rongExtension = view?.findViewById<View>(R.id.rc_extension) as RongExtension
//        rongExtension.setConversation(this.mConversationType, this.mTargetId)
//    }

    override fun onEditTextClick(editText: EditText?) {
        super.onEditTextClick(editText)
    }

    override fun onSendToggleClick(v: View?, text: String?) {
        super.onSendToggleClick(v, text)
    }

    override fun onPluginToggleClick(v: View?, extensionBoard: ViewGroup?) {
        super.onPluginToggleClick(v, extensionBoard)
    }

    override fun onEmoticonToggleClick(v: View?, extensionBoard: ViewGroup?) {
        super.onEmoticonToggleClick(v, extensionBoard)
    }

    override fun onSwitchToggleClick(v: View?, inputBoard: ViewGroup?) {
        super.onSwitchToggleClick(v, inputBoard)
    }

    override fun onVoiceInputToggleTouch(v: View?, event: MotionEvent?) {
        super.onVoiceInputToggleTouch(v, event)
    }
}