Merge branch 'master' into github-master
commit
52cdc4a3df
|
@ -1,3 +1,5 @@
|
|||
## 0.6.0
|
||||
增加api接口
|
||||
## 0.5.0
|
||||
## 0.4.0
|
||||
支持小程序最新依赖
|
||||
|
|
|
@ -12,6 +12,13 @@ buildscript {
|
|||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/finogeeks/"
|
||||
credentials {
|
||||
username "gradle"
|
||||
password "ftjk@@123321"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/applet/"
|
||||
credentials {
|
||||
|
@ -34,6 +41,13 @@ rootProject.allprojects {
|
|||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/finogeeks/"
|
||||
credentials {
|
||||
username "gradle"
|
||||
password "ftjk@@123321"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/applet/"
|
||||
credentials {
|
||||
|
@ -77,6 +91,6 @@ kapt {
|
|||
}
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.finogeeks.lib:finapplet:+'
|
||||
implementation 'com.finogeeks.lib:finapplet:2.1.17'
|
||||
|
||||
}
|
||||
|
|
|
@ -19,81 +19,81 @@ import io.flutter.plugin.common.MethodChannel.Result;
|
|||
import io.flutter.plugin.common.PluginRegistry;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
|
||||
/** MopPlugin */
|
||||
/**
|
||||
* MopPlugin
|
||||
*/
|
||||
public class MopPlugin implements MethodCallHandler {
|
||||
private static final String LOG_TAG = MopPlugin.class.getSimpleName();
|
||||
private static final String LOG_TAG = MopPlugin.class.getSimpleName();
|
||||
|
||||
private static final String CHANNEL = "mop";
|
||||
private PluginRegistry.Registrar registrar;
|
||||
private FlutterInterface flutterInterface;
|
||||
private MopPluginDelegate delegate;
|
||||
private static final String CHANNEL = "mop";
|
||||
private PluginRegistry.Registrar registrar;
|
||||
private FlutterInterface flutterInterface;
|
||||
private MopPluginDelegate delegate;
|
||||
|
||||
|
||||
/**
|
||||
* Plugin registration.
|
||||
*/
|
||||
public static void registerWith(Registrar registrar) {
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
|
||||
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
|
||||
final MopPlugin instance = new MopPlugin(registrar, delegate);
|
||||
channel.setMethodCallHandler(instance);
|
||||
final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugins.mop.finogeeks.com/mop_event");
|
||||
MopEventStream mopEventStream = new MopEventStream();
|
||||
eventChannel.setStreamHandler(mopEventStream);
|
||||
MopPluginService.getInstance().initialize(registrar.activity(), mopEventStream, channel);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin registration.
|
||||
*/
|
||||
public static void registerWith(Registrar registrar) {
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
|
||||
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
|
||||
final MopPlugin instance = new MopPlugin(registrar,delegate);
|
||||
channel.setMethodCallHandler(instance);
|
||||
final EventChannel eventChannel=new EventChannel(registrar.messenger(),"plugins.mop.finogeeks.com/mop_event");
|
||||
MopEventStream mopEventStream = new MopEventStream();
|
||||
eventChannel.setStreamHandler(mopEventStream);
|
||||
MopPluginService.getInstance().initialize(registrar.activity(),mopEventStream);
|
||||
MopPlugin(PluginRegistry.Registrar registrar, MopPluginDelegate delegate) {
|
||||
this.registrar = registrar;
|
||||
this.flutterInterface = new FlutterInterface();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, final Result result) {
|
||||
registrar.addActivityResultListener(delegate);
|
||||
ICallback callback = new ICallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object data) {
|
||||
Map<String, Object> obj = new HashMap<String, Object>();
|
||||
|
||||
MopPlugin(PluginRegistry.Registrar registrar,MopPluginDelegate delegate) {
|
||||
this.registrar = registrar;
|
||||
this.flutterInterface = new FlutterInterface();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
obj.put("success", true);
|
||||
if (data != null)
|
||||
obj.put("data", data);
|
||||
obj.put("retMsg", "ok");
|
||||
result.success(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, final Result result) {
|
||||
registrar.addActivityResultListener(delegate);
|
||||
ICallback callback = new ICallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object data) {
|
||||
Map<String,Object> obj = new HashMap<String,Object>();
|
||||
@Override
|
||||
public void onFail(Object error) {
|
||||
Map<String, Object> obj = new HashMap<String, Object>();
|
||||
obj.put("success", false);
|
||||
obj.put("retMsg", error == null ? "" : error);
|
||||
result.success(obj);
|
||||
}
|
||||
|
||||
obj.put("success",true);
|
||||
if (data != null)
|
||||
obj.put("data",data);
|
||||
obj.put("retMsg","ok");
|
||||
result.success(obj);
|
||||
}
|
||||
@Override
|
||||
public void onCancel(Object cancel) {
|
||||
result.notImplemented();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Object error) {
|
||||
Map<String,Object> obj = new HashMap<String,Object>();
|
||||
obj.put("success",false);
|
||||
obj.put("retMsg",error==null?"":error);
|
||||
result.success(obj);
|
||||
}
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode) {
|
||||
|
||||
@Override
|
||||
public void onCancel(Object cancel) {
|
||||
result.notImplemented();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode) {
|
||||
|
||||
}
|
||||
};
|
||||
Log.d(LOG_TAG,"mopplugin: invoke " + call.method);
|
||||
Event event= new Event(call.method,call.arguments,callback);
|
||||
delegate.setEvent(event);
|
||||
this.flutterInterface.invokeHandler(event);
|
||||
}
|
||||
};
|
||||
Log.d(LOG_TAG, "mopplugin: invoke " + call.method);
|
||||
Event event = new Event(call.method, call.arguments, callback);
|
||||
delegate.setEvent(event);
|
||||
this.flutterInterface.invokeHandler(event);
|
||||
// if (call.method.equals("getPlatformVersion")) {
|
||||
// result.success("Android " + android.os.Build.VERSION.RELEASE);
|
||||
// } else {
|
||||
// result.notImplemented();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@ package com.finogeeks.mop.api;
|
|||
import android.app.Activity;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.finogeeks.mop.api.mop.AppletHandlerModule;
|
||||
import com.finogeeks.mop.api.mop.AppletManageModule;
|
||||
import com.finogeeks.mop.api.mop.AppletModule;
|
||||
import com.finogeeks.mop.api.mop.BaseModule;
|
||||
import com.finogeeks.mop.api.mop.ExtensionApiModule;
|
||||
import com.finogeeks.mop.interfaces.Event;
|
||||
import com.finogeeks.mop.interfaces.IApi;
|
||||
|
||||
|
@ -29,6 +32,7 @@ public class ApisManager {
|
|||
mActivity = activity;
|
||||
initSdkApi(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* api功能调用
|
||||
*
|
||||
|
@ -42,6 +46,7 @@ public class ApisManager {
|
|||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* api功能调用
|
||||
*
|
||||
|
@ -59,7 +64,9 @@ public class ApisManager {
|
|||
private void initSdkApi(Activity activity) {
|
||||
add(new BaseModule(activity));
|
||||
add(new AppletModule(activity));
|
||||
|
||||
add(new AppletManageModule(activity));
|
||||
add(new AppletHandlerModule(activity));
|
||||
add(new ExtensionApiModule(activity));
|
||||
}
|
||||
|
||||
private void add(IApi api) {
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
package com.finogeeks.mop.api.mop;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||
import com.finogeeks.lib.applet.page.view.moremenu.MoreMenuItem;
|
||||
import com.finogeeks.lib.applet.sdk.api.IAppletHandler;
|
||||
import com.finogeeks.mop.api.BaseApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
import com.finogeeks.mop.utils.GsonUtil;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class AppletHandlerModule extends BaseApi {
|
||||
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public AppletHandlerModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"registerAppletHandler"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String event, Map param, ICallback callback) {
|
||||
Log.d("AppletHandlerModule", "registerAppletHandler");
|
||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||
FinAppClient.INSTANCE.getAppletApiManager().setAppletHandler(new IAppletHandler() {
|
||||
@Override
|
||||
public void shareAppMessage(@NotNull String s, @Nullable Bitmap bitmap, @NotNull IAppletCallback iAppletCallback) {
|
||||
Log.d("MopPlugin", "shareAppMessage:" + s);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("appletInfo", GsonUtil.gson.fromJson(s, new TypeToken<Map<String, Object>>() {
|
||||
}.getType()));
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:forwardApplet", params, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
iAppletCallback.onSuccess(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||
iAppletCallback.onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
iAppletCallback.onFailure();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, String> getUserInfo() {
|
||||
Log.d("AppletHandlerModule", "getUserInfo");
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
final Map<String, String>[] ret = new Map[1];
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:getUserInfo", null, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
ret[0] = (Map<String, String>) result;
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (ret[0].size() > 0)
|
||||
return ret[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<MoreMenuItem> getRegisteredMoreMenuItems(@NotNull String s) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
List<MoreMenuItem> moreMenuItems = new ArrayList<>();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("appId", s);
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:getCustomMenus", params, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
List<Map<String, Object>> ret = (List<Map<String, Object>>) result;
|
||||
if (ret != null) {
|
||||
for (Map<String, Object> map : ret) {
|
||||
moreMenuItems.add(new MoreMenuItem((Integer) map.get("menuId"), 0, (String) map.get("title"), true));
|
||||
}
|
||||
}
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return moreMenuItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegisteredMoreMenuItemClicked(@NotNull String s, int i) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("appId", s);
|
||||
params.put("menuId", i);
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:onCustomMenuClick", params);
|
||||
});
|
||||
}
|
||||
});
|
||||
callback.onSuccess(null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.finogeeks.mop.api.mop;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||
import com.finogeeks.lib.applet.db.entity.FinApplet;
|
||||
import com.finogeeks.mop.api.BaseApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class AppletManageModule extends BaseApi {
|
||||
|
||||
public AppletManageModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"currentApplet", "closeAllApplets", "clearApplets"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String event, Map param, ICallback callback) {
|
||||
if (event.equals("currentApplet")) {
|
||||
String appId = FinAppClient.INSTANCE.getAppletApiManager().getCurrentAppletId();
|
||||
if (appId != null) {
|
||||
FinApplet applet = FinAppClient.INSTANCE.getAppletApiManager().getUsedApplet(appId);
|
||||
if (applet != null) {
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
res.put("appId", applet.getId());
|
||||
res.put("name", applet.getName());
|
||||
res.put("icon", applet.getIcon());
|
||||
res.put("description", applet.getDescription());
|
||||
res.put("version", applet.getVersion());
|
||||
res.put("thumbnail", applet.getThumbnail());
|
||||
callback.onSuccess(res);
|
||||
} else {
|
||||
callback.onSuccess(null);
|
||||
}
|
||||
} else {
|
||||
callback.onSuccess(null);
|
||||
}
|
||||
} else if (event.equals("closeAllApplets")) {
|
||||
FinAppClient.INSTANCE.finishAllRunningApplets();
|
||||
callback.onSuccess(null);
|
||||
} else if (event.equals("clearApplets")) {
|
||||
FinAppClient.INSTANCE.getAppletApiManager().clearApplets();
|
||||
callback.onSuccess(null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ public class AppletModule extends BaseApi {
|
|||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, sequence, null);
|
||||
}
|
||||
} else {
|
||||
Log.d("MopPlugin", "openApplet:params:" + param);
|
||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, params);
|
||||
}
|
||||
callback.onSuccess(new HashMap());
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package com.finogeeks.mop.api.mop;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||
import com.finogeeks.mop.api.BaseApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
import com.finogeeks.mop.utils.GsonUtil;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
|
||||
public class ExtensionApiModule extends BaseApi {
|
||||
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public ExtensionApiModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"registerExtensionApi"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String s, Map param, ICallback iCallback) {
|
||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||
String name = (String) param.get("name");
|
||||
FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) {
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{name};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String s, JSONObject jsonObject, com.finogeeks.lib.applet.interfaces.ICallback iCallback) {
|
||||
Log.d("MopPlugin", "invoke extensionApi:" + s + ",params:" + jsonObject);
|
||||
Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class);
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:" + name, params, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
String json = GsonUtil.gson.toJson(result);
|
||||
JSONObject ret = null;
|
||||
if (json != null && !json.equals("null"))
|
||||
try {
|
||||
ret = new JSONObject(json);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
iCallback.onSuccess(ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||
iCallback.onFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
iCallback.onFail();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
package com.finogeeks.mop.service;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.finogeeks.mop.MopEventStream;
|
||||
import com.finogeeks.mop.api.ApisManager;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class MopPluginService {
|
||||
private final static String TAG = MopPluginService.class.getSimpleName();
|
||||
private static volatile MopPluginService _instance = null;
|
||||
|
@ -17,6 +18,7 @@ public class MopPluginService {
|
|||
|
||||
private Context mContext;
|
||||
private Activity mActivity;
|
||||
private MethodChannel mMethodChannel;
|
||||
|
||||
MopPluginService() {
|
||||
}
|
||||
|
@ -32,20 +34,33 @@ public class MopPluginService {
|
|||
return _instance;
|
||||
}
|
||||
|
||||
public ApisManager getApisManager() { return this.apisManager;}
|
||||
public MopEventStream getMopEventStream() {return this.mopEventStream;}
|
||||
public void initialize(Activity activity, MopEventStream mopEventStream) {
|
||||
public ApisManager getApisManager() {
|
||||
return this.apisManager;
|
||||
}
|
||||
|
||||
public MopEventStream getMopEventStream() {
|
||||
return this.mopEventStream;
|
||||
}
|
||||
|
||||
public void initialize(Activity activity, MopEventStream mopEventStream, MethodChannel methodChannel) {
|
||||
this.mopEventStream = mopEventStream;
|
||||
this.mContext = activity.getApplicationContext();
|
||||
this.apisManager = new ApisManager(activity);
|
||||
this.mActivity = activity;
|
||||
this.mMethodChannel = methodChannel;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
public Activity getActivity() {
|
||||
return mActivity;
|
||||
}
|
||||
|
||||
public MethodChannel getMethodChannel() {
|
||||
return mMethodChannel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.finogeeks.mop.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class GsonUtil {
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static Map<String, Object> toMap(Object object) {
|
||||
String str = gson.toJson(object);
|
||||
if (str != null) {
|
||||
return gson.fromJson(str, new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
PODS:
|
||||
- FinApplet (2.0.196)
|
||||
- FinApplet (2.1.5)
|
||||
- Flutter (1.0.0)
|
||||
- mop (0.1.0):
|
||||
- FinApplet
|
||||
- FinApplet (= 2.1.5)
|
||||
- Flutter
|
||||
|
||||
DEPENDENCIES:
|
||||
|
@ -20,9 +20,9 @@ EXTERNAL SOURCES:
|
|||
:path: ".symlinks/plugins/mop/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FinApplet: 629fb114471bb68eea3aace7fd9c28a7ce6326f8
|
||||
FinApplet: adb43373a01ff90832969b1534d40c08344063f6
|
||||
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
|
||||
mop: e3eac9de90d3e331268e9c9e8308e233e540ad1c
|
||||
mop: c0e0dfb65c6a482e47f0fffc9a6576d88e7636b5
|
||||
|
||||
PODFILE CHECKSUM: b66559db98de00d11e349a06f9e603856ed75d6e
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.4.0"
|
||||
version: "0.6.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// MOPAppletDelegate.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOPAppletDelegate : NSObject<FATAppletDelegate>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// MOPAppletDelegate.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import "MOPAppletDelegate.h"
|
||||
#import "MopPlugin.h"
|
||||
|
||||
@implementation MOPAppletDelegate
|
||||
|
||||
- (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion
|
||||
{
|
||||
NSLog(@"forwardAppletWithInfo:%@",contentInfo);
|
||||
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
||||
[channel invokeMethod:@"extensionApi:forwardApplet" arguments:contentInfo result:^(id _Nullable result) {
|
||||
if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ])
|
||||
{
|
||||
completion(FATExtensionCodeFailure,nil);
|
||||
}else
|
||||
{
|
||||
completion(FATExtensionCodeSuccess,result);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSDictionary *)getUserInfoWithAppletInfo:(FATAppletInfo *)appletInfo
|
||||
{
|
||||
NSLog(@"getUserInfoWithAppletInfo");
|
||||
__block NSDictionary *userInfo;
|
||||
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
dispatch_group_enter(group);
|
||||
[channel invokeMethod:@"extensionApi:getUserInfo" arguments:nil result:^(id _Nullable result) {
|
||||
userInfo = result;
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
- (NSArray<id<FATAppletMenuProtocol>> *)customMenusInMoreItemAtPath:(NSString *)path
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)customMenu:(id<FATAppletMenuProtocol>)customMenu didClickAtPath:(NSString *)path
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// MOP_clearApplets.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_clearApplets : MOPBaseApi
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// MOP_clearApplets.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOP_clearApplets.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_clearApplets
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
NSLog(@"clearApplets");
|
||||
[[FATClient sharedClient]clearMemoryCache];
|
||||
[[FATClient sharedClient]clearLocalApplets];
|
||||
success(@{});
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// MOP_closeAllApplets.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_closeAllApplets : MOPBaseApi
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// MOP_closeAllApplets.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOP_closeAllApplets.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_closeAllApplets
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
NSLog(@"closeAllApplets");
|
||||
[[FATClient sharedClient] closeAllApplets];
|
||||
success(@{});
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// MOP_currentApplet.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_currentApplet : MOPBaseApi
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// MOP_currentApplet.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/16.
|
||||
//
|
||||
|
||||
#import "MOP_currentApplet.h"
|
||||
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_currentApplet
|
||||
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
FATAppletInfo *info = [[FATClient sharedClient] currentApplet];
|
||||
if(info != nil)
|
||||
{
|
||||
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
||||
dic[@"appId"] = info.appId;
|
||||
dic[@"name"]= info.appTitle;
|
||||
dic[@"icon"]= info.appAvatar;
|
||||
dic[@"description"]=info.appDescription;
|
||||
dic[@"version"] = info.appVersion;
|
||||
dic[@"thumbnail"]=info.appThumbnail;
|
||||
success(dic);
|
||||
}
|
||||
else
|
||||
{
|
||||
success(@{});
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -26,7 +26,7 @@
|
|||
}
|
||||
}];
|
||||
}else{
|
||||
[[FATClient sharedClient] startRemoteApplet:self.appId sequence:self.sequence startParams:self.params InParentViewController:currentVC transitionStyle:FATTranstionStylePush completion:^(BOOL result, NSError *error) {
|
||||
[[FATClient sharedClient] startRemoteApplet:self.appId sequence:self.sequence startParams:self.params InParentViewController:currentVC transitionStyle:FATTranstionStyleUp completion:^(BOOL result, NSError *error) {
|
||||
NSLog(@"result:%d---error:%@", result, error);
|
||||
if (result){
|
||||
success(@{});
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// MOP_registerAppletHandler.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_registerAppletHandler : MOPBaseApi
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// MOP_registerAppletHandler.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import "MOP_registerAppletHandler.h"
|
||||
#import "MopPlugin.h"
|
||||
#import "MOPAppletDelegate.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_registerAppletHandler
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
NSLog(@"MOP_registerAppletHandler");
|
||||
[[FATClient sharedClient] setDelegate:[[MOPAppletDelegate alloc] init]];
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// MOP_registerExtensionApi.h
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_registerExtensionApi : MOPBaseApi
|
||||
|
||||
@property NSString* name;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// MOP_registerExtensionApi.m
|
||||
// mop
|
||||
//
|
||||
// Created by 康旭耀 on 2020/4/20.
|
||||
//
|
||||
|
||||
#import "MOP_registerExtensionApi.h"
|
||||
#import "MopPlugin.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
|
||||
@implementation MOP_registerExtensionApi
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
NSLog(@"MOP_registerExtensionApi");
|
||||
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
||||
[[FATClient sharedClient] registerExtensionApi:self.name handle:^(id param, FATExtensionApiCallback callback) {
|
||||
NSLog(@"invoke ExtensionApi:");
|
||||
NSLog(@"%@",self.name);
|
||||
NSLog(@"%@",param);
|
||||
NSString* api = [@"extensionApi:" stringByAppendingString:self.name];
|
||||
[channel invokeMethod:api arguments:param result:^(id _Nullable result) {
|
||||
if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ])
|
||||
{
|
||||
callback(FATExtensionCodeFailure,nil);
|
||||
}else
|
||||
{
|
||||
callback(FATExtensionCodeSuccess,result);
|
||||
}
|
||||
}];
|
||||
}];
|
||||
success(@{});
|
||||
}
|
||||
|
||||
@end
|
|
@ -6,5 +6,7 @@
|
|||
|
||||
@interface MopPlugin : NSObject <FlutterPlugin>
|
||||
@property MopEventStream *mopEventStreamHandler;
|
||||
@property FlutterMethodChannel *methodChannel;
|
||||
|
||||
+ (instancetype) instance;
|
||||
@end
|
||||
|
|
|
@ -27,20 +27,27 @@
|
|||
|
||||
|
||||
@implementation MopPlugin
|
||||
|
||||
static MopPlugin *_instance;
|
||||
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
FlutterMethodChannel* channel = [FlutterMethodChannel
|
||||
methodChannelWithName:@"mop"
|
||||
binaryMessenger:[registrar messenger]];
|
||||
MopPlugin* instance = [[MopPlugin alloc] init];
|
||||
[registrar addMethodCallDelegate:instance channel:channel];
|
||||
|
||||
FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]];
|
||||
instance.mopEventStreamHandler = [[MopEventStream alloc] init];
|
||||
[mopEventChannel setStreamHandler:instance.mopEventStreamHandler];
|
||||
|
||||
_instance = [[MopPlugin alloc] init];
|
||||
[registrar addMethodCallDelegate:_instance channel:channel];
|
||||
_instance.methodChannel = channel;
|
||||
|
||||
FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]];
|
||||
_instance.mopEventStreamHandler = [[MopEventStream alloc] init];
|
||||
[mopEventChannel setStreamHandler:_instance.mopEventStreamHandler];
|
||||
}
|
||||
|
||||
+ (instancetype)instance{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
if ([@"getPlatformVersion" isEqualToString:call.method]) {
|
||||
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
|
||||
|
|
|
@ -17,6 +17,6 @@ A new flutter plugin project.
|
|||
s.dependency 'Flutter'
|
||||
s.ios.deployment_target = '8.0'
|
||||
|
||||
s.dependency 'FinApplet'
|
||||
s.dependency 'FinApplet', '2.1.14'
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
class CustomMenu {
|
||||
int menuId;
|
||||
String image;
|
||||
String title;
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{"menuId": menuId, "image": image, "title": title};
|
||||
}
|
||||
|
||||
abstract class AppletHandler {
|
||||
///
|
||||
/// 转发小程序
|
||||
///
|
||||
///
|
||||
///
|
||||
void forwardApplet(Map<String, dynamic> appletInfo);
|
||||
|
||||
///
|
||||
///获取用户信息
|
||||
/// "userId"
|
||||
/// "nickName"
|
||||
/// "avatarUrl"
|
||||
/// "jwt"
|
||||
/// "accessToken"
|
||||
///
|
||||
Future<Map<String, dynamic>> getUserInfo();
|
||||
|
||||
/// 获取自定义菜单
|
||||
Future<List<CustomMenu>> getCustomMenus(String appId);
|
||||
|
||||
///自定义菜单点击处理
|
||||
Future onCustomMenuClick(String appId, int menuId);
|
||||
}
|
90
lib/mop.dart
90
lib/mop.dart
|
@ -1,10 +1,14 @@
|
|||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mop/api.dart';
|
||||
|
||||
typedef MopEventCallback = void Function(dynamic event);
|
||||
typedef MopEventErrorCallback = void Function(dynamic event);
|
||||
|
||||
typedef ExtensionApiHandler = Future Function(dynamic params);
|
||||
|
||||
class Mop {
|
||||
static final Mop _instance = new Mop._internal();
|
||||
MethodChannel _channel;
|
||||
|
@ -12,6 +16,8 @@ class Mop {
|
|||
int eventId = 0;
|
||||
List<Map<String, dynamic>> _mopEventQueye = <Map<String, dynamic>>[];
|
||||
|
||||
Map<String, ExtensionApiHandler> _extensionApis = {};
|
||||
|
||||
factory Mop() {
|
||||
return _instance;
|
||||
}
|
||||
|
@ -20,6 +26,7 @@ class Mop {
|
|||
print('mop: _internal');
|
||||
// init
|
||||
_channel = new MethodChannel('mop');
|
||||
_channel.setMethodCallHandler(_handlePlatformMethodCall);
|
||||
_mopEventChannel = new EventChannel('plugins.mop.finogeeks.com/mop_event');
|
||||
_mopEventChannel.receiveBroadcastStream().listen((dynamic value) {
|
||||
print('matrix: receiveBroadcastStream $value');
|
||||
|
@ -40,6 +47,17 @@ class Mop {
|
|||
return version;
|
||||
}
|
||||
|
||||
Future<dynamic> _handlePlatformMethodCall(MethodCall call) async {
|
||||
print("_handlePlatformMethodCall: method:${call.method}");
|
||||
if (call.method.startsWith("extensionApi:")) {
|
||||
final name = call.method.substring("extensionApi:".length);
|
||||
final handler = _extensionApis[name];
|
||||
if (handler != null) {
|
||||
return await handler(call.arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
/// initialize mop miniprogram engine.
|
||||
|
@ -72,17 +90,71 @@ class Mop {
|
|||
///
|
||||
Future<Map> openApplet(final String appId,
|
||||
{final String path, final String query, final int sequence}) async {
|
||||
Map<String, Object> params;
|
||||
if (path != '') {
|
||||
params = {
|
||||
'appId': appId,
|
||||
'params': {'path': path, 'query': query}
|
||||
};
|
||||
} else {
|
||||
params = {'appId': appId};
|
||||
}
|
||||
Map<String, Object> params = {'appId': appId};
|
||||
Map param = {};
|
||||
if (path != null) param["path"] = path;
|
||||
if (query != null) param["query"] = query;
|
||||
if (param.length > 0) params["params"] = param;
|
||||
if (sequence != null) params["sequence"] = sequence;
|
||||
final Map ret = await _channel.invokeMethod('openApplet', params);
|
||||
return ret;
|
||||
}
|
||||
|
||||
///
|
||||
/// get current using applet
|
||||
/// 获取当前正在使用的小程序信息
|
||||
/// {appId,name,icon,description,version,thumbnail}
|
||||
///
|
||||
///
|
||||
Future<Map<String, dynamic>> currentApplet() async {
|
||||
final ret = await _channel.invokeMapMethod("currentApplet");
|
||||
return Map<String, dynamic>.from(ret);
|
||||
}
|
||||
|
||||
///
|
||||
/// close all running applets
|
||||
/// 关闭当前打开的所有小程序
|
||||
///
|
||||
Future closeAllApplets() async {
|
||||
return await _channel.invokeMethod("closeAllApplets");
|
||||
}
|
||||
|
||||
///
|
||||
/// clear applets cache
|
||||
/// 清除缓存的小程序
|
||||
///
|
||||
Future clearApplets() async {
|
||||
return await _channel.invokeMethod("clearApplets");
|
||||
}
|
||||
|
||||
///
|
||||
/// register handler to provide custom info or behaviour
|
||||
/// 注册小程序事件处理
|
||||
///
|
||||
void registerAppletHandler(AppletHandler handler) {
|
||||
_extensionApis["forwardApplet"] = (params) async {
|
||||
handler.forwardApplet(Map<String, dynamic>.from(params["appletInfo"]));
|
||||
};
|
||||
_extensionApis["getUserInfo"] = (params) {
|
||||
return handler.getUserInfo();
|
||||
};
|
||||
_extensionApis["getCustomMenus"] = (params) async {
|
||||
final res = await handler.getCustomMenus(params["appId"]);
|
||||
res?.map((e) => e.toJson());
|
||||
return res;
|
||||
};
|
||||
_extensionApis["onCustomMenuClick"] = (params) {
|
||||
return handler.onCustomMenuClick(params["appId"], params["menuId"]);
|
||||
};
|
||||
_channel.invokeMethod("registerAppletHandler");
|
||||
}
|
||||
|
||||
///
|
||||
/// register extension api
|
||||
/// 注册拓展api
|
||||
///
|
||||
void registerExtensionApi(String name, ExtensionApiHandler handler) {
|
||||
_extensionApis[name] = handler;
|
||||
_channel.invokeMethod("registerExtensionApi", {"name": name});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
name: mop
|
||||
description: A Finogeeks MiniProgram Flutter SDK.
|
||||
version: 0.5.0
|
||||
authors:
|
||||
- finogeeks <finogeeks.mop@gmail.com>
|
||||
- kang34814 <kang34814@gmail.com>
|
||||
version: 0.6.0
|
||||
homepage: https://github.com/finogeeks/mop-flutter-sdk
|
||||
|
||||
environment:
|
||||
|
|
Loading…
Reference in New Issue