Skip to content

Commit

Permalink
Pull request #427: Jdzubak MCA-3664 set widget theme
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-android from jdzubak-MCA-3664-set-widget-theme to master

Squashed commit of the following:

commit 0a9443fc9a6482371fbc7047d0152ca8b6fc86fb
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Tue Mar 19 13:35:16 2024 +0100

    MCA-3664 Review points

commit ebb584afc394361a75d2d28b1aa0c18cff8a23c3
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Tue Mar 19 13:02:06 2024 +0100

    MCA-3787 WidgetTheme applied once chat is loaded, WidgetInfo contains widgetThemes

commit 0f2fe96744483fc13df8bdf9b7e6359c9bb7bc1d
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Mon Mar 18 10:19:42 2024 +0100

    MCA-3664 Styles internal variable removed

commit a5da35ee7f41ed1a309a9a49773f341e288c6708
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Mon Mar 18 09:55:25 2024 +0100

    MCA-3664 Fixed InAppChatActivityResultDelegate for Flutter plugin

commit 4cc2f258346e05a1256086b9ec96b719b170d09b
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Fri Mar 15 13:07:00 2024 +0100

    MCA-3664 Widget API improved

commit 99382cfa8f302fe89c1df79d5e5277c369cd891e
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Thu Mar 14 17:11:11 2024 +0100

    MCA-3664 removed new lines

commit 3b712a6508a3346788c0ca4d0899598349c9175c
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Thu Mar 14 13:48:33 2024 +0100

    MCA-3664 removed language from WidgetInfo

commit ee5e7cb659cd22545c715fd363e1c7b31a9ba49a
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Thu Mar 14 13:35:42 2024 +0100

    MCA-3664 callAvailable replaced with callsEnabled

commit 17e472000185959be1461ee8c149e56e3e11d4fa
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Thu Mar 14 11:34:39 2024 +0100

    MCA-3664 setDarkMode() deprecated

commit dfe19cbd1f45164250e53b63b7e8f93a26916b4d
Author: Jakub Dzubak <jakub.dzubak@infobip.com>
Date:   Thu Mar 14 10:42:50 2024 +0100

    MCA-3664 InAppChat set widget theme, cleanup + maintenance
  • Loading branch information
jakubdzubak1 committed Mar 19, 2024
1 parent 3f59bc3 commit 35580c6
Show file tree
Hide file tree
Showing 29 changed files with 357 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ abstract class MobileMessagingChatTestCase: MobileMessagingBaseTestCase() {
PreferenceHelper.saveString(context, MobileMessagingChatProperty.IN_APP_CHAT_LANGUAGE.key , "IN_APP_CHAT_LANGUAGE")
PreferenceHelper.saveLong(context, MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_MAX_UPLOAD_CONTENT_SIZE.key , 10L)
PreferenceHelper.saveBoolean(context, MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_MULTITHREAD.key , true)
PreferenceHelper.saveBoolean(context, MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_MULTICHANNEL_CONVERSATION.key , true)
PreferenceHelper.saveBoolean(context, MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_CALLS_AVAILABLE.key , true)
PreferenceHelper.saveBoolean(context, MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_CALLS_ENABLED.key , true)
PreferenceHelper.saveBoolean(context, MobileMessagingChatProperty.IN_APP_CHAT_ACTIVATED.key , true)
propertyHelper = PropertyHelper(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class LivechatRegistrationCheckerTest : MobileMessagingChatTestCase() {

PreferenceHelper.saveBoolean(
context,
MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_CALLS_AVAILABLE.key,
MobileMessagingChatProperty.IN_APP_CHAT_WIDGET_CALLS_ENABLED.key,
true
)
PreferenceHelper.saveString(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<html lang="En">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta
name="viewport"
charset="UTF-8"
content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
>
<script>
(function(I,n,f,o,b,i,p){
I[b]=I[b]||function(){(I[b].q=I[b].q||[]).push(arguments)};
Expand All @@ -21,65 +25,93 @@
<body>
<div id="ib-widget-container"></div>
<script>
// Api call naming section
const CONFIG = 'config';
const IDENTIFY = 'identify';
const INIT = 'init';
const SHOW = 'show';
const SEND = 'send';
const SET_LANGUAGE = 'set_language';
const SEND_CONTEXTUAL_DATA = 'send_contextual_data';
const SHOW_THREAD_LIST = 'show_thread_list';
const MOBILE_CHAT_PAUSE = 'mobile_chat_pause';
const MOBILE_CHAT_RESUME = 'mobile_chat_resume';

const errorCallback = function(error, result) {
// Override widget config
liveChat('config', {
widgetId: getQueryParameter('widgetId'),
container: document.getElementById('ib-widget-container'),
showHeader: false,
showFooter: false,
showFab: false
});

// Try identify user by pushRegId and (optional) jwt
let inputParams = {
'pushRegistrationId' : getQueryParameter('pushRegId'),
};
const jwt = getQueryParameter('jwt');
if (jwt != null){
inputParams.jwt = jwt;
}
liveChat('identify', inputParams, function(error, result) {
if (error) {
errorCallback(error);
} else {
init();
}
});

// If all is OK -> initialize widget, enable native controls and show widget
function init() {
liveChat('init');
liveChat('show', null, onShowCallback);
}

function onShowCallback(error, result) {
if (error) {
errorCallback(error);
} else {
InAppChatMobile.setControlsEnabled(true);
}
}

function errorCallback(error, result) {
if (error) {
if ((typeof error === 'object' || Array.isArray(error)) && error !== null) {
window.InAppChatMobile.onError(JSON.stringify(error));
if (error !== null && (typeof error === 'object' || Array.isArray(error))) {
InAppChatMobile.onError(JSON.stringify(error));
} else {
window.InAppChatMobile.onError(error);
InAppChatMobile.onError(error);
}
}
};

window.handleMessageSend = function(message) {
liveChat(SEND, message);
window.addEventListener('message', (event) => {
if (event.data.destination === 'viewChange') {
InAppChatMobile.onViewChanged(event.data.view);
}
})

//Widget API
function sendMessage(message) {
liveChat('send', message);
}

window.handleMessageWithAttachmentSend = function(message, attachment, fileName) {
liveChat(SEND, {
function sendMessageWithAttachment(message, attachment, fileName) {
liveChat('send', {
'message': message,
'attachment': attachment,
'fileName': fileName,
'type': 'BASIC'
});
}

window.handleMessageDraftSend = function(draft) {
liveChat(SEND, {
function sendDraft(draft) {
liveChat('send', {
'message': draft,
'type': 'DRAFT'
});
}

window.showThreadList = function() {
liveChat(SHOW_THREAD_LIST, null, errorCallback);
function showThreadList() {
liveChat('show_thread_list', null, errorCallback);
}

window.addEventListener('message', (event) => {
if(event.data.destination === 'viewChange') {
window.InAppChatMobile.onViewChanged(event.data.view);
}
})

window.setLanguage = function(language) {
liveChat(SET_LANGUAGE, language, errorCallback);
function setLanguage(language) {
liveChat('set_language', language, errorCallback);
}

window.sendContextualData = function(data, strategy) {
function sendContextualData(data, strategy) {
liveChat(
SEND_CONTEXTUAL_DATA,
'send_contextual_data',
{
metadata: data,
multiThreadStrategy: strategy
Expand All @@ -88,60 +120,23 @@
);
}

window.mobileChatPause = function() {
liveChat(MOBILE_CHAT_PAUSE);
function mobileChatPause() {
liveChat('mobile_chat_pause');
}

window.mobileChatResume = function() {
liveChat(MOBILE_CHAT_RESUME);
function mobileChatResume() {
liveChat('mobile_chat_resume');
}

// Override widget config
liveChat(CONFIG, {
widgetId: getQueryParameter('widgetId'),
container: document.getElementById('ib-widget-container'),
showHeader: false,
showFooter: false,
showFab: false
});

// Try identify user by pushRegId and (optional) jwt
let inputParams = {
'pushRegistrationId' : getQueryParameter('pushRegId'),
};
const jwt = getQueryParameter('jwt');
if(jwt != null){
inputParams.jwt = jwt;
}
liveChat(IDENTIFY, inputParams, function(error, result) {
if (error) {
errorCallback(error);
} else {
init();
}
});

// If all is OK -> initialize widget, enable native controls and show widget
function init() {
liveChat(INIT);
liveChat(SHOW, null, function() {
onShowCallback();
});
}
function setTheme(theme) {
liveChat('set_theme', theme);
}

function getQueryParameter(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search)) {
function getQueryParameter(name) {
if (name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search)) {
return decodeURIComponent(name[1]);
}
}

function onShowCallback(error, result) {
if (error) {
errorCallback(error);
} else {
window.InAppChatMobile.setControlsEnabled(true);
}
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

Expand All @@ -27,6 +28,7 @@ public interface JwtProvider {
*
* @return JWT
*/
@Nullable
String provideJwt();
}

Expand All @@ -36,6 +38,7 @@ public interface JwtProvider {
* @param context android context
* @return instance of chat api
*/
@NonNull
public synchronized static InAppChat getInstance(Context context) {
return InAppChatImpl.getInstance(context);
}
Expand All @@ -51,6 +54,7 @@ public synchronized static InAppChat getInstance(Context context) {
* @return chat view object
* @see InAppChatScreen#show()
*/
@NonNull
public abstract InAppChatScreen inAppChatScreen();

/**
Expand Down Expand Up @@ -167,6 +171,7 @@ public synchronized static InAppChat getInstance(Context context) {
* @return instance of {@link JwtProvider}
* @see JwtProvider
*/
@Nullable
public abstract InAppChat.JwtProvider getJwtProvider();

/**
Expand All @@ -180,22 +185,43 @@ public synchronized static InAppChat getInstance(Context context) {
* <p>DARK_MODE_YES - force dark colors</p>
* <p>DARK_MODE_NO - force light colors</p>
* <p>DARK_MODE_FOLLOW_SYSTEM - use same colors as system-wide mode has</p>
* @deprecated Use combination of InAppChat.setWidgetTheme() and InAppChat.setTheme() instead to achieve dark theme. This function will be removed in a future release.
*
* @param darkMode to be set, null value removes setting and use light theme as default one.
*/
@Deprecated(since = "12.4.0", forRemoval = true)
public abstract void setDarkMode(@Nullable InAppChatDarkMode darkMode);

/**
* Set theme, it is alternative to defining style in xml, if set xml values are replaced.
* Set theme, it is alternative to `IB_AppTheme.Chat` defined in xml, if set xml values are replaced.
* It allows to customise native views of In-app chat.
*
* @param theme data object holding all style attributes
*/
public abstract void setTheme(InAppChatTheme theme);
public abstract void setTheme(@Nullable InAppChatTheme theme);

/**
* Get current theme. Theme is alternative to defining style in xml.
* Get current theme. Theme is alternative to `IB_AppTheme.Chat` defined in xml.
*
* @return theme data object holding all style attributes
*/
@Nullable
public abstract InAppChatTheme getTheme();

/**
* Set the theme of the Livechat Widget.
* You can define widget themes in <a href="https://portal.infobip.com/apps/livechat/widgets">Live chat widget setup page</a> in Infobip Portal, section `Advanced customization`.
* Please check widget <a href="https://www.infobip.com/docs/live-chat/widget-customization">documentation</a> for more details.
*
* @param widgetThemeName unique theme name, empty or blank value is ignored
*/
public abstract void setWidgetTheme(@Nullable String widgetThemeName);

/**
* Get current Livechat Widget theme.
*
* @return applied theme name of Livechat Widget
*/
@Nullable
public abstract String getWidgetTheme();
}
Loading

0 comments on commit 35580c6

Please sign in to comment.