package com.bc_chat.bc_base.view

import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.view.Gravity
import android.view.ViewGroup
import com.alibaba.android.arouter.launcher.ARouter
import com.bc_chat.bc_base.R
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.bc_base.databinding.DialogMenuSelectBinding
import com.bc_chat.bc_base.utils.Const
import com.zhaohaoting.framework.abs.AbsDialogFragment
import com.zhaohaoting.framework.abs.contract.BaseContract
import com.zhaohaoting.framework.utils.DensityUtil


/**
 * author：Created by zhaohaoting on 2019/2/28
 * email：526309416@qq.com
 * desc：首页菜单
 */
class MenuDialogFragment : AbsDialogFragment<BaseContract.BasePresenter>() {

    private val binding by lazy {
        rootDataBinding as DialogMenuSelectBinding
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(DialogFragment.STYLE_NORMAL, R.style.menu_dialog_style)
    }

    override fun onStart() {
        super.onStart()
        val attributes = dialog.window.attributes
        dialog.window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        attributes.x = DensityUtil.dip2px(activity, 10f)
        attributes.y = DensityUtil.dip2px(activity, 48f)
        attributes.gravity = Gravity.TOP or Gravity.RIGHT
        attributes.dimAmount = 0.3f
        dialog.window.attributes = attributes
    }

    override fun initialize() {
        binding.tvAddFriend.setOnClickListener {
            AddFriendDialogFragment().show(activity.supportFragmentManager)
            dismissAllowingStateLoss()
        }
        binding.tvAddGroupChat.setOnClickListener {
            ARouter.getInstance().build(RouteConfig.CHOOSE_FRIEND_ACTIVITY).withString("action", Const.Action.CREATE_GROUP)
                    .navigation()
            dismissAllowingStateLoss()
        }
        binding.tvScanner.setOnClickListener {
            judgePermission(Const.Permission.Key.STORAGE_CAMERA, *Const.Permission.Value.STORAGE_CAMERA)
        }
    }

    override fun requestPermissionSuccess(requestCode: Int) {
        ARouter.getInstance().build(RouteConfig.CAPTURE_ACTIVITY).navigation(activity, Const.RequestCode.SCANNER)
        dismissAllowingStateLoss()
    }

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

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