final List<AccessPoint> accessPoints =
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
- preferenceScreen.removeAll();
+ cacheRemoveAllPrefs(preferenceScreen);
final int accessPointsSize = accessPoints.size();
- for (int i = 0; i < accessPointsSize; ++i){
+ for (int i = 0; i < accessPointsSize; ++i) {
+ AccessPoint ap = accessPoints.get(i);
+ String key = AccessPointPreference.generatePreferenceKey(ap);
LongPressAccessPointPreference preference =
- new LongPressAccessPointPreference(accessPoints.get(i), context,
- mUserBadgeCache, true, this);
- preference.setIcon(null);
- preferenceScreen.addPreference(preference);
+ (LongPressAccessPointPreference) getCachedPreference(key);
+ if (preference == null) {
+ preference = new LongPressAccessPointPreference(
+ ap, context, mUserBadgeCache, true, this);
+ preference.setKey(key);
+ preference.setIcon(null);
+ preferenceScreen.addPreference(preference);
+ }
}
+ removeCachedPrefs(preferenceScreen);
+
if(getPreferenceScreen().getPreferenceCount() < 1) {
Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");
}
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
-import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
AccessPoint accessPoint = accessPoints.get(index);
// Ignore access points that are out of range.
if (accessPoint.isReachable()) {
- String key = generateKey(accessPoint);
+ String key = AccessPointPreference.generatePreferenceKey(accessPoint);
hasAvailableAccessPoints = true;
LongPressAccessPointPreference pref =
(LongPressAccessPointPreference) getCachedPreference(key);
}
}
- private String generateKey(AccessPoint accessPoint) {
- StringBuilder key = new StringBuilder();
- String bssid = accessPoint.getBssid();
- if (TextUtils.isEmpty(bssid)) {
- key.append(accessPoint.getSsidStr());
- } else {
- key.append(bssid);
- }
- key.append(',').append(accessPoint.getSecurity());
- return key.toString();
- }
-
@NonNull
private LongPressAccessPointPreference createLongPressActionPointPreference(
AccessPoint accessPoint) {