package com.sobot.moduletest;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;

import com.sobot.common.ui.SobotMarkConfig;
import com.sobot.common.ui.base.SobotBaseActivity;
import com.sobot.common.ui.toast.SobotToastUtil;
import com.sobot.common.utils.SobotCommonApi;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.network.apiUtils.SobotHttpUtils;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.network.http.db.SobotDownloadManager;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotSDCardUtils;
import com.sobot.utils.SobotSharedPreferencesUtil;
import com.sobot.widget.image.photoview.SobotPhotoView;
import com.sobot.widget.loading.SobotLoadingLayout;
import com.sobot.widget.refresh.layout.api.RefreshLayout;
import com.sobot.widget.refresh.layout.footer.ClassicsFooter;
import com.sobot.widget.refresh.layout.header.ClassicsHeader;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import static com.sobot.common.ui.SobotBaseConstant.REQUEST_CODE_PICTURE;

public class MainActivity extends SobotBaseActivity {

    private ImageView img;
    private SobotPhotoView img2;
    private SobotLoadingLayout loadinglayout ;


    @Override
    protected int getContentViewResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {

        SobotToastUtil.showCustomToast(getSobotBaseActivity(), "sdafdsafsadfasdfsdaf");
        SobotCommonApi.setSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP, true);
        setTitle("ddddd");
        SobotBitmapUtil.display(getSobotBaseActivity(), "https://img.sobot.com/console/common/face/admin.png", getAvatarImageView(true));
        img = findViewById(R.id.img);
        SobotBitmapUtil.display(this, "https://img.sobot.com/console/common/face/admin.png", img, R.mipmap.ic_launcher, R.mipmap.ic_launcher);
        img2 = findViewById(R.id.img2);

//        img2.setScaleType(ImageView.ScaleType.FIT_XY);
        SobotBitmapUtil.display(this,"https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20220421/34a466420d78fa1172bc0acd85166745/9410b53be86b4d589c61c60f6aee2461.jpeg",img2);
//        File save=new File(SobotSDCardUtils.getSDCardRootPath(MainActivity.this)+"/9410b53be86b4d589c61c60f6aee2461.jpeg");
//        HttpBaseUtils.getInstance().download("https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20220421/34a466420d78fa1172bc0acd85166745/9410b53be86b4d589c61c60f6aee2461.jpeg", save, new HttpBaseUtils.FileCallBack() {
//            @Override
//            public void onResponse(File result) {
//                Bitmap bitmap= SobotBitmapUtil.compress(result.getPath(),MainActivity.this,true);
//                img2.setImageBitmap(bitmap);
//            }
//
//            @Override
//            public void onError(Exception e, String msg, int responseCode) {
//                SobotLogUtils.i("下载失败："+msg);
//            }
//
//            @Override
//            public void inProgress(int progress) {
//SobotLogUtils.i("下载进度："+progress);
//            }
//        });
//
//        SobotDownloadManager.getInstance().get("sdfsdfds");
//
//        Map<String, String> map = new HashMap<>();
//        map.put("number", "142160000");
//        map.put("companyId", "1eae128b7e394aedafd28828bfa84767");
//        map.put("agentId", "969a7ee9fd4c42f48171b0128df2f16c");
//        map.put("displayNumber", "01051393569");
//        map.put("callWay", "2");
//        map.put("isRecordStereo", "false");
//
//        map.put("agentState", "1");
//        map.put("appId", "a4b246c8b67e4543b3b870ce62f75546");
//        map.put("groupId", "36b0f8eb2de948d99e89c8f0c3d92e68_5");
//        map.put("agentPhoneNum", "18600978969");
//
//        SobotSharedPreferencesUtil.getInstance(this).put("aa",map);
//        Map<String, String> map1=SobotSharedPreferencesUtil.getInstance(this).get("aa",Map.class);
//        SobotSharedPreferencesUtil.getInstance(this).clearAll();
//        Map<String, String> map2=SobotSharedPreferencesUtil.getInstance(this).get("aa",Map.class);
//
//        SobotSharedPreferencesUtil.getInstance(this).put("aa",map);
//        Map<String, String> map3=SobotSharedPreferencesUtil.getInstance(this).get("aa",Map.class);
//        SobotSharedPreferencesUtil.getInstance(this).remove("aa");
//        Map<String, String> map4=SobotSharedPreferencesUtil.getInstance(this).get("aa",Map.class);
//
//        SobotHttpUtils.doPostByJsonString(this, "https://sobot.com/comm/api/4/call/agentOnWork?access_token=c273b74c-3b37-48cf-937f-9c46940cc19d", map, null, new HttpBaseUtils.StringCallBack() {
//            @Override
//            public void onResponse(String result) {
//                SobotLogUtils.i(result);
//            }
//
//            @Override
//            public void onError(Exception e, String msg, int responseCode) {
//
//            }
//
//            @Override
//            public void inProgress(int progress) {
//
//            }
//        });
//        selectPicFromLocal();
//        selectVedioFromLocal();
//        openCamera();

        RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
        refreshLayout.setRefreshHeader(new ClassicsHeader(this));
        refreshLayout.setRefreshFooter(new ClassicsFooter(this));
        refreshLayout.setEnableLoadMore(false);

        loadinglayout=findViewById(R.id.loadinglayout);
        loadinglayout.showContent();
    }

    @Override
    protected void initData() {
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            super.onActivityResult(requestCode, resultCode, data);
            SobotLogUtils.i("多媒体返回的结果：" + requestCode + "--" + resultCode + "--" + data);

            if (resultCode == Activity.RESULT_OK) {
                if (requestCode == REQUEST_CODE_PICTURE) { // 发送本地图片
                    if (data != null && data.getData() != null) {
                        Uri selectedImage = data.getData();
                        if (selectedImage == null) {
                            selectedImage = SobotImageUtils.getUri(data, getBaseContext());
                        }
                        String path = SobotImageUtils.getPath(getSobotBaseActivity(), selectedImage);
                        SobotLogUtils.i("选取的图片地址：" + path);
                    }
                }
            }
            if (cameraFile != null && cameraFile.exists()) {
                SobotLogUtils.i("相机拍照：" + cameraFile.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}