From 687e6234bdfc6b24680e92f348422f4a5c298529 Mon Sep 17 00:00:00 2001 From: Mansi-mParticle <159845845+Mansi-mParticle@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:56:10 -0400 Subject: [PATCH] refactor: Migrate MPLifecycleCallbackDelegate and MPLocationListener class to Kotlin (#506) --- .../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..2289628e5 --- /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 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) : + 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..3e46250c9 --- /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) { + } +}