1package de.gultsch.chat.entities;
2
3import android.content.ContentValues;
4import android.database.Cursor;
5import android.util.Log;
6
7public class Account extends AbstractEntity{
8
9 private static final long serialVersionUID = 6174825093869578035L;
10
11 public static final String TABLENAME = "accounts";
12
13 public static final String USERNAME = "username";
14 public static final String SERVER = "server";
15 public static final String PASSWORD = "password";
16 public static final String OPTIONS = "options";
17 public static final String ROSTERVERSION = "rosterversion";
18
19 public static final int OPTION_USETLS = 0;
20
21 protected String username;
22 protected String server;
23 protected String password;
24 protected int options;
25 protected String rosterVersion;
26
27 protected boolean online = false;
28
29 public Account() {
30 this.uuid = "0";
31 }
32
33 public Account(String username, String server, String password) {
34 this(java.util.UUID.randomUUID().toString(),username,server,password,0,null);
35 }
36 public Account(String uuid, String username, String server,String password, int options, String rosterVersion) {
37 this.uuid = uuid;
38 this.username = username;
39 this.server = server;
40 this.password = password;
41 this.options = options;
42 this.rosterVersion = rosterVersion;
43 }
44
45 public boolean isOptionSet(int option) {
46 return ((options & (1 << option)) != 0);
47 }
48
49 public String getUsername() {
50 return username;
51 }
52
53 public void setUsername(String username) {
54 this.username = username;
55 }
56
57 public String getServer() {
58 return server;
59 }
60
61 public void setServer(String server) {
62 this.server = server;
63 }
64
65 public String getPassword() {
66 return password;
67 }
68
69 public void setPassword(String password) {
70 this.password = password;
71 }
72
73 public boolean isOnline() {
74 return online;
75 }
76
77 public String getJid() {
78 return username+"@"+server;
79 }
80
81 @Override
82 public ContentValues getContentValues() {
83 ContentValues values = new ContentValues();
84 values.put(UUID,uuid);
85 values.put(USERNAME, username);
86 values.put(SERVER, server);
87 values.put(PASSWORD, password);
88 return values;
89 }
90
91 public static Account fromCursor(Cursor cursor) {
92 return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
93 cursor.getString(cursor.getColumnIndex(USERNAME)),
94 cursor.getString(cursor.getColumnIndex(SERVER)),
95 cursor.getString(cursor.getColumnIndex(PASSWORD)),
96 cursor.getInt(cursor.getColumnIndex(OPTIONS)),
97 cursor.getString(cursor.getColumnIndex(ROSTERVERSION))
98 );
99 }
100
101}