Skip to content

Commit

Permalink
chore: upgrade gradle deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mastersam07 committed Oct 3, 2024
1 parent 3d34b32 commit 38eeb7e
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 209 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import 'package:livechatt/livechatt.dart';
#### Internet and Storage Access
```xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
```

#### ChatWindow
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

Expand All @@ -23,16 +23,16 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 34

defaultConfig {
minSdkVersion 16
minSdkVersion 21
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
implementation 'com.github.livechat:chat-window-android:v2.2.1'
implementation 'com.github.livechat:chat-window-android:v2.3.4'
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
188 changes: 91 additions & 97 deletions android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,121 +17,115 @@
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<String,String> 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<String, String> 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<String, String> customParams) {
return new ChatWindowConfiguration.Builder()
.setLicenceNumber(licenseNo)
.setGroupId(groupId)
.setVisitorName(visitorName)
.setVisitorEmail(visitorEmail)
.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();
}
}
6 changes: 3 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="livechat_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

Expand All @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Loading

0 comments on commit 38eeb7e

Please sign in to comment.