Skip to content

Commit

Permalink
Implement Leave Current Conversation dialog
Browse files Browse the repository at this point in the history
MOB-3637
  • Loading branch information
gugalo committed Dec 12, 2024
1 parent 193bd13 commit bbf1c40
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 40 deletions.
2 changes: 1 addition & 1 deletion widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private fun showLeaveCurrentConversationDialog(action: LeaveDialogAction) = showDialog {
Dialogs.showLeaveCurrentConversationDialog(
context,
action.name,
theme,
onStay = {
resetDialogStateAndDismiss()
controller?.leaveCurrentConversationDialogStayClicked()
Expand Down
33 changes: 16 additions & 17 deletions widgetssdk/src/main/java/com/glia/widgets/view/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,24 @@ internal object Dialogs {
.show()
}

//TODO change this during implementation of the Dialog - https://glia.atlassian.net/browse/MOB-3637
fun showLeaveCurrentConversationDialog(
context: Context,
title: String,
onStay: () -> Unit,
onLeave: () -> Unit
): AlertDialog = MaterialAlertDialogBuilder(context)
.setBackgroundInsetEnd(48)
.setBackgroundInsetStart(48)
.setBackgroundInsetTop(48)
.setBackgroundInsetBottom(48)
.setTitle(title)
.setIcon(R.drawable.ic_glia_logo)
.setMessage("Just random text to make this dialog look not so boring")
.setNegativeButton("Stay") { _, _ -> onStay() }
.setPositiveButton("Leave") { _, _ -> onLeave() }
.setCancelable(true)
.setOnCancelListener { onStay() }
.show()
theme: UiTheme,
onStay: View.OnClickListener,
onLeave: View.OnClickListener
): AlertDialog {
val payload = DialogPayload.Option(
title = LocaleString(R.string.secure_messaging_chat_leave_current_conversation_title),
message = LocaleString(R.string.secure_messaging_chat_leave_current_conversation_message),
positiveButtonText = LocaleString(R.string.secure_messaging_chat_leave_current_conversation_button_positive),
negativeButtonText = LocaleString(R.string.secure_messaging_chat_leave_current_conversation_button_negative),
poweredByText = poweredByText,
positiveButtonClickListener = onStay,
negativeButtonClickListener = onLeave
)

return dialogService.showDialog(context, theme, DialogType.OptionWithNegativeNeutral(payload))
}

private fun Window.allowOutsideTouch() {
setFlags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.glia.widgets.view.dialog.base

internal sealed class DialogType(payload: DialogPayload) {
data class Option(val payload: DialogPayload.Option) : DialogType(payload)
data class OptionWithNegativeNeutral(val payload: DialogPayload.Option) : DialogType(payload)
data class ReversedOption(val payload: DialogPayload.Option) : DialogType(payload)
data class Confirmation(val payload: DialogPayload.Confirmation) : DialogType(payload)
data class Upgrade(val payload: DialogPayload.Upgrade) : DialogType(payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import com.glia.widgets.view.dialog.confirmation.ConfirmationDialogViewInflater
import com.glia.widgets.view.dialog.confirmation.VerticalConfirmationDialogViewInflater
import com.glia.widgets.view.dialog.operatorendedengagement.OperatorEndedEngagementDialogViewInflater
import com.glia.widgets.view.dialog.option.OptionDialogViewInflater
import com.glia.widgets.view.dialog.option.OptionWithNegativeNeutralDialogViewInflater
import com.glia.widgets.view.dialog.option.ReversedOptionDialogViewInflater
import com.glia.widgets.view.dialog.option.VerticalOptionDialogViewInflater
import com.glia.widgets.view.dialog.option.VerticalOptionWithNegativeNeutralDialogViewInflater
import com.glia.widgets.view.dialog.option.VerticalReversedOptionDialogViewInflater
import com.glia.widgets.view.dialog.screensharing.ScreenSharingDialogViewInflater
import com.glia.widgets.view.dialog.screensharing.VerticalScreenSharingDialogViewInflater
Expand All @@ -35,6 +37,8 @@ internal class DialogViewFactory(context: Context, uiTheme: UiTheme, unifiedThem
type is DialogType.Option -> OptionDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.ReversedOption && isVerticalAxis -> VerticalReversedOptionDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.ReversedOption -> ReversedOptionDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.OptionWithNegativeNeutral && isVerticalAxis -> VerticalOptionWithNegativeNeutralDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.OptionWithNegativeNeutral -> OptionWithNegativeNeutralDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.Confirmation && isVerticalAxis -> VerticalConfirmationDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.Confirmation -> ConfirmationDialogViewInflater(layoutInflater, configuration, type.payload)
type is DialogType.Upgrade && isVerticalAxis -> VerticalUpgradeDialogViewInflater(layoutInflater, configuration, type.payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,39 @@ internal class VerticalReversedOptionDialogViewInflater(
themeWrapper,
payload
)


internal class OptionWithNegativeNeutralDialogViewInflater(layoutInflater: LayoutInflater, themeWrapper: AlertDialogConfiguration, payload: DialogPayload.Option) :
DefaultOptionWithNegativeNeutralDialogViewInflater<OptionDialogViewBinding>(OptionDialogViewBinding(layoutInflater), themeWrapper, payload)

internal class VerticalOptionWithNegativeNeutralDialogViewInflater(
layoutInflater: LayoutInflater,
themeWrapper: AlertDialogConfiguration,
payload: DialogPayload.Option
) :
DefaultOptionWithNegativeNeutralDialogViewInflater<VerticalOptionDialogViewBinding>(VerticalOptionDialogViewBinding(layoutInflater), themeWrapper, payload)

internal open class DefaultOptionWithNegativeNeutralDialogViewInflater<T : DefaultOptionDialogViewBinding<*>>(
binding: T,
themeWrapper: AlertDialogConfiguration,
payload: DialogPayload.Option
) : BaseOptionDialogViewInflater<T>(binding, themeWrapper, payload) {
final override fun setup(binding: T, configuration: AlertDialogConfiguration, payload: DialogPayload.Option) {
super.setup(binding, configuration, payload)
val theme = configuration.theme
setupButton(
binding.negativeButton, // Reversed button positions: negative button takes all properties of positive
payload.positiveButtonText,
theme.positiveButton,
configuration.properties.typeface,
payload.positiveButtonClickListener
)
setupButton(
binding.positiveButton, // Reversed button positions: positive button takes all properties of negative
payload.negativeButtonText,
theme.negativeNeutralButton, // Not 'negative' theme but from 'negative neutral' theme
configuration.properties.typeface,
payload.negativeButtonClickListener
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ internal fun TextView.applyTextTheme(
internal fun MaterialButton.applyButtonTheme(buttonTheme: ButtonTheme?) {
buttonTheme?.background?.also { bg ->
bg.fill?.also { backgroundTintList = it.primaryColorStateList }
bg.stroke?.also { strokeColor = ColorStateList.valueOf(it) }
bg.cornerRadiusInt?.also { cornerRadius = it }
bg.borderWidthInt?.also { strokeWidth = it }
bg.stroke?.also { borderColor ->
strokeColor = ColorStateList.valueOf(borderColor)
// If `borderWidth` is `null` even though `strokeColor` is provided then use default border width
strokeWidth = bg.borderWidthInt ?: resources.getDimensionPixelSize(R.dimen.glia_px)
bg.cornerRadiusInt?.also { cornerRadius = it }
}
}

buttonTheme?.elevation?.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal fun AlertTheme(pallet: ColorPallet): AlertTheme = pallet.run {
closeButtonColor = normalColorTheme,
linkButton = LinkDefaultButtonTheme(this),
positiveButton = PositiveDefaultButtonTheme(this),
negativeButton = NegativeDefaultButtonTheme(this)
negativeButton = NegativeDefaultButtonTheme(this),
negativeNeutralButton = NegativeNeutralDefaultButtonTheme(this),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ internal fun NegativeDefaultButtonTheme(pallet: ColorPallet) = pallet.run {
DefaultButtonTheme(text = lightColorTheme, background = negativeColorTheme)
}

/**
* Default theme for Negative Neutral Button
*/
internal fun NegativeNeutralDefaultButtonTheme(pallet: ColorPallet) = pallet.run {
OutlinedButtonTheme(
text = negativeColorTheme,
background = lightColorTheme,
stroke = shadeColorTheme,
)
}

/**
* Default theme for Link Button
*/
Expand All @@ -46,13 +57,14 @@ internal fun LinkDefaultButtonTheme(pallet: ColorPallet) = pallet.run {
*/
internal fun OutlinedButtonTheme(
text: ColorTheme?,
stroke: ColorTheme?
): ButtonTheme? = composeIfAtLeastOneNotNull(text, stroke) {
stroke: ColorTheme?,
background: ColorTheme? = null,
): ButtonTheme? = composeIfAtLeastOneNotNull(text, stroke, background) {
ButtonTheme(
text = TextTheme(textColor = text),
background = LayerTheme(stroke = stroke?.primaryColor),
background = LayerTheme(fill = background, stroke = stroke?.primaryColor),
iconColor = null,
elevation = null,
elevation = 0f,
shadowColor = null
)
}
Expand Down
4 changes: 4 additions & 0 deletions widgetssdk/src/main/res/values/new_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
<string name="secure_messaging_chat_banner_bottom">@string/message_center_bottom_banner</string>
<string name="secure_messaging_chat_unavailable_message">@string/message_center_error_unavailable_message</string>
<string name="secure_messaging_chat_banner_top">@string/need_live_support_label</string>
<string name="secure_messaging_chat_leave_current_conversation_title">@string/message_center_leaving_conversation_title</string>
<string name="secure_messaging_chat_leave_current_conversation_message">@string/message_center_leaving_conversation_message</string>
<string name="secure_messaging_chat_leave_current_conversation_button_positive">@string/message_center_leaving_conversation_positive_button</string>
<string name="secure_messaging_chat_leave_current_conversation_button_negative">@string/message_center_leaving_conversation_negative_button</string>

<!-- General -->
<string name="general_refresh">@string/glia_visitor_code_refresh_button</string>
Expand Down
4 changes: 4 additions & 0 deletions widgetssdk/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<string name="message_center_confirmation_screen_message">Your message has been sent. We will get back to you within 1 business day.</string>
<string name="message_center_bottom_banner">Secure messaging has an expected response time of 1 business day.</string>
<string name="message_center_error_unavailable_message">Sending messages is currently not available.</string>
<string name="message_center_leaving_conversation_title">Leave Current Conversation?</string>
<string name="message_center_leaving_conversation_message">You already have a conversation in progress. Starting a new one may lead to our agents overlooking your current conversation.</string>
<string name="message_center_leaving_conversation_positive_button">Stay</string>
<string name="message_center_leaving_conversation_negative_button">Leave</string>
<string name="need_live_support_label">Need live support?</string>
<string name="call_visualizer_screen_sharing_title">Screen Sharing</string>
<string name="call_visualizer_label">Your Screen is Being Shared</string>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,47 @@ internal class OptionDialogTest : SnapshotTest(
renderingMode = fullWidthRenderMode
), SnapshotDialog {

private val dialogType: DialogType = DialogType.Option(
DialogPayload.Option(
title = title,
message = message,
positiveButtonText = positiveButtonText,
negativeButtonText = negativeButtonText,
poweredByText = poweredByText,
positiveButtonClickListener = {},
negativeButtonClickListener = {}

)
private val dialogPayload = DialogPayload.Option(
title = title,
message = message,
positiveButtonText = positiveButtonText,
negativeButtonText = negativeButtonText,
poweredByText = poweredByText,
positiveButtonClickListener = {},
negativeButtonClickListener = {}

)

private val default = DialogType.Option(dialogPayload)
private val negativeNeutral = DialogType.OptionWithNegativeNeutral(dialogPayload)

@Test
fun withDefaultTheme() {
val view = inflateView(context = context, dialogType = dialogType)
val view = inflateView(context = context, dialogType = default)
snapshot(view)
}

@Test
fun withUnifiedTheme() {
val view = inflateView(context = context, unifiedTheme(), dialogType = dialogType)
val view = inflateView(context = context, unifiedTheme(), dialogType = default)
snapshot(view)
}

@Test
fun withGlobalColors() {
val view = inflateView(context = context, unifiedThemeWithGlobalColors(), dialogType = dialogType)
val view = inflateView(context = context, unifiedThemeWithGlobalColors(), dialogType = default)
snapshot(view)
}

@Test
fun negativeNeutralDefaultTheme() {
val view = inflateView(context = context, dialogType = negativeNeutral)
snapshot(view)
}

@Test
fun negativeNeutralGlobalColors() {
val view = inflateView(context = context, unifiedThemeWithGlobalColors(), dialogType = negativeNeutral)
snapshot(view)
}
}

0 comments on commit bbf1c40

Please sign in to comment.