package com.bc_chat.contacts.view

import android.widget.AdapterView
import com.alibaba.android.arouter.launcher.ARouter
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.contacts.R
import com.bc_chat.contacts.adapter.ReportAdapter
import com.bc_chat.contacts.databinding.DialogReportBinding
import com.zhaohaoting.framework.abs.AbsDialogFragment
import com.zhaohaoting.framework.abs.contract.BaseContract
import com.zhaohaoting.framework.utils.DensityUtil
import java.util.*

/**
 * author：Created by zhaohaoting on 2019/3/1
 * email：526309416@qq.com
 * desc：举报
 */
class ReportDialogFragment : AbsDialogFragment<BaseContract.BasePresenter>() {

    var onItemClickListener: AdapterView.OnItemClickListener? = null
    private var reportArray: Array<String>? = null

    override fun onStart() {
        super.onStart()
        val attributes = dialog.window.attributes
        attributes.width = (DensityUtil.getScreenWidth(activity) * 0.8).toInt()
        dialog.window.attributes = attributes
    }

    override fun initialize() {
        val binding = rootDataBinding as DialogReportBinding
        reportArray = resources.getStringArray(R.array.report_string_list)
        binding.reportListView.adapter = ReportAdapter(activity, Arrays.asList<String>(*reportArray!!))
        binding.reportListView.onItemClickListener = onItemClickListener
    }

    fun setOnItemSelectListener(listener: (reason: String) -> Unit) {
        onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
            view.isSelected = true
            if (position == 6) {
                ARouter.getInstance().build(RouteConfig.REPORT_OTHER_ACTIVITY).navigation(activity, 241)
            } else {
                listener(reportArray!![position])
            }
            handler.postDelayed({ dismissAllowingStateLoss() }, 500)
        }
    }

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

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