Skip to content

Commit

Permalink
Feature:#270-ios-passing language code to all SDK methods for localiz…
Browse files Browse the repository at this point in the history
…ation

Passed languge code to SDK methods such as (DataSharing, GetDataAgreement, GetDataAgreementWithApiKey, CreateIndividual) for localization
  • Loading branch information
lijogeorgep authored and josmilan committed Jan 11, 2024
1 parent 7945cab commit 1328cc8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
12 changes: 8 additions & 4 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ import SwiftMessages
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
let languageCode = arguments?["languageCode"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "")
PrivacyDashboard.updateDataAgreementStatus(dataAgreementId: dataAgreementID ?? "", status: true)
PrivacyDashboard.receiveDataBackFromPrivacyDashboard = { dataReceived in
let dict = dataReceived["consentRecord"] as? [String: Any]
Expand All @@ -108,9 +109,10 @@ import SwiftMessages
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
let languageCode = arguments?["languageCode"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "")
PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in
debugPrint("Data receieved here:\(resultVal)")
let dict = resultVal["dataAgreement"] as? [String: Any]
Expand All @@ -133,9 +135,10 @@ import SwiftMessages
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
let languageCode = arguments?["languageCode"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "")
PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in
debugPrint("Data receieved here:\(resultVal)")
let dict = resultVal["dataAgreement"] as? [String: Any]
Expand All @@ -158,8 +161,9 @@ import SwiftMessages
let userId = arguments?["userId"] as? String
let accessToken = arguments?["accessToken"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let languageCode = arguments?["languageCode"] as? String

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en" , accessToken: accessToken ?? "")
PrivacyDashboard.createAnIndividual(name: "", email: "", phone: "") { success, resultVal in
if success {
if let jsonData = try? JSONSerialization.data(withJSONObject: resultVal, options: .prettyPrinted),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../language/controllers/language_controller.dart';
import '../../login/views/login_view.dart';

class DataAgreementContoller extends BaseController {
final RegisterController _registerController = Get.find();
WebViewController? controller;
var platform = const MethodChannel('io.igrant.data4diabetes.channel');

final LanguageController _languageController= Get.find();
var thirdPartyOrgName = "Data4Diabetes";
String? accessToken;
var redirectUrl = "https://www.govstack.global/";
Expand Down Expand Up @@ -45,6 +46,7 @@ class DataAgreementContoller extends BaseController {
return;
},
onNavigationRequest: (NavigationRequest request) async {
var languageCode = _languageController.languageCode.value;
if (request.url.startsWith(redirectUrl)) {
final uri = Uri.parse(request.url);
if (uri.queryParameters.containsKey('error')) {
Expand All @@ -67,7 +69,8 @@ class DataAgreementContoller extends BaseController {
"apiKey": PrivacyDashboard().apiKey,
"userId": userId,
"dataAgreementID": PrivacyDashboard().registrationDataAgreementId,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode
});
Map<String, dynamic> responseMap = json.decode(response);
if (responseMap['optIn'] == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../language/controllers/language_controller.dart';
import '../../launcher/views/launcher_view.dart';

class PrivacyDashboardCredentialController extends BaseController {
var platform = const MethodChannel('io.igrant.data4diabetes.channel');

final LanguageController _languageController= Get.find();
final TextEditingController apiKeyController = TextEditingController();
final TextEditingController baseUrlController = TextEditingController();
final TextEditingController orgIdController = TextEditingController();
Expand Down Expand Up @@ -43,9 +44,11 @@ class PrivacyDashboardCredentialController extends BaseController {
}

submitButtonAction() async {
var languageCode = _languageController.languageCode.value;
var response = await platform.invokeMethod('CreateIndividual', {
"apiKey": apiKeyController.text,
"baseUrl": baseUrlController.text,
"languageCode": languageCode
});
Map<String, dynamic> responseMap = json.decode(response);
Map<String, dynamic> individual = responseMap['individual'];
Expand Down
23 changes: 18 additions & 5 deletions lib/app/modules/register/controllers/register_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:intl_phone_number_input/intl_phone_number_input.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uuid/uuid.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../language/controllers/language_controller.dart';
import '../../login/controllers/login_controller.dart';
import '/app/core/base/base_controller.dart';

Expand Down Expand Up @@ -53,6 +54,7 @@ class RegisterController extends BaseController {
String? accessToken;
var redirectUrl = "https://www.govstack.global/";
List dataAttributes = [].obs;
final LanguageController _languageController= Get.find();

@override
void onInit() {
Expand All @@ -61,14 +63,16 @@ class RegisterController extends BaseController {
}

void registerUser() async {
var languageCode = _languageController.languageCode.value;
try {
SharedPreferences _prefs = await SharedPreferences.getInstance();
var userId = _prefs.getString('privacyDashboarduserId');
var response = await platform.invokeMethod('DataSharing', {
"apiKey": PrivacyDashboard().apiKey,
"userId": userId,
"dataAgreementID": PrivacyDashboard().backupAndRestoreDataAgreementId,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode
});
Map<String, dynamic> responseMap = json.decode(response);
if (responseMap['optIn'] == true) {
Expand Down Expand Up @@ -244,9 +248,12 @@ class RegisterController extends BaseController {
message: appLocalization.registerExistingUser,
);
} else {
var languageCode = _languageController.languageCode.value;
var response = await platform.invokeMethod('CreateIndividual', {
"apiKey": PrivacyDashboard().apiKey,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode

});

Map<String, dynamic> responseMap = json.decode(response);
Expand All @@ -260,6 +267,7 @@ class RegisterController extends BaseController {
}

onAgreeButtonTap() async {
var languageCode = _languageController.languageCode.value;
try {
showLoading();
SharedPreferences _prefs = await SharedPreferences.getInstance();
Expand All @@ -268,7 +276,8 @@ class RegisterController extends BaseController {
"apiKey": PrivacyDashboard().apiKey,
"userId": userId ,
"dataAgreementID": PrivacyDashboard().donateYourDataDataAgreementId,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode
});
Map<String, dynamic> responseMap = json.decode(response);
if (responseMap['optIn'] == true) {
Expand Down Expand Up @@ -298,6 +307,7 @@ class RegisterController extends BaseController {
{
required String? sharingDataAgreementID,
bool? isFlag}) async {
var languageCode = _languageController.languageCode.value;
try {
showLoading();
SharedPreferences _prefs = await SharedPreferences.getInstance();
Expand All @@ -306,7 +316,8 @@ class RegisterController extends BaseController {
"apiKey": PrivacyDashboard().apiKey,
"userId": userId ,
"dataAgreementID": sharingDataAgreementID,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode
});

Map<String, dynamic> responseMap = json.decode(response);
Expand Down Expand Up @@ -344,6 +355,7 @@ class RegisterController extends BaseController {
}

getDataAgreementWithApiKey({required String? sharingDataAgreementID}) async {
var languageCode = _languageController.languageCode.value;
try {
showLoading();
SharedPreferences _prefs = await SharedPreferences.getInstance();
Expand All @@ -352,7 +364,8 @@ class RegisterController extends BaseController {
"apiKey": PrivacyDashboard().apiKey,
"userId": userId ,
"dataAgreementID": sharingDataAgreementID,
"baseUrl": PrivacyDashboard().baseUrl
"baseUrl": PrivacyDashboard().baseUrl,
"languageCode": languageCode
});

Map<String, dynamic> responseMap = json.decode(response);
Expand Down

0 comments on commit 1328cc8

Please sign in to comment.