Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update SDk so that client can use with latest codebase #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@

group 'com.muljin.zendesk'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.20'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
}
}
Expand All @@ -32,16 +33,18 @@ android {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 21
}

lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation group: 'com.zendesk', name: 'chat', version: '3.1.0'
implementation group: 'com.zendesk', name: 'messaging', version: '5.1.0'
implementation group: 'com.zendesk', name: 'chat-providers', version: '3.1.0'
implementation group: 'com.zendesk', name: 'chat', version: '3.4.0'
implementation group: 'com.zendesk', name: 'messaging', version: '5.4.0'
implementation group: 'com.zendesk', name: 'chat-providers', version: '3.4.0'
implementation group: 'androidx.appcompat', name: 'appcompat', version: '1.6.1'
}
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.muljin.zendesk">
<manifest package="com.muljin.zendesk">
</manifest>
262 changes: 130 additions & 132 deletions android/src/main/kotlin/com/muljin/zendesk/ZendeskHelper.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.muljin.zendesk

import android.app.Activity
import android.util.Log
import androidx.annotation.NonNull
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.internal.ContextUtils.getActivity
import com.zendesk.logger.Logger
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
Expand All @@ -14,139 +10,141 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import zendesk.chat.*
import zendesk.messaging.MessagingActivity
import zendesk.classic.messaging.MessagingActivity


/** ZendeskHelper */
class ZendeskHelper : 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
private lateinit var channel: MethodChannel
private lateinit var activity: Activity

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "zendesk")
channel.setMethodCallHandler(this)
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onDetachedFromActivity() {
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
}

override fun onDetachedFromActivityForConfigChanges() {
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {

try {


when (call.method) {
"getPlatformVersion" -> {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
}
"initialize" -> {
initialize(call)
result.success(true)
}
"setVisitorInfo" -> {
setVisitorInfo(call)
result.success(true)
}
"startChat" -> {
startChat(call)
result.success(true)
}
"addTags" -> {
addTags(call)
result.success(true)
}
"removeTags" -> {
removeTags(call)
result.success(true)
}
else -> {
result.notImplemented()
}
// / 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
private lateinit var channel: MethodChannel
private lateinit var activity: Activity

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "zendesk")
channel.setMethodCallHandler(this)
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onDetachedFromActivity() {
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
}

override fun onDetachedFromActivityForConfigChanges() {
}

override fun onMethodCall(call: MethodCall, result: Result) {

try {


when (call.method) {
"getPlatformVersion" -> {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
}
"initialize" -> {
initialize(call)
result.success(true)
}
"setVisitorInfo" -> {
setVisitorInfo(call)
result.success(true)
}
"startChat" -> {
startChat(call)
result.success(true)
}
"addTags" -> {
addTags(call)
result.success(true)
}
"removeTags" -> {
removeTags(call)
result.success(true)
}
else -> {
result.notImplemented()
}

}
} catch (e: Exception) {
result.error("unKnowen", e.message, e.toString());
}
}

fun initialize(call: MethodCall) {
Logger.setLoggable(BuildConfig.DEBUG)
val accountKey = call.argument<String>("accountKey") ?: ""
val applicationId = call.argument<String>("appId") ?: ""

Chat.INSTANCE.init(activity, accountKey)
}

fun setVisitorInfo(call: MethodCall) {
val name = call.argument<String>("name") ?: ""
val email = call.argument<String>("email") ?: ""
val phoneNumber = call.argument<String>("phoneNumber") ?: ""
val department = call.argument<String>("department") ?: ""

val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
val chatProvider = Chat.INSTANCE.providers()?.chatProvider()

val visitorInfo = VisitorInfo.builder()
.withName(name)
.withEmail(email)
.withPhoneNumber(phoneNumber) // numeric string
.build()
profileProvider?.setVisitorInfo(visitorInfo, null)
chatProvider?.setDepartment(department, null)
}
}catch (e:Exception){
result.error("unKnowen",e.message,e.toString());
}
}

fun initialize(call: MethodCall) {
Logger.setLoggable(BuildConfig.DEBUG)
val accountKey = call.argument<String>("accountKey") ?: ""
val applicationId = call.argument<String>("appId") ?: ""

Chat.INSTANCE.init(activity, accountKey, applicationId)
}

fun setVisitorInfo(call: MethodCall) {
val name = call.argument<String>("name") ?: ""
val email = call.argument<String>("email") ?: ""
val phoneNumber = call.argument<String>("phoneNumber") ?: ""
val department = call.argument<String>("department") ?: ""

val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
val chatProvider = Chat.INSTANCE.providers()?.chatProvider()

val visitorInfo = VisitorInfo.builder()
.withName(name)
.withEmail(email)
.withPhoneNumber(phoneNumber) // numeric string
.build()
profileProvider?.setVisitorInfo(visitorInfo, null)
chatProvider?.setDepartment(department, null)
}

fun addTags(call: MethodCall) {
val tags = call.argument<List<String>>("tags") ?: listOf<String>()
val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
profileProvider?.addVisitorTags(tags, null)
}

fun removeTags(call: MethodCall) {
val tags = call.argument<List<String>>("tags") ?: listOf<String>()
val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
profileProvider?.removeVisitorTags(tags, null)
}

fun startChat(call: MethodCall) {
val isPreChatFormEnabled = call.argument<Boolean>("isPreChatFormEnabled") ?: true
val isAgentAvailabilityEnabled = call.argument<Boolean>("isAgentAvailabilityEnabled") ?: true
val isChatTranscriptPromptEnabled = call.argument<Boolean>("isChatTranscriptPromptEnabled") ?: true
val isOfflineFormEnabled = call.argument<Boolean>("isOfflineFormEnabled") ?: true
val chatConfigurationBuilder = ChatConfiguration.builder()
chatConfigurationBuilder
.withAgentAvailabilityEnabled(isAgentAvailabilityEnabled)
.withTranscriptEnabled(isChatTranscriptPromptEnabled)
.withOfflineFormEnabled(isOfflineFormEnabled)
.withPreChatFormEnabled(isPreChatFormEnabled)
.withChatMenuActions(ChatMenuAction.END_CHAT)

val chatConfiguration = chatConfigurationBuilder.build()
try {
MessagingActivity.builder()
.withToolbarTitle("Contact Us")
.withEngines(ChatEngine.engine())
.show(activity, chatConfiguration)
}catch ( e:Exception){
throw e;
}

}
fun addTags(call: MethodCall) {
val tags = call.argument<List<String>>("tags") ?: listOf<String>()
val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
profileProvider?.addVisitorTags(tags, null)
}

fun removeTags(call: MethodCall) {
val tags = call.argument<List<String>>("tags") ?: listOf<String>()
val profileProvider = Chat.INSTANCE.providers()?.profileProvider()
profileProvider?.removeVisitorTags(tags, null)
}

fun startChat(call: MethodCall) {
val isPreChatFormEnabled = call.argument<Boolean>("isPreChatFormEnabled") ?: true
val isAgentAvailabilityEnabled =
call.argument<Boolean>("isAgentAvailabilityEnabled") ?: true
val isChatTranscriptPromptEnabled =
call.argument<Boolean>("isChatTranscriptPromptEnabled") ?: true
val isOfflineFormEnabled = call.argument<Boolean>("isOfflineFormEnabled") ?: true
val chatConfigurationBuilder = ChatConfiguration.builder()
chatConfigurationBuilder
.withAgentAvailabilityEnabled(isAgentAvailabilityEnabled)
.withTranscriptEnabled(isChatTranscriptPromptEnabled)
.withOfflineFormEnabled(isOfflineFormEnabled)
.withPreChatFormEnabled(isPreChatFormEnabled)
.withChatMenuActions(ChatMenuAction.END_CHAT)

val chatConfiguration = chatConfigurationBuilder.build()
try {
MessagingActivity.builder()
.withToolbarTitle("Powerley support")
.withEngines(ChatEngine.engine())
.show(activity, chatConfiguration)
} catch (e: Exception) {
throw e;
}

}
}
46 changes: 0 additions & 46 deletions example/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions example/.metadata

This file was deleted.