all access to the persistance layer is now done via the new xmppservice
This commit is contained in:
parent
df9dcb1060
commit
665ef7511f
|
@ -15,6 +15,7 @@
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@android:style/Theme.Holo.Light" >
|
android:theme="@android:style/Theme.Holo.Light" >
|
||||||
|
<service android:name="de.gultsch.chat.services.XmppConnectionService"/>
|
||||||
<activity
|
<activity
|
||||||
android:name="de.gultsch.chat.ui.ConversationActivity"
|
android:name="de.gultsch.chat.ui.ConversationActivity"
|
||||||
android:label="Secure Conversations"
|
android:label="Secure Conversations"
|
||||||
|
|
|
@ -74,6 +74,7 @@ public final class R {
|
||||||
}
|
}
|
||||||
public static final class menu {
|
public static final class menu {
|
||||||
public static final int conversations=0x7f090000;
|
public static final int conversations=0x7f090000;
|
||||||
|
public static final int newconversation=0x7f090001;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int action_accounts=0x7f070003;
|
public static final int action_accounts=0x7f070003;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_accounts"
|
||||||
|
android:orderInCategory="90"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/action_accounts"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/action_settings"/>
|
||||||
|
</menu>
|
|
@ -1,97 +0,0 @@
|
||||||
package de.gultsch.chat;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import de.gultsch.chat.entities.Conversation;
|
|
||||||
import de.gultsch.chat.entities.Message;
|
|
||||||
|
|
||||||
|
|
||||||
import android.database.AbstractCursor;
|
|
||||||
|
|
||||||
public class ConversationCursor extends AbstractCursor {
|
|
||||||
|
|
||||||
|
|
||||||
protected ConversationList conversations;
|
|
||||||
|
|
||||||
public static final String NAME = "conversationname";
|
|
||||||
public static final String LAST_MSG = "lastmsg";
|
|
||||||
public static final String DATE = "date";
|
|
||||||
public static final String ID = "_id";
|
|
||||||
|
|
||||||
public ConversationCursor(ConversationList list) {
|
|
||||||
super();
|
|
||||||
this.conversations = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Conversation> getConversationOverview() {
|
|
||||||
return this.conversations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConversationOverview(ConversationList list) {
|
|
||||||
this.conversations = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getColumnNames() {
|
|
||||||
return new String[]{ID,NAME,LAST_MSG,DATE};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return conversations.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getDouble(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getFloat(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInt(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLong(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public short getShort(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getString(int column) {
|
|
||||||
Conversation conversation = conversations.get(getPosition());
|
|
||||||
Message lastMessage = conversation.getLastMessages(1,0).get(0);
|
|
||||||
switch (column) {
|
|
||||||
case 1:
|
|
||||||
return conversation.getName();
|
|
||||||
case 2:
|
|
||||||
return lastMessage.toString();
|
|
||||||
case 3:
|
|
||||||
return lastMessage.getTimeReadable();
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNull(int column) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package de.gultsch.chat;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
import de.gultsch.chat.entities.Conversation;
|
|
||||||
|
|
||||||
public class ConversationList extends ArrayList<Conversation> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3661496589984289968L;
|
|
||||||
|
|
||||||
private int selectedConversationPosition = -1;
|
|
||||||
|
|
||||||
private ConversationCursor cursor = new ConversationCursor(this);
|
|
||||||
|
|
||||||
public ConversationCursor getCursor() {
|
|
||||||
return this.cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Conversation getSelectedConversation() {
|
|
||||||
return this.get(this.selectedConversationPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedConversationPosition(int selectedConversation) {
|
|
||||||
this.selectedConversationPosition = selectedConversation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized int addAndReturnPosition(Conversation conversation) {
|
|
||||||
this.add(conversation);
|
|
||||||
return size() - 1;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
|
||||||
|
public abstract class AbstractEntity implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1895605706690653719L;
|
||||||
|
|
||||||
|
public static final String UUID = "uuid";
|
||||||
|
|
||||||
|
protected String uuid;
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract ContentValues getContentValues();
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,18 @@
|
||||||
package de.gultsch.chat.entities;
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
public class Account {
|
import android.content.ContentValues;
|
||||||
|
|
||||||
private String uuid;
|
public class Account extends AbstractEntity{
|
||||||
|
|
||||||
public String getUuid() {
|
private static final long serialVersionUID = 6174825093869578035L;
|
||||||
return this.uuid;
|
|
||||||
|
public Account() {
|
||||||
|
this.uuid = "";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ContentValues getContentValues() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +1,64 @@
|
||||||
package de.gultsch.chat.entities;
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
public class Conversation implements Serializable {
|
public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6727528868973996739L;
|
private static final long serialVersionUID = -6727528868973996739L;
|
||||||
public static final int STATUS_AVAILABLE = 0;
|
public static final int STATUS_AVAILABLE = 0;
|
||||||
public static final int STATUS_ARCHIVED = 1;
|
public static final int STATUS_ARCHIVED = 1;
|
||||||
public static final int STATUS_DELETED = 2;
|
public static final int STATUS_DELETED = 2;
|
||||||
private String uuid;
|
|
||||||
|
public static final String NAME = "name";
|
||||||
|
public static final String PHOTO_URI = "profilePhotoUri";
|
||||||
|
public static final String ACCOUNT = "accountUuid";
|
||||||
|
public static final String CONTACT = "contactJid";
|
||||||
|
public static final String STATUS = "status";
|
||||||
|
public static final String CREATED = "created";
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String profilePhotoUri;
|
private String profilePhotoUri;
|
||||||
private String accountUuid;
|
private String accountUuid;
|
||||||
private String contactJid;
|
private String contactJid;
|
||||||
private int status;
|
private int status;
|
||||||
|
private long created;
|
||||||
|
|
||||||
// legacy. to be removed
|
private transient List<Message> messages;
|
||||||
private ArrayList<Message> msgs = new ArrayList<Message>();
|
|
||||||
|
|
||||||
public Conversation(String name, Uri profilePhoto, Account account,
|
public Conversation(String name, Uri profilePhoto, Account account,
|
||||||
String contactJid) {
|
String contactJid) {
|
||||||
this(UUID.randomUUID().toString(), name, profilePhoto.toString(),
|
this(java.util.UUID.randomUUID().toString(), name, profilePhoto
|
||||||
account.getUuid(), contactJid, STATUS_AVAILABLE);
|
.toString(), account.getUuid(), contactJid, System
|
||||||
|
.currentTimeMillis(), STATUS_AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conversation(String uuid, String name, String profilePhoto,
|
public Conversation(String uuid, String name, String profilePhoto,
|
||||||
String accountUuid, String contactJid, int status) {
|
String accountUuid, String contactJid, long created, int status) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.profilePhotoUri = profilePhoto;
|
this.profilePhotoUri = profilePhoto;
|
||||||
this.accountUuid = accountUuid;
|
this.accountUuid = accountUuid;
|
||||||
this.contactJid = contactJid;
|
this.contactJid = contactJid;
|
||||||
|
this.created = created;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Message> getLastMessages(int count, int offset) {
|
public List<Message> getMessages() {
|
||||||
msgs.add(new Message("this is my last message"));
|
return messages;
|
||||||
return msgs;
|
}
|
||||||
|
|
||||||
|
public void setMessages(List<Message> msgs) {
|
||||||
|
this.messages = msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
|
||||||
return this.uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProfilePhotoString() {
|
public String getProfilePhotoString() {
|
||||||
return this.profilePhotoUri;
|
return this.profilePhotoUri;
|
||||||
}
|
}
|
||||||
|
@ -78,22 +84,23 @@ public class Conversation implements Serializable {
|
||||||
|
|
||||||
public ContentValues getContentValues() {
|
public ContentValues getContentValues() {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put("uuid", this.uuid);
|
values.put(UUID, uuid);
|
||||||
values.put("name", this.name);
|
values.put(NAME, name);
|
||||||
values.put("profilePhotoUri", this.profilePhotoUri);
|
values.put(PHOTO_URI, profilePhotoUri);
|
||||||
values.put("accountUuid", this.accountUuid);
|
values.put(ACCOUNT, accountUuid);
|
||||||
values.put("contactJid", this.contactJid);
|
values.put(CONTACT, contactJid);
|
||||||
values.put("status", this.status);
|
values.put(CREATED, created);
|
||||||
|
values.put(STATUS, status);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Conversation fromCursor(Cursor cursor) {
|
public static Conversation fromCursor(Cursor cursor) {
|
||||||
return new Conversation(
|
return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
|
||||||
cursor.getString(cursor.getColumnIndex("uuid")),
|
cursor.getString(cursor.getColumnIndex(NAME)),
|
||||||
cursor.getString(cursor.getColumnIndex("name")),
|
cursor.getString(cursor.getColumnIndex(PHOTO_URI)),
|
||||||
cursor.getString(cursor.getColumnIndex("profilePhotoUri")),
|
cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
||||||
cursor.getString(cursor.getColumnIndex("accountUuid")),
|
cursor.getString(cursor.getColumnIndex(CONTACT)),
|
||||||
cursor.getString(cursor.getColumnIndex("contactJid")),
|
cursor.getLong(cursor.getColumnIndex(CREATED)),
|
||||||
cursor.getInt(cursor.getColumnIndex("status")));
|
cursor.getInt(cursor.getColumnIndex(STATUS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,98 @@
|
||||||
package de.gultsch.chat.entities;
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
public class Message {
|
import android.content.ContentValues;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
String msg;
|
public class Message extends AbstractEntity {
|
||||||
|
|
||||||
public Message(String msg) {
|
private static final long serialVersionUID = 7222081895167103025L;
|
||||||
this.msg = msg;
|
|
||||||
}
|
public static final int STATUS_RECIEVED = 0;
|
||||||
|
public static final int STATUS_UNSEND = 1;
|
||||||
public String toString() {
|
public static final int STATUS_SEND = 2;
|
||||||
return msg;
|
|
||||||
|
public static final int ENCRYPTION_NONE = 0;
|
||||||
|
public static final int ENCRYPTION_PGP = 1;
|
||||||
|
public static final int ENCRYPTION_OTR = 2;
|
||||||
|
|
||||||
|
public static String CONVERSATION = "conversationUuid";
|
||||||
|
public static String COUNTERPART = "counterpart";
|
||||||
|
public static String BODY = "body";
|
||||||
|
public static String TIME_SENT = "timeSent";
|
||||||
|
public static String ENCRYPTION = "encryption";
|
||||||
|
public static String STATUS = "status";
|
||||||
|
|
||||||
|
protected String conversationUuid;
|
||||||
|
protected String counterpart;
|
||||||
|
protected String body;
|
||||||
|
protected long timeSent;
|
||||||
|
protected int encryption;
|
||||||
|
protected int status;
|
||||||
|
|
||||||
|
protected transient Conversation conversation = null;
|
||||||
|
|
||||||
|
public Message(Conversation conversation, String body, int encryption) {
|
||||||
|
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
||||||
|
conversation.getContactJid(), body, 0, encryption,
|
||||||
|
Message.STATUS_UNSEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimeReadable() {
|
public Message(String uuid, String conversationUUid, String counterpart,
|
||||||
return "2 min";
|
String body, long timeSent, int encryption, int status) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.conversationUuid = conversationUUid;
|
||||||
|
this.counterpart = counterpart;
|
||||||
|
this.body = body;
|
||||||
|
this.timeSent = timeSent;
|
||||||
|
this.encryption = encryption;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentValues getContentValues() {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(UUID, this.uuid);
|
||||||
|
values.put(CONVERSATION, conversationUuid);
|
||||||
|
values.put(COUNTERPART, counterpart);
|
||||||
|
values.put(BODY, body);
|
||||||
|
values.put(TIME_SENT, timeSent);
|
||||||
|
values.put(ENCRYPTION, encryption);
|
||||||
|
values.put(STATUS, status);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConversationUuid() {
|
||||||
|
return conversationUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCounterpart() {
|
||||||
|
return counterpart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimeSent() {
|
||||||
|
return timeSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEncryption() {
|
||||||
|
return encryption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Message fromCursor(Cursor cursor) {
|
||||||
|
return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(COUNTERPART)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(BODY)),
|
||||||
|
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(STATUS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class DatabaseBackend extends SQLiteOpenHelper {
|
public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
db.execSQL("create table conversations (uuid TEXT, name TEXT, profilePhotoUri TEXT, accountUuid TEXT, contactJid TEXT)");
|
db.execSQL("create table conversations (uuid TEXT, name TEXT, profilePhotoUri TEXT, accountUuid TEXT, contactJid TEXT, created NUMBER, status NUMBER)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +33,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static synchronized DatabaseBackend getInstance(Context context) {
|
public static synchronized DatabaseBackend getInstance(Context context) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new DatabaseBackend(context.getApplicationContext());
|
instance = new DatabaseBackend(context);
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -56,10 +55,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
List<Conversation> list = new ArrayList<Conversation>();
|
List<Conversation> list = new ArrayList<Conversation>();
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
String[] selectionArgs = {""+status};
|
String[] selectionArgs = {""+status};
|
||||||
Cursor cursor = db.rawQuery("select * from conversations where status = ?", selectionArgs);
|
Cursor cursor = db.rawQuery("select * from conversations where status = ? order by created desc", selectionArgs);
|
||||||
Log.d("gultsch","getConversations has found "+cursor.getCount()+" rows");
|
|
||||||
while(cursor.moveToNext()) {
|
while(cursor.moveToNext()) {
|
||||||
Log.d("gultsch","converting row #"+cursor.getPosition());
|
|
||||||
list.add(Conversation.fromCursor(cursor));
|
list.add(Conversation.fromCursor(cursor));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -1,29 +1,49 @@
|
||||||
package de.gultsch.chat.services;
|
package de.gultsch.chat.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
|
import de.gultsch.chat.entities.Message;
|
||||||
|
import de.gultsch.chat.persistance.DatabaseBackend;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class XmppConnectionService extends Service {
|
public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
|
protected static final String LOGTAG = "xmppConnection";
|
||||||
|
protected DatabaseBackend databaseBackend;
|
||||||
|
|
||||||
// Binder given to clients
|
|
||||||
private final IBinder mBinder = new XmppConnectionBinder();
|
private final IBinder mBinder = new XmppConnectionBinder();
|
||||||
|
|
||||||
/**
|
|
||||||
* Class used for the client Binder. Because we know this service always
|
|
||||||
* runs in the same process as its clients, we don't need to deal with IPC.
|
|
||||||
*/
|
|
||||||
public class XmppConnectionBinder extends Binder {
|
public class XmppConnectionBinder extends Binder {
|
||||||
XmppConnectionService getService() {
|
public XmppConnectionService getService() {
|
||||||
// Return this instance of LocalService so clients can call public methods
|
return XmppConnectionService.this;
|
||||||
return XmppConnectionService.this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessage(Message message) {
|
||||||
|
Log.d(LOGTAG,"sending message");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConversation(Conversation conversation) {
|
||||||
|
databaseBackend.addConversation(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Conversation> getConversations(int status) {
|
||||||
|
return databaseBackend.getConversations(status);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package de.gultsch.chat.ui;
|
package de.gultsch.chat.ui;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.gultsch.chat.ConversationCursor;
|
|
||||||
import de.gultsch.chat.ConversationList;
|
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
import de.gultsch.chat.R.id;
|
import de.gultsch.chat.R.id;
|
||||||
import de.gultsch.chat.entities.Account;
|
import de.gultsch.chat.entities.Account;
|
||||||
import de.gultsch.chat.entities.Contact;
|
import de.gultsch.chat.entities.Contact;
|
||||||
import de.gultsch.chat.entities.Conversation;
|
import de.gultsch.chat.entities.Conversation;
|
||||||
import de.gultsch.chat.persistance.DatabaseBackend;
|
import de.gultsch.chat.persistance.DatabaseBackend;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.FragmentManager;
|
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -35,59 +30,52 @@ import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
public class ConversationActivity extends Activity {
|
public class ConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
public static final String START_CONVERSATION = "startconversation";
|
public static final String VIEW_CONVERSATION = "viewConversation";
|
||||||
public static final String CONVERSATION_CONTACT = "conversationcontact";
|
private static final String LOGTAG = "secureconversation";
|
||||||
|
protected static final String CONVERSATION = "conversationUuid";
|
||||||
|
|
||||||
protected SlidingPaneLayout spl;
|
protected SlidingPaneLayout spl;
|
||||||
|
|
||||||
protected HashMap<Conversation, ConversationFragment> conversationFragments = new HashMap<Conversation, ConversationFragment>();
|
final List<Conversation> conversationList = new ArrayList<Conversation>();
|
||||||
private DatabaseBackend dbb;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
dbb = DatabaseBackend.getInstance(this);
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
final List<Conversation> conversationList = dbb.getConversations(Conversation.STATUS_AVAILABLE);
|
|
||||||
|
|
||||||
if (getIntent().getAction().equals(Intent.ACTION_MAIN)) {
|
|
||||||
if (conversationList.size() < 0) {
|
|
||||||
Log.d("gultsch",
|
|
||||||
"no conversations detected. redirect to new conversation activity");
|
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(R.layout.fragment_conversations_overview);
|
setContentView(R.layout.fragment_conversations_overview);
|
||||||
|
|
||||||
final ListView listView = (ListView) findViewById(R.id.list);
|
final ListView listView = (ListView) findViewById(R.id.list);
|
||||||
|
|
||||||
listView.setAdapter(new ArrayAdapter<Conversation>(this, R.layout.conversation_list_row, conversationList) {
|
listView.setAdapter(new ArrayAdapter<Conversation>(this,
|
||||||
|
R.layout.conversation_list_row, conversationList) {
|
||||||
@Override
|
@Override
|
||||||
public View getView (int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
view = (View) inflater.inflate(R.layout.conversation_list_row,null);
|
view = (View) inflater.inflate(
|
||||||
((TextView) view.findViewById(R.id.conversation_name)).setText(getItem(position).getName());
|
R.layout.conversation_list_row, null);
|
||||||
((ImageView) view.findViewById(R.id.conversation_image)).setImageURI(getItem(position).getProfilePhotoUri());
|
|
||||||
}
|
}
|
||||||
|
((TextView) view.findViewById(R.id.conversation_name))
|
||||||
|
.setText(getItem(position).getName());
|
||||||
|
((ImageView) view.findViewById(R.id.conversation_image))
|
||||||
|
.setImageURI(getItem(position).getProfilePhotoUri());
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> arg0, View clickedView,
|
public void onItemClick(AdapterView<?> arg0, View clickedView,
|
||||||
int position, long arg3) {
|
int position, long arg3) {
|
||||||
|
Log.d(LOGTAG, "List view was klicked on position " + position);
|
||||||
swapConversationFragment(conversationList.get(position));
|
swapConversationFragment(conversationList.get(position));
|
||||||
getActionBar().setTitle(conversationList.get(position).getName());
|
getActionBar().setTitle(
|
||||||
|
conversationList.get(position).getName());
|
||||||
spl.closePane();
|
spl.closePane();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -121,8 +109,14 @@ public class ConversationActivity extends Activity {
|
||||||
public void onPanelClosed(View arg0) {
|
public void onPanelClosed(View arg0) {
|
||||||
if (conversationList.size() > 0) {
|
if (conversationList.size() > 0) {
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
ConversationFragment convFrag = (ConversationFragment) getFragmentManager().findFragmentById(R.id.selected_conversation);
|
ConversationFragment convFrag = (ConversationFragment) getFragmentManager()
|
||||||
getActionBar().setTitle(convFrag.getConversation().getName());
|
.findFragmentById(R.id.selected_conversation);
|
||||||
|
if (convFrag == null) {
|
||||||
|
Log.d(LOGTAG, "conversation fragment was not found.");
|
||||||
|
return; // just do nothing. at least dont crash
|
||||||
|
}
|
||||||
|
getActionBar().setTitle(
|
||||||
|
convFrag.getConversation().getName());
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,36 +127,6 @@ public class ConversationActivity extends Activity {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
|
|
||||||
if (getIntent().getType().equals(
|
|
||||||
ConversationActivity.START_CONVERSATION)) {
|
|
||||||
Contact contact = (Contact) getIntent().getExtras().get(
|
|
||||||
ConversationActivity.CONVERSATION_CONTACT);
|
|
||||||
Log.d("gultsch",
|
|
||||||
"start conversation with " + contact.getDisplayName());
|
|
||||||
|
|
||||||
// start new conversation
|
|
||||||
Conversation conversation = new Conversation(
|
|
||||||
contact.getDisplayName(), contact.getProfilePhoto(),
|
|
||||||
new Account(), contact.getJid());
|
|
||||||
|
|
||||||
//@TODO don't write to database here; always go through service
|
|
||||||
dbb.addConversation(conversation);
|
|
||||||
conversationList.add(0, conversation);
|
|
||||||
swapConversationFragment(conversationList.get(0));
|
|
||||||
spl.closePane();
|
|
||||||
|
|
||||||
// why do i even need this
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
getActionBar().setTitle(conversationList.get(0).getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// normal startup
|
|
||||||
if (conversationList.size() >= 1) {
|
|
||||||
swapConversationFragment(conversationList.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,7 +159,8 @@ public class ConversationActivity extends Activity {
|
||||||
case R.id.action_add:
|
case R.id.action_add:
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
case R.id.action_archive:
|
case R.id.action_archive:
|
||||||
|
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -203,14 +168,9 @@ public class ConversationActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void swapConversationFragment(Conversation conv) {
|
protected void swapConversationFragment(Conversation conv) {
|
||||||
ConversationFragment selectedFragment;
|
Log.d(LOGTAG, "swap conversation fragment to " + conv.getName());
|
||||||
if (conversationFragments.containsKey(conv)) {
|
ConversationFragment selectedFragment = new ConversationFragment();
|
||||||
selectedFragment = conversationFragments.get(conv);
|
selectedFragment.setConversation(conv);
|
||||||
} else {
|
|
||||||
selectedFragment = new ConversationFragment();
|
|
||||||
selectedFragment.setConversation(conv);
|
|
||||||
conversationFragments.put(conv,selectedFragment);
|
|
||||||
}
|
|
||||||
FragmentTransaction transaction = getFragmentManager()
|
FragmentTransaction transaction = getFragmentManager()
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
transaction.replace(R.id.selected_conversation, selectedFragment);
|
transaction.replace(R.id.selected_conversation, selectedFragment);
|
||||||
|
@ -228,4 +188,45 @@ public class ConversationActivity extends Activity {
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (xmppConnectionServiceBound) {
|
||||||
|
conversationList.clear();
|
||||||
|
conversationList.addAll(xmppConnectionService
|
||||||
|
.getConversations(Conversation.STATUS_AVAILABLE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void servConnected() {
|
||||||
|
conversationList.clear();
|
||||||
|
conversationList.addAll(xmppConnectionService
|
||||||
|
.getConversations(Conversation.STATUS_AVAILABLE));
|
||||||
|
|
||||||
|
//spl.openPane();
|
||||||
|
|
||||||
|
if ((getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) {
|
||||||
|
if (getIntent().getType().equals(
|
||||||
|
ConversationActivity.VIEW_CONVERSATION)) {
|
||||||
|
handledViewIntent = true;
|
||||||
|
|
||||||
|
swapConversationFragment(conversationList.get(0));
|
||||||
|
spl.closePane();
|
||||||
|
|
||||||
|
// why do i even need this
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
getActionBar().setTitle(conversationList.get(0).getName());
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (conversationList.size() <= 0) {
|
||||||
|
//add no history
|
||||||
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
swapConversationFragment(conversationList.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
|
import de.gultsch.chat.entities.Account;
|
||||||
import de.gultsch.chat.entities.Contact;
|
import de.gultsch.chat.entities.Contact;
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
import de.gultsch.chat.persistance.DatabaseBackend;
|
import de.gultsch.chat.persistance.DatabaseBackend;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
@ -14,12 +16,13 @@ import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.CursorLoader;
|
import android.content.CursorLoader;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -27,7 +30,7 @@ import android.content.Loader;
|
||||||
import android.content.Loader.OnLoadCompleteListener;
|
import android.content.Loader.OnLoadCompleteListener;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
public class NewConversationActivity extends Activity {
|
public class NewConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
final protected LinkedHashMap<Contact, View> availablePhoneContacts = new LinkedHashMap<Contact, View>();
|
final protected LinkedHashMap<Contact, View> availablePhoneContacts = new LinkedHashMap<Contact, View>();
|
||||||
final protected LinkedHashMap<Contact, View> availableJabberContacts = new LinkedHashMap<Contact, View>();
|
final protected LinkedHashMap<Contact, View> availableJabberContacts = new LinkedHashMap<Contact, View>();
|
||||||
|
@ -78,12 +81,20 @@ public class NewConversationActivity extends Activity {
|
||||||
clickedContact = newContact;
|
clickedContact = newContact;
|
||||||
}
|
}
|
||||||
Log.d("gultsch","clicked on "+clickedContact.getDisplayName());
|
Log.d("gultsch","clicked on "+clickedContact.getDisplayName());
|
||||||
Intent startConversationIntent = new Intent(v.getContext(),ConversationActivity.class);
|
|
||||||
startConversationIntent.setAction(Intent.ACTION_VIEW);
|
|
||||||
startConversationIntent.putExtra(ConversationActivity.CONVERSATION_CONTACT, clickedContact);
|
Account account = new Account();
|
||||||
startConversationIntent.setType(ConversationActivity.START_CONVERSATION);
|
|
||||||
startConversationIntent.setFlags(startConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
Conversation conversation = new Conversation(clickedContact.getDisplayName(), clickedContact.getProfilePhoto(), account, clickedContact.getJid());
|
||||||
startActivity(startConversationIntent);
|
|
||||||
|
xmppConnectionService.addConversation(conversation);
|
||||||
|
|
||||||
|
Intent viewConversationIntent = new Intent(v.getContext(),ConversationActivity.class);
|
||||||
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid());
|
||||||
|
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
viewConversationIntent.setFlags(viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(viewConversationIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return view;
|
return view;
|
||||||
|
@ -205,4 +216,33 @@ public class NewConversationActivity extends Activity {
|
||||||
lastContact.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
lastContact.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void servConnected() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
getMenuInflater().inflate(R.menu.newconversation, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_settings:
|
||||||
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
|
break;
|
||||||
|
case R.id.action_accounts:
|
||||||
|
startActivity(new Intent(this, ManageAccountActivity.class));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package de.gultsch.chat.ui;
|
||||||
|
|
||||||
|
import de.gultsch.chat.services.XmppConnectionService;
|
||||||
|
import de.gultsch.chat.services.XmppConnectionService.XmppConnectionBinder;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
public abstract class XmppActivity extends Activity {
|
||||||
|
protected XmppConnectionService xmppConnectionService;
|
||||||
|
protected boolean xmppConnectionServiceBound = false;
|
||||||
|
protected boolean handledViewIntent = false;
|
||||||
|
protected ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
|
XmppConnectionBinder binder = (XmppConnectionBinder) service;
|
||||||
|
xmppConnectionService = binder.getService();
|
||||||
|
xmppConnectionServiceBound = true;
|
||||||
|
servConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName arg0) {
|
||||||
|
xmppConnectionServiceBound = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (!xmppConnectionServiceBound) {
|
||||||
|
Intent intent = new Intent(this, XmppConnectionService.class);
|
||||||
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
if (xmppConnectionServiceBound) {
|
||||||
|
unbindService(mConnection);
|
||||||
|
xmppConnectionServiceBound = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract void servConnected();
|
||||||
|
}
|
Loading…
Reference in New Issue