package treehou.se.habit.core.db.model.controller; import io.realm.Realm; import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; import treehou.se.habit.core.db.model.ItemDB; public class ColorCellDB extends RealmObject { @PrimaryKey private long id = 0; private String icon; private CellDB cell; private String command; private ItemDB item; public long getId() { return id; } public void setId(long id) { this.id = id; } public ItemDB getItem() { return item; } public void setItem(ItemDB item) { this.item = item; } public String getIcon() { return icon; } public void setIcon(String iconOn) { this.icon = iconOn; } public CellDB getCell() { return cell; } public void setCell(CellDB cell) { this.cell = cell; } public String getCommand() { return command; } public void setCommand(String command) { this.command = command; } public static void save(Realm realm, ColorCellDB item){ realm.beginTransaction(); if(item.getId() <= 0) { item.setId(getUniqueId(realm)); } realm.copyToRealmOrUpdate(item); realm.commitTransaction(); } public static ColorCellDB getCell(Realm realm, CellDB cell){ return realm.where(ColorCellDB.class).equalTo("cell.id", cell.getId()).findFirst(); } public static long getUniqueId(Realm realm) { Number num = realm.where(ChartCellDB.class).max("id"); long newId = 1; if (num != null) newId = num.longValue() + 1; return newId; } }