From efad64cab5d9bd9445f9d9a457aaae61e7117abe Mon Sep 17 00:00:00 2001 From: Mansi-mParticle <159845845+Mansi-mParticle@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:06:59 -0400 Subject: [PATCH] refactor: Migrate Internal OS Helper class to kotlin (#515) --- .../mparticle/internal/JellybeanHelper.kt} | 19 ++++++++++--------- .../com/mparticle/internal/KitKatHelper.kt} | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) rename android-core/src/main/{java/com/mparticle/internal/JellybeanHelper.java => kotlin/com/mparticle/internal/JellybeanHelper.kt} (54%) rename android-core/src/main/{java/com/mparticle/internal/KitKatHelper.java => kotlin/com/mparticle/internal/KitKatHelper.kt} (52%) diff --git a/android-core/src/main/java/com/mparticle/internal/JellybeanHelper.java b/android-core/src/main/kotlin/com/mparticle/internal/JellybeanHelper.kt similarity index 54% rename from android-core/src/main/java/com/mparticle/internal/JellybeanHelper.java rename to android-core/src/main/kotlin/com/mparticle/internal/JellybeanHelper.kt index 6b22e3b77..e5ba6e641 100644 --- a/android-core/src/main/java/com/mparticle/internal/JellybeanHelper.java +++ b/android-core/src/main/kotlin/com/mparticle/internal/JellybeanHelper.kt @@ -1,24 +1,25 @@ -package com.mparticle.internal; +package com.mparticle.internal -import android.annotation.TargetApi; -import android.os.Build; -import android.os.StatFs; +import android.annotation.TargetApi +import android.os.Build +import android.os.StatFs /** * This is solely used to avoid logcat warnings that Android will generate when loading a class, * even if you use conditional execution based on VERSION. */ @TargetApi(18) -public class JellybeanHelper { - public static long getAvailableMemory(StatFs stat) { +object JellybeanHelper { + @JvmStatic + fun getAvailableMemory(stat: StatFs): Long { try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { - return stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); + return stat.availableBlocksLong * stat.blockSizeLong } - } catch (Exception e) { + } catch (e: Exception) { //For some reason, it appears some devices even in jelly bean don't have this method. } - return 0; + return 0 } } diff --git a/android-core/src/main/java/com/mparticle/internal/KitKatHelper.java b/android-core/src/main/kotlin/com/mparticle/internal/KitKatHelper.kt similarity index 52% rename from android-core/src/main/java/com/mparticle/internal/KitKatHelper.java rename to android-core/src/main/kotlin/com/mparticle/internal/KitKatHelper.kt index b6e8ba548..07fdbf11e 100644 --- a/android-core/src/main/java/com/mparticle/internal/KitKatHelper.java +++ b/android-core/src/main/kotlin/com/mparticle/internal/KitKatHelper.kt @@ -1,19 +1,19 @@ -package com.mparticle.internal; +package com.mparticle.internal -import android.annotation.TargetApi; -import android.os.Build; - -import org.json.JSONArray; +import android.annotation.TargetApi +import android.os.Build +import org.json.JSONArray /** * This is solely used to avoid logcat warnings that Android will generate when loading a class, * even if you use conditional execution based on VERSION. */ @TargetApi(19) -public class KitKatHelper { - public static void remove(JSONArray array, int index) { +object KitKatHelper { + @JvmStatic + fun remove(array: JSONArray, index: Int) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - array.remove(index); + array.remove(index) } } }