Skip to content
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

Mob 3604 devs want to implement business logic for the engagement launcher approach #1094

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions app/src/main/java/com/glia/exampleapp/Application.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,8 +16,6 @@ public void onCreate() {

GliaWidgets.onAppCreate(this);
GliaWidgets.setCustomCardAdapter(new ExampleCustomCardAdapter());

initGliaWidgets();
}

private void initFirebase() {
Expand All @@ -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) {}
});
}
andrews-moc marked this conversation as resolved.
Show resolved Hide resolved
}
65 changes: 0 additions & 65 deletions app/src/main/java/com/glia/exampleapp/ChatFragment.java

This file was deleted.

118 changes: 39 additions & 79 deletions app/src/main/java/com/glia/exampleapp/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.os.Parcelable
import android.text.InputType
import android.util.TypedValue
import android.view.Gravity
Expand All @@ -27,18 +26,14 @@ 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.entrywidget.EntryWidgetActivity
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 kotlin.concurrent.thread
import kotlin.properties.Delegates
Expand All @@ -60,6 +55,19 @@ class MainFragment : Fragment() {
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?,
Expand All @@ -76,17 +84,15 @@ 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 {
startActivity(Intent(requireContext(), EntryWidgetActivity::class.java))
}
.setOnClickListener { entryWidget.show(requireActivity()) }
view.findViewById<View>(R.id.chat_activity_button)
.setOnClickListener { navigateToChat(ChatType.LIVE_CHAT) }
.setOnClickListener { engagementLauncher.startChat(requireActivity()) }
view.findViewById<View>(R.id.audio_call_button)
.setOnClickListener { navigateToCall(GliaWidgets.MEDIA_TYPE_AUDIO) }
.setOnClickListener { engagementLauncher.startAudioCall(requireActivity()) }
view.findViewById<View>(R.id.video_call_button)
.setOnClickListener { navigateToCall(GliaWidgets.MEDIA_TYPE_VIDEO) }
.setOnClickListener { engagementLauncher.startVideoCall(requireActivity()) }
view.findViewById<View>(R.id.message_center_activity_button)
.setOnClickListener { navigateToMessageCenter() }
.setOnClickListener { engagementLauncher.startSecureMessaging(requireActivity()) }
view.findViewById<View>(R.id.end_engagement_button)
.setOnClickListener { GliaWidgets.endEngagement() }
view.findViewById<View>(R.id.visitor_info_button)
Expand Down Expand Up @@ -199,9 +205,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())
}
}

Expand Down Expand Up @@ -278,52 +284,6 @@ class MainFragment : Fragment() {
}
}

private fun navigateToChat(chatType: ChatType) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val intent = Intent(requireContext(), ChatActivity::class.java).apply {
putExtra(GliaWidgets.CHAT_TYPE, chatType as Parcelable)
putExtra(GliaWidgets.CONTEXT_ASSET_ID, getContextAssetIdFromPrefs(sharedPreferences))
putExtra(GliaWidgets.QUEUE_IDS, ArrayList(getQueueIdsFromPrefs(sharedPreferences)))
setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
}
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<String> {
val defaultQueues = sharedPreferences.getBoolean(resources.getString(R.string.pref_default_queues), false)
if (defaultQueues) {
Expand All @@ -350,15 +310,6 @@ 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())
Expand Down Expand Up @@ -442,8 +393,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()
Expand All @@ -455,8 +408,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()
Expand Down Expand Up @@ -502,7 +457,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")
Expand All @@ -513,6 +468,12 @@ class MainFragment : Fragment() {
saveAuthToken(jwt)
}

private fun ensureInitialized() {
if (!Glia.isInitialized()) {
initGliaWidgets()
}
}

private fun initGliaWidgets() {
if (Glia.isInitialized()) {
setupAuthButtonsVisibility()
Expand All @@ -523,7 +484,7 @@ class MainFragment : Fragment() {
GliaWidgets.init(
createDefaultConfig(
context = requireActivity().applicationContext,
// uiJsonRemoteConfig = UnifiedUiConfigurationLoader.fetchRemoteConfiguration(),
// uiJsonRemoteConfig = UnifiedUiConfigurationLoader.fetchLocalConfigSample(requireContext()),
// runtimeConfig = createSampleRuntimeConfig(),
// region = "us"
)
Expand All @@ -543,8 +504,7 @@ class MainFragment : Fragment() {

private fun prepareAuthentication() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
authentication =
GliaWidgets.getAuthentication(getAuthenticationBehaviorFromPrefs(sharedPreferences, resources))
authentication = GliaWidgets.getAuthentication(getAuthenticationBehaviorFromPrefs(sharedPreferences, resources))
}

private fun authenticate(
Expand Down
Loading