mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-13 18:41:14 +01:00
57 lines
1.9 KiB
Java
57 lines
1.9 KiB
Java
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.widget.Toast;
|
||
|
|
||
|
import java.util.Date;
|
||
|
import java.util.List;
|
||
|
|
||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||
|
|
||
|
public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySummary> {
|
||
|
public ActivitySummariesAdapter(Context context) {
|
||
|
super(context);
|
||
|
loadItems();
|
||
|
}
|
||
|
|
||
|
public void loadItems() {
|
||
|
try (DBHandler handler = GBApplication.acquireDB()) {
|
||
|
BaseActivitySummaryDao summaryDao = handler.getDaoSession().getBaseActivitySummaryDao();
|
||
|
List<BaseActivitySummary> allSummaries = summaryDao.loadAll();
|
||
|
setItems(allSummaries, true);
|
||
|
} catch (Exception e) {
|
||
|
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected String getName(BaseActivitySummary item) {
|
||
|
String name = item.getName();
|
||
|
if (name != null && name.length() > 0) {
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
Date startTime = item.getStartTime();
|
||
|
if (startTime != null) {
|
||
|
return DateTimeUtils.formatDateTime(startTime);
|
||
|
}
|
||
|
return "Unknown activity";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected String getDetails(BaseActivitySummary item) {
|
||
|
return ActivityKind.asString(item.getActivityKind(), getContext());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected int getIcon(BaseActivitySummary item) {
|
||
|
return ActivityKind.getIconId(item.getActivityKind());
|
||
|
}
|
||
|
}
|