mac
2023-11-20 734babb3a7348050fdffe845c560ba8b0b218152
app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java
@@ -27,10 +27,9 @@
import io.dcloud.feature.sdk.Interface.IUniMP;
import io.dcloud.feature.sdk.Interface.IUniMPOnCloseCallBack;
import io.dcloud.feature.unimp.DCUniMPJSCallback;
import io.dcloud.feature.unimp.config.UniMPOpenConfiguration;
/**
 * Created by jlchen on 12/15/21.
 */
public class HDLUniMPSDKManager {
    private static final String TAG = "HDLUniMPSDKManager";
    /**
@@ -102,7 +101,7 @@
            @Override
            public void onClose(String appid) {
                if (AppConfigManage.isDebug()) {
                    HdlLogLogic.print(TAG, "收到小程序通知  被关闭了");
                    HdlLogLogic.print("收到小程序通知  被关闭了");
                }
                //小程序被关闭需要对实例缓存删除操作
                if (mUniMPCaches.containsKey(appid)) {
@@ -120,7 +119,7 @@
            @Override
            public void onUniMPEventReceive(String appid, String event, Object data, DCUniMPJSCallback callback) {
//                handelUniMPEventReceive(appid, event, data, callback);
                HdlLogLogic.print(TAG, "收到小程序通知    event=" + event);
                HdlLogLogic.print("收到小程序通知    event=" + event);
                //暂时通过这个处理小程序同时多条相同的请求
                if (data == null) {
                    return;
@@ -138,7 +137,7 @@
                    //回传数据给小程序
                    JSONObject params = getAppParams();
                    callback.invoke(params);
                    HdlLogLogic.print(TAG, "uni_GetAppParams callback:" + params.toString());
                    HdlLogLogic.print( "uni_GetAppParams callback:" + params.toString());
                } else {
                    //除了统一处理,剩余其它特定场景的事件通知
                    if (onOtherUniMPEventCallBack != null) {
@@ -186,12 +185,12 @@
    public void checkUniMPResource(String uniAppId) {
        //2.不是第一次启动了,先判断wgt包之前有么有部署过
        if (!DCUniMPSDK.getInstance().isExistsApp(uniAppId)) {
            HdlLogLogic.print(TAG, "DCUni wgt之前还没部署过");
            HdlLogLogic.print("DCUni wgt之前还没部署过");
            //之前没部署过重新部署
            hdlReleaseAppResourceToRunPathWithAppid(uniAppId);
//            [self hdlReleaseAppResourceToRunPathWithAppid:uniAppId];
        } else {
            HdlLogLogic.print(TAG, "DCUni wgt已经部署过");
            HdlLogLogic.print("DCUni wgt已经部署过");
        }
    }
@@ -204,7 +203,7 @@
        String wgtPath = mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/" + uniAppId + ".wgt";
        boolean b = fileIsExists(wgtPath);
        if (b) {
            HdlLogLogic.print(TAG, "wgt包本地存在");
            HdlLogLogic.print("wgt包本地存在");
            DCUniMPSDK.getInstance().releaseWgtToRunPathFromePath(uniAppId, wgtPath, new ICallBack() {
                @Override
                public Object onCallBack(int code, Object pArgs) {
@@ -213,13 +212,13 @@
                    } else {
                        //释放wgt失败
                        HdlLogLogic.print(TAG, "资源释放失败");
                        HdlLogLogic.print("资源释放失败");
                    }
                    return null;
                }
            });
        } else {
            HdlLogLogic.print(TAG, "wgt包本地不存在");
            HdlLogLogic.print( "wgt包本地不存在");
        }
    }
@@ -245,15 +244,16 @@
    /**
     * 打开小程序
     *
     * @param uniAppId 小程序ID
     * @param path     指定路径
     *                 例:pages/component/scroll-view/scroll-view?a=1&b=2&c=3
     * @param callBack 监听小程序OtherUniMPEvent事件
     * @param uniAppId   小程序ID
     * @param path       指定路径
     *                   例:pages/component/scroll-view/scroll-view?a=1&b=2&c=3
     * @param jsonObject 附加数据
     * @param callBack   监听小程序OtherUniMPEvent事件
     */
    public void openUniMP(String uniAppId, String path, IOnOtherUniMPEventCallBack callBack) {
    public void openUniMP(String uniAppId, String path, JSONObject jsonObject, IOnOtherUniMPEventCallBack callBack) {
        if (TextUtils.isEmpty(uniAppId)) {
            HdlThreadLogic.toast(mContext, "uni Id null");
            HdlLogLogic.print(TAG, "小程序ID 不能为空");
            HdlLogLogic.print( "小程序ID 不能为空");
            return;
        }
        try {
@@ -262,9 +262,10 @@
            if (TextUtils.isEmpty(path)) {
                uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId);
            } else {
//                UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
//                uniMPOpenConfiguration.path = path;
                uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, path);
                UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
                uniMPOpenConfiguration.path = path;
                uniMPOpenConfiguration.extraData = jsonObject;
                uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, uniMPOpenConfiguration);
            }
            mCurrentAppId = uniAppId;//记录当前小程序
            mUniMPCaches.put(uniMP.getAppid(), uniMP);
@@ -272,7 +273,7 @@
            e.printStackTrace();
            HdlThreadLogic.toast(HDLApp.getInstance(), R.string.uni_open_error);
            initDCUniMPSDK(HDLApp.getInstance());
            HdlLogLogic.print(TAG, "打开失败" + e.getMessage());
            HdlLogLogic.print("打开失败===" + e.getMessage());
        }
    }
@@ -291,7 +292,7 @@
            @Override
            public void onInitFinished(boolean b) {
                HdlLogLogic.print("unimp", "UniMPSDK 初始化完成----" + b);
                HdlLogLogic.print("UniMPSDK 初始化完成----" + b);
            }
        });
@@ -314,19 +315,19 @@
     */
    public void openUniMP(String uniAppId, JSONObject arguments, IOnOtherUniMPEventCallBack callBack) {
        if (TextUtils.isEmpty(uniAppId)) {
            HdlLogLogic.print(TAG, "小程序ID 不能为空");
            HdlLogLogic.print("小程序ID 不能为空");
            return;
        }
        try {
            setOnOtherUniMPEventCallBack(callBack);
//            UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
//            uniMPOpenConfiguration.extraData = arguments;
            uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, arguments);
            UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
            uniMPOpenConfiguration.extraData = arguments;
            uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, uniMPOpenConfiguration);
            mCurrentAppId = uniAppId;//记录当前小程序
            mUniMPCaches.put(uniMP.getAppid(), uniMP);
        } catch (Exception e) {
            e.printStackTrace();
            HdlLogLogic.print(TAG, "打开失败" + e.getMessage());
            HdlLogLogic.print( "打开失败===" + e.getMessage());
        }
    }
@@ -343,12 +344,12 @@
        if (mUniMPCaches.containsKey(uniAppId)) {
            if (mUniMPCaches.get(uniAppId) != null) {
                mUniMPCaches.get(uniAppId).sendUniMPEvent(event, data);
                HdlLogLogic.print(TAG, "发送通知成功:event:" + event + " data:" + new Gson().toJson(data));
                HdlLogLogic.print("发送通知成功:event:" + event + " data:" + new Gson().toJson(data));
            } else {
                HdlLogLogic.print(TAG, "发送失败,小程序对象为空:" + uniAppId);
                HdlLogLogic.print("发送失败,小程序对象为空:" + uniAppId);
            }
        } else {
            HdlLogLogic.print(TAG, "发送失败,找不到对应的小程序:" + uniAppId);
            HdlLogLogic.print( "发送失败,找不到对应的小程序:" + uniAppId);
        }
    }
@@ -362,7 +363,7 @@
     */
    public void sendUniMPEventToCurrentOpenAppId(String event, Object data) {
        if (TextUtils.isEmpty(mCurrentAppId)) {
            HdlLogLogic.print(TAG, "当前没打开的小程序");
            HdlLogLogic.print("当前没打开的小程序");
            return;
        }
        sendUniMPEvent(mCurrentAppId, event, data);
@@ -390,7 +391,7 @@
    public void setOnOtherUniMPEventCallBack(IOnOtherUniMPEventCallBack onOtherUniMPEventCallBack) {
        this.onOtherUniMPEventCallBack = onOtherUniMPEventCallBack;
        HdlLogLogic.print("onOtherUniMPEventCallBack", "set callback");
        HdlLogLogic.print("onOtherUniMPEventCallBack set callback");
    }
    /**
@@ -401,7 +402,7 @@
    public void checkRemoveOtherUniMPEventCallBack(IOnOtherUniMPEventCallBack onOtherUniMPEventCallBack) {
        if (this.onOtherUniMPEventCallBack == onOtherUniMPEventCallBack) {
            this.onOtherUniMPEventCallBack = null;
            HdlLogLogic.print("onOtherUniMPEventCallBack", "remove callback");
            HdlLogLogic.print("onOtherUniMPEventCallBack remove callback");
        }
    }