Add limitation for wikivoyage search history size
This commit is contained in:
parent
9ef3f5144b
commit
9480d571a0
1 changed files with 20 additions and 0 deletions
|
@ -15,6 +15,8 @@ import gnu.trove.map.hash.TLongObjectHashMap;
|
|||
|
||||
public class WikivoyageLocalDataHelper {
|
||||
|
||||
private static final int HISTORY_ITEMS_LIMIT = 300;
|
||||
|
||||
private static WikivoyageLocalDataHelper instance;
|
||||
|
||||
private WikivoyageLocalDataDbHelper dbHelper;
|
||||
|
@ -70,6 +72,12 @@ public class WikivoyageLocalDataHelper {
|
|||
} else {
|
||||
dbHelper.updateHistoryItem(item);
|
||||
}
|
||||
if (historyMap.size() > HISTORY_ITEMS_LIMIT) {
|
||||
List<WikivoyageSearchHistoryItem> allHistory = getAllHistory();
|
||||
WikivoyageSearchHistoryItem lastItem = allHistory.get(allHistory.size() - 1);
|
||||
dbHelper.removeHistoryItem(lastItem);
|
||||
historyMap.remove(lastItem.cityId);
|
||||
}
|
||||
}
|
||||
|
||||
private static class WikivoyageLocalDataDbHelper {
|
||||
|
@ -183,6 +191,18 @@ public class WikivoyageLocalDataHelper {
|
|||
}
|
||||
}
|
||||
|
||||
void removeHistoryItem(WikivoyageSearchHistoryItem item) {
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME + " WHERE " + HISTORY_COL_CITY_ID + " = ?",
|
||||
new Object[]{item.cityId});
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private WikivoyageSearchHistoryItem readHistoryItem(SQLiteCursor cursor) {
|
||||
WikivoyageSearchHistoryItem res = new WikivoyageSearchHistoryItem();
|
||||
|
||||
|
|
Loading…
Reference in a new issue