diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index ec811229b..baabf5d19 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -40,6 +40,7 @@ import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -313,10 +314,23 @@ public class GBApplication extends Application { return NotificationManager.INTERRUPTION_FILTER_ALL; } - public static HashSet blacklist = null; + private static HashSet blacklist = null; + + public static boolean isBlacklisted(String packageName) { + return blacklist != null && blacklist.contains(packageName); + } + + public static void setBlackList(Set packageNames) { + if (packageNames == null) { + blacklist = new HashSet<>(); + } else { + blacklist = new HashSet<>(packageNames); + } + saveBlackList(); + } private static void loadBlackList() { - blacklist = (HashSet) sharedPrefs.getStringSet("package_blacklist", null); + blacklist = (HashSet) sharedPrefs.getStringSet(GBPrefs.PACKAGE_BLACKLIST, null); if (blacklist == null) { blacklist = new HashSet<>(); } @@ -325,16 +339,15 @@ public class GBApplication extends Application { private static void saveBlackList() { SharedPreferences.Editor editor = sharedPrefs.edit(); if (blacklist.isEmpty()) { - editor.putStringSet("package_blacklist", null); + editor.putStringSet(GBPrefs.PACKAGE_BLACKLIST, null); } else { - editor.putStringSet("package_blacklist", blacklist); + editor.putStringSet(GBPrefs.PACKAGE_BLACKLIST, blacklist); } editor.apply(); } public static void addToBlacklist(String packageName) { - if (!blacklist.contains(packageName)) { - blacklist.add(packageName); + if (blacklist.add(packageName)) { saveBlackList(); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java index cb975442a..fb49fee73 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java @@ -21,7 +21,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v4.content.LocalBroadcastManager; @@ -33,8 +32,6 @@ import android.view.MenuItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.IdentityHashMap; - import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.AppBlacklistAdapter; @@ -55,8 +52,6 @@ public class AppBlacklistActivity extends GBActivity { } }; - private IdentityHashMap nameMap; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java index b2b2a3c12..a99ae6284 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java @@ -40,13 +40,13 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter(applicationInfoList.size()); + mNameMap = new IdentityHashMap<>(applicationInfoList.size()); for (ApplicationInfo ai : applicationInfoList) { CharSequence name = mPm.getApplicationLabel(ai); if (name == null) { name = ai.packageName; } - if (GBApplication.blacklist.contains(ai.packageName)) { + if (GBApplication.isBlacklisted(ai.packageName)) { // sort blacklisted first by prefixing with a '!' name = "!" + name; } @@ -78,7 +78,7 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter blacklist = new HashSet<>(); text=text.replace("[","").replace("]",""); for (int z=0;z