[tuxdroid-svn] r5712 - software_suite_v3/software/plugin/plugin-facebook/branches/october_release/s
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-10-16 09:35:37
|
Author: jerome Date: 2009-10-16 11:35:26 +0200 (Fri, 16 Oct 2009) New Revision: 5712 Added: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java Log: * Added an object to store session history. Added: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java (rev 0) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/FacebookDatasStruct.java 2009-10-16 09:35:26 UTC (rev 5712) @@ -0,0 +1,285 @@ +/* This file is part of "TuxDroid Gadget Facebook". + * Copyright 2009, kysoh + * Author : Conan Jerome. + * eMail : jer...@ky... + * Site : http://www.kysoh.com/ + * + * "TuxDroid Gadget Facebook" is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * "TuxDroid Gadget Facebook" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with "TuxDroid Gadget Facebook"; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Vector; + +public class FacebookDatasStruct extends Object implements Serializable{ + + private static final long serialVersionUID = 8395814134877723556L; + + public static final byte FRIENDS_QUERIES = 0; + public static final byte GROUP_INVITES = 1; + public static final byte EVENT_INVITE = 2; + public static final byte MESSAGES = 3; + public static final byte POKES = 4; + + public SerializedVector vktStruct; + private File structFile; + private boolean firstCycle; + + + + + public FacebookDatasStruct(String username) + { + //tds = tuxdroid datas saved. + + File path = new File(""); + structFile = new File( path.getAbsolutePath() + File.separator + username + "@facebook.sav"); + + if(structFile.exists()) + { + //Getting serialized object struct. + this.firstCycle = false; + vktStruct = this.loadStruct(); + } + else + { + this.firstCycle = true; + //Create struct. + vktStruct = new SerializedVector(); + if(vktStruct == null) + { + vktStruct = new SerializedVector(); + } + } + } + + + /** + * Regiter the structure. + */ + public void registerStruct() + { + if(this.vktStruct.size() <= 0) + { + return; + } + + try + { + FileOutputStream file = new FileOutputStream(this.structFile); + ObjectOutputStream oos = new ObjectOutputStream(file); + oos.writeObject(this.vktStruct); + oos.flush(); + oos.close(); + } + catch (java.io.IOException e) + { + e.printStackTrace(); + } + } + + + + /** + * Load the twitterDatasStruct object. + */ + private SerializedVector loadStruct() + { + try + { + FileInputStream fichier = new FileInputStream(this.structFile); + ObjectInputStream ois = new ObjectInputStream(fichier); + return (SerializedVector) ois.readObject(); + } + catch (java.io.IOException e) + { + e.printStackTrace(); + } + catch (ClassNotFoundException e) + { + e.printStackTrace(); + } + return null; + } + + + /** + * Add a message to the message hashtable. + */ + public void addMessage(String uuid) + { + this.vktStruct.addMessage(uuid); + } + + + /** + * Add a reply to the reply hashtable. + */ + public void addEventInvite(String uuid) + { + this.vktStruct.addEventInvite(uuid); + } + + + /** + * Add a status for selected friend. + */ + public void addFriendRequest(String uuid) + { + this.vktStruct.addFriendQuery(uuid); + } + + /** + * Add a reply to the reply hashtable. + */ + public void addPoke(String uuid) + { + this.vktStruct.addPoke(uuid); + } + + + /** + * Add a status for selected friend. + */ + public void addGroupInvite(String uuid) + { + this.vktStruct.addGroupInvite(uuid); + } + + + + /** + * This function return the state of cycle ( first start or not for the current user ). + * @return + */ + public boolean isFirstCycle() + { + return this.firstCycle; + } + + /** + * Return true if the target is registered. + * @param uuid. + * @return + */ + public boolean isRegistered(byte list, String uuid) + { + + switch(list) + { + case FacebookDatasStruct.FRIENDS_QUERIES: + return vktStruct.FID.contains(uuid); + + case FacebookDatasStruct.MESSAGES: + return vktStruct.MES.contains(uuid); + + case FacebookDatasStruct.GROUP_INVITES: + return vktStruct.GID.contains(uuid); + + case FacebookDatasStruct.EVENT_INVITE: + return vktStruct.EID.contains(uuid); + + case FacebookDatasStruct.POKES: + return vktStruct.POK.contains(uuid); + + default: + return false; + } + } + + + + + /** + * Handle a serialized vector of vector<String> + */ + class SerializedVector extends Vector<Object> implements Serializable{ + + private static final long serialVersionUID = 7018170438526763010L; + + private Vector<String> GID = new Vector<String>(); + private Vector<String> FID = new Vector<String>(); + private Vector<String> POK = new Vector<String>(); + private Vector<String> EID = new Vector<String>(); + private Vector<String> MES = new Vector<String>(); + + public SerializedVector() + { + super(); + } + + /** + * Add a new message in the object. + */ + public void addMessage(String uuid) + { + if (! MES.contains(uuid)) + { + MES.add(uuid); + } + } + + + /** + * Add a new event invite in the object. + */ + public void addEventInvite(String uuid) + { + if (! EID.contains(uuid)) + { + EID.add(uuid); + } + } + + + /** + * Add a new user request in the object. + */ + public void addFriendQuery(String uuid) + { + if (! FID.contains(uuid)) + { + FID.add(uuid); + } + } + + /** + * Add a new user status in the object. + */ + public void addGroupInvite(String uuid) + { + if (! GID.contains(uuid)) + { + GID.add(uuid); + } + } + + /** + * Add a new poke notification in the object. + */ + public void addPoke(String uuid) + { + if (! POK.contains(uuid)) + { + POK.add(uuid); + } + } + } +} |