Page.java :  » UnTagged » easy-dialer » com » uip » EasyDialer » dbo » Android Open Source

Android Open Source » UnTagged » easy dialer 
easy dialer » com » uip » EasyDialer » dbo » Page.java
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;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.