conversations-classic/src/de/gultsch/chat/services/XmppConnectionService.java

76 lines
2.3 KiB
Java
Raw Normal View History

2014-01-24 01:04:05 +00:00
package de.gultsch.chat.services;
import java.util.List;
import de.gultsch.chat.entities.Account;
import de.gultsch.chat.entities.Contact;
import de.gultsch.chat.entities.Conversation;
import de.gultsch.chat.entities.Message;
import de.gultsch.chat.persistance.DatabaseBackend;
2014-01-24 01:04:05 +00:00
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
2014-01-24 01:04:05 +00:00
public class XmppConnectionService extends Service {
protected static final String LOGTAG = "xmppConnection";
protected DatabaseBackend databaseBackend;
2014-01-24 01:04:05 +00:00
private final IBinder mBinder = new XmppConnectionBinder();
public class XmppConnectionBinder extends Binder {
public XmppConnectionService getService() {
return XmppConnectionService.this;
2014-01-24 01:04:05 +00:00
}
}
@Override
public void onCreate() {
databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
}
2014-01-24 01:04:05 +00:00
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public void sendMessage(Message message) {
databaseBackend.createMessage(message);
}
public void addConversation(Conversation conversation) {
databaseBackend.createConversation(conversation);
}
public List<Conversation> getConversations(int status) {
return databaseBackend.getConversations(status);
}
public List<Message> getMessages(Conversation conversation) {
return databaseBackend.getMessages(conversation, 100);
}
2014-01-24 01:04:05 +00:00
public Conversation findOrCreateConversation(Account account, Contact contact) {
Conversation conversation = databaseBackend.findConversation(account, contact);
if (conversation!=null) {
Log.d("gultsch","found one. unarchive it");
conversation.setStatus(Conversation.STATUS_AVAILABLE);
this.databaseBackend.updateConversation(conversation);
} else {
conversation = new Conversation(contact.getDisplayName(), contact.getProfilePhoto(), account, contact.getJid());
this.databaseBackend.createConversation(conversation);
}
return conversation;
}
public void updateConversation(Conversation conversation) {
this.databaseBackend.updateConversation(conversation);
}
public int getConversationCount() {
return this.databaseBackend.getConversationCount();
}
2014-01-24 01:04:05 +00:00
}