Skip to content

Commit

Permalink
Merge pull request #482 from mindbox-cloud/release/2.10.2-rc
Browse files Browse the repository at this point in the history
Release/2.10.2-rc
  • Loading branch information
AndreyEmtsov authored Aug 1, 2024
2 parents 195200c + 5c2e7e6 commit 5b1644e
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: ./git-release.sh "${{secrets.GITHUBACCESSTOKEN}}" "${{secrets.GITHUBUSER}}"

- name: Publish to Sonatype
run: ./gradlew --no-daemon publish -PsonatypeUsername=${{secrets.OSSRHUSERNAME}} -PsonatypePassword=${{secrets.OSSRHPASSWORD}}
run: ./gradlew --no-daemon publish -PsonatypeUsername=${{secrets.OSSRHTOKEN}} -PsonatypePassword=${{secrets.OSSRHTOKENPASSWORD}}

#To update version in Github README.md
# - name: Version Upgrade
Expand Down
6 changes: 3 additions & 3 deletions example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ dependencies {


//Mindbox
implementation 'cloud.mindbox:mobile-sdk:2.10.1'
implementation 'cloud.mindbox:mindbox-firebase:2.10.1'
implementation 'cloud.mindbox:mindbox-huawei:2.10.1'
implementation 'cloud.mindbox:mobile-sdk:2.10.2-rc'
implementation 'cloud.mindbox:mindbox-firebase'
implementation 'cloud.mindbox:mindbox-huawei'

//Glade for custom loader
implementation 'com.github.bumptech.glide:glide:4.15.1'
Expand Down
2 changes: 0 additions & 2 deletions git-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ sed -i '' "s/^SDK_VERSION_NAME=.*/SDK_VERSION_NAME=$version/" $properties_file

build_gradle_example_path="example/app/build.gradle"
sed -i '' -E "s/cloud.mindbox:mobile-sdk:[0-9]+\.[0-9]+\.[0-9]+(-rc)?/cloud.mindbox:mobile-sdk:$version/" $build_gradle_example_path
sed -i '' -E "s/cloud.mindbox:mindbox-firebase:[0-9]+\.[0-9]+\.[0-9]+(-rc)?/cloud.mindbox:mindbox-firebase:$version/" $build_gradle_example_path
sed -i '' -E "s/cloud.mindbox:mindbox-huawei:[0-9]+\.[0-9]+\.[0-9]+(-rc)?/cloud.mindbox:mindbox-huawei:$version/" $build_gradle_example_path

echo "Bump SDK version from $current_version to $version."

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# SDK version property
SDK_VERSION_NAME=2.10.1
SDK_VERSION_NAME=2.10.2-rc
19 changes: 19 additions & 0 deletions sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,25 @@ object Mindbox : MindboxLog {
return intent?.let(PushNotificationManager::getPayloadFromPushIntent)
}

/**
* Writes a log message to the Mindbox logging system with the specified log level.
* This method should be used only after Mindbox has been initialized by calling `Mindbox.init`.
* Otherwise, the logs will not be recorded.
* This method takes a log message and a log level, and routes the message to the appropriate
* @param message The message to be logged.
* @param logLevel The severity level of the log message. See [Level].
*/
fun writeLog(message: String, logLevel: Level) {
when(logLevel){
Level.VERBOSE -> mindboxLogD(message = message)
Level.DEBUG -> mindboxLogD(message = message)
Level.INFO -> mindboxLogI(message = message)
Level.WARN -> mindboxLogW(message = message)
Level.ERROR -> mindboxLogE(message = message)
Level.NONE -> mindboxLogD(message = message)
}
}

private fun deliverToken(token: String?) {
Executors.newSingleThreadScheduledExecutor().schedule({
tokenCallbacks.keys.asIterable().forEach { key ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.Notification.VISIBILITY_PRIVATE
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.os.Build
import androidx.annotation.DrawableRes
Expand All @@ -16,14 +17,13 @@ import androidx.core.content.ContextCompat
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.R
import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import cloud.mindbox.mobile_sdk.logger.mindboxLogE
import cloud.mindbox.mobile_sdk.logger.mindboxLogI
import cloud.mindbox.mobile_sdk.pushes.handler.MessageHandlingState
import cloud.mindbox.mobile_sdk.pushes.handler.MindboxMessageHandler
import cloud.mindbox.mobile_sdk.pushes.handler.image.ImageRetryStrategy
import cloud.mindbox.mobile_sdk.services.BackgroundWorkManager
import cloud.mindbox.mobile_sdk.utils.Generator
import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
import cloud.mindbox.mobile_sdk.utils.loggingRunCatching
import cloud.mindbox.mobile_sdk.utils.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.UnknownHostException
Expand Down Expand Up @@ -471,6 +471,7 @@ internal object PushNotificationManager {
val correctedLinksActivities = activities?.mapKeys { (key, _) ->
key.replace("*", ".*").toRegex()
}
val hasButtons = pushActions.isNotEmpty()
return NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentText(text)
Expand Down Expand Up @@ -503,6 +504,8 @@ internal object PushNotificationManager {
image = image,
title = title,
text = text,
hasButtons = hasButtons,
context = context
)
.build()
}
Expand Down Expand Up @@ -627,11 +630,15 @@ internal object PushNotificationManager {
image: Bitmap?,
title: String,
text: String?,
hasButtons: Boolean,
context: Context
) = apply {
LoggingExceptionHandler.runCatching(
block = {
if (image != null) {
setImage(image, title, text)
val useScale = context.resources.getBoolean(R.bool.mindbox_use_central_inside_notification_scale)
val bigPicture = if (useScale) createCenterInsideBitmap(image, hasButtons, title.length) else image
setImage(image, bigPicture, title, text)
} else {
setText(text)
}
Expand All @@ -642,13 +649,13 @@ internal object PushNotificationManager {

private fun NotificationCompat.Builder.setImage(
imageBitmap: Bitmap,
bigPicture: Bitmap,
title: String,
text: String?,
text: String?
): NotificationCompat.Builder {
setLargeIcon(imageBitmap)

val style = NotificationCompat.BigPictureStyle()
.bigPicture(imageBitmap)
.bigPicture(bigPicture)
.bigLargeIcon(null)
.setBigContentTitle(title)
text?.let(style::setSummaryText)
Expand Down Expand Up @@ -694,4 +701,45 @@ internal object PushNotificationManager {
`package` = context.packageName
}

private fun createCenterInsideBitmap(src: Bitmap, hasButtons: Boolean, charCountInTitle:Int): Bitmap {
return runCatching {

val targetWidth = imageWidthInPixels
val targetHeight =
if (hasButtons) getImageHeightWithButtonIxPixels(charCountInTitle) else getImageHeightWithoutButtonIxPixels(charCountInTitle)
mindboxLogI("Target dimensions: width=$targetWidth, height=$targetHeight")

if (targetWidth == 0 || targetHeight == 0) {
mindboxLogI("Target dimensions are zero. Returning original bitmap")
return src
}
val srcWidth = src.width
val srcHeight = src.height

val scale = minOf(targetWidth.toFloat() / srcWidth, targetHeight.toFloat() / srcHeight)
mindboxLogI("Source dimensions: width=$srcWidth, height=$srcHeight. Scale factor: $scale")

val scaledWidth = (srcWidth * scale).toInt()
val scaledHeight = (srcHeight * scale).toInt()
mindboxLogI("Scaled dimensions: width=$scaledWidth, height=$scaledHeight")

val result = Bitmap.createBitmap(targetWidth, scaledHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(result)
canvas.drawColor(Color.TRANSPARENT)

val left = (targetWidth - scaledWidth) / 2
mindboxLogI("Drawing bitmap at position: left=$left")

if (left == 0) {
mindboxLogI("Left=0, we will get the same bitmap as the original. Returning original bitmap.")
return src
}

val scaledBitmap = Bitmap.createScaledBitmap(src, scaledWidth, scaledHeight, true)
canvas.drawBitmap(scaledBitmap, left.toFloat(), 0f, null)
return result
}.onFailure {
mindboxLogE("Error occurred during image scaling return original bitmap ", it)
}.getOrDefault(src)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cloud.mindbox.mobile_sdk.utils

import android.content.res.Resources
import android.os.Build
import cloud.mindbox.mobile_sdk.px
private const val EXPANDED_PUSH_IMAGE_HEIGHT_31_PLUS_TITLE_2_STRING = 250
private const val EXPANDED_PUSH_IMAGE_HEIGHT_31_WITH_BUTTONS_TITLE_2_STRING = 190
private const val EXPANDED_PUSH_IMAGE_HEIGHT_31_PLUS = 270
private const val EXPANDED_PUSH_IMAGE_HEIGHT_31_WITH_BUTTONS = 220
private const val EXPANDED_PUSH_IMAGE_HEIGHT_28_30 = 175
private const val EXPANDED_PUSH_IMAGE_HEIGHT_28_30_WITH_BUTTONS = 135
private const val EXPANDED_PUSH_IMAGE_HEIGHT_24_27 = 180
private const val EXPANDED_PUSH_IMAGE_HEIGHT_24_27_WITH_BUTTONS = 120
private const val EXPANDED_PUSH_IMAGE_HEIGHT_23_AND_LESS = 130
private const val MARGIN_ANDROID_30_AND_LESS = 32
private const val CHAR_COUNT_WHEN_TITLE_2_STRING = 35

internal val imageWidthInPixels: Int
get() {
return runCatching {
val defaultWidth = Resources.getSystem().displayMetrics.widthPixels
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) defaultWidth - MARGIN_ANDROID_30_AND_LESS.px else defaultWidth
}.getOrElse { 0 }
}

fun getImageHeightWithoutButtonIxPixels(charCountInTitle: Int): Int {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
if (charCountInTitle <= CHAR_COUNT_WHEN_TITLE_2_STRING)
EXPANDED_PUSH_IMAGE_HEIGHT_31_PLUS
else EXPANDED_PUSH_IMAGE_HEIGHT_31_PLUS_TITLE_2_STRING
Build.VERSION.SDK_INT in Build.VERSION_CODES.P..Build.VERSION_CODES.R -> EXPANDED_PUSH_IMAGE_HEIGHT_28_30
Build.VERSION.SDK_INT in Build.VERSION_CODES.N..Build.VERSION_CODES.O_MR1 -> EXPANDED_PUSH_IMAGE_HEIGHT_24_27
else -> EXPANDED_PUSH_IMAGE_HEIGHT_23_AND_LESS
}.px
}

fun getImageHeightWithButtonIxPixels(charCountInTitle: Int): Int {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
if (charCountInTitle <= CHAR_COUNT_WHEN_TITLE_2_STRING)
EXPANDED_PUSH_IMAGE_HEIGHT_31_WITH_BUTTONS
else EXPANDED_PUSH_IMAGE_HEIGHT_31_WITH_BUTTONS_TITLE_2_STRING
Build.VERSION.SDK_INT in Build.VERSION_CODES.P..Build.VERSION_CODES.R -> EXPANDED_PUSH_IMAGE_HEIGHT_28_30_WITH_BUTTONS
Build.VERSION.SDK_INT in Build.VERSION_CODES.N..Build.VERSION_CODES.O_MR1 -> EXPANDED_PUSH_IMAGE_HEIGHT_24_27_WITH_BUTTONS
else -> EXPANDED_PUSH_IMAGE_HEIGHT_23_AND_LESS
}.px
}
4 changes: 4 additions & 0 deletions sdk/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="mindbox_use_central_inside_notification_scale">true</bool>
</resources>

0 comments on commit 5b1644e

Please sign in to comment.