diff --git a/README.md b/README.md index 42db761..6f6ab95 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ import 'package:livechatt/livechatt.dart'; #### Internet and Storage Access ```xml - ``` #### ChatWindow diff --git a/android/build.gradle b/android/build.gradle index ec75c4d..bac7672 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.4.2' } } @@ -23,10 +23,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 30 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 + minSdkVersion 21 } lintOptions { disable 'InvalidPackage' @@ -34,5 +34,5 @@ android { } dependencies { - implementation 'com.github.livechat:chat-window-android:v2.2.1' + implementation 'com.github.livechat:chat-window-android:v2.3.4' } \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 01a286e..3c472b9 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java b/android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java index dff52d5..99530c8 100644 --- a/android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java +++ b/android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java @@ -17,78 +17,79 @@ import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; -/// Files imported from livechat android sdk import com.livechatinc.inappchat.ChatWindowConfiguration; -import com.livechatinc.inappchat.ChatWindowErrorType; import com.livechatinc.inappchat.ChatWindowView; -import com.livechatinc.inappchat.models.NewMessageModel; import java.util.HashMap; -/// Implement chat bubble -// import com.google.android.material.floatingactionbutton.FloatingActionButton; -// import com.livechatinc.inappchat.ChatWindowEventsListener; -// import com.livechatinc.inappchat.ChatWindowUtils; - -/** LivechatPlugin */ -public class LivechatPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware{ - /// The MethodChannel that will the communication between Flutter and native Android - /// - /// This local reference serves to register the plugin with the Flutter Engine and unregister it - /// when the Flutter Engine is detached from the Activity - Activity activity; - private Context context; - ChatWindowConfiguration config = null; - ChatWindowView windowView = null; - private MethodChannel channel; - - // This static function is optional and equivalent to onAttachedToEngine. It supports the old - // pre-Flutter-1.12 Android projects. You are encouraged to continue supporting - // plugin registration via this function while apps migrate to use the new Android APIs - // post-flutter-1.12 via https://flutter.dev/go/android-project-migration. - // - // It is encouraged to share logic between onAttachedToEngine and registerWith to keep - // them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called - // depending on the user's project. onAttachedToEngine or registerWith must both be defined - // in the same class. - public static void registerWith(Registrar registrar) { - final LivechatPlugin instance = new LivechatPlugin(); - instance.onAttachedToEngine(registrar.context(), registrar.messenger()); - } - - @Override - public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { - onAttachedToEngine(flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger()); - } - - private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) { - this.context = applicationContext; - channel = new MethodChannel(messenger, "livechatt"); - channel.setMethodCallHandler(this); - } - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { - if (call.method.equals("getPlatformVersion")) { - result.success("Android " + android.os.Build.VERSION.RELEASE); - } else if (call.method.equals("beginChat")) { - final String licenseNo = call.argument("licenseNo"); - final HashMap customParams = call.argument("customParams"); - final String groupId = call.argument("groupId"); - final String visitorName = call.argument("visitorName"); - final String visitorEmail = call.argument("visitorEmail"); - - if (licenseNo.trim().equalsIgnoreCase("")) { - result.error("LICENSE NUMBER EMPTY", null, null); - }else if (visitorName.trim().equalsIgnoreCase("")) { - result.error("VISITOR NAME EMPTY", null, null); - }else if (visitorEmail.trim().equalsIgnoreCase("")) { - result.error("VISITOR EMAIL EMPTY", null, null); - }else{ - Intent intent = new Intent(activity, com.livechatinc.inappchat.ChatWindowActivity.class); - Bundle config = new ChatWindowConfiguration.Builder() +public class LivechatPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware { + private MethodChannel channel; + private Context context; + private Activity activity; + private ChatWindowView windowView; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + this.context = flutterPluginBinding.getApplicationContext(); + setupChannel(flutterPluginBinding.getBinaryMessenger()); + } + + private void setupChannel(BinaryMessenger messenger) { + channel = new MethodChannel(messenger, "livechatt"); + channel.setMethodCallHandler(this); + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + switch (call.method) { + case "getPlatformVersion": + result.success("Android " + android.os.Build.VERSION.RELEASE); + break; + case "beginChat": + handleBeginChat(call, result); + break; + default: + result.notImplemented(); + break; + } + } + + private void handleBeginChat(@NonNull MethodCall call, @NonNull Result result) { + final String licenseNo = call.argument("licenseNo"); + final HashMap customParams = call.argument("customParams"); + final String groupId = call.argument("groupId"); + final String visitorName = call.argument("visitorName"); + final String visitorEmail = call.argument("visitorEmail"); + + if (licenseNo == null || licenseNo.trim().isEmpty()) { + result.error("LICENSE_ERROR", "License number cannot be empty", null); + return; + } + + if (visitorName == null || visitorName.trim().isEmpty()) { + result.error("VISITOR_NAME_ERROR", "Visitor name cannot be empty", null); + return; + } + + if (visitorEmail == null || visitorEmail.trim().isEmpty()) { + result.error("VISITOR_EMAIL_ERROR", "Visitor email cannot be empty", null); + return; + } + + try { + Intent intent = new Intent(activity, com.livechatinc.inappchat.ChatWindowActivity.class); + Bundle config = buildChatConfig(licenseNo, groupId, visitorName, visitorEmail, customParams); + intent.putExtras(config); + activity.startActivity(intent); + result.success(null); + } catch (Exception e) { + result.error("CHAT_WINDOW_ERROR", "Failed to start chat window", e); + } + } + + private Bundle buildChatConfig(String licenseNo, String groupId, String visitorName, String visitorEmail, HashMap customParams) { + return new ChatWindowConfiguration.Builder() .setLicenceNumber(licenseNo) .setGroupId(groupId) .setVisitorName(visitorName) @@ -96,42 +97,35 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { .setCustomParams(customParams) .build() .asBundle(); - // intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_GROUP_ID, licenseNo); - // intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_LICENCE_NUMBER, groupId); - // intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_NAME, visitorName); - // intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_EMAIL, visitorEmail); - intent.putExtras(config); - activity.startActivity(intent); - - result.success(null); - } - } else { - result.notImplemented(); } - } - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - - } - - @Override - public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) { - activity = activityPluginBinding.getActivity(); - } - - @Override - public void onDetachedFromActivity() { + @Override + public void onAttachedToActivity(ActivityPluginBinding binding) { + this.activity = binding.getActivity(); + } - } + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + teardownChannel(); + } - @Override - public void onDetachedFromActivityForConfigChanges() { + private void teardownChannel() { + if (channel != null) { + channel.setMethodCallHandler(null); + channel = null; + } + } - } + @Override + public void onDetachedFromActivity() { + this.activity = null; + } - @Override - public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) { + @Override + public void onDetachedFromActivityForConfigChanges() {} - } + @Override + public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) { + this.activity = binding.getActivity(); + } } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index d357e16..edfd833 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 34 lintOptions { disable 'InvalidPackage' @@ -34,8 +34,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "tech.mastersam.livechat_example" - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 5f8d762..5579a11 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -10,11 +10,12 @@ =2.12.0 <3.0.0" - flutter: ">=1.10.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8394e4f..43e0633 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: diff --git a/pubspec.lock b/pubspec.lock index 4fe6b9f..df9b838 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.1" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -60,27 +59,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.11.1" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.15.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -90,58 +124,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" source: hosted - version: "0.4.2" - typed_data: + version: "0.7.2" + vector_math: dependency: transitive description: - name: typed_data - url: "https://pub.dartlang.org" + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "1.3.0" - vector_math: + version: "2.1.4" + vm_service: dependency: transitive description: - name: vector_math - url: "https://pub.dartlang.org" + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "14.2.5" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=1.10.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 0fcb3c4..478f56b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,8 +7,8 @@ issue_tracker: https://github.com/Mastersam07/livechat/issues documentation: https://github.com/Mastersam07/livechat environment: - sdk: '>=2.12.0 <3.0.0' - flutter: ">=1.10.0" + sdk: '>=3.0.0 <4.0.0' + flutter: ">=2.0.0" dependencies: flutter: