fix loading profiles
This commit is contained in:
parent
815336c686
commit
32ce8af144
1 changed files with 28 additions and 7 deletions
|
@ -1602,15 +1602,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
queryBuilder.limit(100L);
|
queryBuilder.limit(100L);
|
||||||
Where where = queryBuilder.where();
|
Where where = queryBuilder.where();
|
||||||
where.ge("date", from);
|
where.ge("date", from);
|
||||||
queryBuilder.setCountOf(true);
|
|
||||||
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
|
||||||
long count = daoProfileSwitch.countOf(preparedQuery);
|
|
||||||
// now do query of count + 1
|
|
||||||
queryBuilder = daoProfileSwitch.queryBuilder();
|
|
||||||
queryBuilder.orderBy("date", ascending);
|
|
||||||
queryBuilder.limit(count + 1);
|
|
||||||
preparedQuery = queryBuilder.prepare();
|
|
||||||
profileSwitches = daoProfileSwitch.query(preparedQuery);
|
profileSwitches = daoProfileSwitch.query(preparedQuery);
|
||||||
|
//add last one without duration
|
||||||
|
ProfileSwitch last = getLastProfileSwitchWithoutDuration();
|
||||||
|
if (last != null) {
|
||||||
|
if (!profileSwitches.contains(last))
|
||||||
|
profileSwitches.add(last);
|
||||||
|
}
|
||||||
return profileSwitches;
|
return profileSwitches;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -1618,6 +1617,28 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private ProfileSwitch getLastProfileSwitchWithoutDuration() {
|
||||||
|
try {
|
||||||
|
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();
|
||||||
|
List<ProfileSwitch> profileSwitches;
|
||||||
|
QueryBuilder<ProfileSwitch, Long> queryBuilder = daoProfileSwitch.queryBuilder();
|
||||||
|
queryBuilder.orderBy("date", false);
|
||||||
|
queryBuilder.limit(1L);
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("durationInMinutes", 0);
|
||||||
|
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
|
||||||
|
profileSwitches = daoProfileSwitch.query(preparedQuery);
|
||||||
|
if (profileSwitches.size() > 0)
|
||||||
|
return profileSwitches.get(0);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ProfileSwitch> getProfileSwitchEventsFromTime(long mills, boolean ascending) {
|
public List<ProfileSwitch> getProfileSwitchEventsFromTime(long mills, boolean ascending) {
|
||||||
try {
|
try {
|
||||||
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();
|
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();
|
||||||
|
|
Loading…
Reference in a new issue