Skip to content

Commit

Permalink
Add ability to show embedded Entry Widget view in the example app
Browse files Browse the repository at this point in the history
MOB-3714
  • Loading branch information
AH-MOC committed Oct 30, 2024
1 parent 4f0cd8b commit 0cb61af
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
22 changes: 19 additions & 3 deletions app/src/main/java/com/glia/exampleapp/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
Expand Down Expand Up @@ -83,7 +84,13 @@ class MainFragment : Fragment() {
view.findViewById<View>(R.id.settings_button)
.setOnClickListener { navController.navigate(R.id.settings) }
view.findViewById<View>(R.id.entry_widget_button)
.setOnClickListener { entryWidget.show(requireActivity()) }
.setOnClickListener {
if ((view.findViewById<View>(R.id.entry_widget_switch) as SwitchCompat).isChecked) {
showEntryWidgetInADedicatedView()
} else {
entryWidget.show(requireActivity())
}
}
view.findViewById<View>(R.id.chat_activity_button)
.setOnClickListener { engagementLauncher.startChat(requireActivity()) }
view.findViewById<View>(R.id.audio_call_button)
Expand Down Expand Up @@ -543,6 +550,15 @@ class MainFragment : Fragment() {
setupAuthButtonsVisibility()
}

// For testing the embedded Entry Widget
private fun showEntryWidgetInADedicatedView() {
val entryWidgetView = entryWidget.getView(requireContext())
val container = containerView!!.findViewById<FrameLayout>(R.id.entry_widget_container)
container.removeAllViews()
container.addView(entryWidgetView)
container.visibility = View.VISIBLE
}

private fun showVisitorCode() {
val visitorContext = getContextAssetIdFromPrefs(sharedPreferences)
val cv = GliaWidgets.getCallVisualizer()
Expand All @@ -555,14 +571,14 @@ class MainFragment : Fragment() {
// For testing the integrated Visitor Code solution
private fun showVisitorCodeInADedicatedView() {
val visitorCodeView = GliaWidgets.getCallVisualizer().createVisitorCodeView(requireContext())
val cv = containerView!!.findViewById<CardView>(R.id.container)
val cv = containerView!!.findViewById<CardView>(R.id.visitor_code_container)
cv.removeAllViews()
cv.addView(visitorCodeView)
cv.visibility = View.VISIBLE
}

private fun removeVisitorCodeFromDedicatedView() {
val cv = containerView!!.findViewById<CardView>(R.id.container)
val cv = containerView!!.findViewById<CardView>(R.id.visitor_code_container)
cv.removeAllViews()
cv.visibility = View.GONE
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/bg_container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="@color/glia_base_shade_color" />
</shape>
48 changes: 46 additions & 2 deletions app/src/main/res/layout/main_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,50 @@
app:layout_constraintStart_toStartOf="@id/start_guideline"
app:layout_constraintTop_toBottomOf="@id/settings_button" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/entry_widget_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
app:layout_constraintTop_toBottomOf="@id/entry_widget_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/entry_widget_bottom_sheet_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Application.Glia.Subtitle2"
android:textColor="@color/glia_black_color"
android:text="@string/main_start_entry_widget_bottom_sheet"
android:layout_marginEnd="@dimen/glia_medium"
app:layout_constraintTop_toTopOf="@id/entry_widget_switch"
app:layout_constraintBottom_toBottomOf="@id/entry_widget_switch"
app:layout_constraintEnd_toStartOf="@+id/entry_widget_switch" />

<TextView
android:id="@+id/entry_widget_switch_view_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Application.Glia.Subtitle2"
android:textColor="@color/glia_black_color"
android:text="@string/main_start_entry_widget_embedded_view"
android:layout_marginStart="@dimen/glia_medium"
app:layout_constraintTop_toTopOf="@id/entry_widget_switch"
app:layout_constraintBottom_toBottomOf="@id/entry_widget_switch"
app:layout_constraintStart_toEndOf="@+id/entry_widget_switch" />

<FrameLayout
android:id="@+id/entry_widget_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/glia_large"
android:background="@drawable/bg_container"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/end_guideline"
app:layout_constraintStart_toStartOf="@id/start_guideline"
app:layout_constraintTop_toBottomOf="@id/entry_widget_switch" />

<Button
android:id="@+id/chat_activity_button"
android:layout_width="0dp"
Expand All @@ -89,7 +133,7 @@
app:icon="@drawable/ic_baseline_chat_bubble"
app:layout_constraintEnd_toEndOf="@id/end_guideline"
app:layout_constraintStart_toStartOf="@id/start_guideline"
app:layout_constraintTop_toBottomOf="@id/entry_widget_button" />
app:layout_constraintTop_toBottomOf="@id/entry_widget_container" />

<Button
android:id="@+id/audio_call_button"
Expand Down Expand Up @@ -251,7 +295,7 @@
app:constraint_referenced_ids="visitor_code_switch, visitor_code_dialog_label, visitor_code_view_label"/>

<androidx.cardview.widget.CardView
android:id="@+id/container"
android:id="@+id/visitor_code_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/glia_medium"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@
<string name="main_launch_activity">Launch Chat in Activity</string>
<string name="main_launch_fragment">Launch Chat in Fragment</string>
<string name="main_start_in_integrator_app">Start Chat in integrator app</string>
<string name="main_start_entry_widget">Entry Widget</string>
<string name="main_start_entry_widget">Show Entry Widget</string>
<string name="main_start_entry_widget_bottom_sheet">Bottom Sheet</string>
<string name="main_start_entry_widget_embedded_view">Embedded View</string>
<string name="main_start_chat_flow">Start new chat flow</string>
<string name="main_start_message_center_flow">Start new messaging flow</string>
<string name="main_start_audio_call">Start new audio call</string>
Expand Down

0 comments on commit 0cb61af

Please sign in to comment.