Skip to content

Commit

Permalink
Updating Android SDK to version 32.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radixdev committed Jul 29, 2024
1 parent 3bae4d2 commit eb60d6f
Show file tree
Hide file tree
Showing 63 changed files with 327 additions and 229 deletions.
Binary file modified .github/assets/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/assets/logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## 32.0.0

[Release Date](https://github.com/braze-inc/braze-android-sdk/releases/tag/v32.0.0)

##### Breaking
- Fixed issue where cards with duplicate IDs would cause a crash in Jetpack Compose Content Cards.
- If you manually add cards, please ensure that they have unique IDs.

##### Fixed
- Fixed an issue where closing an In-App Message could throw an error if the previously focused `View` was removed.
- Fixed an issue where some In-App Messages could display after their expiration time.
- Fixed an issue with In-App Message and Content Cards not displaying RTL language properly.
- Fixed an issue where logging In-App Message impression or clicks could result in blocking the main thread.

##### Added
- Added support for Android 15 (API 35).
- Note that apps targeting API 35 should update to this SDK version.

##### Changed
- Changed the behavior of `Braze.wipeData()` to retain external subscriptions (like `Braze.subscribeToContentCardsUpdates()`) after being called.

## 31.1.0

[Release Date](https://github.com/braze-inc/braze-android-sdk/releases/tag/v31.1.0)
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
![Braze Logo](https://github.com/braze-inc/braze-android-sdk/blob/master/braze-logo.png)
<p align="center">
<img width="480" alt="Braze Logo" src=".github/assets/logo-light.png#gh-light-mode-only" />
<img width="480" alt="Braze Logo" src=".github/assets/logo-dark.png#gh-dark-mode-only" />
</p>

# Android SDK

Expand All @@ -11,7 +14,7 @@ Successful marketing automation is essential to the future of your mobile app. B
## Version Information

- The Braze Android SDK supports Android 5.0+ / API 21+ (Lollipop and up).
- Last Target SDK Version: 34
- Last Target SDK Version: 35
- Kotlin version: `org.jetbrains.kotlin:kotlin-stdlib:1.8.10`
- Last Compiled Firebase Cloud Messaging Version: 23.2.0
- Braze uses [Font Awesome](https://fortawesome.github.io/Font-Awesome/) 4.3.0 for in-app message icons. Check out the [cheat sheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) to browse available icons.
Expand All @@ -33,8 +36,8 @@ Our SDK is now hosted in Maven Central. You can remove `https://braze-inc.github

```
dependencies {
implementation 'com.braze:android-sdk-ui:31.1.+'
implementation 'com.braze:android-sdk-location:31.1.+'
implementation 'com.braze:android-sdk-ui:32.0.+'
implementation 'com.braze:android-sdk-location:32.0.+'
...
}
```
Expand All @@ -53,7 +56,7 @@ repositories {

```
dependencies {
implementation 'com.braze:android-sdk-ui:31.1.+'
implementation 'com.braze:android-sdk-ui:32.0.+'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.braze.jetpackcompose.contentcards.cards.ContentCard
import com.braze.jetpackcompose.contentcards.styling.ContentCardListStyling
import com.braze.jetpackcompose.contentcards.styling.ContentCardStyling
import com.braze.models.cards.Card
import com.braze.support.BrazeLogger.Priority.W
import com.braze.support.BrazeLogger.Priority.V
import com.braze.support.BrazeLogger.brazelog
import com.braze.ui.contentcards.BrazeContentCardUtils
Expand Down Expand Up @@ -163,6 +164,7 @@ fun ContentCardsList(
val processedCards = cardUpdateHandler?.invoke(newCards) ?: BrazeContentCardUtils.defaultCardHandling(newCards)
val cardsToAdd = mutableListOf<Card>()
var lastCardId = ""
val cardIDs = mutableSetOf<String>()
for (card in processedCards) {
if (card.isControl) {
val idCardPair = Pair(lastCardId, card)
Expand All @@ -173,10 +175,11 @@ fun ContentCardsList(
// This control card will log impression when the last "real" card has its impression logged.
controlCardInference.add(idCardPair)
}
} else if (cardIDs.contains(card.id)) {
brazelog(TAG, W) { "Card ID ${card.id} already exists. Skipping card $card." }
} else {
cardIDs.add(card.id)
cardsToAdd.add(card)
}
if (!card.isControl) {
lastCardId = card.id
}
}
Expand Down Expand Up @@ -312,12 +315,12 @@ fun ContentCardsList(
val viewportHeight = layoutInfo.viewportEndOffset + layoutInfo.viewportStartOffset

if (lastItem.offset + lastItem.size > viewportHeight) {
fullyVisibleItemsInfo.removeLast()
fullyVisibleItemsInfo.removeAt(fullyVisibleItemsInfo.lastIndex)
}

val firstItemIfLeft = fullyVisibleItemsInfo.firstOrNull()
if (firstItemIfLeft != null && firstItemIfLeft.offset < layoutInfo.viewportStartOffset) {
fullyVisibleItemsInfo.removeFirst()
fullyVisibleItemsInfo.removeAt(0)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.braze.jetpackcompose.contentcards.cards

import android.os.Build
import android.util.LayoutDirection
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -26,11 +27,13 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.core.text.layoutDirection
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import coil.compose.AsyncImage
Expand All @@ -48,6 +51,7 @@ import com.braze.models.cards.ShortNewsCard
import com.braze.models.cards.TextAnnouncementCard
import com.braze.support.BrazeLogger.brazelog
import com.braze.ui.contentcards.BrazeContentCardUtils
import java.util.Locale

@Composable
@Suppress("LongMethod", "ComplexMethod")
Expand Down Expand Up @@ -344,6 +348,13 @@ fun ContentCard(
modifier = Modifier
.align(style.pinnedAlignment(card))
.padding(horizontal = extraPadding)
.run {
if (Locale.getDefault().layoutDirection == LayoutDirection.RTL) {
this.scale(scaleX = -1f, scaleY = 1f)
} else {
this
}
}
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion android-sdk-ui/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<uses-sdk tools:overrideLibrary="com.google.firebase.messaging"/>
<application>
<application android:supportsRtl="true">
<activity
android:name="com.braze.ui.BrazeWebViewActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.braze.support.BrazeLogger.Priority.I
import com.braze.support.BrazeLogger.Priority.V
import com.braze.support.BrazeLogger.Priority.W
import com.braze.support.BrazeLogger.brazelog
import com.braze.support.nowInMilliseconds
import com.braze.ui.inappmessage.BrazeInAppMessageManager
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -234,7 +235,7 @@ open class BrazePushReceiver : BroadcastReceiver() {
if (!notificationExtras.containsKey(Constants.BRAZE_PUSH_RECEIVED_TIMESTAMP_MILLIS)) {
notificationExtras.putLong(
Constants.BRAZE_PUSH_RECEIVED_TIMESTAMP_MILLIS,
System.currentTimeMillis()
nowInMilliseconds()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.braze.ui;

import static com.braze.support.DateTimeUtils.nowInMilliseconds;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -210,7 +212,7 @@ public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleI

// If we got our feed from offline storage, and it was old, we asynchronously request a new one from the server,
// putting up a spinner if the old feed was empty.
if (event.isFromOfflineStorage() && (event.lastUpdatedInSecondsFromEpoch() + MAX_FEED_TTL_SECONDS) * 1000 < System.currentTimeMillis()) {
if (event.isFromOfflineStorage() && (event.lastUpdatedInSecondsFromEpoch() + MAX_FEED_TTL_SECONDS) * 1000 < nowInMilliseconds()) {
BrazeLogger.i(TAG, "Feed received was older than the max time to live of " + MAX_FEED_TTL_SECONDS + " seconds, displaying it "
+ "for now, but requesting an updated view from the server.");
Braze.getInstance(getContext()).requestFeedRefresh();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.braze.ui;

import static com.braze.support.DateTimeUtils.nowInMilliseconds;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -197,7 +199,7 @@ public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleI

// If we got our feed from offline storage, and it was old, we asynchronously request a new one from the server,
// putting up a spinner if the old feed was empty.
if (event.isFromOfflineStorage() && (event.lastUpdatedInSecondsFromEpoch() + MAX_FEED_TTL_SECONDS) * 1000 < System.currentTimeMillis()) {
if (event.isFromOfflineStorage() && (event.lastUpdatedInSecondsFromEpoch() + MAX_FEED_TTL_SECONDS) * 1000 < nowInMilliseconds()) {
BrazeLogger.i(TAG, "Feed received was older than the max time to live of " + MAX_FEED_TTL_SECONDS + " seconds, displaying it "
+ "for now, but requesting an updated view from the server.");
mBraze.requestFeedRefresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.braze.ui.contentcards.view
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.text.layoutDirection
import androidx.recyclerview.widget.RecyclerView
import com.braze.ui.R
import java.util.Locale

open class ContentCardViewHolder(view: View, showUnreadIndicator: Boolean) :
RecyclerView.ViewHolder(view) {
Expand Down Expand Up @@ -32,6 +34,12 @@ open class ContentCardViewHolder(view: View, showUnreadIndicator: Boolean) :
*/
fun setPinnedIconVisible(isVisible: Boolean) {
pinnedIcon?.visibility = if (isVisible) View.VISIBLE else View.GONE

// Flip the icon if the layout direction is RTL
// This code can be removed once we have vector images that have autoMirror enabled in them
if (isVisible && Locale.getDefault().layoutDirection == View.LAYOUT_DIRECTION_RTL) {
pinnedIcon?.scaleX = -1.0f
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.braze.support.BrazeLogger.Priority.V
import com.braze.support.BrazeLogger.Priority.W
import com.braze.support.BrazeLogger.brazelog
import com.braze.support.getPrettyPrintedString
import com.braze.support.nowInMilliseconds
import com.braze.support.wouldPushPermissionPromptDisplay
import com.braze.ui.actions.brazeactions.containsAnyPushPermissionBrazeActions
import com.braze.ui.actions.brazeactions.containsInvalidBrazeAction
Expand Down Expand Up @@ -465,22 +466,20 @@ open class BrazeInAppMessageManager : InAppMessageManagerBase() {
"displayed when the next Activity registers to receive in-app messages."
)
}
if (!isCarryOver) {
val inAppMessageExpirationTimestamp = inAppMessage.expirationTimestamp
if (inAppMessageExpirationTimestamp > 0) {
val currentTimeMillis = System.currentTimeMillis()
if (currentTimeMillis > inAppMessageExpirationTimestamp) {
throw Exception(
"In-app message is expired. Doing nothing. Expiration: " +
"$inAppMessageExpirationTimestamp. Current time: $currentTimeMillis"
)
}
} else {
brazelog { "Expiration timestamp not defined. Continuing." }

val inAppMessageExpirationTimestamp = inAppMessage.expirationTimestamp
if (inAppMessageExpirationTimestamp > 0) {
val currentTimeMillis = nowInMilliseconds()
if (currentTimeMillis > inAppMessageExpirationTimestamp) {
throw Exception(
"In-app message is expired. Doing nothing. Expiration: " +
"$inAppMessageExpirationTimestamp. Current time: $currentTimeMillis"
)
}
} else {
brazelog { "Not checking expiration status for carry-over in-app message." }
brazelog { "Expiration timestamp not defined. Continuing." }
}

if (!verifyOrientationStatus(inAppMessage)) {
// No display failure gets logged here since control in-app messages would also be affected.
throw Exception("Current orientation did not match specified orientation for in-app message. Doing nothing.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.braze.enums.inappmessage.SlideFrom
import com.braze.models.inappmessage.IInAppMessage
import com.braze.models.inappmessage.IInAppMessageImmersive
import com.braze.models.inappmessage.InAppMessageSlideup
import com.braze.support.BrazeLogger.Priority.E
import com.braze.support.BrazeLogger.Priority.V
import com.braze.support.BrazeLogger.Priority.W
import com.braze.support.BrazeLogger.brazelog
Expand Down Expand Up @@ -377,7 +378,11 @@ open class DefaultInAppMessageViewWrapper @JvmOverloads constructor(
// Return the focus before closing the message
if (previouslyFocusedView != null) {
brazelog { "Returning focus to view after closing message. View: $previouslyFocusedView" }
previouslyFocusedView?.requestFocus()
try {
previouslyFocusedView?.requestFocus()
} catch (e: Exception) {
brazelog(E, e) { "Failed to request focus on previous view" }
}
}
inAppMessageViewLifecycleListener.afterClosed(inAppMessage)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/com_braze_inappmessage_chevron_png"
android:autoMirrored="true"/>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
android:layout_marginRight="10.0dp"
android:layout_marginTop="11.0dp"
android:layout_marginBottom="11.0dp"
android:textAlignment="viewStart"
style="@style/Braze.Cards.CaptionedImage.Title"/>
</RelativeLayout>

Expand All @@ -33,6 +34,7 @@
android:layout_marginLeft="10.0dp"
android:layout_marginRight="10.0dp"
android:layout_marginTop="8.0dp"
android:textAlignment="viewStart"
style="@style/Braze.Cards.CaptionedImage.Description"/>

<!-- Optional -->
Expand All @@ -43,5 +45,6 @@
android:layout_below="@id/com_braze_captioned_image_description"
android:layout_marginLeft="10.0dp"
android:layout_marginRight="10.0dp"
android:textAlignment="viewStart"
style="@style/Braze.Cards.CaptionedImage.Domain"/>
</merge>
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
<TextView
android:id="@+id/com_braze_content_cards_captioned_image_title"
tools:text="Content Card Title"
android:textAlignment="viewStart"
style="@style/Braze.ContentCards.CaptionedImage.Title"/>

<TextView
android:id="@+id/com_braze_content_cards_captioned_image_description"
tools:text="Content Card Description"
android:textAlignment="viewStart"
style="@style/Braze.ContentCards.CaptionedImage.Description"/>

<TextView
android:id="@+id/com_braze_content_cards_action_hint"
android:textAlignment="viewStart"
style="@style/Braze.ContentCards.ActionHint.CaptionedImage"/>
</RelativeLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
<TextView
android:id="@+id/com_braze_inappmessage_full_header_text"
style="@style/Braze.InAppMessage.Header.Full"
android:textAlignment="viewStart"
tools:text="In App Message Header Text"/>
<TextView
android:id="@+id/com_braze_inappmessage_full_message"
style="@style/Braze.InAppMessage.Message.Full"
android:textAlignment="viewStart"
tools:text="In App Message Message Text"/>
</LinearLayout>
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
style="@style/Braze.InAppMessage.Image.Modal"/>
<TextView
android:id="@+id/com_braze_inappmessage_modal_icon"
android:textAlignment="viewStart"
style="@style/Braze.InAppMessage.Icon.Modal"/>
</RelativeLayout>
<LinearLayout
Expand All @@ -34,10 +35,12 @@
<TextView
android:id="@+id/com_braze_inappmessage_modal_header_text"
style="@style/Braze.InAppMessage.Header.Modal"
android:textAlignment="viewStart"
tools:text="In App Message Header Text"/>
<TextView
android:id="@+id/com_braze_inappmessage_modal_message"
style="@style/Braze.InAppMessage.Message.Modal"
android:textAlignment="viewStart"
tools:text="In App Message Message Text"/>
</LinearLayout>
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</RelativeLayout>
<TextView
android:id="@+id/com_braze_inappmessage_slideup_message"
android:textAlignment="viewStart"
style="@style/Braze.InAppMessage.Message.Slideup"/>
<ImageView
android:id="@+id/com_braze_inappmessage_slideup_chevron"
Expand Down
Loading

0 comments on commit eb60d6f

Please sign in to comment.