package com.bc_chat.im.module;

import android.content.Intent;
import android.support.v4.app.Fragment;

import com.bc_chat.im.activity.MapLocationActivity;

import io.rong.imkit.RongExtension;
import io.rong.imkit.plugin.DefaultLocationPlugin;
import io.rong.imkit.utilities.PermissionCheckUtil;

/**
 * author：Created by zhaohaoting on 2018/11/22
 * email：526309416@qq.com
 * desc：
 */
public class MLocationPlugin extends DefaultLocationPlugin {

    @Override
    public void onClick(Fragment currentFragment, RongExtension extension) {
        String[] permissions = new String[]{"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_NETWORK_STATE"};
        if (PermissionCheckUtil.checkPermissions(currentFragment.getActivity(), permissions)) {
            this.startLocationActivity(currentFragment, extension);
        } else {
            extension.requestPermissionForPluginResult(permissions, 255, this);
        }
    }


    private void startLocationActivity(Fragment fragment, RongExtension extension) {
        Intent intent = new Intent(fragment.getActivity(), MapLocationActivity.class);
        extension.startActivityForPluginResult(intent, 1, this);
    }

}
