├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── answerbot_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── answerbot_sample │ │ ├── Global.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── chat_v2_jwt_sample ├── .gitignore ├── README.md ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── chat_v2 │ │ └── jwt │ │ └── sample │ │ ├── Global.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── jwt_layout.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── styles.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── chat_v2_message_counter_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── chat_v2 │ │ └── sample │ │ ├── Global.java │ │ ├── MainActivity.java │ │ └── UnreadMessageCounter.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── styles.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── chat_v2_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── chat_v2 │ │ └── sample │ │ ├── Global.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── styles.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── demo_apps_commons ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── res │ ├── layout │ └── missing_credentials.xml │ └── values │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── messaging_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── messaging_sample │ │ ├── Global.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── scripts └── shell │ └── travis.sh ├── settings.gradle ├── support_custom_fields_sample ├── .gitignore ├── README ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── sample │ │ └── customfields │ │ ├── CustomFieldsActivity.java │ │ └── Global.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── support_override_styles ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── bfahy │ │ └── support_override_styles │ │ ├── Global.kt │ │ └── MainActivity.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── support_request_updates_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── support_request_updates_sample │ │ ├── Global.java │ │ └── RequestUpdatesActivity.java │ └── res │ ├── drawable │ └── ic_add_light.xml │ ├── layout │ └── activity_request_updates.xml │ ├── menu │ └── request_list.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── support_sample ├── .gitignore ├── build.gradle ├── lint-rules.xml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── zenchat.png │ ├── java │ └── com │ │ └── zendesk │ │ └── sample │ │ ├── Global.java │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── support_upload_attachment_sample ├── .gitignore ├── README.md ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zendesk │ │ └── sample │ │ └── uploadattachment │ │ ├── Global.java │ │ └── UploadAttachmentActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_action_add.png │ ├── drawable-mdpi │ └── ic_action_add.png │ ├── drawable-xhdpi │ └── ic_action_add.png │ ├── drawable-xxhdpi │ └── ic_action_add.png │ ├── layout │ ├── activity_upload_attachment.xml │ └── content_upload_attachment.xml │ ├── menu │ └── menu_upload_attachment.xml │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── support_urbanairship_sample ├── .gitignore ├── README.md ├── build.gradle ├── lint-rules.xml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── airshipconfig.properties │ ├── java │ └── com │ │ └── zendesk │ │ └── example │ │ └── ua │ │ ├── Global.java │ │ ├── IntentReceiver.java │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable │ └── ic_chat_bubble.xml │ ├── layout │ └── activity_main.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── talk_sample ├── .gitignore ├── README.md ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── zendesk │ └── talk │ └── sample │ ├── LineStatusChecker.kt │ ├── MainActivity.kt │ └── SampleApplication.kt └── res ├── drawable-v24 └── ic_launcher_foreground.xml ├── drawable ├── chat_bubble.xml ├── ic_baseline_phone_24.xml ├── ic_baseline_send_24.xml └── ic_launcher_background.xml ├── layout └── activity_main.xml ├── menu └── main_activity_menu.xml ├── mipmap-anydpi-v26 ├── ic_launcher.xml └── ic_launcher_round.xml ├── mipmap-hdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-mdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── values-night └── themes.xml └── values ├── colors.xml ├── strings.xml ├── styles.xml └── themes.xml /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Product 2 | Which product does this affect? Add an 'x' in all that apply. 3 | - [ ] Support 4 | - [ ] Chat 5 | 6 | ## Problem 7 | Which type of issue have you encountered? Add an 'x' in all that apply. 8 | - [ ] Demo app request 9 | - [ ] Demo app broken 10 | - [ ] Other 11 | 12 | ## Description 13 | 14 | *Which feature would you like to see demonstrated?
15 | Which demo app has broken?* 16 | 17 | 18 | 19 | ## Reviewers 20 | @zendesk/adventure-android @zendesk/two-brothers-android @zendesk/ogham @baz8080 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Changes 2 | * 3 | 4 | ### Reviewers 5 | * @zendesk/banshee-android -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | # Android Studio IDEA folder 35 | .idea 36 | *.iml 37 | 38 | # OSX specific 39 | .DS_Store 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: android 4 | group: edge 5 | jdk: 6 | - oraclejdk8 7 | before_cache: 8 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 9 | cache: 10 | directories: 11 | - "$HOME/.gradle/caches/" 12 | - "$HOME/.gradle/wrapper/" 13 | android: 14 | components: 15 | - tools 16 | - android-27 17 | - platform-tools 18 | - build-tools-27.0.3 19 | - extra-android-m2repository 20 | licenses: 21 | - 'android-sdk-preview-license-.+' 22 | - 'android-sdk-license-.+' 23 | - '.+' 24 | branches: 25 | only: 26 | - master 27 | script: 28 | - ./scripts/shell/travis.sh 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :warning: *Use of this software is subject to important terms and conditions as set forth in the License file* :warning: 2 | 3 | # Zendesk Sample Apps for Android 4 | 5 | ## Description 6 | This repository provides you with sample Apps to help learn how to use the [Classic Zendesk Apps](https://developer.zendesk.com/documentation/classic-web-widget-sdks/) framework and APIs. 7 | 8 | We hope you'll find those sample Apps useful and encourage you to re-use some of this code in your own Apps. 9 | 10 | To be noted that the messaging-sample here **is not** the [Zendesk SDK](https://developer.zendesk.com/documentation/zendesk-web-widget-sdks/). This repository only conver the Classic SDKs. 11 | 12 | ## Owners 13 | Please submit a ticket to [Zendesk](https://support.zendesk.com/hc/en-us/articles/4408843597850). 14 | 15 | ## Getting Started 16 | Each of the modules in this project is a stand-alone Android app, capable of being run independently through Gradle or Android Studio. 17 | 18 | ## Bugs 19 | Please submit bug reports to [Zendesk](https://support.zendesk.com/hc/en-us/articles/4408843597850) and be sure to consult our [Getting help section](https://developer.zendesk.com/documentation/classic-web-widget-sdks/getting_started/ticket-submission-guidelines-for-mobile-sdk-developers/) of our documentation. 20 | 21 | -------------------------------------------------------------------------------- /answerbot_sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /answerbot_sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | namespace "com.zendesk.answerbot_sample" 5 | compileSdkVersion rootProject.ext.compileSdkVersion 6 | 7 | defaultConfig { 8 | applicationId rootProject.ext.applicationId + ".answerbot_sample" 9 | minSdkVersion rootProject.ext.minSdkVersion 10 | targetSdkVersion rootProject.ext.targetSdkVersion 11 | versionCode 1 12 | versionName "1.0.0" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_17 24 | targetCompatibility JavaVersion.VERSION_17 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation group: 'com.zendesk', name: 'answerbot', version: rootProject.ext.answerBotSdkVersion 30 | implementation group: 'com.zendesk', name: 'support', version: rootProject.ext.supportSdkVersion 31 | implementation group: 'com.zendesk', name: 'messaging', version: rootProject.ext.messagingSdkVersion 32 | 33 | implementation project(":demo_apps_commons") 34 | } 35 | -------------------------------------------------------------------------------- /answerbot_sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Keep classes which may be lost by Proguard or R8 when using Answer Bot 2 | 3 | -keep class zendesk.core.AuthenticationRequestWrapper { *; } 4 | -keep class zendesk.core.PushRegistrationRequestWrapper { *; } 5 | -keep class zendesk.core.PushRegistrationRequest { *; } 6 | -keep class zendesk.core.PushRegistrationResponse { *; } 7 | -keep class zendesk.core.ApiAnonymousIdentity { *; } 8 | 9 | -keep class zendesk.support.CreateRequestWrapper { *; } 10 | -keep class zendesk.support.Comment { *; } 11 | 12 | -keep class zendesk.answerbot.Deflection { *; } 13 | -keep class zendesk.answerbot.AnswerBotSettings { *; } 14 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/java/com/zendesk/answerbot_sample/Global.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.answerbot_sample; 2 | 3 | import android.app.Application; 4 | 5 | import com.zendesk.logger.Logger; 6 | import com.zendesk.util.StringUtils; 7 | 8 | import zendesk.answerbot.AnswerBot; 9 | import zendesk.core.AnonymousIdentity; 10 | import zendesk.core.Zendesk; 11 | import zendesk.support.Guide; 12 | import zendesk.support.Support; 13 | 14 | public class Global extends Application { 15 | 16 | private static final String SUBDOMAIN_URL = ""; 17 | private static final String APPLICATION_ID = ""; 18 | private static final String OAUTH_CLIENT_ID = ""; 19 | 20 | private static boolean missingCredentials = false; 21 | 22 | @Override 23 | public void onCreate() { 24 | super.onCreate(); 25 | 26 | // Enable logging 27 | Logger.setLoggable(true); 28 | 29 | if (StringUtils.isEmpty(SUBDOMAIN_URL) 30 | || StringUtils.isEmpty(APPLICATION_ID) 31 | || StringUtils.isEmpty(OAUTH_CLIENT_ID)) { 32 | missingCredentials = true; 33 | return; 34 | } 35 | 36 | /* 37 | Initialize the SDK with your Zendesk subdomain, mobile SDK app ID, and client ID. 38 | 39 | Get these details from your Zendesk dashboard: Admin -> Channels -> MobileSDK. 40 | */ 41 | Zendesk.INSTANCE.init(this, 42 | SUBDOMAIN_URL, 43 | APPLICATION_ID, 44 | OAUTH_CLIENT_ID); 45 | 46 | /* 47 | Set an identity (authentication). 48 | 49 | Set either Anonymous or JWT identity, as below: 50 | */ 51 | 52 | // a). Anonymous (All fields are optional) 53 | Zendesk.INSTANCE.setIdentity( 54 | new AnonymousIdentity.Builder() 55 | .withNameIdentifier("{optional name}") 56 | .withEmailIdentifier("{optional email}") 57 | .build() 58 | ); 59 | 60 | // b). JWT (Must be initialized with your JWT identifier) 61 | // Zendesk.INSTANCE.setIdentity(new JwtIdentity("{JWT User Identifier}")); 62 | Support.INSTANCE.init(Zendesk.INSTANCE); 63 | AnswerBot.INSTANCE.init(Zendesk.INSTANCE, Guide.INSTANCE); 64 | } 65 | 66 | static boolean isMissingCredentials() { 67 | return missingCredentials; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/java/com/zendesk/answerbot_sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.answerbot_sample; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | 7 | import zendesk.answerbot.AnswerBotEngine; 8 | import zendesk.messaging.MessagingActivity; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(@Nullable Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | } 16 | 17 | @Override 18 | protected void onStart() { 19 | super.onStart(); 20 | if (Global.isMissingCredentials()) { 21 | setContentView(com.zendesk.demo_apps_commons.R.layout.missing_credentials); 22 | return; 23 | } 24 | MessagingActivity.builder() 25 | .withEngines(AnswerBotEngine.engine()) 26 | .show(this); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/answerbot_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Answer Bot Sample App 3 | You must provide a valid Zendesk subdomain url, application id, and oauth client id for this demo to function 4 | 5 | -------------------------------------------------------------------------------- /answerbot_sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | ext { 4 | applicationId = "com.zendesk" 5 | compileSdkVersion = 34 6 | minSdkVersion = 21 7 | targetSdkVersion = 34 8 | 9 | // SDK Versions 10 | 11 | supportSdkVersion = "5.1.0" 12 | chatSdkVersion = "3.3.6" 13 | answerBotSdkVersion = "3.0.9" 14 | messagingSdkVersion = "5.2.5" 15 | talkSdkVersion = "1.3.0" 16 | 17 | // Other Dependencies 18 | 19 | appCompatVersion = "1.7.0" 20 | constraintlayoutVersion = "2.1.4" 21 | lifecycleVersion = "2.5.1" 22 | belvedere2Version = "3.0.5" 23 | picassoVersion = "2.5.2" 24 | firebaseVersion = "20.2.4" 25 | 26 | } 27 | 28 | buildscript { 29 | ext.kotlin_version = '1.9.24' 30 | 31 | repositories { 32 | google() 33 | mavenCentral() 34 | } 35 | dependencies { 36 | classpath 'com.android.tools.build:gradle:8.2.1' 37 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 38 | } 39 | } 40 | 41 | allprojects { 42 | repositories { 43 | google() 44 | mavenCentral() 45 | maven { url 'https://zendesk.jfrog.io/zendesk/repo' } 46 | } 47 | } 48 | 49 | task clean(type: Delete) { 50 | delete rootProject.buildDir 51 | } 52 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /chat_v2_jwt_sample/README.md: -------------------------------------------------------------------------------- 1 | ### Chat v2 JWT Sample 2 | 3 | Please reference the HC article on JWT https://develop.zendesk.com/hc/en-us/articles/360052354433-Enabling-authenticated-users-with-the-Chat-SDK- -------------------------------------------------------------------------------- /chat_v2_jwt_sample/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | namespace "com.zendesk.chat_v2.sample" 7 | compileSdkVersion rootProject.ext.compileSdkVersion 8 | 9 | defaultConfig { 10 | applicationId rootProject.ext.applicationId + ".chat_v2_sample" 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.targetSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_17 27 | targetCompatibility JavaVersion.VERSION_17 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation group: 'com.zendesk', name: 'messaging', version: rootProject.ext.messagingSdkVersion 33 | implementation group: 'com.zendesk', name: 'chat', version: rootProject.ext.chatSdkVersion 34 | 35 | implementation project(":demo_apps_commons") 36 | } -------------------------------------------------------------------------------- /chat_v2_jwt_sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/java/com/zendesk/chat_v2/jwt/sample/Global.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.chat_v2.jwt.sample; 2 | 3 | import android.app.Application; 4 | 5 | import com.zendesk.logger.Logger; 6 | import com.zendesk.util.StringUtils; 7 | 8 | import zendesk.chat.Chat; 9 | 10 | public class Global extends Application { 11 | 12 | private static final String CHAT_ACCOUNT_KEY = ""; 13 | 14 | private static boolean missingCredentials = false; 15 | 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | 20 | // Enable logging 21 | Logger.setLoggable(true); 22 | 23 | if (StringUtils.isEmpty(CHAT_ACCOUNT_KEY)) { 24 | missingCredentials = true; 25 | return; 26 | } 27 | 28 | Chat.INSTANCE.init(this, CHAT_ACCOUNT_KEY); 29 | } 30 | 31 | 32 | static boolean isMissingCredentials() { 33 | return missingCredentials; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/java/com/zendesk/chat_v2/jwt/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.chat_v2.jwt.sample; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import androidx.appcompat.app.AppCompatActivity; 7 | import androidx.appcompat.widget.AppCompatButton; 8 | 9 | import com.zendesk.chat_v2.sample.R; 10 | 11 | import zendesk.chat.Chat; 12 | import zendesk.chat.ChatConfiguration; 13 | import zendesk.chat.ChatEngine; 14 | import zendesk.chat.CompletionCallback; 15 | import zendesk.chat.JwtAuthenticator; 16 | import zendesk.messaging.MessagingActivity; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | AppCompatButton btnSet; 21 | AppCompatButton btnReset; 22 | AppCompatButton btnStart; 23 | 24 | JwtAuthenticator jwtAuthenticator; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | if (Global.isMissingCredentials()) { 31 | setContentView(com.zendesk.demo_apps_commons.R.layout.missing_credentials); 32 | return; 33 | } 34 | setContentView(R.layout.jwt_layout); 35 | 36 | btnSet = findViewById(R.id.btnSet); 37 | btnReset = findViewById(R.id.btnReset); 38 | btnStart = findViewById(R.id.btnStart); 39 | 40 | jwtAuthenticator = new JwtAuthenticator() { 41 | @Override 42 | public void getToken(JwtCompletion jwtCompletion) { 43 | //Fetch or generate the JWT token at this point 44 | //OnSuccess 45 | jwtCompletion.onTokenLoaded("TOKEN-HERE"); 46 | //OnError 47 | jwtCompletion.onError(); 48 | } 49 | }; 50 | 51 | btnSet.setOnClickListener(new View.OnClickListener() { 52 | @Override 53 | public void onClick(View view) { 54 | Chat.INSTANCE.setIdentity(jwtAuthenticator); 55 | } 56 | }); 57 | 58 | btnReset.setOnClickListener(new View.OnClickListener() { 59 | @Override 60 | public void onClick(View view) { 61 | Chat.INSTANCE.resetIdentity(); 62 | } 63 | }); 64 | 65 | btnStart.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View view) { 68 | ChatConfiguration chatConfiguration = ChatConfiguration.builder().build(); 69 | 70 | MessagingActivity.builder() 71 | .withEngines(ChatEngine.engine()) 72 | .show(MainActivity.this, chatConfiguration); 73 | } 74 | }); 75 | } 76 | } -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/layout/jwt_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 27 | 28 | 29 | 30 | 36 | 37 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/android_sdk_demo_apps/ca8a900164e4a6b2413b44ba5013ae54dae5f219/chat_v2_jwt_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #BB86FC 4 | #6200EE 5 | #3700B3 6 | #03DAC5 7 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Application 3 | -------------------------------------------------------------------------------- /chat_v2_jwt_sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | namespace "com.zendesk.chat_v2.sample" 7 | compileSdkVersion rootProject.ext.compileSdkVersion 8 | 9 | defaultConfig { 10 | applicationId rootProject.ext.applicationId + ".chat_v2_message_counter_sample" 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.targetSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_17 27 | targetCompatibility JavaVersion.VERSION_17 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation group: 'com.zendesk', name: 'messaging', version: rootProject.ext.messagingSdkVersion 33 | implementation group: 'com.zendesk', name: 'chat', version: rootProject.ext.chatSdkVersion 34 | 35 | implementation project(":demo_apps_commons") 36 | } -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/java/com/zendesk/chat_v2/sample/Global.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.chat_v2.sample; 2 | 3 | import android.app.Application; 4 | 5 | import com.zendesk.logger.Logger; 6 | import com.zendesk.util.StringUtils; 7 | 8 | import zendesk.chat.Chat; 9 | 10 | public class Global extends Application { 11 | 12 | private static final String CHAT_ACCOUNT_KEY = ""; 13 | 14 | private static boolean missingCredentials = false; 15 | 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | 20 | // Enable logging 21 | Logger.setLoggable(true); 22 | 23 | if (StringUtils.isEmpty(CHAT_ACCOUNT_KEY)) { 24 | missingCredentials = true; 25 | } 26 | 27 | Chat.INSTANCE.init(this, CHAT_ACCOUNT_KEY); 28 | } 29 | 30 | 31 | static boolean isMissingCredentials() { 32 | return missingCredentials; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/java/com/zendesk/chat_v2/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.chat_v2.sample; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | 9 | import zendesk.chat.ChatConfiguration; 10 | import zendesk.chat.ChatEngine; 11 | import zendesk.messaging.MessagingActivity; 12 | 13 | public class MainActivity extends AppCompatActivity implements UnreadMessageCounter.UnreadMessageCounterListener { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | 19 | if (Global.isMissingCredentials()) { 20 | setContentView(com.zendesk.demo_apps_commons.R.layout.missing_credentials); 21 | return; 22 | } 23 | setContentView(R.layout.activity_main); 24 | final UnreadMessageCounter unreadMessageCounter = new UnreadMessageCounter(this); 25 | 26 | findViewById(R.id.btnChat).setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View view) { 29 | unreadMessageCounter.stopCounter(); 30 | MessagingActivity.builder() 31 | .withEngines(ChatEngine.engine()) 32 | .show(MainActivity.this); 33 | 34 | } 35 | }); 36 | 37 | findViewById(R.id.btnCounter).setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View view) { 40 | unreadMessageCounter.startCounter(); 41 | } 42 | }); 43 | } 44 | 45 | @Override 46 | public void onUnreadCountUpdated(int unreadCount) { 47 | ((TextView) findViewById(R.id.tvMessageCounter)).setText(Integer.toString(unreadCount)); 48 | } 49 | } -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/java/com/zendesk/chat_v2/sample/UnreadMessageCounter.java: -------------------------------------------------------------------------------- 1 | package com.zendesk.chat_v2.sample; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import zendesk.chat.Chat; 7 | import zendesk.chat.ChatLog; 8 | import zendesk.chat.ChatState; 9 | import zendesk.chat.ObservationScope; 10 | import zendesk.chat.Observer; 11 | 12 | class UnreadMessageCounter { 13 | 14 | private final UnreadMessageCounterListener unreadMessageCounterListener; 15 | 16 | private boolean shouldCount; 17 | private String lastChatLogId; 18 | private String lastReadChatLogId; 19 | 20 | public UnreadMessageCounter(UnreadMessageCounterListener unreadMessageCounterListener) { 21 | this.unreadMessageCounterListener = unreadMessageCounterListener; 22 | 23 | Chat.INSTANCE.providers().chatProvider().observeChatState(new ObservationScope(), new Observer() { 24 | @Override 25 | public void update(ChatState chatState) { 26 | if (chatState != null && !chatState.getChatLogs().isEmpty()) { 27 | if (shouldCount && lastReadChatLogId != null) { 28 | updateCounter(chatState.getChatLogs(), lastReadChatLogId); 29 | } 30 | lastChatLogId = chatState.getChatLogs().get( 31 | chatState.getChatLogs().size() - 1 32 | ).getId(); 33 | } 34 | } 35 | }); 36 | } 37 | 38 | 39 | // Determines whether or not the chat websocket should be re-connected to. 40 | // A connected, open websocket will disable push notifications and receive messages as normal. 41 | public void startCounter() { 42 | shouldCount = true; 43 | lastReadChatLogId = lastChatLogId; 44 | Chat.INSTANCE.providers().connectionProvider().connect(); 45 | } 46 | 47 | public void stopCounter() { 48 | lastReadChatLogId = null; 49 | shouldCount = false; 50 | unreadMessageCounterListener.onUnreadCountUpdated(0); 51 | } 52 | 53 | // Increment the counter and send an update to the listener 54 | synchronized private void updateCounter(List chatLogs, String lastReadId) { 55 | for (ChatLog chatLog : chatLogs) { 56 | if (chatLog.getId().equals(lastReadId)) { 57 | int lastReadIndex = chatLogs.indexOf(chatLog); 58 | List unreadLogs = chatLogs.subList(lastReadIndex, chatLogs.size() - 1); 59 | unreadMessageCounterListener.onUnreadCountUpdated(unreadLogs.size()); 60 | break; 61 | } 62 | } 63 | 64 | } 65 | 66 | interface UnreadMessageCounterListener { 67 | void onUnreadCountUpdated(int unreadCount); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /chat_v2_message_counter_sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 20 | 21 |