-
Notifications
You must be signed in to change notification settings - Fork 8
[MFD-13002] Add customised colours API to demo app #49
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ee1e47
[MFD-13002] Add customised colours API to demo app
IanArb 1a55912
* PR feedback: Introduce new section for changing colors at runtime u…
IanArb 5b51514
* PR feedback: Remove Hilt and make ZendeskManager an object singleton
IanArb 523d532
* Remove redundant comment lines
IanArb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 11 additions & 26 deletions
37
zendesk_sdk_demo/app/src/main/java/com/example/zendesk_sdk_demo/MainApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,23 @@ | ||
| package com.example.zendesk_sdk_demo | ||
|
|
||
| import android.app.Application | ||
| import android.util.Log | ||
| import zendesk.android.Zendesk | ||
| import dagger.hilt.android.HiltAndroidApp | ||
| import zendesk.messaging.android.DefaultMessagingFactory | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltAndroidApp | ||
| class MainApplication : Application() { | ||
|
|
||
| @Inject | ||
| lateinit var zendeskManager: ZendeskManager | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
|
|
||
| // https://developer.zendesk.com/documentation/zendesk-web-widget-sdks/sdks/android/getting_started/#3-initialize-the-sdk | ||
| Zendesk.initialize(this, this.getString(R.string.channel_key), successCallback = { zendesk -> | ||
| Log.i(LOG_TAG, getString(R.string.msg_init_success)) | ||
| // https://developer.zendesk.com/documentation/zendesk-web-widget-sdks/sdks/android/analytics_tracking | ||
| // Enable/Disable analytics tracking, enabled by default | ||
| zendesk.messaging.enableAnalyticsTracking(enabled = true) | ||
| }, failureCallback = { error -> | ||
| // Tracking the cause of exceptions in your crash reporting dashboard will help to triage any unexpected failures in production | ||
| Log.e(LOG_TAG, "${getString(R.string.msg_init_error)}: $error") | ||
| }, messagingFactory = DefaultMessagingFactory()) | ||
| } | ||
|
|
||
| companion object { | ||
| private val LOG_TAG = "[${Companion::class.java.simpleName}]" | ||
|
|
||
| /** | ||
| * Private reference to the instance of [MainApplication], initialized during [onCreate]. | ||
| */ | ||
| private lateinit var instance: MainApplication | ||
|
|
||
| /** | ||
| * Returns this instance of [MainApplication]. | ||
| */ | ||
| fun get(): MainApplication = instance | ||
| zendeskManager.initialize( | ||
| context = this, | ||
| channelKey = this.getString(R.string.channel_key), | ||
| factory = DefaultMessagingFactory(), | ||
| ) | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
zendesk_sdk_demo/app/src/main/java/com/example/zendesk_sdk_demo/ZendeskManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.example.zendesk_sdk_demo | ||
|
|
||
| import android.content.Context | ||
| import android.widget.Toast | ||
| import zendesk.android.Zendesk | ||
| import zendesk.android.messaging.MessagingFactory | ||
| import zendesk.logger.Logger | ||
| import javax.inject.Inject | ||
|
|
||
| class ZendeskManager @Inject constructor() { | ||
|
|
||
| fun initialize( | ||
| context: Context, | ||
| channelKey: String, | ||
| factory: MessagingFactory, | ||
| ) { | ||
| // https://developer.zendesk.com/documentation/zendesk-web-widget-sdks/sdks/android/getting_started/#3-initialize-the-sdk | ||
| Zendesk.initialize( | ||
| context = context, | ||
| channelKey = channelKey, | ||
| successCallback = { zendesk -> | ||
| Logger.d(LOG_TAG, "Initialization Success", zendesk) | ||
| Toast.makeText( | ||
| context, | ||
| "Initialization Success", Toast.LENGTH_SHORT, | ||
| ).show() | ||
| }, | ||
| failureCallback = { | ||
| Toast.makeText( | ||
| context, | ||
| "Initialization failed", Toast.LENGTH_SHORT, | ||
| ).show() | ||
| Logger.d(LOG_TAG, "Zendesk initialization failed", it) | ||
| }, | ||
| messagingFactory = factory | ||
| ) | ||
| } | ||
|
|
||
| fun showMessaging(context: Context) { | ||
| Zendesk.instance.messaging.showMessaging(context = context) | ||
| } | ||
|
|
||
| fun invalidate() { | ||
| Zendesk.invalidate() | ||
| } | ||
|
|
||
| companion object { | ||
| private const val LOG_TAG = "ZendeskManager" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
zendesk_sdk_demo/app/src/main/res/layout/colors_api_cardview.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
|
||
| <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:card_view="http://schemas.android.com/apk/res-auto"> | ||
|
|
||
| <com.google.android.material.card.MaterialCardView | ||
| android:id="@+id/ConversationCard" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginVertical="8dp" | ||
| android:layout_marginHorizontal="16dp" | ||
| android:layout_gravity="start" | ||
| card_view:cardCornerRadius="@dimen/card_radius"> | ||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:layout_margin="16dp" | ||
| android:gravity="start" | ||
| android:orientation="vertical"> | ||
|
|
||
| <TextView | ||
| style="@style/style_card_title" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="@string/colors_api_card_title" /> | ||
|
|
||
| <TextView | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginVertical="16dp" | ||
| android:text="@string/colors_api_card_description" /> | ||
|
|
||
| <Button | ||
| android:id="@+id/ChangeColorsButton" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="end" | ||
| android:text="@string/colors_api_button" /> | ||
|
|
||
| </LinearLayout> | ||
| </com.google.android.material.card.MaterialCardView> | ||
|
|
||
| </merge> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,10 @@ | |
| <string name="conversation_card_description">Displays the conversation screen for the initial conversation created for your user. A user and a new conversation will automatically be created if they don\'t exist. Ensure you have previously initialized the Zendesk SDK.</string> | ||
| <string name="conversation_button">Show conversation</string> | ||
|
|
||
| <string name="colors_api_card_title">Change the theme color</string> | ||
|
||
| <string name="colors_api_card_description">Demonstrates changing the theme color of the Zendesk SDK using the Colors API.</string> | ||
| <string name="colors_api_button">Change theme color</string> | ||
|
|
||
| <!-- SNACK BAR --> | ||
|
|
||
| <string name="msg_init_success">Initialization Successful</string> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't need Hilt for this demo. We can simply wrap ZendeskManager in object and keep the demo free from any specific API constraints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right. It's overly complicating it. I can remove it.