From c12f7523df4e39f087cd8aae0283b59ec16e1d3c Mon Sep 17 00:00:00 2001 From: "Mr. Dragon" Date: Sun, 24 Mar 2019 00:37:57 +0530 Subject: [PATCH] PackageUtil : Add new utils - Add a PseudoPackageMap to store of all downloaded app. --- .../store/fragment/details/ActionButton.java | 4 ++ .../com/aurora/store/installer/Installer.java | 7 +-- .../com/aurora/store/utility/PackageUtil.java | 46 +++++++++++++++++++ .../com/aurora/store/utility/PrefUtil.java | 8 ++-- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/aurora/store/utility/PackageUtil.java diff --git a/app/src/main/java/com/aurora/store/fragment/details/ActionButton.java b/app/src/main/java/com/aurora/store/fragment/details/ActionButton.java index 11c33f67d..5324b2fc0 100644 --- a/app/src/main/java/com/aurora/store/fragment/details/ActionButton.java +++ b/app/src/main/java/com/aurora/store/fragment/details/ActionButton.java @@ -46,6 +46,7 @@ import com.aurora.store.model.App; import com.aurora.store.notification.GeneralNotification; import com.aurora.store.task.DeliveryData; import com.aurora.store.utility.Log; +import com.aurora.store.utility.PackageUtil; import com.aurora.store.utility.PathUtil; import com.aurora.store.utility.Util; import com.aurora.store.utility.ViewUtil; @@ -306,6 +307,9 @@ public class ActionButton extends AbstractHelper { Log.i("Downloading ObbFiles : %s", app.getPackageName()); }); } + + //Add to PseudoPackageMap + PackageUtil.addToPseudoPackageMap(context, app.getPackageName(), app.getDisplayName()); } private FetchListener getFetchListener() { diff --git a/app/src/main/java/com/aurora/store/installer/Installer.java b/app/src/main/java/com/aurora/store/installer/Installer.java index 83f362976..d278a4c19 100644 --- a/app/src/main/java/com/aurora/store/installer/Installer.java +++ b/app/src/main/java/com/aurora/store/installer/Installer.java @@ -37,6 +37,7 @@ import com.aurora.store.R; import com.aurora.store.model.App; import com.aurora.store.notification.QuickNotification; import com.aurora.store.utility.Log; +import com.aurora.store.utility.PackageUtil; import com.aurora.store.utility.PathUtil; import com.aurora.store.utility.PrefUtil; import com.aurora.store.utility.Util; @@ -108,7 +109,7 @@ public class Installer { new QuickNotification(context).show(context.getString(R.string.app_name), String.format(Locale.getDefault(), context.getString(R.string.notification_installation_failed), - packageName)); + PackageUtil.getDisplayName(context,packageName))); unregisterReceiver(installer); break; case INSTALLING: @@ -116,13 +117,13 @@ public class Installer { new QuickNotification(context).show(context.getString(R.string.app_name), String.format(Locale.getDefault(), context.getString(R.string.notification_installation_progress), - packageName)); + PackageUtil.getDisplayName(context,packageName))); break; case INSTALLATION_SUCCEED: new QuickNotification(context).show(context.getString(R.string.app_name), String.format(Locale.getDefault(), context.getString(R.string.notification_installation_complete), - packageName)); + PackageUtil.getDisplayName(context,packageName))); if (Util.shouldDeleteApk(context)) clearInstallationFiles(apkFiles); unregisterReceiver(installer); diff --git a/app/src/main/java/com/aurora/store/utility/PackageUtil.java b/app/src/main/java/com/aurora/store/utility/PackageUtil.java new file mode 100644 index 000000000..31d8dd33e --- /dev/null +++ b/app/src/main/java/com/aurora/store/utility/PackageUtil.java @@ -0,0 +1,46 @@ +/* + * Aurora Store + * Copyright (C) 2019, Rahul Kumar Patel + * + * Aurora Store is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Aurora Store is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Aurora Store. If not, see . + * + * + */ + +package com.aurora.store.utility; + +import android.content.Context; + +import java.util.Map; + +public class PackageUtil { + + public static final String PSEUDO_PACKAGE_MAP = "PSEUDO_PACKAGE_MAP"; + + public static String getDisplayName(Context context, String packageName) { + Map pseudoMap = getPseudoPackageMap(context); + return TextUtil.emptyIfNull(pseudoMap.get(packageName)); + } + + public static Map getPseudoPackageMap(Context context) { + return PrefUtil.getMap(context, PSEUDO_PACKAGE_MAP); + } + + public static void addToPseudoPackageMap(Context context, String packageName, String displayName) { + Map pseudoMap = getPseudoPackageMap(context); + pseudoMap.put(packageName, displayName); + PrefUtil.saveMap(context, pseudoMap, PSEUDO_PACKAGE_MAP); + } + +} diff --git a/app/src/main/java/com/aurora/store/utility/PrefUtil.java b/app/src/main/java/com/aurora/store/utility/PrefUtil.java index 6df5763a8..01436dc81 100644 --- a/app/src/main/java/com/aurora/store/utility/PrefUtil.java +++ b/app/src/main/java/com/aurora/store/utility/PrefUtil.java @@ -87,7 +87,7 @@ public class PrefUtil { return Util.getPrefs(context.getApplicationContext()).getStringSet(key, new HashSet<>()); } - public static void saveMap(Context context, Map map, String key) { + public static void saveMap(Context context, Map map, String key) { SharedPreferences mPreferences = Util.getPrefs(context); if (mPreferences != null) { JSONObject jsonObject = new JSONObject(map); @@ -99,8 +99,8 @@ public class PrefUtil { } } - public static Map getMap(Context context, String key) { - Map outputMap = new HashMap<>(); + public static Map getMap(Context context, String key) { + Map outputMap = new HashMap<>(); SharedPreferences mPreferences = Util.getPrefs(context); try { if (mPreferences != null) { @@ -109,7 +109,7 @@ public class PrefUtil { Iterator keysItr = jsonObject.keys(); while (keysItr.hasNext()) { String k = keysItr.next(); - Integer value = (Integer) jsonObject.get(k); + String value = (String) jsonObject.get(k); outputMap.put(k, value); } }