aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations')
-rw-r--r--src/eu/siacs/conversations/entities/Message.java24
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java8
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java20
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java11
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java5
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java61
6 files changed, 88 insertions, 41 deletions
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index b91d822d..a81ff0d3 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -18,6 +18,9 @@ public class Message extends AbstractEntity {
public static final int ENCRYPTION_PGP = 1;
public static final int ENCRYPTION_OTR = 2;
public static final int ENCRYPTION_DECRYPTED = 3;
+
+ public static final int TYPE_TEXT = 0;
+ public static final int TYPE_IMAGE = 1;
public static String CONVERSATION = "conversationUuid";
public static String COUNTERPART = "counterpart";
@@ -25,6 +28,7 @@ public class Message extends AbstractEntity {
public static String TIME_SENT = "timeSent";
public static String ENCRYPTION = "encryption";
public static String STATUS = "status";
+ public static String TYPE = "type";
protected String conversationUuid;
protected String counterpart;
@@ -33,6 +37,7 @@ public class Message extends AbstractEntity {
protected long timeSent;
protected int encryption;
protected int status;
+ protected int type;
protected boolean read = true;
protected transient Conversation conversation = null;
@@ -40,17 +45,17 @@ public class Message extends AbstractEntity {
public Message(Conversation conversation, String body, int encryption) {
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
- Message.STATUS_UNSEND);
+ Message.STATUS_UNSEND,TYPE_TEXT);
this.conversation = conversation;
}
public Message(Conversation conversation, String counterpart, String body, int encryption, int status) {
- this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, body, System.currentTimeMillis(), encryption,status);
+ this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT);
this.conversation = conversation;
}
public Message(String uuid, String conversationUUid, String counterpart,
- String body, long timeSent, int encryption, int status) {
+ String body, long timeSent, int encryption, int status, int type) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -58,6 +63,7 @@ public class Message extends AbstractEntity {
this.timeSent = timeSent;
this.encryption = encryption;
this.status = status;
+ this.type = type;
}
@Override
@@ -70,6 +76,7 @@ public class Message extends AbstractEntity {
values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption);
values.put(STATUS, status);
+ values.put(TYPE, type);
return values;
}
@@ -108,7 +115,8 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(BODY)),
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
- cursor.getInt(cursor.getColumnIndex(STATUS)));
+ cursor.getInt(cursor.getColumnIndex(STATUS)),
+ cursor.getInt(cursor.getColumnIndex(TYPE)));
}
public void setConversation(Conversation conv) {
@@ -150,4 +158,12 @@ public class Message extends AbstractEntity {
public void setEncryptedBody(String body) {
this.encryptedBody = body;
}
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getType() {
+ return this.type;
+ }
}
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index 4c0d6216..852a9315 100644
--- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -23,7 +23,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history";
- private static final int DATABASE_VERSION = 2;
+ private static final int DATABASE_VERSION = 3;
public DatabaseBackend(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -50,7 +50,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
+ " TEXT, " + Message.BODY + " TEXT, " + Message.ENCRYPTION
- + " NUMBER, " + Message.STATUS + " NUMBER," + "FOREIGN KEY("
+ + " NUMBER, " + Message.STATUS + " NUMBER," +Message.TYPE +" NUMBER, FOREIGN KEY("
+ Message.CONVERSATION + ") REFERENCES "
+ Conversation.TABLENAME + "(" + Conversation.UUID
+ ") ON DELETE CASCADE);");
@@ -72,6 +72,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("update " + Account.TABLENAME
+ " set " + Account.OPTIONS + " = " + Account.OPTIONS + " | 8");
}
+ if (oldVersion < 3 && newVersion >= 3) {
+ //add field type to message
+ db.execSQL("ALTER TABLE "+Message.TABLENAME+" ADD COLUMN "+Message.TYPE+" NUMBER");;
+ }
}
public static synchronized DatabaseBackend getInstance(Context context) {
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 05c50530..9ae40645 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -15,6 +15,7 @@ import android.net.Uri;
import android.util.Log;
import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Message;
public class FileBackend {
@@ -27,14 +28,18 @@ public class FileBackend {
this.context = context;
}
+ private File getImageFile(Message message) {
+ Conversation conversation = message.getConversation();
+ String prefix = context.getFilesDir().getAbsolutePath();
+ String path = prefix+"/"+conversation.getAccount().getJid()+"/"+conversation.getContactJid();
+ String filename = message.getUuid() + ".webp";
+ return new File(path+"/"+filename);
+ }
- public File copyImageToPrivateStorage(Conversation conversation, Uri image) {
+ public File copyImageToPrivateStorage(Message message, Uri image) {
try {
InputStream is = context.getContentResolver().openInputStream(image);
- String prefix = context.getFilesDir().getAbsolutePath();
- String path = prefix+"/"+conversation.getAccount().getJid()+"/"+conversation.getContactJid();
- String filename =new BigInteger(""+System.currentTimeMillis()).toString(32) + ".webp";
- File file = new File(path+"/"+filename);
+ File file = getImageFile(message);
file.getParentFile().mkdirs();
file.createNewFile();
OutputStream os = new FileOutputStream(file);
@@ -73,4 +78,9 @@ public class FileBackend {
return null;
}
+
+
+ public Bitmap getImageFromMessage(Message message) {
+ return BitmapFactory.decodeFile(getImageFile(message).getAbsolutePath());
+ }
}
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 76e7d728..e8ec6f7f 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1,5 +1,6 @@
package eu.siacs.conversations.services;
+import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
@@ -60,6 +61,7 @@ import android.database.ContentObserver;
import android.database.DatabaseUtils;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@@ -387,6 +389,15 @@ public class XmppConnectionService extends Service {
return this.fileBackend;
}
+ public void attachImageToConversation(Conversation conversation, Uri uri) {
+ Message message = new Message(conversation, "", Message.ENCRYPTION_NONE);
+ message.setType(Message.TYPE_IMAGE);
+ File file = this.fileBackend.copyImageToPrivateStorage(message, uri);
+ Log.d(LOGTAG,"new file"+file.getAbsolutePath());
+ conversation.getMessages().add(message);
+ databaseBackend.createMessage(message);
+ }
+
protected Conversation findMuc(String name, Account account) {
for (Conversation conversation : this.conversations) {
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 82b33499..85186e9b 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -494,10 +494,7 @@ public class ConversationActivity extends XmppActivity {
selectedFragment.hidePgpPassphraseBox();
}
} else if (requestCode == ATTACH_FILE) {
- FileBackend backend = xmppConnectionService.getFileBackend();
- File file = backend.copyImageToPrivateStorage(getSelectedConversation(), data.getData());
- Log.d(LOGTAG,"new file"+file.getAbsolutePath());
-
+ xmppConnectionService.attachImageToConversation(getSelectedConversation(), data.getData());
}
}
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 51caafbd..a9bde53d 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -89,7 +89,6 @@ public class ConversationFragment extends Fragment {
@Override
public void onClick(View v) {
- Log.d("gultsch", "clicked to decrypt");
if (askForPassphraseIntent != null) {
try {
getActivity().startIntentSenderForResult(
@@ -97,7 +96,7 @@ public class ConversationFragment extends Fragment {
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
0, 0);
} catch (SendIntentException e) {
- Log.d("gultsch", "couldnt fire intent");
+ Log.d("xmppService", "couldnt fire intent");
}
}
}
@@ -210,6 +209,7 @@ public class ConversationFragment extends Fragment {
.findViewById(R.id.message_photo);
viewHolder.imageView.setImageBitmap(selfBitmap);
viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
+ viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
break;
case RECIEVED:
view = (View) inflater.inflate(
@@ -262,32 +262,40 @@ public class ConversationFragment extends Fragment {
}
}
}
- String body = item.getBody();
- if (body != null) {
- if (item.getEncryption() == Message.ENCRYPTION_PGP) {
- viewHolder.messageBody
- .setText(getString(R.string.encrypted_message));
- viewHolder.messageBody.setTextColor(0xff33B5E5);
- viewHolder.messageBody.setTypeface(null,
- Typeface.ITALIC);
- viewHolder.indicator.setVisibility(View.VISIBLE);
- } else if ((item.getEncryption() == Message.ENCRYPTION_OTR)||(item.getEncryption() == Message.ENCRYPTION_DECRYPTED)) {
- viewHolder.messageBody.setText(body.trim());
- viewHolder.messageBody.setTextColor(0xff000000);
- viewHolder.messageBody.setTypeface(null,
- Typeface.NORMAL);
- viewHolder.indicator.setVisibility(View.VISIBLE);
- } else {
- viewHolder.messageBody.setText(body.trim());
- viewHolder.messageBody.setTextColor(0xff000000);
- viewHolder.messageBody.setTypeface(null,
- Typeface.NORMAL);
- if (item.getStatus() != Message.STATUS_ERROR) {
- viewHolder.indicator.setVisibility(View.GONE);
+ if (item.getType() == Message.TYPE_IMAGE) {
+ viewHolder.image.setVisibility(View.VISIBLE);
+ viewHolder.image.setImageBitmap(activity.xmppConnectionService.getFileBackend().getImageFromMessage(item));
+ viewHolder.messageBody.setVisibility(View.GONE);
+ } else {
+ if (viewHolder.image != null) viewHolder.image.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.VISIBLE);
+ String body = item.getBody();
+ if (body != null) {
+ if (item.getEncryption() == Message.ENCRYPTION_PGP) {
+ viewHolder.messageBody
+ .setText(getString(R.string.encrypted_message));
+ viewHolder.messageBody.setTextColor(0xff33B5E5);
+ viewHolder.messageBody.setTypeface(null,
+ Typeface.ITALIC);
+ viewHolder.indicator.setVisibility(View.VISIBLE);
+ } else if ((item.getEncryption() == Message.ENCRYPTION_OTR)||(item.getEncryption() == Message.ENCRYPTION_DECRYPTED)) {
+ viewHolder.messageBody.setText(body.trim());
+ viewHolder.messageBody.setTextColor(0xff000000);
+ viewHolder.messageBody.setTypeface(null,
+ Typeface.NORMAL);
+ viewHolder.indicator.setVisibility(View.VISIBLE);
+ } else {
+ viewHolder.messageBody.setText(body.trim());
+ viewHolder.messageBody.setTextColor(0xff000000);
+ viewHolder.messageBody.setTypeface(null,
+ Typeface.NORMAL);
+ if (item.getStatus() != Message.STATUS_ERROR) {
+ viewHolder.indicator.setVisibility(View.GONE);
+ }
}
+ } else {
+ viewHolder.indicator.setVisibility(View.GONE);
}
- } else {
- viewHolder.indicator.setVisibility(View.GONE);
}
if (item.getStatus() == Message.STATUS_UNSEND) {
viewHolder.time.setTypeface(null, Typeface.ITALIC);
@@ -585,6 +593,7 @@ public class ConversationFragment extends Fragment {
private static class ViewHolder {
+ protected ImageView image;
protected ImageView indicator;
protected TextView time;
protected TextView messageBody;