diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/SettingsProvider.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/SettingsProvider.java index 07b7252..abfb599 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/SettingsProvider.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/SettingsProvider.java @@ -1,6 +1,7 @@ package com.veticia.piLauncherNext; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -62,6 +63,8 @@ public static synchronized SettingsProvider getInstance (Context context) private Set mSelectedGroups = new HashSet<>(); private Map mRecents = new HashMap<>(); Set def = new HashSet<>(); + public static final Map launchIntents = new HashMap<>(); + public static final Map installDates = new HashMap<>(); private SettingsProvider(Context context) { mPreferences = context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_PRIVATE); @@ -94,7 +97,6 @@ public void updateRecent(String packageName, Long timestamp) { } public ArrayList getInstalledApps(Context context, List selected, boolean first) { - // Get list of installed apps Map apps = getAppList(); ArrayList installedApplications = new ArrayList<>(); @@ -107,7 +109,6 @@ public ArrayList getInstalledApps(Context context, List } installedApplications.addAll(vrApps); } - if (isPlatformEnabled(KEY_PLATFORM_ANDROID)) { List androidApps = new AndroidPlatform().getInstalledApps(context); for (ApplicationInfo app : androidApps) { @@ -117,7 +118,6 @@ public ArrayList getInstalledApps(Context context, List } installedApplications.addAll(androidApps); } - if (isPlatformEnabled(KEY_PLATFORM_PSP)) { // only add PSP apps if the platform is supported List pspApps = new PSPPlatform().getInstalledApps(context); @@ -128,7 +128,6 @@ public ArrayList getInstalledApps(Context context, List } installedApplications.addAll(pspApps); } - // Save changes to app list setAppList(mAppList); diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AbstractPlatform.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AbstractPlatform.java index a4d58f5..281301a 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AbstractPlatform.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AbstractPlatform.java @@ -199,7 +199,7 @@ public static boolean isOculusHeadset() { public static boolean isPicoHeadset() { String vendor = Build.MANUFACTURER.toUpperCase(); - return vendor.replace("İ","I").startsWith("PICO"); + return vendor.startsWith("PICO") || vendor.startsWith("PİCO"); } protected static boolean isVirtualRealityApp(ApplicationInfo app) { diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AndroidPlatform.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AndroidPlatform.java index 5d6bcfb..d461b5f 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AndroidPlatform.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/AndroidPlatform.java @@ -7,27 +7,35 @@ import android.content.pm.PackageManager; import android.util.Log; +import com.veticia.piLauncherNext.SettingsProvider; + import java.util.ArrayList; public class AndroidPlatform extends AbstractPlatform { public ArrayList getInstalledApps(Context context) { + ArrayList installedApps = new ArrayList<>(); PackageManager pm = context.getPackageManager(); - ArrayList output = new ArrayList<>(); for (ApplicationInfo app : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { - Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(app.packageName); - if (!isVirtualRealityApp(app) && launchIntent != null) { - try { - PackageInfo packageInfo = pm.getPackageInfo(app.packageName, 0); - long installDate = packageInfo.firstInstallTime; - app.taskAffinity = Long.toString(installDate); + if (!isVirtualRealityApp(app)) { + if (!SettingsProvider.launchIntents.containsKey(app.packageName)) { + SettingsProvider.launchIntents.put(app.packageName, pm.getLaunchIntentForPackage(app.packageName)); } - catch (PackageManager.NameNotFoundException e) { - app.taskAffinity = "0"; + if(SettingsProvider.launchIntents.get(app.packageName) != null) { + if(!SettingsProvider.installDates.containsKey(app.packageName)) { + long installDate; + try { + PackageInfo packageInfo = pm.getPackageInfo(app.packageName, 0); + installDate = packageInfo.firstInstallTime; + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException(e); + } + SettingsProvider.installDates.put(app.packageName, installDate); + } + installedApps.add(app); } - output.add(app); } } - return output; + return installedApps; } @Override diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/PSPPlatform.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/PSPPlatform.java index 010a508..ef52d00 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/PSPPlatform.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/PSPPlatform.java @@ -10,6 +10,7 @@ import android.widget.ImageView; import com.veticia.piLauncherNext.MainActivity; +import com.veticia.piLauncherNext.SettingsProvider; import net.didion.loopy.iso9660.ISO9660FileEntry; import net.didion.loopy.iso9660.ISO9660FileSystem; @@ -38,12 +39,11 @@ public ArrayList getInstalledApps(Context context) { ApplicationInfo app = new ApplicationInfo(); app.name = path.substring(path.lastIndexOf('/') + 1); app.packageName = PACKAGE_PREFIX + path; - File file = new File(path); - long lastModDate = file.lastModified(); - app.taskAffinity = Long.toString(lastModDate); + if(!SettingsProvider.installDates.containsKey(app.packageName)) { + File file = new File(path); + SettingsProvider.installDates.put(app.packageName, file.lastModified()); + } output.add(app); - //debug - //Log.e("PSPmDate", app.name + " @ " + app.taskAffinity); } return output; } diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/VRPlatform.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/VRPlatform.java index 3a087e7..6a04bd7 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/VRPlatform.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/platforms/VRPlatform.java @@ -7,6 +7,8 @@ import android.content.pm.PackageManager; import android.util.Log; +import com.veticia.piLauncherNext.SettingsProvider; + import java.util.ArrayList; public class VRPlatform extends AbstractPlatform { @@ -15,20 +17,25 @@ public ArrayList getInstalledApps(Context context) { if (!isSupported()) { return installedApps; } - PackageManager pm = context.getPackageManager(); for (ApplicationInfo app : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { - Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(app.packageName); - if (isVirtualRealityApp(app) && launchIntent != null) { - try { - PackageInfo packageInfo = pm.getPackageInfo(app.packageName, 0); - long installDate = packageInfo.firstInstallTime; - app.taskAffinity = Long.toString(installDate); + if (isVirtualRealityApp(app)) { + if (!SettingsProvider.launchIntents.containsKey(app.packageName)) { + SettingsProvider.launchIntents.put(app.packageName, pm.getLaunchIntentForPackage(app.packageName)); } - catch (PackageManager.NameNotFoundException e) { - app.taskAffinity = "0"; + if(SettingsProvider.launchIntents.get(app.packageName) != null) { + if(!SettingsProvider.installDates.containsKey(app.packageName)) { + long installDate; + try { + PackageInfo packageInfo = pm.getPackageInfo(app.packageName, 0); + installDate = packageInfo.firstInstallTime; + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException(e); + } + SettingsProvider.installDates.put(app.packageName, installDate); + } + installedApps.add(app); } - installedApps.add(app); } } return installedApps; diff --git a/Launcher/App/src/main/java/com/veticia/piLauncherNext/ui/AppsAdapter.java b/Launcher/App/src/main/java/com/veticia/piLauncherNext/ui/AppsAdapter.java index 667810e..78aeb07 100644 --- a/Launcher/App/src/main/java/com/veticia/piLauncherNext/ui/AppsAdapter.java +++ b/Launcher/App/src/main/java/com/veticia/piLauncherNext/ui/AppsAdapter.java @@ -248,21 +248,12 @@ public void onImageSelected(String path, ImageView selectedImageView) { this.notifyDataSetChanged(); // for real time updates } - @SuppressWarnings("RedundantVariableInitializer") private Long getInstallDate(ApplicationInfo applicationInfo) { - String installDateString; - long installDateLong = 0L; - if (applicationInfo.taskAffinity != null) { - installDateString = applicationInfo.taskAffinity; - } else { - installDateString = "0"; - } - try { - installDateLong = Long.parseLong(installDateString); - } catch (NumberFormatException e) { - // result 0 is already defined by default + if(SettingsProvider.installDates.containsKey(applicationInfo.packageName)) { + return SettingsProvider.installDates.get(applicationInfo.packageName); + }else{ + return 0L; } - return installDateLong; } public void sort(SORT_FIELD field, SORT_ORDER order) {