From 202d67e455162973b2c1f3602e51afe98d22408b Mon Sep 17 00:00:00 2001 From: Cristian Dregan Date: Wed, 1 Mar 2023 17:55:57 +0200 Subject: [PATCH] Release 1.4.2 --- OmetriaSDK/build.gradle.kts | 2 +- OmetriaSDK/src/main/AndroidManifest.xml | 7 ++-- .../com/android/ometriasdk/core/Repository.kt | 16 +++++---- .../NotificationInteractionActivity.kt | 2 -- .../notification/OmetriaPushNotification.kt | 4 +-- README.md | 2 +- app/build.gradle.kts | 4 +-- .../main/java/com/android/sample/SampleApp.kt | 24 +++---------- .../presentation/EnterApiTokenDialog.kt | 1 + .../sample/presentation/MainActivity.kt | 34 +++++++++++++++---- 10 files changed, 54 insertions(+), 42 deletions(-) diff --git a/OmetriaSDK/build.gradle.kts b/OmetriaSDK/build.gradle.kts index 97c5aa7..c108836 100644 --- a/OmetriaSDK/build.gradle.kts +++ b/OmetriaSDK/build.gradle.kts @@ -1,4 +1,4 @@ -val versionName = "1.4.1" +val versionName = "1.4.2" plugins { id("com.android.library") diff --git a/OmetriaSDK/src/main/AndroidManifest.xml b/OmetriaSDK/src/main/AndroidManifest.xml index f88d66e..960021d 100644 --- a/OmetriaSDK/src/main/AndroidManifest.xml +++ b/OmetriaSDK/src/main/AndroidManifest.xml @@ -1,9 +1,12 @@ - - + + \ No newline at end of file diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Repository.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Repository.kt index e891b8f..9383059 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Repository.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Repository.kt @@ -120,22 +120,26 @@ internal class Repository( fun getRedirectForUrl(url: String, listener: ProcessAppLinkListener) { executor.execute { - var urlTemp: URL? = null - var connection: HttpURLConnection? = null + val urlTemp: URL? + val connection: HttpURLConnection? try { urlTemp = URL(url) } catch (e: MalformedURLException) { - listener.onProcessFailed(e.message ?: "Something went wrong") + resultHandler.post { listener.onProcessFailed(e.message ?: "Something went wrong") } + return@execute } try { - connection = urlTemp?.openConnection() as HttpURLConnection + connection = urlTemp.openConnection() as? HttpURLConnection } catch (e: IOException) { - listener.onProcessFailed(e.message ?: "Something went wrong") + resultHandler.post { listener.onProcessFailed(e.message ?: "Something went wrong") } + return@execute } try { connection?.responseCode } catch (e: IOException) { - listener.onProcessFailed(e.message ?: "Something went wrong") + resultHandler.post { listener.onProcessFailed(e.message ?: "Something went wrong") } + connection?.disconnect() + return@execute } resultHandler.post { listener.onProcessResult(connection?.url.toString()) } connection?.disconnect() diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/NotificationInteractionActivity.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/NotificationInteractionActivity.kt index b329385..83a4d0d 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/NotificationInteractionActivity.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/NotificationInteractionActivity.kt @@ -35,7 +35,5 @@ class NotificationInteractionActivity : Activity() { Ometria.instance().trackNotificationInteractedEvent(it) } } - - finish() } } \ No newline at end of file diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt index 5754e75..78f2534 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt @@ -68,9 +68,9 @@ internal class OmetriaPushNotification( options.putString(OMETRIA_NOTIFICATION_BODY_KEY, it.toJson().toString()) } - return Intent() - .setClass(context, NotificationInteractionActivity::class.java) + return Intent(context, NotificationInteractionActivity::class.java) .putExtras(options) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) } private fun getFlags(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { diff --git a/README.md b/README.md index b9cc335..ec3dd1e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ To install the library inside **Android Studio**, declare it as dependency in yo ```gradle dependencies { - implementation 'com.ometria:android-sdk:1.4.1' + implementation 'com.ometria:android-sdk:1.4.2' } ``` diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 969abe3..ef24497 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,8 +12,8 @@ android { applicationId = "com.android.sample" minSdk = 21 targetSdk = 33 - versionCode = 5 - versionName = "1.0.4" + versionCode = 8 + versionName = "1.0.5" } signingConfigs { getByName("debug") { diff --git a/app/src/main/java/com/android/sample/SampleApp.kt b/app/src/main/java/com/android/sample/SampleApp.kt index 5a83e2e..73132ea 100644 --- a/app/src/main/java/com/android/sample/SampleApp.kt +++ b/app/src/main/java/com/android/sample/SampleApp.kt @@ -2,14 +2,12 @@ package com.android.sample import android.app.Application import android.content.Intent -import android.net.Uri -import android.util.Log -import android.webkit.URLUtil import androidx.core.content.ContextCompat import com.android.ometriasdk.core.Ometria import com.android.ometriasdk.notification.OmetriaNotification import com.android.ometriasdk.notification.OmetriaNotificationInteractionHandler import com.android.sample.data.AppPreferencesUtils +import com.android.sample.presentation.DEEPLINK_ACTION_URL_EXTRA_KEY import com.android.sample.presentation.MainActivity import com.android.sample.presentation.OMETRIA_NOTIFICATION_STRING_EXTRA_KEY @@ -39,28 +37,14 @@ class SampleApp : Application(), OmetriaNotificationInteractionHandler { } override fun onNotificationInteraction(ometriaNotification: OmetriaNotification) { - openMainActivity(ometriaNotification.toString()) - openBrowser(ometriaNotification.deepLinkActionUrl) + openMainActivity(ometriaNotification.toString(), ometriaNotification.deepLinkActionUrl) } - private fun openMainActivity(ometriaNotificationString: String) { + private fun openMainActivity(ometriaNotificationString: String, deepLinkActionUrl: String?) { val intent = Intent(this, MainActivity::class.java) intent.putExtra(OMETRIA_NOTIFICATION_STRING_EXTRA_KEY, ometriaNotificationString) + intent.putExtra(DEEPLINK_ACTION_URL_EXTRA_KEY, deepLinkActionUrl) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) } - - private fun openBrowser(deepLink: String?) { - deepLink?.let { safeDeepLink -> - if (URLUtil.isValidUrl(safeDeepLink).not()) return - - Ometria.instance() - .trackDeepLinkOpenedEvent(safeDeepLink, "Browser") - Log.d(SampleApp::class.java.simpleName, "Open URL: $safeDeepLink") - val intent = Intent(Intent.ACTION_VIEW) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - intent.data = Uri.parse(safeDeepLink) - startActivity(intent) - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/android/sample/presentation/EnterApiTokenDialog.kt b/app/src/main/java/com/android/sample/presentation/EnterApiTokenDialog.kt index b88e0b6..d1ee26a 100644 --- a/app/src/main/java/com/android/sample/presentation/EnterApiTokenDialog.kt +++ b/app/src/main/java/com/android/sample/presentation/EnterApiTokenDialog.kt @@ -39,6 +39,7 @@ class EnterApiTokenDialog : DialogFragment() { notificationColor = ContextCompat.getColor(requireContext(), R.color.colorAccent), notificationChannelName = "Custom Channel Name" ).loggingEnabled(true) + Ometria.instance().notificationInteractionHandler = SampleApp.instance AppPreferencesUtils.saveApiToken(apiToken) dismiss() } diff --git a/app/src/main/java/com/android/sample/presentation/MainActivity.kt b/app/src/main/java/com/android/sample/presentation/MainActivity.kt index 4956853..b765266 100644 --- a/app/src/main/java/com/android/sample/presentation/MainActivity.kt +++ b/app/src/main/java/com/android/sample/presentation/MainActivity.kt @@ -1,9 +1,13 @@ package com.android.sample.presentation +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.text.SpannableString import android.text.method.LinkMovementMethod import android.text.util.Linkify +import android.util.Log +import android.webkit.URLUtil import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity @@ -11,9 +15,11 @@ import androidx.viewpager2.widget.ViewPager2 import com.android.ometriasdk.core.Ometria import com.android.ometriasdk.core.listener.ProcessAppLinkListener import com.android.sample.R +import com.android.sample.SampleApp import com.android.sample.databinding.ActivityMainBinding const val OMETRIA_NOTIFICATION_STRING_EXTRA_KEY = "ometria_notification_string_extra_key" +const val DEEPLINK_ACTION_URL_EXTRA_KEY = "deeplink_action_url_extra_key" const val FIRST_FRAGMENT_POS = 0 const val SECOND_FRAGMENT_POS = 1 @@ -28,10 +34,11 @@ class MainActivity : AppCompatActivity() { val ometriaNotificationString = intent.getStringExtra(OMETRIA_NOTIFICATION_STRING_EXTRA_KEY).orEmpty() + val deepLinkActionUrl = intent.getStringExtra(DEEPLINK_ACTION_URL_EXTRA_KEY) setUpBottomNavMenu() setupViewPager(ometriaNotificationString) - handleAppLinkFromIntent() + handleAppLinkFromIntent(deepLinkActionUrl) } private fun switchFragment(position: Int) { @@ -77,19 +84,20 @@ class MainActivity : AppCompatActivity() { }) } - private fun handleAppLinkFromIntent() { + private fun handleAppLinkFromIntent(deepLinkActionUrl: String?) { // Here you should check whether the link is one that can already be handled by the app. // If the link is identified as one coming from an Ometria campaign, you will be able to get the final URL // by calling the processAppLink method. // The processing is done async, so you should present a loading screen. - intent.dataString?.let { url -> - Ometria.instance().processAppLink(url, object : ProcessAppLinkListener { + val url = deepLinkActionUrl ?: intent.dataString + url?.let { safeUrl -> + Ometria.instance().processAppLink(safeUrl, object : ProcessAppLinkListener { override fun onProcessResult(url: String) { - displayRedirectUrlDialog(url) + openBrowser(url) } override fun onProcessFailed(error: String) { - displayRedirectUrlDialog(error) + displayRedirectUrlDialog("$error $safeUrl") } }) } @@ -111,4 +119,18 @@ class MainActivity : AppCompatActivity() { } .show() } + + private fun openBrowser(deepLink: String?) { + deepLink?.let { safeDeepLink -> + if (URLUtil.isValidUrl(safeDeepLink).not()) return + + Ometria.instance() + .trackDeepLinkOpenedEvent(safeDeepLink, "Browser") + Log.d(SampleApp::class.java.simpleName, "Open URL: $safeDeepLink") + val intent = Intent(Intent.ACTION_VIEW) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.data = Uri.parse(safeDeepLink) + startActivity(intent) + } + } } \ No newline at end of file