package com.uip.EasyDialer.dbo;
import java.util.ArrayList;
import java.util.List;
import com.uip.EasyDialer.PageLayout;
import com.uip.EasyDialer.dba.DbAdapter;
public class Page {
public long key;
public String page_name;
public int sort_id;
public boolean isDefault;
public List<Contact> contacts = new ArrayList<Contact>();
public boolean isLoaded = false;
public boolean isDirty = true;
public PageLayout layout;
public Page(long key, String page_name, int sort_id, boolean isDefault) {
this.key = key;
this.page_name = page_name;
this.sort_id = sort_id;
this.isDefault = isDefault;
}
public void LoadContacts(DbAdapter db) {
contacts = db.contacts.GetByPage((int)key);
isLoaded = true;
}
public int GetNewId() {
int newId = 0;
if (contacts.size() > 0) {
newId = contacts.get(contacts.size()-1).id + 1;
}
return newId;
}
public boolean IsContainsNumber(String number){
for (Contact c : contacts) {
if (c.Number.compareTo(number) == 0)
return true;
}
return false;
}
public void Save(DbAdapter db) {
if (key == 0) {
key = sort_id;
db.pages.Create(key, page_name, sort_id, isDefault);
}
else db.pages.Update(key, page_name, sort_id, isDefault);
}
public void Delete(DbAdapter db) {
if (contacts != null) {
db.contacts.DeleteByPageId((int)key);
}
db.pages.Delete(key);
}
public void invalidate() {
isDirty = true;
}
}
|