diff --git a/android/src/main/java/com/finogeeks/mop/api/SyncApi.java b/android/src/main/java/com/finogeeks/mop/api/SyncApi.java new file mode 100644 index 0000000..7657131 --- /dev/null +++ b/android/src/main/java/com/finogeeks/mop/api/SyncApi.java @@ -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 + "}"; + } + } +} + + diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java index 6f8bac6..23092ff 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java @@ -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(); diff --git a/ios/Classes/Api/MOP_initSDK.m b/ios/Classes/Api/MOP_initSDK.m index fa72791..f5e6e1d 100644 --- a/ios/Classes/Api/MOP_initSDK.m +++ b/ios/Classes/Api/MOP_initSDK.m @@ -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 { diff --git a/ios/Classes/Api/MOP_initialize.m b/ios/Classes/Api/MOP_initialize.m index ef11dc4..e8fe5f8 100644 --- a/ios/Classes/Api/MOP_initialize.m +++ b/ios/Classes/Api/MOP_initialize.m @@ -7,7 +7,8 @@ #import "MOP_initialize.h" #import -#import +#import "FinAppletExt.h" +#import #import "MOPTools.h" @implementation MOP_initialize diff --git a/ios/Classes/Api/MOP_registerSyncExtensionApi.h b/ios/Classes/Api/MOP_registerSyncExtensionApi.h new file mode 100644 index 0000000..741ec63 --- /dev/null +++ b/ios/Classes/Api/MOP_registerSyncExtensionApi.h @@ -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 diff --git a/ios/Classes/Api/MOP_registerSyncExtensionApi.m b/ios/Classes/Api/MOP_registerSyncExtensionApi.m new file mode 100644 index 0000000..c399518 --- /dev/null +++ b/ios/Classes/Api/MOP_registerSyncExtensionApi.m @@ -0,0 +1,33 @@ +// +// MOP_registerSyncExtensionApi.m +// mop +// +// Created by Stewen on 2023/6/30. +// + +#import "MOP_registerSyncExtensionApi.h" +#import "MopPlugin.h" +#import +#import "PhizLanguageData.h" + +@implementation MOP_registerSyncExtensionApi + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _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 diff --git a/ios/Classes/Api/PhizLanguageData.h b/ios/Classes/Api/PhizLanguageData.h new file mode 100644 index 0000000..6093159 --- /dev/null +++ b/ios/Classes/Api/PhizLanguageData.h @@ -0,0 +1,20 @@ +// +// PhizLanguageData.h +// FinDemo +// +// Created by stewen on 2023/8/4. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface PhizLanguageData : NSObject + +@property (nonatomic, copy) NSString *languageCode; +@property (nonatomic, copy) NSString *countryCode; + ++ (instancetype)sharedInstance; +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/PhizLanguageData.m b/ios/Classes/Api/PhizLanguageData.m new file mode 100644 index 0000000..2280122 --- /dev/null +++ b/ios/Classes/Api/PhizLanguageData.m @@ -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 \ No newline at end of file diff --git a/ios/Classes/MopPlugin.m b/ios/Classes/MopPlugin.m index b373cde..4b7e617 100644 --- a/ios/Classes/MopPlugin.m +++ b/ios/Classes/MopPlugin.m @@ -6,6 +6,7 @@ #import #import "MopShareView.h" #import +#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;