Merge branch 'development' of https://github.com/siacs/Conversations into development

This commit is contained in:
kruks23 2014-05-19 21:42:23 +02:00
commit a5a356a7a7
3 changed files with 30 additions and 41 deletions

View File

@ -1,6 +1,5 @@
package eu.siacs.conversations.entities;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
@ -11,9 +10,7 @@ import eu.siacs.conversations.xml.Element;
import android.content.ContentValues;
import android.database.Cursor;
public class Contact extends AbstractEntity implements Serializable {
private static final long serialVersionUID = -4570817093119419962L;
public class Contact {
public static final String TABLENAME = "contacts";
public static final String SYSTEMNAME = "systemname";
@ -39,10 +36,9 @@ public class Contact extends AbstractEntity implements Serializable {
protected boolean inRoster = true;
public Contact(String uuid, String account, String systemName,
public Contact(String account, String systemName,
String serverName, String jid, int subscription, String photoUri,
String systemAccount, String keys) {
this.uuid = uuid;
this.accountUuid = account;
this.systemName = systemName;
this.serverName = serverName;
@ -87,10 +83,8 @@ public class Contact extends AbstractEntity implements Serializable {
.toLowerCase().contains(needle.toLowerCase())));
}
@Override
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
values.put(UUID, uuid);
values.put(ACCOUNT, accountUuid);
values.put(SYSTEMNAME, systemName);
values.put(SERVERNAME, serverName);
@ -103,8 +97,7 @@ public class Contact extends AbstractEntity implements Serializable {
}
public static Contact fromCursor(Cursor cursor) {
return new Contact(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(ACCOUNT)),
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
cursor.getString(cursor.getColumnIndex(JID)),
@ -131,10 +124,6 @@ public class Contact extends AbstractEntity implements Serializable {
return this.account;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public boolean couldBeMuc() {
String[] split = this.getJid().split("@");
if (split.length != 2) {

View File

@ -2,21 +2,17 @@ package eu.siacs.conversations.persistance;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.entities.Roster;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.util.Log;
public class DatabaseBackend extends SQLiteOpenHelper {
@ -27,16 +23,16 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 5;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.UUID + " TEXT PRIMARY KEY, "
+ Contact.ACCOUNT + " TEXT, " + Contact.SERVERNAME + " TEXT, "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " + Contact.SERVERNAME + " TEXT, "
+ Contact.SYSTEMNAME + " TEXT," + Contact.JID + " TEXT,"
+ Contact.KEYS + " TEXT," + Contact.PHOTOURI + " TEXT,"
+ Contact.OPTIONS + " NUMBER," + Contact.SYSTEMACCOUNT
+ " NUMBER, " + "FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES "
+ Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE);";
+ Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE, UNIQUE("+Contact.ACCOUNT+", "+Contact.JID+") ON CONFLICT REPLACE);";
public DatabaseBackend(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Log.d("xmppService",CREATE_CONTATCS_STATEMENT);
}
@Override
@ -220,7 +216,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public void writeRoster(Roster roster) {
Account account = roster.getAccount();
SQLiteDatabase db = this.getWritableDatabase();
for(Contact contact : roster.getContacts()) {
if (contact.getOption(Contact.Options.IN_ROSTER)) {
db.insert(Contact.TABLENAME, null, contact.getContentValues());
} else {
String where = Contact.ACCOUNT + "=? AND "+Contact.JID+"=?";
String[] whereArgs = {account.getUuid(), contact.getJid()};
db.delete(Contact.TABLENAME, where, whereArgs);
}
}
account.setRosterVersion(roster.getVersion());
updateAccount(account);
}
public void deleteMessage(Message message) {
@ -235,24 +243,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.delete(Message.TABLENAME, Message.CONVERSATION + "=?", args);
}
public void deleteContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = { contact.getUuid() };
db.delete(Contact.TABLENAME, Contact.UUID + "=?", args);
}
public Contact getContact(String uuid) {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = { uuid };
Cursor cursor = db.query(Contact.TABLENAME, null, Contact.UUID + "=?",
args, null, null, null);
if (cursor.getCount() == 0) {
return null;
}
cursor.moveToFirst();
return Contact.fromCursor(cursor);
}
public Conversation findConversationByUuid(String conversationUuid) {
SQLiteDatabase db = this.getReadableDatabase();
String[] selectionArgs = { conversationUuid };

View File

@ -616,14 +616,24 @@ public class XmppConnectionService extends Service {
@Override
public void onDestroy() {
Log.d(LOGTAG, "stopping service");
super.onDestroy();
this.logoutAndSave();
}
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
this.logoutAndSave();
}
private void logoutAndSave() {
for (Account account : accounts) {
databaseBackend.writeRoster(account.getRoster());
if (account.getXmppConnection() != null) {
disconnect(account, true);
}
}
Log.d(LOGTAG,"good bye");
}
protected void scheduleWakeupCall(int seconds, boolean ping) {