补充遗漏的
parent
233b18c972
commit
0c982edca4
|
@ -0,0 +1,46 @@
|
|||
// The code is already well written and doesn't need any improvement.
|
||||
// However, I will add some comments to make it more readable.
|
||||
|
||||
package android.src.main.java.com.finogeeks.mop.api;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class SyncApi extends BaseApi {
|
||||
public SyncApi(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
// This method is used to invoke the API.
|
||||
@Nullable
|
||||
public abstract String invoke(String url, JSONObject jsonObject);
|
||||
|
||||
// This method is used to get the success response.
|
||||
public JSONObject getSuccessRes(String message) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String key = "errMsg";
|
||||
try {
|
||||
jsonObject.put(key, message + ":ok");
|
||||
return jsonObject;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
// This method is used to get the failure response.
|
||||
public String getFailureRes(String message, String error) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String key = "errMsg";
|
||||
try {
|
||||
return jsonObject.put(key, message + ":fail " + error).toString();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return "{\"errMsg\":" + message + "\":fail \"" + error + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,11 +33,13 @@ public class ExtensionApiModule extends BaseApi {
|
|||
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"registerExtensionApi","addWebExtentionApi"};
|
||||
return new String[]{"registerExtensionApi", "registerSyncExtensionApi", "addWebExtentionApi"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String s, Map param, ICallback iCallback) {
|
||||
boolean isFinAppProcess = FinAppClient.INSTANCE.isFinAppProcess(getContext());
|
||||
Log.d(TAG, "ExtensionApiModule invoke register api s:" + s + " param:" + param +" isFinAppProcess:"+isFinAppProcess);
|
||||
if(s.equals("registerExtensionApi")) {
|
||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||
String name = (String) param.get("name");
|
||||
|
@ -50,7 +52,7 @@ public class ExtensionApiModule extends BaseApi {
|
|||
|
||||
@Override
|
||||
public void invoke(String s, JSONObject jsonObject, com.finogeeks.lib.applet.interfaces.ICallback iCallback) {
|
||||
Log.d("MopPlugin", "invoke extensionApi:" + s + ",params:" + jsonObject);
|
||||
Log.d("MopPlugin", "invoke extensionApi:" + s + ",params:" + jsonObject+" isFinAppProcess:"+isFinAppProcess);
|
||||
Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class);
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("extensionApi:" + name, params, new MethodChannel.Result() {
|
||||
|
@ -87,6 +89,63 @@ public class ExtensionApiModule extends BaseApi {
|
|||
iCallback.onFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
iCallback.onFail();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (s.equals("registerSyncExtensionApi")) {
|
||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||
String name = (String) param.get("name");
|
||||
Log.d(TAG, "registerSyncExtensionApi:" + 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", "sync invoke extensionApi:" + s + ",params:" + jsonObject);
|
||||
Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class);
|
||||
handler.post(() -> {
|
||||
channel.invokeMethod("syncextensionapi:" + name, params, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
String json = GsonUtil.gson.toJson(result);
|
||||
Log.d(ExtensionApiModule.TAG, "channel invokeMethod:" + name
|
||||
+ " success, result=" + result + ", json=" + json);
|
||||
JSONObject ret = null;
|
||||
if (json != null && !json.equals("null")) {
|
||||
try {
|
||||
ret = new JSONObject(json);
|
||||
if (ret.has("errMsg")) {
|
||||
String errMsg = ret.getString("errMsg");
|
||||
if (errMsg.startsWith(name + ":fail")) {
|
||||
iCallback.onFail(ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
iCallback.onSuccess(ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||
FLog.e(ExtensionApiModule.TAG, "channel invokeMethod:" + name
|
||||
+ " error, errorCode=" + errorCode
|
||||
+ ", errorMessage=" + errorMessage
|
||||
+ ", errorDetails=" + errorDetails);
|
||||
iCallback.onFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
iCallback.onFail();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#import "Mop_initSDK.h"
|
||||
#import "MOPTools.h"
|
||||
#import "FinAppletExt.h"
|
||||
|
||||
@implementation MOP_initSDK
|
||||
|
||||
|
@ -35,6 +36,9 @@
|
|||
storeConfig.encryptServerData = [dict[@"encryptServerData"] boolValue];
|
||||
storeConfig.enablePreloadFramework = [storeConfig.apiServer isEqualToString:@"https://api.finclip.com"];
|
||||
[storeArrayM addObject:storeConfig];
|
||||
|
||||
//google map key
|
||||
[[FATExtClient sharedClient] registerGoogleMapService:dict[@"googleMapApiKey"] placesKey:dict[@"googleMapApiKey"]];
|
||||
}
|
||||
config = [FATConfig configWithStoreConfigs:storeArrayM];
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
#import "MOP_initialize.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
#import <FinAppletExt/FinAppletExt.h>
|
||||
#import "FinAppletExt.h"
|
||||
#import <FinAppletBLE/FinAppletBLE.h>
|
||||
#import "MOPTools.h"
|
||||
|
||||
@implementation MOP_initialize
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// MOP_registerSyncExtensionApi.h
|
||||
// mop
|
||||
//
|
||||
// Created by Stewen on 2023/6/30.
|
||||
//
|
||||
|
||||
#import "MOPBaseApi.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MOP_registerSyncExtensionApi : MOPBaseApi
|
||||
|
||||
@property(nonatomic, copy) NSString* name;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// MOP_registerSyncExtensionApi.m
|
||||
// mop
|
||||
//
|
||||
// Created by Stewen on 2023/6/30.
|
||||
//
|
||||
|
||||
#import "MOP_registerSyncExtensionApi.h"
|
||||
#import "MopPlugin.h"
|
||||
#import <FinApplet/FinApplet.h>
|
||||
#import "PhizLanguageData.h"
|
||||
|
||||
@implementation MOP_registerSyncExtensionApi
|
||||
|
||||
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
|
||||
{
|
||||
NSLog(@"MOP_registerSyncExtensionApi,name=%@",self.name);
|
||||
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
||||
[[FATClient sharedClient] registerSyncExtensionApi:self.name handler:^NSDictionary *(FATAppletInfo *appletInfo, id param) {
|
||||
if([self.name isEqualToString:@"getLanguageCodeSync"]){
|
||||
NSDictionary *resultDict = [NSDictionary dictionary];
|
||||
NSString* shortCode = [PhizLanguageData sharedInstance].languageCode;
|
||||
NSString* countryCode = [PhizLanguageData sharedInstance].countryCode;
|
||||
resultDict = @{@"languageCode":shortCode,@"countryCode":countryCode};
|
||||
return resultDict;
|
||||
}
|
||||
return @{};
|
||||
}];
|
||||
success(@{});
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// PhizLanguageData.h
|
||||
// FinDemo
|
||||
//
|
||||
// Created by stewen on 2023/8/4.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface PhizLanguageData : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *languageCode;
|
||||
@property (nonatomic, copy) NSString *countryCode;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// PhizLanguageData.m
|
||||
// FinDemo
|
||||
//
|
||||
// Created by stewen on 2023/8/4.
|
||||
//
|
||||
|
||||
#import "PhizLanguageData.h"
|
||||
|
||||
@implementation PhizLanguageData
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static PhizLanguageData *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
sharedInstance.languageCode = @"en"; // Set default language code
|
||||
sharedInstance.countryCode = @"US";
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
@end
|
|
@ -6,6 +6,7 @@
|
|||
#import <mop/MOPTools.h>
|
||||
#import "MopShareView.h"
|
||||
#import <UIView+MOPFATToast.h>
|
||||
#import "PhizLanguageData.h"
|
||||
|
||||
@implementation MopEventStream {
|
||||
FlutterEventSink _eventSink;
|
||||
|
@ -141,6 +142,13 @@ static MopPlugin *_instance;
|
|||
// [MOPAppletDelegate instance].bindGetPhoneNumbers(jsonDic);
|
||||
}
|
||||
}
|
||||
else if ([@"updateLanguage" isEqualToString:call.method]) {
|
||||
NSLog(@"updateLanguage,");
|
||||
NSString *cCode = call.arguments[@"countryCode"];
|
||||
NSString *cLang = call.arguments[@"languageCode"];
|
||||
[PhizLanguageData sharedInstance].countryCode = cCode;
|
||||
[PhizLanguageData sharedInstance].languageCode = cLang;
|
||||
}
|
||||
else {
|
||||
MOPApiRequest* request = [[MOPApiRequest alloc] init];
|
||||
request.command = call.method;
|
||||
|
|
Loading…
Reference in New Issue