Fix potential crash search history

This commit is contained in:
Victor Shcherb 2017-04-25 10:18:24 +02:00
parent 8919740cf9
commit 6667051460

View file

@ -39,7 +39,7 @@ public class SearchHistoryHelper {
5, 60, 60 * 24, 5 * 60 * 24, 10 * 60 * 24, 30 * 60 * 24 5, 60, 60 * 24, 5 * 60 * 24, 10 * 60 * 24, 30 * 60 * 24
}; };
private static Comparator<HistoryEntry> historyEntryComparator = new Comparator<HistoryEntry>() { private static class HistoryEntryComparator implements Comparator<HistoryEntry> {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@Override @Override
@ -200,7 +200,7 @@ public class SearchHistoryHelper {
HistoryItemDBHelper helper = new HistoryItemDBHelper(); HistoryItemDBHelper helper = new HistoryItemDBHelper();
if (loadedEntries == null) { if (loadedEntries == null) {
loadedEntries = helper.getEntries(); loadedEntries = helper.getEntries();
Collections.sort(loadedEntries, historyEntryComparator); Collections.sort(loadedEntries, new HistoryEntryComparator());
for(HistoryEntry he : loadedEntries) { for(HistoryEntry he : loadedEntries) {
mp.put(he.getName(), he); mp.put(he.getName(), he);
} }
@ -236,7 +236,7 @@ public class SearchHistoryHelper {
model.markAsAccessed(System.currentTimeMillis()); model.markAsAccessed(System.currentTimeMillis());
helper.add(model); helper.add(model);
} }
Collections.sort(loadedEntries, historyEntryComparator); Collections.sort(loadedEntries, new HistoryEntryComparator());
if(loadedEntries.size() > HISTORY_LIMIT){ if(loadedEntries.size() > HISTORY_LIMIT){
if(helper.remove(loadedEntries.get(loadedEntries.size() - 1))){ if(helper.remove(loadedEntries.get(loadedEntries.size() - 1))){
loadedEntries.remove(loadedEntries.size() - 1); loadedEntries.remove(loadedEntries.size() - 1);