Search in sources :

Example 1 with BaseActivitySummaryDao

use of nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao in project Gadgetbridge by Freeyourgadget.

the class ActivitySummariesAdapter method loadItems.

@Override
public void loadItems() {
    try (DBHandler handler = GBApplication.acquireDB()) {
        BaseActivitySummaryDao summaryDao = handler.getDaoSession().getBaseActivitySummaryDao();
        Device dbDevice = DBHelper.findDevice(device, handler.getDaoSession());
        QueryBuilder<BaseActivitySummary> qb = summaryDao.queryBuilder();
        if (deviceFilter == ALL_DEVICES) {
            qb.orderDesc(BaseActivitySummaryDao.Properties.StartTime);
        } else if (deviceFilter != 0) {
            qb.where(BaseActivitySummaryDao.Properties.DeviceId.eq(deviceFilter)).orderDesc(BaseActivitySummaryDao.Properties.StartTime);
        } else {
            qb.where(BaseActivitySummaryDao.Properties.DeviceId.eq(dbDevice.getId())).orderDesc(BaseActivitySummaryDao.Properties.StartTime);
        }
        if (activityKindFilter != 0) {
            qb.where(BaseActivitySummaryDao.Properties.ActivityKind.eq(activityKindFilter));
        }
        if (dateFromFilter != 0) {
            qb.where(BaseActivitySummaryDao.Properties.StartTime.gt(new Date(dateFromFilter)));
        }
        if (dateToFilter != 0) {
            qb.where(BaseActivitySummaryDao.Properties.EndTime.lt(new Date(dateToFilter)));
        }
        if (nameContainsFilter != null && nameContainsFilter.length() > 0) {
            qb.where(BaseActivitySummaryDao.Properties.Name.like("%" + nameContainsFilter + "%"));
        }
        if (itemsFilter != null) {
            qb.where(BaseActivitySummaryDao.Properties.Id.in(itemsFilter));
        }
        List<BaseActivitySummary> allSummaries = new ArrayList<>();
        allSummaries.add(new BaseActivitySummary());
        allSummaries.addAll(qb.build().list());
        setItems(allSummaries, true);
    } catch (Exception e) {
        GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) BaseActivitySummaryDao(nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) ArrayList(java.util.ArrayList) BaseActivitySummary(nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary) Date(java.util.Date) JSONException(org.json.JSONException)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)1 BaseActivitySummary (nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary)1 BaseActivitySummaryDao (nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1 JSONException (org.json.JSONException)1