diff --git a/app/src/main/java/com/glia/exampleapp/Application.java b/app/src/main/java/com/glia/exampleapp/Application.java index abf6528e0..1f4cc0ed3 100644 --- a/app/src/main/java/com/glia/exampleapp/Application.java +++ b/app/src/main/java/com/glia/exampleapp/Application.java @@ -1,14 +1,8 @@ package com.glia.exampleapp; -import android.app.Activity; -import android.os.Bundle; import android.text.TextUtils; import android.util.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.glia.androidsdk.Glia; import com.glia.widgets.GliaWidgets; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; @@ -22,8 +16,6 @@ public void onCreate() { GliaWidgets.onAppCreate(this); GliaWidgets.setCustomCardAdapter(new ExampleCustomCardAdapter()); - - initGliaWidgets(); } private void initFirebase() { @@ -43,35 +35,4 @@ private void initFirebase() { .build(); FirebaseApp.initializeApp(this, options); } - - private void initGliaWidgets() { - registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { - @Override - public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { - if (activity.getClass() != com.glia.exampleapp.Activity.class) { - if (Glia.isInitialized()) return; - - GliaWidgets.init(ExampleAppConfigManager.createDefaultConfig(getApplicationContext())); - } - } - - @Override - public void onActivityStarted(@NonNull Activity activity) {} - - @Override - public void onActivityResumed(@NonNull Activity activity) {} - - @Override - public void onActivityPaused(@NonNull Activity activity) {} - - @Override - public void onActivityStopped(@NonNull Activity activity) {} - - @Override - public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {} - - @Override - public void onActivityDestroyed(@NonNull Activity activity) {} - }); - } } diff --git a/app/src/main/java/com/glia/exampleapp/ChatFragment.java b/app/src/main/java/com/glia/exampleapp/ChatFragment.java deleted file mode 100644 index 66a0e7793..000000000 --- a/app/src/main/java/com/glia/exampleapp/ChatFragment.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.glia.exampleapp; - -import static java.util.Collections.singletonList; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.navigation.NavController; -import androidx.navigation.fragment.NavHostFragment; -import androidx.preference.PreferenceManager; - -import com.glia.widgets.UiTheme; -import com.glia.widgets.chat.ChatView; - -import java.util.Collections; - -public class ChatFragment extends Fragment { - - private NavController navController; - private ChatView chatView; - private ChatView.OnEndListener onEndListener = () -> navController.popBackStack(); - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.chat_fragment, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - navController = NavHostFragment.findNavController(this); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()); - chatView = view.findViewById(R.id.chat_view); - UiTheme theme = Utils.getRunTimeThemeByPrefs(sharedPreferences, getResources()); - chatView.setUiTheme(theme); - chatView.setOnEndListener(onEndListener); - chatView.startChat( - Utils.getStringFromPrefs(R.string.pref_company_name, getString(R.string.settings_value_default_company_name), sharedPreferences, getResources()), - singletonList(Utils.getStringFromPrefs(R.string.pref_queue_id, getString(R.string.glia_queue_id), sharedPreferences, getResources())), - Utils.getStringFromPrefs(R.string.pref_context_asset_id, null, sharedPreferences, getResources())); - } - - @Override - public void onResume() { - chatView.onResume(); - super.onResume(); - } - - @Override - public void onDestroyView() { - onEndListener = null; - chatView.onDestroyView(); - super.onDestroyView(); - } -} diff --git a/app/src/main/java/com/glia/exampleapp/ExampleAppConfigManager.kt b/app/src/main/java/com/glia/exampleapp/ExampleAppConfigManager.kt index c969d307a..84d5b203a 100644 --- a/app/src/main/java/com/glia/exampleapp/ExampleAppConfigManager.kt +++ b/app/src/main/java/com/glia/exampleapp/ExampleAppConfigManager.kt @@ -7,7 +7,6 @@ import androidx.preference.PreferenceManager import com.glia.androidsdk.SiteApiKey import com.glia.androidsdk.screensharing.ScreenSharing import com.glia.widgets.GliaWidgetsConfig -import com.glia.widgets.UiTheme /** * Helper class to obtain Glia Config params from deep-link or preferences. @@ -103,7 +102,6 @@ object ExampleAppConfigManager { fun createDefaultConfig( context: Context, uiJsonRemoteConfig: String? = null, - runtimeConfig: UiTheme? = null, region: String? = null, baseDomain: String = DEFAULT_BASE_DOMAIN, preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) @@ -157,7 +155,6 @@ object ExampleAppConfigManager { .setScreenSharingMode(screenSharingMode) .setContext(context) .setUiJsonRemoteConfig(uiJsonRemoteConfig ?: Utils.getRemoteThemeByPrefs(preferences, context.resources)) - .setUiTheme(runtimeConfig ?: Utils.getRunTimeThemeByPrefs(preferences, context.resources)) .setManualLocaleOverride(manualLocaleOverride) .build() } diff --git a/app/src/main/java/com/glia/exampleapp/MainFragment.kt b/app/src/main/java/com/glia/exampleapp/MainFragment.kt index dd6d69d34..b3010d38b 100644 --- a/app/src/main/java/com/glia/exampleapp/MainFragment.kt +++ b/app/src/main/java/com/glia/exampleapp/MainFragment.kt @@ -26,22 +26,20 @@ import com.glia.androidsdk.Glia import com.glia.androidsdk.GliaException import com.glia.androidsdk.fcm.GliaPushMessage import com.glia.androidsdk.omnibrowse.Omnibrowse -import com.glia.androidsdk.screensharing.ScreenSharing import com.glia.androidsdk.visitor.Authentication import com.glia.exampleapp.ExampleAppConfigManager.createDefaultConfig import com.glia.exampleapp.Utils.getAuthenticationBehaviorFromPrefs import com.glia.widgets.GliaWidgets -import com.glia.widgets.UiTheme -import com.glia.widgets.call.CallActivity -import com.glia.widgets.chat.ChatActivity -import com.glia.widgets.chat.ChatType import com.glia.widgets.core.notification.NotificationActionReceiver -import com.glia.widgets.messagecenter.MessageCenterActivity +import com.glia.widgets.entrywidget.EntryWidget +import com.glia.widgets.launcher.EngagementLauncher import com.google.android.material.appbar.MaterialToolbar +import com.google.android.material.card.MaterialCardView import kotlin.concurrent.thread import kotlin.properties.Delegates class MainFragment : Fragment() { + private var containerView: ConstraintLayout? = null private var authentication: Authentication? = null @@ -53,11 +51,23 @@ class MainFragment : Fragment() { private val authToken: String get() { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) val authTokenFromPrefs = getAuthTokenFromPrefs(sharedPreferences) return authTokenFromPrefs.ifEmpty { getString(R.string.glia_jwt) } } + private val sharedPreferences: SharedPreferences by lazy { + PreferenceManager.getDefaultSharedPreferences(requireContext()) + } + + private val engagementLauncher: EngagementLauncher by lazy { + ensureInitialized() + GliaWidgets.getEngagementLauncher(getQueueIdsFromPrefs(sharedPreferences)) + } + + private val entryWidget: EntryWidget by lazy { + GliaWidgets.getEntryWidget(getQueueIdsFromPrefs(sharedPreferences)) + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -73,14 +83,23 @@ class MainFragment : Fragment() { view.findViewById(R.id.settings_button) .setOnClickListener { navController.navigate(R.id.settings) } + view.findViewById(R.id.entry_widget_button) + .setOnClickListener { + if ((view.findViewById(R.id.entry_widget_switch) as SwitchCompat).isChecked) { + showEntryWidgetInADedicatedView() + } else { + entryWidget.show(requireActivity()) + } + } + val visitorContextAssetId = getContextAssetIdFromPrefs(sharedPreferences) view.findViewById(R.id.chat_activity_button) - .setOnClickListener { navigateToChat(ChatType.LIVE_CHAT) } + .setOnClickListener { engagementLauncher.startChat(requireActivity(), visitorContextAssetId) } view.findViewById(R.id.audio_call_button) - .setOnClickListener { navigateToCall(GliaWidgets.MEDIA_TYPE_AUDIO) } + .setOnClickListener { engagementLauncher.startAudioCall(requireActivity(), visitorContextAssetId) } view.findViewById(R.id.video_call_button) - .setOnClickListener { navigateToCall(GliaWidgets.MEDIA_TYPE_VIDEO) } + .setOnClickListener { engagementLauncher.startVideoCall(requireActivity(), visitorContextAssetId) } view.findViewById(R.id.message_center_activity_button) - .setOnClickListener { navigateToMessageCenter() } + .setOnClickListener { engagementLauncher.startSecureMessaging(requireActivity(), visitorContextAssetId) } view.findViewById(R.id.end_engagement_button) .setOnClickListener { GliaWidgets.endEngagement() } view.findViewById(R.id.visitor_info_button) @@ -193,9 +212,9 @@ class MainFragment : Fragment() { .handleOnMainActivityCreate(requireActivity().intent.extras) ?: return if (push.type == GliaPushMessage.PushType.QUEUED_MESSAGE) { - authenticate { navigateToChat(ChatType.SECURE_MESSAGING) } + authenticate { engagementLauncher.startSecureMessaging(requireActivity()) } } else { - navigateToChat(ChatType.LIVE_CHAT) + engagementLauncher.startChat(requireActivity()) } } @@ -272,52 +291,6 @@ class MainFragment : Fragment() { } } - private fun navigateToChat(chatType: ChatType) { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - val intent = ChatActivity.getIntent( - requireContext(), - getContextAssetIdFromPrefs(sharedPreferences), - getQueueIdsFromPrefs(sharedPreferences), - chatType - ) - startActivity(intent) - } - - private fun navigateToMessageCenter() { - val intent = Intent(requireContext(), MessageCenterActivity::class.java) - setNavigationIntentData(intent) - startActivity(intent) - } - - private fun navigateToCall(mediaType: String) { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - val intent = Intent(context, CallActivity::class.java) - .putExtra(GliaWidgets.QUEUE_IDS, ArrayList(getQueueIdsFromPrefs(sharedPreferences))) - .putExtra(GliaWidgets.CONTEXT_ASSET_ID, getContextAssetIdFromPrefs(sharedPreferences)) - .putExtra(GliaWidgets.UI_THEME, getRuntimeThemeFromPrefs(sharedPreferences)) -// .putExtra(GliaWidgets.USE_OVERLAY, true) // Use it to make sure this deprecated approach is still working - .putExtra(GliaWidgets.SCREEN_SHARING_MODE, getScreenSharingModeFromPrefs(sharedPreferences)) - .putExtra(GliaWidgets.MEDIA_TYPE, Utils.toMediaType(mediaType)) - startActivity(intent) - } - - private fun setNavigationIntentData(intent: Intent) { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - intent.putExtra(GliaWidgets.QUEUE_IDS, ArrayList(getQueueIdsFromPrefs(sharedPreferences))) - .putExtra(GliaWidgets.CONTEXT_ASSET_ID, getContextAssetIdFromPrefs(sharedPreferences)) - .putExtra(GliaWidgets.UI_THEME, getRuntimeThemeFromPrefs(sharedPreferences)) -// .putExtra(GliaWidgets.USE_OVERLAY, true) // Use it to make sure this deprecated approach is still working - .putExtra(GliaWidgets.SCREEN_SHARING_MODE, getScreenSharingModeFromPrefs(sharedPreferences)) - } - - private fun getScreenSharingModeFromPrefs(sharedPreferences: SharedPreferences): ScreenSharing.Mode { - return Utils.getScreenSharingModeFromPrefs(sharedPreferences, resources) - } - - private fun getRuntimeThemeFromPrefs(sharedPreferences: SharedPreferences): UiTheme? { - return Utils.getRunTimeThemeByPrefs(sharedPreferences, resources) - } - private fun getQueueIdsFromPrefs(sharedPreferences: SharedPreferences): List { val defaultQueues = sharedPreferences.getBoolean(resources.getString(R.string.pref_default_queues), false) if (defaultQueues) { @@ -344,24 +317,13 @@ class MainFragment : Fragment() { ) } - private fun getCompanyNameFromPrefs(sharedPreferences: SharedPreferences): String { - return Utils.getStringFromPrefs( - R.string.pref_company_name, - "", - sharedPreferences, - resources - ) - } - private fun saveAuthToken(jwt: String) { if (jwt != getString(R.string.glia_jwt)) { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) putAuthTokenToPrefs(sharedPreferences, jwt) } } private fun clearAuthToken() { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) putAuthTokenToPrefs(sharedPreferences, null) } @@ -436,8 +398,10 @@ class MainFragment : Fragment() { return container } - private fun prepareJwtInputViewEditText(builder: AlertDialog.Builder, - dialogTitle: Int): EditText { + private fun prepareJwtInputViewEditText( + builder: AlertDialog.Builder, + dialogTitle: Int + ): EditText { val input = EditText(context) input.setHint(R.string.authentication_dialog_jwt_input_hint) input.setSingleLine() @@ -449,8 +413,10 @@ class MainFragment : Fragment() { return input } - private fun prepareExternalTokenInputViewEditText(builder: AlertDialog.Builder, - dialogTitle: Int): EditText { + private fun prepareExternalTokenInputViewEditText( + builder: AlertDialog.Builder, + dialogTitle: Int + ): EditText { val input = EditText(context) input.setHint(R.string.authentication_dialog_external_token_input_hint) input.setSingleLine() @@ -496,7 +462,7 @@ class MainFragment : Fragment() { if (externalToken!!.isEmpty()) externalToken = null authentication?.refresh( jwt, externalToken - ) { response, exception -> + ) { _, exception -> setupAuthButtonsVisibility() if (exception != null || !authentication!!.isAuthenticated) { showToast("Error: $exception") @@ -507,6 +473,12 @@ class MainFragment : Fragment() { saveAuthToken(jwt) } + private fun ensureInitialized() { + if (!Glia.isInitialized()) { + initGliaWidgets() + } + } + private fun initGliaWidgets() { if (Glia.isInitialized()) { setupAuthButtonsVisibility() @@ -517,8 +489,7 @@ class MainFragment : Fragment() { GliaWidgets.init( createDefaultConfig( context = requireActivity().applicationContext, -// uiJsonRemoteConfig = UnifiedUiConfigurationLoader.fetchRemoteConfiguration(), -// runtimeConfig = createSampleRuntimeConfig(), +// uiJsonRemoteConfig = UnifiedUiConfigurationLoader.fetchLocalConfigSample(requireContext()), // region = "us" ) ) @@ -529,14 +500,9 @@ class MainFragment : Fragment() { view?.post { initMenu() } } - private fun createSampleRuntimeConfig(): UiTheme = UiTheme( - gvaQuickReplyTextColor = android.R.color.holo_green_dark, - gvaQuickReplyStrokeColor = android.R.color.holo_green_dark, - brandPrimaryColor = android.R.color.holo_green_dark - ) - private fun prepareAuthentication() { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + authentication = GliaWidgets.getAuthentication(getAuthenticationBehaviorFromPrefs(sharedPreferences, resources)) authentication = GliaWidgets.getAuthentication(getAuthenticationBehaviorFromPrefs(sharedPreferences, resources)) } @@ -585,12 +551,20 @@ class MainFragment : Fragment() { setupAuthButtonsVisibility() } + // For testing the embedded Entry Widget + private fun showEntryWidgetInADedicatedView() { + val entryWidgetView = entryWidget.getView(requireContext()) + val container = containerView!!.findViewById(R.id.entry_widget_container) + container.removeAllViews() + container.addView(entryWidgetView) + container.visibility = View.VISIBLE + } + private fun showVisitorCode() { - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - val visitorContext = getContextAssetIdFromPrefs(sharedPreferences) + val visitorContextAssetId = getContextAssetIdFromPrefs(sharedPreferences) val cv = GliaWidgets.getCallVisualizer() - if (!visitorContext.isNullOrBlank()) { - cv.addVisitorContext(visitorContext) + if (!visitorContextAssetId.isNullOrBlank()) { + cv.addVisitorContext(visitorContextAssetId) } cv.showVisitorCodeDialog() } @@ -598,14 +572,14 @@ class MainFragment : Fragment() { // For testing the integrated Visitor Code solution private fun showVisitorCodeInADedicatedView() { val visitorCodeView = GliaWidgets.getCallVisualizer().createVisitorCodeView(requireContext()) - val cv = containerView!!.findViewById(R.id.container) + val cv = containerView!!.findViewById(R.id.visitor_code_container) cv.removeAllViews() cv.addView(visitorCodeView) cv.visibility = View.VISIBLE } private fun removeVisitorCodeFromDedicatedView() { - val cv = containerView!!.findViewById(R.id.container) + val cv = containerView!!.findViewById(R.id.visitor_code_container) cv.removeAllViews() cv.visibility = View.GONE } diff --git a/app/src/main/java/com/glia/exampleapp/RuntimeThemeSettingsFragment.kt b/app/src/main/java/com/glia/exampleapp/RuntimeThemeSettingsFragment.kt deleted file mode 100644 index 098a65a53..000000000 --- a/app/src/main/java/com/glia/exampleapp/RuntimeThemeSettingsFragment.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.glia.exampleapp - -import android.os.Bundle -import androidx.preference.PreferenceFragmentCompat - -class RuntimeThemeSettingsFragment : PreferenceFragmentCompat() { - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.runtime_theme_prefs, rootKey) - } -} diff --git a/app/src/main/java/com/glia/exampleapp/SettingsFragment.java b/app/src/main/java/com/glia/exampleapp/SettingsFragment.java index de5a65343..a2ea729dd 100644 --- a/app/src/main/java/com/glia/exampleapp/SettingsFragment.java +++ b/app/src/main/java/com/glia/exampleapp/SettingsFragment.java @@ -37,14 +37,11 @@ public boolean onPreferenceTreeClick(Preference preference) { // IllegalStateException: Fragment 'MyFragment' declared target fragment 'AnotherMyFragment' // that does not belong to this FragmentManager! String baseSettingsKey = getString(R.string.pref_glia_basic_settings); - String runtimeSettingsKey = getString(R.string.pref_glia_runtime_theme_settings); String remoteSettingsKey = getString(R.string.pref_glia_remote_theme_settings); String currentKey = preference.getKey(); NavController navController = NavHostFragment.findNavController(this); if (currentKey.equals(baseSettingsKey)) { navController.navigate(R.id.base_settings); - } else if (currentKey.equals(runtimeSettingsKey)) { - navController.navigate(R.id.runtime_settings); } else if (currentKey.equals(remoteSettingsKey)) { navController.navigate(R.id.remote_settings); } else { diff --git a/app/src/main/java/com/glia/exampleapp/Utils.java b/app/src/main/java/com/glia/exampleapp/Utils.java index 169cbf86f..8038d634e 100644 --- a/app/src/main/java/com/glia/exampleapp/Utils.java +++ b/app/src/main/java/com/glia/exampleapp/Utils.java @@ -1,29 +1,16 @@ package com.glia.exampleapp; -import android.content.Context; import android.content.SharedPreferences; -import android.content.res.ColorStateList; import android.content.res.Resources; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; -import androidx.core.content.ContextCompat; -import com.glia.androidsdk.Engagement; -import com.glia.androidsdk.screensharing.ScreenSharing; import com.glia.androidsdk.visitor.Authentication; -import com.glia.widgets.GliaWidgets; -import com.glia.widgets.UiTheme; -import com.glia.widgets.view.configuration.ButtonConfiguration; -import com.glia.widgets.view.configuration.ChatHeadConfiguration; -import com.glia.widgets.view.configuration.TextConfiguration; import org.json.JSONException; import org.json.JSONObject; -import java.security.InvalidParameterException; - class Utils { public static String getStringFromPrefs(@StringRes int keyValue, String defaultValue, SharedPreferences sharedPreferences, Resources resources) { @@ -72,156 +59,6 @@ private static String toHexColor(Integer intColor, Resources resources) { // %08X gives you zero-padded hex that is 8 chars long) return String.format("#%08X", resources.getColor(intColor, null)); } - - @Nullable - public static UiTheme getRunTimeThemeByPrefs(SharedPreferences sharedPreferences, Resources resources) { - boolean isRunTimeThemeEnabled = sharedPreferences.getBoolean(resources.getString(R.string.pref_runtime_theme), false); - if (!isRunTimeThemeEnabled) { - return null; - } - - String title = Utils.getStringFromPrefs(R.string.pref_header_title, null, sharedPreferences, resources); - Integer baseLightColor = getColorValueFromPrefs(R.string.pref_base_light_color, sharedPreferences, resources); - Integer baseDarkColor = getColorValueFromPrefs(R.string.pref_base_dark_color, sharedPreferences, resources); - Integer baseNormalColor = getColorValueFromPrefs(R.string.pref_base_normal_color, sharedPreferences, resources); - Integer baseShadeColor = getColorValueFromPrefs(R.string.pref_base_shade_color, sharedPreferences, resources); - Integer brandPrimaryColor = getColorValueFromPrefs(R.string.pref_brand_primary_color, sharedPreferences, resources); - Integer systemAgentBubbleColor = getColorValueFromPrefs(R.string.pref_system_agent_bubble_color, sharedPreferences, resources); - Integer chatSendMessageButtonTintColor = getColorValueFromPrefs(R.string.pref_send_message_button_tint_color, sharedPreferences, resources); - Integer chatHeaderTitleTintColor = getColorValueFromPrefs(R.string.pref_chat_header_title_tint_color, sharedPreferences, resources); - Integer chatHeaderHomeButtonTintColor = getColorValueFromPrefs(R.string.pref_chat_header_home_button_tint_color, sharedPreferences, resources); - Integer chatHeaderExitQueueButtonTintColor = getColorValueFromPrefs(R.string.pref_chat_header_exit_queue_button_tint_color, sharedPreferences, resources); - Integer chatStartingHeadingTextColorRes = getColorValueFromPrefs(R.string.pref_chat_starting_heading_text_color, sharedPreferences, resources); - Integer chatStartingCaptionTextColorRes = getColorValueFromPrefs(R.string.pref_chat_starting_caption_text_color, sharedPreferences, resources); - Integer chatStartedHeadingTextColorRes = getColorValueFromPrefs(R.string.pref_chat_started_heading_text_color, sharedPreferences, resources); - Integer chatStartedCaptionTextColorRes = getColorValueFromPrefs(R.string.pref_chat_started_caption_text_color, sharedPreferences, resources); - Integer fontFamily = getTypefaceFromPrefs(sharedPreferences, resources); - Integer systemNegativeColor = getColorValueFromPrefs(R.string.pref_system_negative_color, sharedPreferences, resources); - Integer visitorMessageBackgroundColor = getColorValueFromPrefs(R.string.pref_visitor_message_bg_color, sharedPreferences, resources); - Integer visitorMessageTextColor = getColorValueFromPrefs(R.string.pref_visitor_message_txt_color, sharedPreferences, resources); - Integer operatorMessageBackgroundColor = getColorValueFromPrefs(R.string.pref_operator_message_bg_color, sharedPreferences, resources); - Integer operatorMessageTextColor = getColorValueFromPrefs(R.string.pref_operator_message_txt_color, sharedPreferences, resources); - Integer botActionButtonBackgroundColor = getColorValueFromPrefs(R.string.pref_bot_action_button_bg_color, sharedPreferences, resources); - Integer botActionButtonTextColor = getColorValueFromPrefs(R.string.pref_bot_action_button_txt_color, sharedPreferences, resources); - Integer botActionButtonSelectedBackgroundColor = getColorValueFromPrefs(R.string.pref_bot_action_button_selected_bg_color, sharedPreferences, resources); - Integer botActionButtonSelectedTextColor = getColorValueFromPrefs(R.string.pref_bot_action_button_selected_txt_color, sharedPreferences, resources); - - Boolean whiteLabel = sharedPreferences.getBoolean(resources.getString(R.string.pref_white_label), false); - - Boolean gliaAlertDialogButtonUseVerticalAlignment = sharedPreferences.getBoolean( - resources.getString(R.string.pref_use_alert_dialog_button_vertical_alignment), - false - ); - - UiTheme.UiThemeBuilder builder = new UiTheme.UiThemeBuilder(); - - builder.setAppBarTitle(title); - builder.setBaseLightColor(baseLightColor); - builder.setBaseDarkColor(baseDarkColor); - builder.setBaseNormalColor(baseNormalColor); - builder.setBaseShadeColor(baseShadeColor); - builder.setSystemAgentBubbleColor(systemAgentBubbleColor); - builder.setBrandPrimaryColor(brandPrimaryColor); - builder.setFontRes(fontFamily); - builder.setSystemNegativeColor(systemNegativeColor); - builder.setVisitorMessageBackgroundColor(visitorMessageBackgroundColor); - builder.setVisitorMessageTextColor(visitorMessageTextColor); - builder.setOperatorMessageBackgroundColor(operatorMessageBackgroundColor); - builder.setOperatorMessageTextColor(operatorMessageTextColor); - - builder.setWhiteLabel(whiteLabel); - - // choice card attributes - builder.setChoiceCardContentTextConfiguration(null); - builder.setBotActionButtonBackgroundColor(botActionButtonBackgroundColor); - builder.setBotActionButtonTextColor(botActionButtonTextColor); - builder.setBotActionButtonSelectedBackgroundColor(botActionButtonSelectedBackgroundColor); - builder.setBotActionButtonSelectedTextColor(botActionButtonSelectedTextColor); - - // to set alert buttons to align vertically in runtime - builder.setGliaAlertDialogButtonUseVerticalAlignment(gliaAlertDialogButtonUseVerticalAlignment); - - // here goes header end engagement button configuration - builder.setHeaderEndButtonConfiguration(null); - builder.setPositiveButtonConfiguration(null); - builder.setNegativeButtonConfiguration(null); - builder.setNeutralButtonConfiguration(null); - - builder.setChatHeadConfiguration( - getChatHeadConfiguration( - brandPrimaryColor, - baseLightColor - ) - ); - - builder.setSendMessageButtonTintColor(chatSendMessageButtonTintColor); - - builder.setGliaChatHeaderTitleTintColor(chatHeaderTitleTintColor); - builder.setGliaChatHeaderHomeButtonTintColor(chatHeaderHomeButtonTintColor); - builder.setGliaChatHeaderExitQueueButtonTintColor(chatHeaderExitQueueButtonTintColor); - - builder.setChatStartingHeadingTextColor(chatStartingHeadingTextColorRes); - builder.setChatStartingCaptionTextColor(chatStartingCaptionTextColorRes); - builder.setChatStartedHeadingTextColor(chatStartedHeadingTextColorRes); - builder.setChatStartedCaptionTextColor(chatStartedCaptionTextColorRes); - return builder.build(); - } - - // Positive button configuration Example runtime - private static ButtonConfiguration getPositiveButtonTestingConfiguration(Context context) { - return ButtonConfiguration.builder() - .backgroundColor( - ColorStateList.valueOf(ContextCompat.getColor(context, R.color.color_blue)) - ) - .textConfiguration( - TextConfiguration.builder() - .textColor( - ColorStateList.valueOf(ContextCompat.getColor(context, R.color.color_black)) - ) - .build() - ) - .build(); - } - - // Negative button configuration Example runtime - private static ButtonConfiguration getNegativeButtonTestingConfiguration(Context context) { - return ButtonConfiguration.builder() - .backgroundColor( - ColorStateList.valueOf(ContextCompat.getColor(context, R.color.color_white)) - ) - .textConfiguration( - TextConfiguration.builder() - .textColor( - ColorStateList.valueOf(ContextCompat.getColor(context, R.color.color_black)) - ) - .build() - ) - .strokeWidth(1) - .strokeColor(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.color_black))) - .build(); - } - - private static ChatHeadConfiguration getChatHeadConfiguration( - Integer colorPrimary, - Integer colorBright - ) { - return ChatHeadConfiguration.builder() - .backgroundColorRes(colorPrimary) - .operatorPlaceholderIconTintList(colorBright) - .operatorPlaceholderBackgroundColor(colorPrimary) - .badgeTextColor(colorBright) - .badgeBackgroundTintList(colorPrimary) - .build(); - } - - private static TextConfiguration getChoiceCardContentTextConfiguration(Context context) { - return TextConfiguration.builder() - .textSize(16f) // in sp - .fontFamily(R.font.tangerine) - .textColor(ContextCompat.getColorStateList(context, R.color.color_dark_cyan)) - .build(); - } - public static Integer getColorValueFromPrefs(@StringRes int keyValue, SharedPreferences sharedPreferences, Resources resources) { String colorGrey = resources.getString(R.string.color_grey_value); String colorRed = resources.getString(R.string.color_red_value); @@ -267,44 +104,6 @@ public static Integer getColorValueFromPrefs(@StringRes int keyValue, SharedPref return null; } - public static Integer getTypefaceFromPrefs(SharedPreferences sharedPreferences, Resources resources) { - String delius = resources.getString(R.string.font_delius_value); - String expletus = resources.getString(R.string.font_expletus_value); - String tangerine = resources.getString(R.string.font_tangerine_value); - String defaultPrefValue = resources.getString(R.string.settings_value_default); - - String typeFaceValue = sharedPreferences.getString(resources.getString(R.string.pref_font_family), defaultPrefValue); - - if (!typeFaceValue.equals(defaultPrefValue)) { - if (typeFaceValue.equals(delius)) { - return R.font.delius; - } else if (typeFaceValue.equals(expletus)) { - return R.font.expletus; - } else if (typeFaceValue.equals(tangerine)) { - return R.font.tangerine; - } - } - return null; - } - - public static ScreenSharing.Mode getScreenSharingModeFromPrefs( - SharedPreferences sharedPreferences, - Resources resources - ) { - String unboundedValue = resources.getString(R.string.screen_sharing_mode_unbounded); - String appBoundedValue = resources.getString(R.string.screen_sharing_mode_app_bounded); - String valueFromPrefs = sharedPreferences.getString( - resources.getString(R.string.pref_screen_sharing_mode), - unboundedValue - ); - - if (valueFromPrefs.equals(appBoundedValue)) { - return ScreenSharing.Mode.APP_BOUNDED; - } else { - return ScreenSharing.Mode.UNBOUNDED; - } - } - public static Authentication.Behavior getAuthenticationBehaviorFromPrefs( SharedPreferences sharedPreferences, Resources resources @@ -321,15 +120,4 @@ public static Authentication.Behavior getAuthenticationBehaviorFromPrefs( return Authentication.Behavior.FORBIDDEN_DURING_ENGAGEMENT; } } - - public static Engagement.MediaType toMediaType(@NonNull String mediaType) { - switch (mediaType) { - case GliaWidgets.MEDIA_TYPE_VIDEO: - return Engagement.MediaType.VIDEO; - case GliaWidgets.MEDIA_TYPE_AUDIO: - return Engagement.MediaType.AUDIO; - default: - throw new InvalidParameterException("Invalid Media Type"); - } - } } diff --git a/app/src/main/res/layout/chat_fragment.xml b/app/src/main/res/layout/chat_fragment.xml deleted file mode 100644 index 915fa734e..000000000 --- a/app/src/main/res/layout/chat_fragment.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/main_fragment.xml b/app/src/main/res/layout/main_fragment.xml index 31aaf060d..0cb4b5a36 100644 --- a/app/src/main/res/layout/main_fragment.xml +++ b/app/src/main/res/layout/main_fragment.xml @@ -67,17 +67,64 @@ app:layout_constraintStart_toStartOf="@id/start_guideline" app:layout_constraintTop_toBottomOf="@id/tool_bar_layout" /> - + app:layout_constraintTop_toBottomOf="@id/entry_widget_switch" />