Skip to content

Commit

Permalink
Merge pull request #122 from Notificare/release/3.7.0-beta.1
Browse files Browse the repository at this point in the history
3.7.0-beta.1
  • Loading branch information
hpinhal committed Jan 9, 2024
2 parents ac0a7cc + be5133e commit a10a83c
Show file tree
Hide file tree
Showing 133 changed files with 1,451 additions and 255 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ local.properties

# Android Studio
/.idea

# Sample configurations
sample/**/notificare.xml
sample/**/notificare-services.json
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# CHANGELOG

## 3.7.0-beta.1

- Add manifest flag to disable the auto configuration
- Automatically enable remote notifications during launch when possible
- Automatically enable location updates during launch when possible
- Prevent the `device_registered` event from invoking before the `ready` event
- Fix warning when notification intents are handled by the broadcast receiver
- Include proguard rule to work around the issue with Moshi in R8
- Fix crash when presenting an in-app browser when the phone has none installed
- Fix `getParcelableExtra` on API 33 in certain cases

**Important notice:** Re-enabling remote notifications and location services is no longer required.
You can safely remove the following piece of code as the SDK will automatically handle it for you during the launch flow.

```kotlin
override fun onReady(application: NotificareApplication) {
// This check is no longer necessary.
if (Notificare.push().hasRemoteNotificationsEnabled) {
Notificare.push().enableRemoteNotifications()
}

// This check is no longer necessary.
if (Notificare.geo().hasLocationServicesEnabled) {
Notificare.geo().enableLocationUpdates()
}
}
```

## 3.6.1

- Fix race condition when synchronising monitored regions
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ buildscript {
maven { url 'https://developer.huawei.com/repo' }
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.1'
classpath 'com.android.tools.build:gradle:8.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 're.notifica.gradle:notificare-services:1.0.1'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.huawei.agconnect:agcp:1.7.3.300'
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.huawei.agconnect:agcp:1.9.1.301'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jun 01 15:03:56 WEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
2 changes: 2 additions & 0 deletions notificare-geo-beacons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies {
implementation project(':notificare')
implementation project(':notificare-geo')

implementation "androidx.core:core-ktx:$androidx_core_version"

// AltBeacon
implementation "org.altbeacon:android-beacon-library:$altbeacon_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ internal object NotificareGeoImpl : NotificareModule(), NotificareGeo, Notificar
}
}

override suspend fun postLaunch() {
if (hasLocationServicesEnabled) {
NotificareLogger.debug("Enabling locations updates automatically.")
enableLocationUpdatesInternal()
}
}

override suspend fun unlaunch() {
localStorage.locationServicesEnabled = false

Expand Down Expand Up @@ -298,43 +305,7 @@ internal object NotificareGeoImpl : NotificareModule(), NotificareGeo, Notificar
return
}

// Ensure we keep the bluetooth state updated in the API.
updateBluetoothState(hasBeaconSupport)

if (!hasForegroundLocationPermission) {
Notificare.coroutineScope.launch {
try {
lastKnownLocation = null
clearLocation()
NotificareLogger.debug("Device location cleared.")

clearRegions()
clearBeacons()
} catch (e: Exception) {
NotificareLogger.error("Failed to clear the device location.", e)
}
}

return
}

// Keep track of the location services status.
localStorage.locationServicesEnabled = true

// Start the location updates.
serviceManager?.enableLocationUpdates()

if (hasBeaconSupport) {
val enteredRegions =
localStorage.monitoredRegions.values.filter { localStorage.enteredRegions.contains(it.id) }
if (enteredRegions.size > 1) {
NotificareLogger.warning("Detected multiple entered regions. Beacon monitoring is limited to a single region at a time.")
}

val region = enteredRegions.firstOrNull()
if (region != null) startMonitoringBeacons(region)
}

enableLocationUpdatesInternal()
NotificareLogger.info("Location updates enabled.")
}

Expand Down Expand Up @@ -735,6 +706,45 @@ internal object NotificareGeoImpl : NotificareModule(), NotificareGeo, Notificar
}
}

private fun enableLocationUpdatesInternal() {
// Ensure we keep the bluetooth state updated in the API.
updateBluetoothState(hasBeaconSupport)

if (!hasForegroundLocationPermission) {
Notificare.coroutineScope.launch {
try {
lastKnownLocation = null
clearLocation()
NotificareLogger.debug("Device location cleared.")

clearRegions()
clearBeacons()
} catch (e: Exception) {
NotificareLogger.error("Failed to clear the device location.", e)
}
}

return
}

// Keep track of the location services status.
localStorage.locationServicesEnabled = true

// Start the location updates.
serviceManager?.enableLocationUpdates()

if (hasBeaconSupport) {
val enteredRegions =
localStorage.monitoredRegions.values.filter { localStorage.enteredRegions.contains(it.id) }
if (enteredRegions.size > 1) {
NotificareLogger.warning("Detected multiple entered regions. Beacon monitoring is limited to a single region at a time.")
}

val region = enteredRegions.firstOrNull()
if (region != null) startMonitoringBeacons(region)
}
}

private fun shouldUpdateLocation(location: Location): Boolean {
val lastKnownLocation = lastKnownLocation ?: return true

Expand Down
4 changes: 0 additions & 4 deletions notificare-loyalty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ android {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version

manifestPlaceholders = [
notificareApplicationId: '${notificareApplicationId}',
]

javaCompileOptions {
annotationProcessorOptions {
arguments = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ internal fun NotificarePass.PassbookField.formatNumber(): String? {


@Throws(ParseException::class)
internal fun NotificarePass.Companion.parseDate(dateStr: String, ignoreTimeZone: Boolean = false): Date? {
internal fun NotificarePass.Companion.parseDate(dateStr: String, @Suppress("UNUSED_PARAMETER") ignoreTimeZone: Boolean = false): Date? {
@Suppress("NAME_SHADOWING")
var dateStr = dateStr

if (dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}Z$".toRegex()) ||
Expand Down Expand Up @@ -158,14 +159,17 @@ private fun getDateFormat(dateStr: String): DateFormat? {
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}Z$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}[+\\-]\\d{2}:\\d{2}$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}[+\\-]\\d{4}$".toRegex()) -> "yyyy-MM-dd'T'HH:mmZ"

dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$".toRegex()) -> "yyyy-MM-dd'T'HH:mm:ss"
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+\\-]\\d{2}:\\d{2}$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+\\-]\\d{4}$".toRegex()) -> "yyyy-MM-dd'T'HH:mm:ssZ"

dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}$".toRegex()) -> "yyyy-MM-dd'T'HH:mm:ss.SSS"
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}[+\\-]\\d{2}:\\d{2}$".toRegex()) ||
dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}[+\\-]\\d{4}$".toRegex()) -> "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

else -> return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,18 @@ internal object NotificarePushUIImpl : NotificareModule(), NotificarePushUI, Not
return
}

createInAppBrowser().launchUrl(activity, Uri.parse(content.data as String))
try {
createInAppBrowser().launchUrl(activity, Uri.parse(content.data as String))

onMainThread {
lifecycleListeners.forEach { it.onNotificationPresented(notification) }
onMainThread {
lifecycleListeners.forEach { it.onNotificationPresented(notification) }
}
} catch (e: Exception) {
NotificareLogger.error("Failed launch in-app browser.", e)

onMainThread {
lifecycleListeners.forEach { it.onNotificationFailedToPresent(notification) }
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public class NotificareCallbackActionFragment private constructor() : Fragment()
// Read bitmap, convert to JPEG
options.inSampleSize = calculateSampleSize(options)
options.inJustDecodeBounds = false
options.inPurgeable = true

val srcBitmap = BitmapFactory.decodeFile(imagePath, options) ?: return false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Color
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -147,6 +148,13 @@ internal object NotificarePushImpl : NotificareModule(), NotificarePush, Notific
updateNotificationSettings()
}

override suspend fun postLaunch() {
if (sharedPreferences.remoteNotificationsEnabled) {
NotificareLogger.debug("Enabling remote notifications automatically.")
serviceManager?.requestPushToken()
}
}

override suspend fun unlaunch() {
sharedPreferences.remoteNotificationsEnabled = false
sharedPreferences.firstRegistration = true
Expand Down Expand Up @@ -428,7 +436,7 @@ internal object NotificarePushImpl : NotificareModule(), NotificarePush, Notific
if (notificationIntent.resolveActivity(Notificare.requireContext().packageManager) != null) {
// Notification handled by custom activity in package
Notificare.requireContext().startActivity(notificationIntent)
} else {
} else if (intentReceiver.simpleName == NotificarePushIntentReceiver::class.java.simpleName) {
NotificareLogger.warning("Could not find an activity with the '${notificationIntent.action}' action.")
}
}
Expand Down Expand Up @@ -696,7 +704,7 @@ internal object NotificarePushImpl : NotificareModule(), NotificarePush, Notific
NotificationCompat.BigPictureStyle()
.setSummaryText(message.alert)
.bigPicture(attachmentImage)
.bigLargeIcon(null)
.bigLargeIcon(null as Bitmap?)
)
} else {
builder.setStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/surface_view" />
app:layout_constraintTop_toBottomOf="@id/camera_view" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions notificare/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ android {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version

consumerProguardFiles 'consumer-rules.pro'

javaCompileOptions {
annotationProcessorOptions {
arguments = [
Expand Down
2 changes: 2 additions & 0 deletions notificare/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://docs.notifica.re/sdk/v3/android/troubleshooting/#known-issue-with-moshi-in-gradle-80
-keep,allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter
21 changes: 16 additions & 5 deletions notificare/src/main/java/re/notifica/Notificare.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public object Notificare {
try {
val useTestApi = context.resources.getBoolean(R.bool.notificare_services_use_test_api)
if (useTestApi) return@run NotificareServicesInfo.Environment.TEST
} catch (e: Resources.NotFoundException) {
} catch (_: Resources.NotFoundException) {
}

return@run NotificareServicesInfo.Environment.PRODUCTION
Expand Down Expand Up @@ -154,7 +154,7 @@ public object Notificare {
val application = fetchApplication()

// Loop all possible modules and launch the available ones.
NotificareModule.Module.values().forEach { module ->
NotificareModule.Module.entries.forEach { module ->
module.instance?.run {
NotificareLogger.debug("Launching module: ${module.name.lowercase()}")
try {
Expand Down Expand Up @@ -192,6 +192,18 @@ public object Notificare {
// Notify the listeners.
listeners.forEach { it.onReady(application) }
}

// Loop all possible modules and post-launch the available ones.
NotificareModule.Module.entries.forEach { module ->
module.instance?.run {
NotificareLogger.debug("Post-launching module: ${module.name.lowercase()}")
try {
this.postLaunch()
} catch (e: Exception) {
NotificareLogger.error("Failed to post-launch '${module.name.lowercase()}': $e")
}
}
}
} catch (e: Exception) {
NotificareLogger.error("Failed to launch Notificare.", e)
state = NotificareLaunchState.CONFIGURED
Expand All @@ -211,7 +223,7 @@ public object Notificare {
Notificare.coroutineScope.launch {
try {
// Loop all possible modules and un-launch the available ones.
NotificareModule.Module.values().reversed().forEach { module ->
NotificareModule.Module.entries.reversed().forEach { module ->
module.instance?.run {
NotificareLogger.debug("Un-launching module: ${module.name.lowercase()}.")

Expand Down Expand Up @@ -321,7 +333,6 @@ public object Notificare {
public suspend fun fetchDynamicLink(uri: Uri): NotificareDynamicLink = withContext(Dispatchers.IO) {
if (!isConfigured) throw NotificareNotConfiguredException()

@Suppress("BlockingMethodInNonBlockingContext")
val uriEncodedLink = URLEncoder.encode(uri.toString(), "UTF-8")

NotificareRequest.Builder()
Expand Down Expand Up @@ -513,7 +524,7 @@ public object Notificare {
this.database = NotificareDatabase.create(context.applicationContext)
this.sharedPreferences = NotificareSharedPreferences(context.applicationContext)

NotificareModule.Module.values().forEach { module ->
NotificareModule.Module.entries.forEach { module ->
module.instance?.run {
NotificareLogger.debug("Configuring module: ${module.name.lowercase()}")
this.configure()
Expand Down

0 comments on commit a10a83c

Please sign in to comment.