Skip to content

Commit

Permalink
Pull request #426: Jdzubak MCA-3708 InfobipRtcUi bugfixes and small I…
Browse files Browse the repository at this point in the history
…nAppChat maintenance

Merge in MML/infobip-mobile-messaging-android from jdzubak-MCA-3708-rtc-ui-bugfixes to master

Squashed commit of the following:

commit 05290ec7dd26028a9f7e33ca441d21e2c5146737
Author: Jakub Dzubak <[email protected]>
Date:   Tue Mar 5 10:13:00 2024 +0100

    MCA-3742 Rename

commit d565d6f3d221197616a04f304d014295a0423bf0
Author: Jakub Dzubak <[email protected]>
Date:   Tue Mar 5 09:38:50 2024 +0100

    MCA-3757 InAppChat maintenance

commit 0dbc1d302b7706c7e28085c69f683c96eddea8fa
Author: Jakub Dzubak <[email protected]>
Date:   Mon Mar 4 17:27:32 2024 +0100

    MCA-3756 Hide PIP button when PIP permission is not granted

commit 99332a4baaf901cf21d5619588dbb21d684c81ef
Author: Jakub Dzubak <[email protected]>
Date:   Mon Mar 4 17:04:40 2024 +0100

    MCA-3755 Stop screen share text hidden when PIP is active

commit ea836d6247725afaf666fd1dbd9c316055668724
Author: Jakub Dzubak <[email protected]>
Date:   Mon Mar 4 14:51:16 2024 +0100

    MCA-3748 Introduced RtcUiCallErrorMapper, refactored packages to reflect class public/internal status

commit 069c315e9027de10b8726f0db448119d761f775b
Author: Jakub Dzubak <[email protected]>
Date:   Fri Mar 1 16:45:08 2024 +0100

    MCA-3747 Fixed loop in requesting audio permission

commit 55b3d6d34c5ae4349401dec888cd301ee7d0d9c5
Author: Jakub Dzubak <[email protected]>
Date:   Fri Mar 1 13:24:31 2024 +0100

    MCA-3742 Added translations

commit 83816a291d4773d9b65da88b5a4b55507eeaa3e3
Author: Jakub Dzubak <[email protected]>
Date:   Fri Mar 1 12:55:20 2024 +0100

    MCA-3742 Handle parallel cellular and InfobipRtcUi  calls

commit 3449556160638257a79d496ef9eab19d35738cdf
Author: Jakub Dzubak <[email protected]>
Date:   Wed Feb 28 15:09:36 2024 +0100

    MCA-3708 Added LC Reg ID into main activity, InfobipRtcUi supports audio for bluetooth headset and cleanup,
  • Loading branch information
jakubdzubak1 committed Mar 5, 2024
1 parent 3a97ce2 commit ee24339
Show file tree
Hide file tree
Showing 99 changed files with 1,382 additions and 618 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,11 @@ public synchronized static InAppChat getInstance(Context context) {
* @param theme data object holding all style attributes
*/
public abstract void setTheme(InAppChatTheme theme);

/**
* Get current theme. Theme is alternative to defining style in xml.
*
* @return theme data object holding all style attributes
*/
public abstract InAppChatTheme getTheme();
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public void setTheme(InAppChatTheme theme) {
this.theme = theme;
}

@Override
@Nullable
public InAppChatTheme getTheme() {
return theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class InAppChatFragment : Fragment(), InAppChatFragmentActivityResultDelegate.Re
}

fun sendContextualMetaData(data: String, allMultiThreadStrategy: Boolean) {
binding.ibLcChat.sendContextualMetaData(data, allMultiThreadStrategy)
binding.ibLcChat.sendContextualData(data, allMultiThreadStrategy)
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,19 @@ class InAppChatView @JvmOverloads constructor(
* @param data contextual data in the form of JSON string
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
*/
@Deprecated("Use new sendContextualData() instead.", replaceWith = ReplaceWith("sendContextualData(data, allMultiThreadStrategy)"), level = DeprecationLevel.WARNING)
fun sendContextualMetaData(data: String, allMultiThreadStrategy: Boolean) {
val flag =
if (allMultiThreadStrategy) InAppChatMultiThreadFlag.ALL else InAppChatMultiThreadFlag.ACTIVE
sendContextualData(data, allMultiThreadStrategy)
}

/**
* Set contextual data of the Livechat Widget
*
* @param data contextual data in the form of JSON string
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
*/
fun sendContextualData(data: String, allMultiThreadStrategy: Boolean) {
val flag = if (allMultiThreadStrategy) InAppChatMultiThreadFlag.ALL else InAppChatMultiThreadFlag.ACTIVE
inAppChatClient.sendContextualData(data, flag)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.infobip.mobile.messaging.chat.view.styles.factory
import android.content.Context
import android.util.AttributeSet
import org.infobip.mobile.messaging.api.chat.WidgetInfo
import org.infobip.mobile.messaging.chat.InAppChatImpl
import org.infobip.mobile.messaging.chat.InAppChat
import org.infobip.mobile.messaging.chat.view.styles.InAppChatInputViewStyle
import org.infobip.mobile.messaging.chat.view.styles.InAppChatStyle
import org.infobip.mobile.messaging.chat.view.styles.InAppChatToolbarStyle
Expand All @@ -22,7 +22,7 @@ interface StyleFactory {

companion object {
fun create(context: Context, attributeSet: AttributeSet? = null, widgetInfo: WidgetInfo? = null): StyleFactory {
return InAppChatImpl.getInstance(context).theme?.let {
return InAppChat.getInstance(context).theme?.let {
RuntimeThemeFactory(it)
} ?: XMLThemeFactory(context, attributeSet, widgetInfo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
import com.google.android.material.button.MaterialButtonToggleGroup;
import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;

import org.infobip.mobile.messaging.BroadcastParameter;
import org.infobip.mobile.messaging.Event;
import org.infobip.mobile.messaging.MobileMessaging;
import org.infobip.mobile.messaging.SuccessPending;
import org.infobip.mobile.messaging.User;
import org.infobip.mobile.messaging.chat.InAppChat;
import org.infobip.mobile.messaging.chat.core.InAppChatEvent;
import org.infobip.mobile.messaging.chat.utils.DarkModeUtils;
import org.infobip.mobile.messaging.chat.view.InAppChatFragment;
import org.infobip.mobile.messaging.chat.view.styles.InAppChatDarkMode;
Expand Down Expand Up @@ -74,6 +76,7 @@ public class MainActivity extends AppCompatActivity implements InAppChatFragment
private final String WIDGET_SECRET_KEY_JSON = "your_widget_secret_key";
private final InAppChat inAppChat = InAppChat.getInstance(this);
private boolean pushRegIdReceiverRegistered = false;
private boolean lcRegIdReceiverRegistered = false;
private JWTSubjectType jwtSubjectType = null;
private AuthData lastUsedAuthData = null;
private TextInputEditText nameEditText = null;
Expand All @@ -88,6 +91,15 @@ public void onReceive(Context context, Intent intent) {
}
}
};
private final BroadcastReceiver lcRegIdReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String lcRegId = intent.getStringExtra(BroadcastParameter.EXTRA_LIVECHAT_REGISTRATION_ID);
showLivechatRegId(lcRegId);
}
}
};

/* InAppChatActionBarProvider */
@Nullable
Expand All @@ -111,6 +123,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setSupportActionBar(this.findViewById(R.id.toolbar));
inAppChat.activate();
setUpPushRegIdField();
setUpLivechatRegIdField();
setUpSubjectTypeSpinner();
setUpOpenChatActivityButton();
setUpOpenChatFragmentButton();
Expand All @@ -124,14 +137,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

@Override
protected void onDestroy() {
if (this.pushRegIdReceiverRegistered) {
pushRegIdReceiverRegistered = !unregisterBroadcastReceiver(pushRegIdReceiverRegistered, pushRegIdReceiver);
lcRegIdReceiverRegistered = !unregisterBroadcastReceiver(lcRegIdReceiverRegistered, lcRegIdReceiver);
super.onDestroy();
}

private boolean unregisterBroadcastReceiver(Boolean isRegistered, BroadcastReceiver receiver) {
if (isRegistered) {
try {
LocalBroadcastManager.getInstance(this).unregisterReceiver(pushRegIdReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
return true;
} catch (Throwable t) {
MobileMessagingLogger.e(TAG, "Unable to unregister pushRegIdReceiverRegistered", t);
MobileMessagingLogger.e("MainActivity", "Unable to unregister broadcast receiver", t);
}
}
super.onDestroy();
return false;
}

@Override
Expand Down Expand Up @@ -160,8 +180,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_id) {
setPushRegIdToClipboard(getPushRegId());
Toast.makeText(this, R.string.toast_registration_id_copy, Toast.LENGTH_SHORT).show();
saveToClipboard(getString(R.string.push_registration_id), getPushRegId());
Toast.makeText(this, getString(R.string.push_registration_id) + " " + getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
return true;
} else if (item.getGroupId() == R.id.languages) {
String language = langMenuIdToLocale(item.getItemId());
Expand Down Expand Up @@ -252,11 +272,10 @@ private void setUpPushRegIdField() {
}
}

private void setPushRegIdToClipboard(String pushRegId) {
private void saveToClipboard(String label, String value) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.action_registration_id_copy), pushRegId);
ClipData clip = ClipData.newPlainText(label, value);
clipboard.setPrimaryClip(clip);
Toast.makeText(this, R.string.toast_registration_id_copy, Toast.LENGTH_SHORT).show();
}

private boolean showPushRegId(String pushRegId) {
Expand All @@ -265,13 +284,33 @@ private boolean showPushRegId(String pushRegId) {
pushRegIdEditText.setText(pushRegId);
pushRegIdEditText.setKeyListener(null);
pushRegIdEditText.setOnClickListener(view -> {
setPushRegIdToClipboard(pushRegId);
saveToClipboard(getString(R.string.push_registration_id), pushRegId);
});
return true;
}
return false;
}

private void setUpLivechatRegIdField() {
TextInputLayout lcRegIdInputLayout = findViewById(R.id.lcRegIdInputLayout);
lcRegIdInputLayout.setVisibility(View.VISIBLE);
if (!lcRegIdReceiverRegistered) {
LocalBroadcastManager.getInstance(this).registerReceiver(lcRegIdReceiver, new IntentFilter(InAppChatEvent.LIVECHAT_REGISTRATION_ID_UPDATED.getKey()));
this.pushRegIdReceiverRegistered = true;
}
}

private void showLivechatRegId(String lcRegId) {
if (StringUtils.isNotBlank(lcRegId)) {
TextInputEditText lcRegIdEditText = findViewById(R.id.lcRegIdEditText);
lcRegIdEditText.setText(lcRegId);
lcRegIdEditText.setKeyListener(null);
lcRegIdEditText.setOnClickListener(view -> {
saveToClipboard(getString(R.string.livechat_registration_id), lcRegId);
});
}
}

private void setUpSubjectTypeSpinner() {
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.subjectTypeAutocompleteTextView);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.subject_types, android.R.layout.simple_dropdown_item_1line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toTopOf="@+id/nameIdInputLayout"
app:layout_constraintBottom_toTopOf="@+id/lcRegIdInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand All @@ -56,6 +56,31 @@

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/lcRegIdInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
app:layout_constraintTop_toBottomOf="@+id/pushRegIdInputLayout"
app:layout_constraintBottom_toTopOf="@+id/nameIdInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible"
android:visibility="gone"
android:hint="@string/livechat_registration_id">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/lcRegIdEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:textIsSelectable="true" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nameIdInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Expand Down Expand Up @@ -254,6 +279,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
android:text="@string/custom_button_checked"
app:layout_constraintBottom_toTopOf="@id/customButtonEnabled"
app:layout_constraintEnd_toEndOf="@id/darkModeToggle"
Expand All @@ -265,6 +291,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
android:checked="true"
android:text="@string/custom_button_enabled"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<item
android:id="@+id/action_id"
android:icon="@drawable/ic_content_copy_white_24dp"
android:title="@string/action_registration_id_copy"
android:title="@string/push_registration_id"
app:showAsAction="always" />
<group android:id="@+id/languages">
<item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<string name="chinese_simplified">简体中文</string>

<string name="push_registration_id">Push registration ID</string>
<string name="livechat_registration_id">Livechat registration ID</string>
<string name="customer_name">Customer name</string>
<string name="subject_type">Subject type</string>
<string-array name="subject_types">
Expand All @@ -50,8 +51,7 @@
<string name="dark_mode_dark">Dark</string>
<string name="dark_mode_light">Light</string>
<string name="dark_mode_auto">Auto</string>
<string name="toast_registration_id_copy">Registration ID copied to clipboard</string>
<string name="action_registration_id_copy">Registration ID</string>
<string name="copied_to_clipboard">copied to clipboard</string>
<string name="language_changed">Language changed to %1$s</string>
<string name="custom_button_checked">Custom button checked</string>
<string name="custom_button_enabled">Custom button enabled</string>
Expand Down
Loading

0 comments on commit ee24339

Please sign in to comment.