FM: Scanned frequencies are saved in ascending ordering
Change-Id: Ie426ec3fa4aa3e8f4136938eb35f419ecc0aa71a
diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index b29f779..fd48210 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -243,6 +243,9 @@
private ScrollerText mRadioTextScroller = null;
private ScrollerText mERadioTextScroller = null;
+ /* Scanning frequencies */
+ ArrayList<Integer> mScannedFrequencies;
+
private PresetStation mTunedStation = new PresetStation("", 102100);
private PresetStation mPresetButtonStation = null;
@@ -1995,6 +1998,23 @@
}
}
+ private void saveStations() {
+ if (mScannedFrequencies != null && mScannedFrequencies.size() > 0) {
+ Collections.sort(mScannedFrequencies);
+ SharedPreferences sp = getSharedPreferences(SCAN_STATION_PREFS_NAME, 0);
+ SharedPreferences.Editor editor = sp.edit();
+
+ int index = 0;
+ for (Integer freq : mScannedFrequencies) {
+ index++;
+ editor.putString(STATION_NAME + index, index + "");
+ editor.putInt(STATION_FREQUENCY + index, freq);
+ }
+ editor.putInt(NUM_OF_STATIONS, index);
+ editor.commit();
+ }
+ }
+
private void setupPresetLayout() {
int numStations = FmSharedPreferences.getListStationCount();
int addedStations = 0;
@@ -2602,6 +2622,7 @@
updateSearchProgress();
resetFMStationInfoUI();
invalidateOptionsMenu();
+ saveStations();
}
};
@@ -3014,15 +3035,11 @@
Log.d(LOGTAG, "mServiceCallbacks.onTuneStatusChanged: ");
if (mIsScaning) {
Log.d(LOGTAG, "isScanning....................");
- SharedPreferences sp = getSharedPreferences(SCAN_STATION_PREFS_NAME, 0);
- SharedPreferences.Editor editor = sp.edit();
- int station_number = sp.getInt(NUM_OF_STATIONS, 0);
- station_number++;
- editor.putInt(NUM_OF_STATIONS, station_number);
- editor.putString(STATION_NAME + station_number, station_number + "");
- editor.putInt(STATION_FREQUENCY + station_number,
- FmSharedPreferences.getTunedFrequency());
- editor.commit();
+ if (mScannedFrequencies == null) {
+ mScannedFrequencies = new ArrayList<Integer>();
+ }
+
+ mScannedFrequencies.add(FmSharedPreferences.getTunedFrequency());
}
cleanupTimeoutHandler();
mHandler.post(mUpdateStationInfo);