From 5ce0c1ccf85cbb3ae40f1ab6bdc079ba09ef22b5 Mon Sep 17 00:00:00 2001 From: ShellWen Chen Date: Sat, 6 Apr 2024 06:25:19 +0800 Subject: [PATCH] refactor: migrate `AppsHelper` to Kotlin Remove `appIconLookup()` as not used --- .../kde/kdeconnect/Helpers/AppsHelper.java | 49 ------------------- src/org/kde/kdeconnect/Helpers/AppsHelper.kt | 25 ++++++++++ 2 files changed, 25 insertions(+), 49 deletions(-) delete mode 100644 src/org/kde/kdeconnect/Helpers/AppsHelper.java create mode 100644 src/org/kde/kdeconnect/Helpers/AppsHelper.kt diff --git a/src/org/kde/kdeconnect/Helpers/AppsHelper.java b/src/org/kde/kdeconnect/Helpers/AppsHelper.java deleted file mode 100644 index 595ef499..00000000 --- a/src/org/kde/kdeconnect/Helpers/AppsHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL -*/ - -package org.kde.kdeconnect.Helpers; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.graphics.drawable.Drawable; -import android.util.Log; - -public class AppsHelper { - - public static String appNameLookup(Context context, String packageName) { - - try { - - PackageManager pm = context.getPackageManager(); - ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); - - return pm.getApplicationLabel(ai).toString(); - - } catch (final PackageManager.NameNotFoundException e) { - - Log.e("AppsHelper", "Could not resolve name " + packageName, e); - - return null; - - } - - } - - public static Drawable appIconLookup(Context context, String packageName) { - - try { - - PackageManager pm = context.getPackageManager(); - ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); - return pm.getApplicationIcon(ai); - - } catch (final PackageManager.NameNotFoundException e) { - Log.e("AppsHelper", "Could not find icon for " + packageName, e); - return null; - } - } -} diff --git a/src/org/kde/kdeconnect/Helpers/AppsHelper.kt b/src/org/kde/kdeconnect/Helpers/AppsHelper.kt new file mode 100644 index 00000000..3608f64f --- /dev/null +++ b/src/org/kde/kdeconnect/Helpers/AppsHelper.kt @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ +package org.kde.kdeconnect.Helpers + +import android.content.Context +import android.content.pm.PackageManager +import android.util.Log + +object AppsHelper { + @JvmStatic + fun appNameLookup(context: Context, packageName: String): String? { + return try { + val manager = context.packageManager + val info = manager.getApplicationInfo(packageName, 0) + + manager.getApplicationLabel(info).toString() + } catch (e: PackageManager.NameNotFoundException) { + Log.e("AppsHelper", "Could not resolve name $packageName", e) + null + } + } +}