补充缺失的import;一些其它修改。

This commit is contained in:
2026-01-22 09:31:01 +08:00
parent a06c7abfc8
commit 4d5db99903

View File

@@ -2,6 +2,9 @@ package cn.shuto.feishuapi;
import android.view.View;
import java.util.Map;
import java.util.HashMap;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
@@ -16,13 +19,14 @@ import org.json.JSONObject;
*/
public class ShutoApi extends CordovaPlugin {
private static final String TAG = "ShutoApi";
private JSONObject userInfo;
// 保存事件回调上下文
private CallbackContext eventCallbackContext;
// 保存带回调的事件回调映射
private Map<String, EventCallback> eventCallbacks = new HashMap<>();
// 事件回调接口
public interface EventCallback {
void onResult(JSONObject result);
@@ -54,9 +58,9 @@ public class ShutoApi extends CordovaPlugin {
@Override
public void run() {
cordova.getActivity().moveTaskToBack(true);
callbackContext.success();
}
});
callbackContext.success();
}
private void registerEvent(CallbackContext callbackContext) {
@@ -70,12 +74,15 @@ public class ShutoApi extends CordovaPlugin {
}
private void getUserInfo(CallbackContext callbackContext) {
// TODO: Implement getUserInfo method
callbackContext.success();
callbackContext.success(this.userInfo);
}
public void setUserInfo(JSONObject userInfo) {
this.userInfo = userInfo;
}
// 触发导航到指定路由的事件
private void navigateToRoute(String route, JSONObject parameters) {
public void navigateToRoute(String route, JSONObject parameters) {
try {
JSONObject data = new JSONObject();
data.put("route", route);
@@ -91,11 +98,11 @@ public class ShutoApi extends CordovaPlugin {
}
// 触发通用事件
private void fireEvent(String type, JSONObject parameters) {
public void fireEvent(String type, JSONObject parameters) {
if (this.eventCallbackContext == null) {
return;
}
LOG.d(TAG, "type: " + type + ", params: " + parameters);
try {
// 创建事件数据
JSONObject eventData = new JSONObject();
@@ -123,22 +130,22 @@ public class ShutoApi extends CordovaPlugin {
}
return;
}
try {
String callbackId = java.util.UUID.randomUUID().toString();
if (callback != null) {
eventCallbacks.put(callbackId, callback);
}
JSONObject eventData = new JSONObject();
eventData.put("eventName", eventName);
eventData.put("callbackId", callbackId);
if (parameters != null) {
eventData.put("params", parameters);
}
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, eventData);
pluginResult.setKeepCallback(true);
this.eventCallbackContext.sendPluginResult(pluginResult);
@@ -156,9 +163,9 @@ public class ShutoApi extends CordovaPlugin {
String callbackId = args.getString(0);
JSONObject result = args.optJSONObject(1);
String errorMessage = args.optString(2);
EventCallback callback = eventCallbacks.get(callbackId);
if (callback != null) {
if (errorMessage != null && !errorMessage.isEmpty()) {
callback.onError(errorMessage);
@@ -168,7 +175,7 @@ public class ShutoApi extends CordovaPlugin {
eventCallbacks.remove(callbackId);
}
} catch (JSONException e) {
e.printStackTrace();
LOG.e(TAG, "error", e);
}
}
}