From ae7fbbfb98f74a49085db4859241c328d0ec81ff Mon Sep 17 00:00:00 2001 From: "taha.alam" Date: Sun, 15 Sep 2024 14:56:30 +0300 Subject: [PATCH] WD: penguin view navigation to clinic id added and username modified. --- .../PenguinInPlatformBridge.kt | 1 + .../penguin/PenguinMethod.kt | 13 +++++ .../penguin/PenguinView.kt | 29 +++++----- lib/uitl/penguin_method_channel.dart | 57 ++++++++++++++++++- 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinMethod.kt diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/PenguinInPlatformBridge.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/PenguinInPlatformBridge.kt index b6b4d7ad..93affaef 100644 --- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/PenguinInPlatformBridge.kt +++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/PenguinInPlatformBridge.kt @@ -37,6 +37,7 @@ class PenguinInPlatformBridge( args, flutterEngine.dartExecutor.binaryMessenger, activity = mainActivity, + channel ) } } diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinMethod.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinMethod.kt new file mode 100644 index 00000000..c76f9784 --- /dev/null +++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinMethod.kt @@ -0,0 +1,13 @@ +package com.cloud.diplomaticquarterapp.penguin + +enum class PenguinMethod { + // initializePenguin("initializePenguin"), + // configurePenguin("configurePenguin"), + // showPenguinUI("showPenguinUI"), + // onPenNavUIDismiss("onPenNavUIDismiss"), + // onReportIssue("onReportIssue"), + // onPenNavSuccess("onPenNavSuccess"), + onPenNavInitializationError // onLocationOffCampus("onLocationOffCampus"), + // navigateToPOI("navigateToPOI"), + // openSharedLocation("openSharedLocation"); +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinView.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinView.kt index 1b905c18..58223d56 100644 --- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinView.kt +++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/penguin/PenguinView.kt @@ -41,7 +41,8 @@ internal class PenguinView( id: Int, val creationParams: Map, messenger: BinaryMessenger, - activity: MainActivity + activity: MainActivity, + val channel: MethodChannel ) : PlatformView, MethodChannel.MethodCallHandler, PenNavUIDelegate { // The layout for displaying the Penguin UI private val mapLayout: RelativeLayout = RelativeLayout(context) @@ -200,7 +201,7 @@ internal class PenguinView( .setLanguageID(language) .setSimulationModeEnabled(creationParams["isSimulationModeEnabled"] as Boolean) .setEnableBackButton(true) - .setDeepLinkData("deeplink") +// .setDeepLinkData("deeplink") .setCustomizeColor("#2CA0AF") .setDeepLinkSchema("") .build() @@ -238,7 +239,7 @@ internal class PenguinView( // referenceId = refID - navigator.navigateTo(mContext, "",object : RefIdDelegate { + navigator.navigateTo(mContext, refID,object : RefIdDelegate { override fun onRefByIDSuccess(PoiId: String?) { Log.e("navigateTo", "PoiId is penguin view+++++++ $PoiId") @@ -273,19 +274,11 @@ internal class PenguinView( * @param warningCode Optional warning code received from the SDK. */ override fun onPenNavSuccess(warningCode: String?) { + val clinicId = creationParams["clinic_id"] as String - navigateTo("123") -// if (_context is Activity) { -// _context.runOnUiThread { -// Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show() -// } -// } else { -// println("the warming is presented $$warningCode") -//// val handler = Handler(Looper.getMainLooper()) -//// handler.post { -//// Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show() -//// } -// } + if(clinicId.isEmpty()) return + + navigateTo(clinicId) } /** @@ -298,6 +291,12 @@ internal class PenguinView( description: String?, errorType: InitializationErrorType? ) { + val arguments: Map = mapOf( + "description" to description, + "type" to errorType?.name + ) + + channel.invokeMethod(PenguinMethod.onPenNavInitializationError.name, arguments) Toast.makeText(mContext, "Navigation Error: $description", Toast.LENGTH_SHORT).show() } diff --git a/lib/uitl/penguin_method_channel.dart b/lib/uitl/penguin_method_channel.dart index 06968bfe..3419b1da 100644 --- a/lib/uitl/penguin_method_channel.dart +++ b/lib/uitl/penguin_method_channel.dart @@ -16,7 +16,7 @@ class PenguinMethodChannel { "dataServiceName": "api", "positionServiceName": "pe", "clientID": "PIF", - "username": "Test", + "username": "test", "isSimulationModeEnabled": true, "isShowUserName": false, "isUpdateUserLocationSmoothly": true, @@ -32,6 +32,61 @@ class PenguinMethodChannel { print("Failed to launch PenguinIn: '${e.message}'."); } } + + void setMethodCallHandler(){ + _channel.setMethodCallHandler((MethodCall call) async { + try { + + print(call.method); + + switch (call.method) { + + case PenguinMethodNames.onPenNavInitializationError: + _handleInitializationError(call.arguments); // Handle onPenNavInitializationError errors. + break; + case PenguinMethodNames.onPenNavUIDismiss: + //todo handle pen dismissable + // _handlePenNavUIDismiss(); // Handle UI dismissal event. + break; + case PenguinMethodNames.onReportIssue: + // Handle the report issue event. + _handleInitializationError(call.arguments); + break; + default: + _handleUnknownMethod(call.method); // Handle unknown method calls. + } + } catch (e) { + print("Error handling method call '${call.method}': $e"); + // Optionally, log this error to an external service + } + }); + } + static void _handleUnknownMethod(String method) { + print("Unknown method: $method"); + // Optionally, handle this unknown method case, such as reporting or ignoring it + } + + + static void _handleInitializationError(Map error) { + final type = error['type'] as String?; + final description = error['description'] as String?; + print("Initialization Error: ${type ?? 'Unknown Type'}, ${description ?? 'No Description'}"); + + } + +} +// Define constants for method names +class PenguinMethodNames { + static const String showPenguinUI = 'showPenguinUI'; + static const String openSharedLocation = 'openSharedLocation'; + + // ---- Handler Method + static const String onPenNavSuccess = 'onPenNavSuccess'; // Tested Android,iOS + static const String onPenNavInitializationError = 'onPenNavInitializationError'; // Tested Android,iOS + static const String onPenNavUIDismiss = 'onPenNavUIDismiss'; //Tested Android,iOS + static const String onReportIssue = 'onReportIssue'; // Tested Android,iOS + static const String onLocationOffCampus = 'onLocationOffCampus'; // Tested iOS,Android + static const String navigateToPOI = 'navigateToPOI'; // Tested Android,iOS }