MyContact.java :  » UnTagged » hide-my-secret » com » ld » secret » dom » Android Open Source

Android Open Source » UnTagged » hide my secret 
hide my secret » com » ld » secret » dom » MyContact.java
package com.ld.secret.dom;

import java.util.List;
import android.content.ContentResolver;
import android.database.sqlite.SQLiteConstraintException;
import android.util.Log;

import com.ld.secret.db.MyContactCache;
import com.ld.secret.dom.MyData;
import com.ld.secret.dom.contact.*;
import com.ld.secret.ui.utils.Global;


public class MyContact extends MyData{// This class contain all info of 1 user (UserInfo, ImInfo, Org, etc)
  private UserInfo userInfo;
  private List<PhoneInfo> listPhone;
  private List<EmailInfo> listEmail;
  private List<PostalAddressInfo> listPA;
  private List<OrganizationInfo> listOrg;
  private List<ImInfo> listIm;
  private List<WebsiteInfo> listWeb;
  private ContactAccessor mContactAccessor = ContactAccessor.getInstance();
  public MyContact(UserInfo userInfo, List<PhoneInfo> listPhone, List<EmailInfo> listEmail,
      List<PostalAddressInfo> listPA, List<OrganizationInfo> listOrg, List<ImInfo> listIm,
      List<WebsiteInfo> listWeb){
    this.userInfo = userInfo;
    this.listPhone = listPhone;
    this.listEmail = listEmail;
    this.listPA = listPA;
    this.listOrg = listOrg;
    this.listIm = listIm;
    this.listWeb = listWeb;
    
  }
  public MyContact(){};
  public UserInfo getUserInfo(){
    return this.userInfo;
  }
  public List<PhoneInfo> getListPhone(){
    return this.listPhone;
  }
  public List<EmailInfo> getListEmail(){
    return this.listEmail;
  }
  public List<PostalAddressInfo> getListPA(){
    return this.listPA;
  }
  public List<OrganizationInfo> getListOrg(){
    return this.listOrg;
  }
  public List<ImInfo> getListIm(){
    return this.listIm;
  }
  public List<WebsiteInfo> getListWeb(){
    return this.listWeb;
  }
  @Override
  public void hide() {
    ContentResolver cr = Global.cr;
    UserInfo user = mContactAccessor.loadUserInfos(cr, id);
    List<PhoneInfo> phone = mContactAccessor.loadUserPhones(cr, id);
    List<EmailInfo> email = mContactAccessor.loadUserEmails(cr, id);
    List<OrganizationInfo> org = mContactAccessor.loadUserOrg(cr, id);
    List<ImInfo> im = mContactAccessor.loadUserIm(cr, id);
    List<PostalAddressInfo> pa = mContactAccessor.loadUserPA(cr, id);
    List<WebsiteInfo> web = mContactAccessor.loadUserWebsite(cr, id);
    MyContact myContact = new MyContact(user, phone, email, pa, org, im, web);
    Log.d("My Contact", id+"");
    // insert into secret DB
    try{
      MyContactCache cache = MyContactCache.getInstance(Global.db);
      cache.insertContactToCache(myContact);
    }catch(SQLiteConstraintException ex){
      ex.printStackTrace();
    }
    // delete user has id in android
    mContactAccessor.deleteUser(cr, user.getUserId());
    Log.d("delete user", "success");
  }
  @Override
  public void restore() {
    ContentResolver cr = Global.cr;
    MyContactCache cache = MyContactCache.getInstance(Global.db);
    MyContact myContact = cache.getContactById(id);
    
    // insert into Android
    //TODO (vanloi999) doi voi ham insert nay, hok the kiem soat dc id cua user trong qua trinh restore==> id cua user
    // vua moi duoc restore se khac voi id cua user trong db, do do ta se xoa user vua moi duoc restore trong secret DB
    mContactAccessor.insertAllInfoOfOneUser
    (cr, myContact.getUserInfo(), myContact.getListPhone(), myContact.getListEmail(),
        myContact.getListPA(), myContact.getListOrg(), myContact.getListIm(), myContact.getListWeb());
    Log.d("Restore", myContact.getUserInfo().getUserName());
    // vay thi danh sach de hien thi cho chuong trinh se dc lay tu db thu 2 (secret2 ???)
    Log.d("MYCONTACT: ID RESTORE", id+"");
    cache.deleteUser(id);
  }
}
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.