|
@@ -53,16 +53,18 @@ public class DataHelper {
|
53
|
53
|
public static final String JOURNEYSTEPS_TABLE = "journeysteps";
|
54
|
54
|
|
55
|
55
|
private static final String DATABASE_NAME = "contextapi.db";
|
56
|
|
- private static final int DATABASE_VERSION = 5;
|
|
56
|
+ private static final int DATABASE_VERSION = 6;
|
57
|
57
|
|
58
|
58
|
private static final String INSERT_LOCATION = "insert into "
|
59
|
59
|
+ LOCATIONS_TABLE + "(name, lat, lon) values (?, ?, ?)";
|
60
|
60
|
private static final String INSERT_JOURNEY = "insert into "
|
61
|
|
- + JOURNEYS_TABLE + "(start, end, steps) values (?, ?, ?)";
|
|
61
|
+ + JOURNEYS_TABLE + "(start, end, steps, number) values (?, ?, ?, 1)";
|
62
|
62
|
private static final String INSERT_JOURNEYSTEP = "insert into "
|
63
|
63
|
+ JOURNEYSTEPS_TABLE + "(activity, repetitions, journey, next) values (?, ?, ?, ?)";
|
64
|
64
|
private static final String UPDATE_LOCATION = "update "
|
65
|
65
|
+ LOCATIONS_TABLE + " set name = ? where _id = ?";
|
|
66
|
+ private static final String UPDATE_JOURNEY = "update "
|
|
67
|
+ + JOURNEYS_TABLE + " set number = number + 1 WHERE _id = ?";
|
66
|
68
|
private static final String UNNAMED_QUERY = "name LIKE '%.%,%.%'";
|
67
|
69
|
private static final String LOCATION_QUERY = "lat > %1$s - 0.005 and "
|
68
|
70
|
+ "lat < %1$s + 0.005 and lon > %2$s - 0.01 and lon < %2$s + 0.01";
|
|
@@ -71,7 +73,8 @@ public class DataHelper {
|
71
|
73
|
private static final String JOURNEY_BOTH_QUERY = JOURNEY_START_QUERY + " AND end = %1$s";
|
72
|
74
|
|
73
|
75
|
private final SQLiteStatement insertLocationStatement, insertJourneyStatement,
|
74
|
|
- insertJourneyStepStatement, updateLocationStatement;
|
|
76
|
+ insertJourneyStepStatement, updateLocationStatement,
|
|
77
|
+ updateJourneyStatement;
|
75
|
78
|
|
76
|
79
|
private SQLiteDatabase db;
|
77
|
80
|
|
|
@@ -82,6 +85,7 @@ public class DataHelper {
|
82
|
85
|
this.updateLocationStatement = db.compileStatement(UPDATE_LOCATION);
|
83
|
86
|
this.insertJourneyStatement = db.compileStatement(INSERT_JOURNEY);
|
84
|
87
|
this.insertJourneyStepStatement = db.compileStatement(INSERT_JOURNEYSTEP);
|
|
88
|
+ this.updateJourneyStatement = db.compileStatement(UPDATE_JOURNEY);
|
85
|
89
|
}
|
86
|
90
|
|
87
|
91
|
public SQLiteDatabase getDatabase() {
|
|
@@ -137,13 +141,13 @@ public class DataHelper {
|
137
|
141
|
}
|
138
|
142
|
|
139
|
143
|
final Cursor cursor = db.query(JOURNEYS_TABLE,
|
140
|
|
- new String[] { "_id", "start", "end", "steps" },
|
|
144
|
+ new String[] { "_id", "start", "end", "steps", "number" },
|
141
|
145
|
query, null, null, null, null);
|
142
|
146
|
|
143
|
147
|
if (cursor.moveToFirst()) {
|
144
|
148
|
do {
|
145
|
149
|
results.add(new Journey(cursor.getLong(0), cursor.getLong(1),
|
146
|
|
- cursor.getLong(2), cursor.getInt(3)));
|
|
150
|
+ cursor.getLong(2), cursor.getInt(3), cursor.getInt(4)));
|
147
|
151
|
} while (cursor.moveToNext());
|
148
|
152
|
}
|
149
|
153
|
|
|
@@ -161,7 +165,8 @@ public class DataHelper {
|
161
|
165
|
final List<JourneyStep> theirSteps = getSteps(journey);
|
162
|
166
|
|
163
|
167
|
if (theirSteps.equals(steps)) {
|
164
|
|
- // TODO: Increment journey count/time/etc
|
|
168
|
+ updateJourneyStatement.bindLong(1, journey.getId());
|
|
169
|
+ updateJourneyStatement.execute();
|
165
|
170
|
return;
|
166
|
171
|
}
|
167
|
172
|
}
|
|
@@ -299,7 +304,7 @@ public class DataHelper {
|
299
|
304
|
if (oldVersion <= 2) {
|
300
|
305
|
db.execSQL("DROP TABLE " + LOCATIONS_TABLE);
|
301
|
306
|
onCreate(db);
|
302
|
|
- } else if (oldVersion <= 5) {
|
|
307
|
+ } else if (oldVersion <= 6) {
|
303
|
308
|
db.execSQL("DROP TABLE " + LOCATIONS_TABLE);
|
304
|
309
|
db.execSQL("DROP TABLE " + JOURNEYS_TABLE);
|
305
|
310
|
db.execSQL("DROP TABLE " + JOURNEYSTEPS_TABLE);
|