From 2ccbd3bc802b0ef8b281f9e2212ff7aa931135c1 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Wed, 11 Sep 2024 15:49:57 -0400 Subject: [PATCH 1/5] refactor: Migrate MPLifecycleCallbackDelegate and MPLocationListener class to Kotlin --- .../internal/MPLifecycleCallbackDelegate.java | 56 ------------------- .../internal/MPLocationListener.java | 42 -------------- .../mparticle}/TypedUserAttributeListener.kt | 0 .../mparticle}/UserAttributeListenerType.kt | 0 .../mparticle}/WrapperSdk.kt | 0 .../internal/MPLifecycleCallbackDelegate.kt | 44 +++++++++++++++ .../mparticle/internal/MPLocationListener.kt | 21 +++++++ 7 files changed, 65 insertions(+), 98 deletions(-) delete mode 100644 android-core/src/main/java/com/mparticle/internal/MPLifecycleCallbackDelegate.java delete mode 100644 android-core/src/main/java/com/mparticle/internal/MPLocationListener.java rename android-core/src/main/kotlin/{com.mparticle => com/mparticle}/TypedUserAttributeListener.kt (100%) rename android-core/src/main/kotlin/{com.mparticle => com/mparticle}/UserAttributeListenerType.kt (100%) rename android-core/src/main/kotlin/{com.mparticle => com/mparticle}/WrapperSdk.kt (100%) create mode 100644 android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt create mode 100644 android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt diff --git a/android-core/src/main/java/com/mparticle/internal/MPLifecycleCallbackDelegate.java b/android-core/src/main/java/com/mparticle/internal/MPLifecycleCallbackDelegate.java deleted file mode 100644 index d8265a937..000000000 --- a/android-core/src/main/java/com/mparticle/internal/MPLifecycleCallbackDelegate.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.mparticle.internal; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.Application; -import android.os.Build; -import android.os.Bundle; - -/** - * This class is used by the AppStateManager to determine when the app is visible or in the background. - * - * Separated into it's own class to avoid annoying logcat messages on pre-ICS devices. - */ -@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) -class MPLifecycleCallbackDelegate implements Application.ActivityLifecycleCallbacks { - private AppStateManager mStateManager; - - public MPLifecycleCallbackDelegate(AppStateManager stateManager) { - mStateManager = stateManager; - } - - @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { - mStateManager.onActivityCreated(activity, savedInstanceState); - } - - @Override - public void onActivityStarted(Activity activity) { - mStateManager.onActivityStarted(activity); - } - - @Override - public void onActivityResumed(Activity activity) { - mStateManager.onActivityResumed(activity); - } - - @Override - public void onActivityPaused(Activity activity) { - mStateManager.onActivityPaused(activity); - } - - @Override - public void onActivityStopped(Activity activity) { - mStateManager.onActivityStopped(activity); - } - - @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { - mStateManager.onActivitySaveInstanceState(activity, outState); - } - - @Override - public void onActivityDestroyed(Activity activity) { - mStateManager.onActivityDestroyed(activity); - } -} diff --git a/android-core/src/main/java/com/mparticle/internal/MPLocationListener.java b/android-core/src/main/java/com/mparticle/internal/MPLocationListener.java deleted file mode 100644 index d43476a2a..000000000 --- a/android-core/src/main/java/com/mparticle/internal/MPLocationListener.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.mparticle.internal; - -import android.location.Location; -import android.location.LocationListener; -import android.os.Bundle; - -import com.mparticle.MParticle; - -/** - * Created by sdozor on 3/9/15. - */ -public final class MPLocationListener implements LocationListener { - private final MParticle mParticle; - - public MPLocationListener(MParticle mParticle) { - this.mParticle = mParticle; - } - - @Override - public void onLocationChanged(Location location) { - if (mParticle != null) { - mParticle.setLocation(location); - } - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - - } - - @Override - public void onProviderEnabled(String provider) { - - } - - @Override - public void onProviderDisabled(String provider) { - - } - - -} diff --git a/android-core/src/main/kotlin/com.mparticle/TypedUserAttributeListener.kt b/android-core/src/main/kotlin/com/mparticle/TypedUserAttributeListener.kt similarity index 100% rename from android-core/src/main/kotlin/com.mparticle/TypedUserAttributeListener.kt rename to android-core/src/main/kotlin/com/mparticle/TypedUserAttributeListener.kt diff --git a/android-core/src/main/kotlin/com.mparticle/UserAttributeListenerType.kt b/android-core/src/main/kotlin/com/mparticle/UserAttributeListenerType.kt similarity index 100% rename from android-core/src/main/kotlin/com.mparticle/UserAttributeListenerType.kt rename to android-core/src/main/kotlin/com/mparticle/UserAttributeListenerType.kt diff --git a/android-core/src/main/kotlin/com.mparticle/WrapperSdk.kt b/android-core/src/main/kotlin/com/mparticle/WrapperSdk.kt similarity index 100% rename from android-core/src/main/kotlin/com.mparticle/WrapperSdk.kt rename to android-core/src/main/kotlin/com/mparticle/WrapperSdk.kt diff --git a/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt b/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt new file mode 100644 index 000000000..b95c7e590 --- /dev/null +++ b/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt @@ -0,0 +1,44 @@ +package com.mparticle.internal + +import android.annotation.TargetApi +import android.app.Activity +import android.app.Application.ActivityLifecycleCallbacks +import android.os.Build +import android.os.Bundle + +/** + * This class is used by the AppStateManager to determine when the app is visible or in the background. + * + * Separated into it's own class to avoid annoying logcat messages on pre-ICS devices. + */ +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) +internal class MPLifecycleCallbackDelegate(private val mStateManager: AppStateManager) : + ActivityLifecycleCallbacks { + override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { + mStateManager.onActivityCreated(activity, savedInstanceState) + } + + override fun onActivityStarted(activity: Activity) { + mStateManager.onActivityStarted(activity) + } + + override fun onActivityResumed(activity: Activity) { + mStateManager.onActivityResumed(activity) + } + + override fun onActivityPaused(activity: Activity) { + mStateManager.onActivityPaused(activity) + } + + override fun onActivityStopped(activity: Activity) { + mStateManager.onActivityStopped(activity) + } + + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { + mStateManager.onActivitySaveInstanceState(activity, outState) + } + + override fun onActivityDestroyed(activity: Activity) { + mStateManager.onActivityDestroyed(activity) + } +} diff --git a/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt b/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt new file mode 100644 index 000000000..230838723 --- /dev/null +++ b/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt @@ -0,0 +1,21 @@ +package com.mparticle.internal + +import android.location.Location +import android.location.LocationListener +import android.os.Bundle +import com.mparticle.MParticle + +class MPLocationListener(private val mParticle: MParticle?) : LocationListener { + override fun onLocationChanged(location: Location) { + mParticle?.setLocation(location) + } + + override fun onStatusChanged(provider: String, status: Int, extras: Bundle) { + } + + override fun onProviderEnabled(provider: String) { + } + + override fun onProviderDisabled(provider: String) { + } +} From e4d97dbb07a46e520285c5a89cec0c0acea66fa5 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Mon, 16 Sep 2024 14:57:48 -0400 Subject: [PATCH 2/5] Address review comments --- .../com/mparticle/MPLocationListener.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 android-core/src/main/kotlin/com/mparticle/MPLocationListener.java diff --git a/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java b/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java new file mode 100644 index 000000000..949a7c16d --- /dev/null +++ b/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java @@ -0,0 +1,40 @@ +package com.mparticle; + +import android.location.Location; +import android.location.LocationListener; +import android.os.Bundle; + +/** + * Created by sdozor on 3/9/15. + */ +public final class MPLocationListener implements LocationListener { + private final MParticle mParticle; + + public MPLocationListener(MParticle mParticle) { + this.mParticle = mParticle; + } + + @Override + public void onLocationChanged(Location location) { + if (mParticle != null) { + mParticle.setLocation(location); + } + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + + } + + @Override + public void onProviderDisabled(String provider) { + + } + + +} From 23807cd2994fc36e8ec7c21f848ceccae43f18f7 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Mon, 16 Sep 2024 15:25:06 -0400 Subject: [PATCH 3/5] Revert "Address review comments" This reverts commit e4d97dbb07a46e520285c5a89cec0c0acea66fa5. --- .../com/mparticle/MPLocationListener.java | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 android-core/src/main/kotlin/com/mparticle/MPLocationListener.java diff --git a/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java b/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java deleted file mode 100644 index 949a7c16d..000000000 --- a/android-core/src/main/kotlin/com/mparticle/MPLocationListener.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.mparticle; - -import android.location.Location; -import android.location.LocationListener; -import android.os.Bundle; - -/** - * Created by sdozor on 3/9/15. - */ -public final class MPLocationListener implements LocationListener { - private final MParticle mParticle; - - public MPLocationListener(MParticle mParticle) { - this.mParticle = mParticle; - } - - @Override - public void onLocationChanged(Location location) { - if (mParticle != null) { - mParticle.setLocation(location); - } - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - - } - - @Override - public void onProviderEnabled(String provider) { - - } - - @Override - public void onProviderDisabled(String provider) { - - } - - -} From f48c8c4b6987cdd3ba8187003995b32f32652731 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Mon, 16 Sep 2024 15:30:22 -0400 Subject: [PATCH 4/5] Update comment description --- .../com/mparticle/internal/MPLifecycleCallbackDelegate.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt b/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt index b95c7e590..2289628e5 100644 --- a/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt +++ b/android-core/src/main/kotlin/com/mparticle/internal/MPLifecycleCallbackDelegate.kt @@ -9,7 +9,7 @@ import android.os.Bundle /** * This class is used by the AppStateManager to determine when the app is visible or in the background. * - * Separated into it's own class to avoid annoying logcat messages on pre-ICS devices. + * Separated into its own class to avoid annoying logcat messages on pre-ICS devices. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) internal class MPLifecycleCallbackDelegate(private val mStateManager: AppStateManager) : From 64bb2d6c7934287f1dd3ba7f2d5516221da6a47b Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 17 Sep 2024 11:21:07 -0400 Subject: [PATCH 5/5] Updated MPLocationListener to eliminate nullable --- .../main/kotlin/com/mparticle/internal/MPLocationListener.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt b/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt index 230838723..3e46250c9 100644 --- a/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt +++ b/android-core/src/main/kotlin/com/mparticle/internal/MPLocationListener.kt @@ -5,9 +5,9 @@ import android.location.LocationListener import android.os.Bundle import com.mparticle.MParticle -class MPLocationListener(private val mParticle: MParticle?) : LocationListener { +class MPLocationListener(private val mParticle: MParticle) : LocationListener { override fun onLocationChanged(location: Location) { - mParticle?.setLocation(location) + mParticle.setLocation(location) } override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {