Fix formatting in SearchHistoryHelper
This commit is contained in:
parent
2fe7debf05
commit
7c6d09f5f2
1 changed files with 108 additions and 111 deletions
|
@ -18,15 +18,17 @@ import java.util.Map;
|
|||
public class SearchHistoryHelper {
|
||||
|
||||
private static final int HISTORY_LIMIT = 1500;
|
||||
|
||||
private OsmandApplication context;
|
||||
private List<HistoryEntry> loadedEntries = null;
|
||||
private Map<PointDescription, HistoryEntry> mp = new HashMap<PointDescription, SearchHistoryHelper.HistoryEntry>();
|
||||
private Map<PointDescription, HistoryEntry> mp = new HashMap<>();
|
||||
|
||||
public SearchHistoryHelper(OsmandApplication context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private static SearchHistoryHelper instance = null;
|
||||
|
||||
public static SearchHistoryHelper getInstance(OsmandApplication context) {
|
||||
if (instance == null) {
|
||||
instance = new SearchHistoryHelper(context);
|
||||
|
@ -34,7 +36,6 @@ public class SearchHistoryHelper {
|
|||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private static final int[] DEF_INTERVALS_MIN = new int[]{
|
||||
5, 60, 60 * 24, 5 * 60 * 24, 10 * 60 * 24, 30 * 60 * 24
|
||||
};
|
||||
|
@ -48,7 +49,7 @@ public class SearchHistoryHelper {
|
|||
double r = rhs.getRank(time);
|
||||
return -Double.compare(l, r);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class HistoryEntry {
|
||||
double lat;
|
||||
|
@ -58,7 +59,7 @@ public class SearchHistoryHelper {
|
|||
private int[] intervals = new int[0];
|
||||
private double[] intervalValues = new double[0];
|
||||
|
||||
public HistoryEntry(double lat, double lon, PointDescription name){
|
||||
HistoryEntry(double lat, double lon, PointDescription name) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.name = name;
|
||||
|
@ -100,6 +101,7 @@ public class SearchHistoryHelper {
|
|||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public double getLon() {
|
||||
return lon;
|
||||
}
|
||||
|
@ -116,7 +118,7 @@ public class SearchHistoryHelper {
|
|||
this.lastAccessedTime = time;
|
||||
}
|
||||
|
||||
public double getUsageLastTime(long time, int days, int hours, int minutes) {
|
||||
double getUsageLastTime(long time, int days, int hours, int minutes) {
|
||||
long mins = (minutes + (hours + 24 * days) * 60);
|
||||
long timeInPast = time - mins * 60 * 1000;
|
||||
if (this.lastAccessedTime <= timeInPast) {
|
||||
|
@ -193,7 +195,7 @@ public class SearchHistoryHelper {
|
|||
if (loadedEntries == null) {
|
||||
checkLoadedEntries();
|
||||
}
|
||||
return new ArrayList<SearchHistoryHelper.HistoryEntry>(loadedEntries);
|
||||
return new ArrayList<>(loadedEntries);
|
||||
}
|
||||
|
||||
private HistoryItemDBHelper checkLoadedEntries() {
|
||||
|
@ -224,7 +226,7 @@ public class SearchHistoryHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addNewItemToHistory(HistoryEntry model) {
|
||||
private void addNewItemToHistory(HistoryEntry model) {
|
||||
HistoryItemDBHelper helper = checkLoadedEntries();
|
||||
if (mp.containsKey(model.getName())) {
|
||||
model = mp.get(model.getName());
|
||||
|
@ -247,24 +249,24 @@ public class SearchHistoryHelper {
|
|||
|
||||
private class HistoryItemDBHelper {
|
||||
|
||||
private static final String DB_NAME = "search_history"; //$NON-NLS-1$
|
||||
private static final String DB_NAME = "search_history";
|
||||
private static final int DB_VERSION = 2;
|
||||
private static final String HISTORY_TABLE_NAME = "history_recents"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_NAME = "name"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_TIME = "time"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_FREQ_INTERVALS = "freq_intervals"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_FREQ_VALUES = "freq_values"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_LAT = "latitude"; //$NON-NLS-1$
|
||||
private static final String HISTORY_COL_LON = "longitude"; //$NON-NLS-1$
|
||||
private static final String HISTORY_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + HISTORY_TABLE_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final String HISTORY_TABLE_NAME = "history_recents";
|
||||
private static final String HISTORY_COL_NAME = "name";
|
||||
private static final String HISTORY_COL_TIME = "time";
|
||||
private static final String HISTORY_COL_FREQ_INTERVALS = "freq_intervals";
|
||||
private static final String HISTORY_COL_FREQ_VALUES = "freq_values";
|
||||
private static final String HISTORY_COL_LAT = "latitude";
|
||||
private static final String HISTORY_COL_LON = "longitude";
|
||||
private static final String HISTORY_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + HISTORY_TABLE_NAME + " (" +
|
||||
HISTORY_COL_NAME + " TEXT, " +
|
||||
HISTORY_COL_TIME + " long, " +
|
||||
HISTORY_COL_FREQ_INTERVALS + " TEXT, " +
|
||||
HISTORY_COL_FREQ_VALUES + " TEXT, " +
|
||||
HISTORY_COL_LAT + " double, " +HISTORY_COL_LON + " double);"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
HISTORY_COL_LAT + " double, " + HISTORY_COL_LON + " double);";
|
||||
|
||||
|
||||
public HistoryItemDBHelper() {
|
||||
HistoryItemDBHelper() {
|
||||
}
|
||||
|
||||
private SQLiteConnection openConnection(boolean readonly) {
|
||||
|
@ -280,7 +282,6 @@ public class SearchHistoryHelper {
|
|||
onUpgrade(conn, conn.getVersion(), DB_VERSION);
|
||||
}
|
||||
conn.setVersion(DB_VERSION);
|
||||
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
@ -313,14 +314,14 @@ public class SearchHistoryHelper {
|
|||
|
||||
private void removeQuery(String name, SQLiteConnection db) {
|
||||
db.execSQL("DELETE FROM " + HISTORY_TABLE_NAME + " WHERE " + HISTORY_COL_NAME + " = ?",
|
||||
new Object[] { name }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
new Object[]{name});
|
||||
}
|
||||
|
||||
public boolean removeAll() {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
db.execSQL("DELETE FROM " + HISTORY_TABLE_NAME); //$NON-NLS-1$
|
||||
db.execSQL("DELETE FROM " + HISTORY_TABLE_NAME);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -339,7 +340,7 @@ public class SearchHistoryHelper {
|
|||
", " + HISTORY_COL_FREQ_VALUES + "= ? WHERE " +
|
||||
HISTORY_COL_NAME + " = ?",
|
||||
new Object[]{e.getLastAccessTime(), e.getIntervals(), e.getIntervalsValues(),
|
||||
e.getSerializedName() }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
e.getSerializedName()});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -365,15 +366,15 @@ public class SearchHistoryHelper {
|
|||
db.execSQL(
|
||||
"INSERT INTO " + HISTORY_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{e.getSerializedName(), e.getLastAccessTime(),
|
||||
e.getIntervals(), e.getIntervalsValues(), e.getLat(), e.getLon() }); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
e.getIntervals(), e.getIntervalsValues(), e.getLat(), e.getLon()});
|
||||
}
|
||||
|
||||
public List<HistoryEntry> getLegacyEntries(SQLiteConnection db){
|
||||
List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
|
||||
List<HistoryEntry> getLegacyEntries(SQLiteConnection db) {
|
||||
List<HistoryEntry> entries = new ArrayList<>();
|
||||
if (db != null) {
|
||||
// LEGACY QUERY !!
|
||||
SQLiteCursor query = db.rawQuery(
|
||||
"SELECT name, latitude, longitude, time FROM history ORDER BY time DESC", null); //$NON-NLS-1$//$NON-NLS-2$
|
||||
"SELECT name, latitude, longitude, time FROM history ORDER BY time DESC", null);
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String name = query.getString(0);
|
||||
|
@ -409,15 +410,15 @@ public class SearchHistoryHelper {
|
|||
}
|
||||
|
||||
public List<HistoryEntry> getEntries() {
|
||||
List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
|
||||
List<HistoryEntry> entries = new ArrayList<>();
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(
|
||||
"SELECT " + HISTORY_COL_NAME + ", " + HISTORY_COL_LAT + "," + HISTORY_COL_LON + ", " +
|
||||
HISTORY_COL_TIME + ", " + HISTORY_COL_FREQ_INTERVALS + ", " + HISTORY_COL_FREQ_VALUES +
|
||||
" FROM " + HISTORY_TABLE_NAME , null); //$NON-NLS-1$//$NON-NLS-2$
|
||||
Map<PointDescription, HistoryEntry> st = new HashMap<PointDescription, HistoryEntry>();
|
||||
" FROM " + HISTORY_TABLE_NAME, null);
|
||||
Map<PointDescription, HistoryEntry> st = new HashMap<>();
|
||||
if (query != null && query.moveToFirst()) {
|
||||
boolean reinsert = false;
|
||||
do {
|
||||
|
@ -436,7 +437,7 @@ public class SearchHistoryHelper {
|
|||
} while (query.moveToNext());
|
||||
if (reinsert) {
|
||||
System.err.println("Reinsert all values for search history");
|
||||
db.execSQL("DELETE FROM " + HISTORY_TABLE_NAME); //$NON-NLS-1$
|
||||
db.execSQL("DELETE FROM " + HISTORY_TABLE_NAME);
|
||||
entries.clear();
|
||||
entries.addAll(st.values());
|
||||
for (HistoryEntry he : entries) {
|
||||
|
@ -461,8 +462,4 @@ public class SearchHistoryHelper {
|
|||
addNewItemToHistory(new HistoryEntry(latitude, longitude, pointDescription));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue