PackageUtil : Add new utils

- Add a PseudoPackageMap to store <PackageName,DisplayName> of
   all downloaded app.
This commit is contained in:
Mr. Dragon
2019-03-24 00:37:57 +05:30
parent 9d90ae29c8
commit c12f7523df
4 changed files with 58 additions and 7 deletions

View File

@@ -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 <PackageName,DisplayName> to PseudoPackageMap
PackageUtil.addToPseudoPackageMap(context, app.getPackageName(), app.getDisplayName());
}
private FetchListener getFetchListener() {

View File

@@ -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);

View File

@@ -0,0 +1,46 @@
/*
* Aurora Store
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*
*/
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<String, String> pseudoMap = getPseudoPackageMap(context);
return TextUtil.emptyIfNull(pseudoMap.get(packageName));
}
public static Map<String, String> getPseudoPackageMap(Context context) {
return PrefUtil.getMap(context, PSEUDO_PACKAGE_MAP);
}
public static void addToPseudoPackageMap(Context context, String packageName, String displayName) {
Map<String, String> pseudoMap = getPseudoPackageMap(context);
pseudoMap.put(packageName, displayName);
PrefUtil.saveMap(context, pseudoMap, PSEUDO_PACKAGE_MAP);
}
}

View File

@@ -87,7 +87,7 @@ public class PrefUtil {
return Util.getPrefs(context.getApplicationContext()).getStringSet(key, new HashSet<>());
}
public static void saveMap(Context context, Map<String, Integer> map, String key) {
public static void saveMap(Context context, Map<String, String> 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<String, Integer> getMap(Context context, String key) {
Map<String, Integer> outputMap = new HashMap<>();
public static Map<String, String> getMap(Context context, String key) {
Map<String, String> outputMap = new HashMap<>();
SharedPreferences mPreferences = Util.getPrefs(context);
try {
if (mPreferences != null) {
@@ -109,7 +109,7 @@ public class PrefUtil {
Iterator<String> 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);
}
}