gui for images
This commit is contained in:
parent
9fc7a1b980
commit
c30bf75a5d
|
@ -21,6 +21,14 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="5dp" >
|
android:padding="5dp" >
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/message_image"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:maxHeight="300dp"
|
||||||
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message_body"
|
android:id="@+id/message_body"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -20,6 +20,14 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="5dp" >
|
android:padding="5dp" >
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/message_image"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:maxHeight="300dp"
|
||||||
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message_body"
|
android:id="@+id/message_body"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -19,12 +19,16 @@ public class Message extends AbstractEntity {
|
||||||
public static final int ENCRYPTION_OTR = 2;
|
public static final int ENCRYPTION_OTR = 2;
|
||||||
public static final int ENCRYPTION_DECRYPTED = 3;
|
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 CONVERSATION = "conversationUuid";
|
||||||
public static String COUNTERPART = "counterpart";
|
public static String COUNTERPART = "counterpart";
|
||||||
public static String BODY = "body";
|
public static String BODY = "body";
|
||||||
public static String TIME_SENT = "timeSent";
|
public static String TIME_SENT = "timeSent";
|
||||||
public static String ENCRYPTION = "encryption";
|
public static String ENCRYPTION = "encryption";
|
||||||
public static String STATUS = "status";
|
public static String STATUS = "status";
|
||||||
|
public static String TYPE = "type";
|
||||||
|
|
||||||
protected String conversationUuid;
|
protected String conversationUuid;
|
||||||
protected String counterpart;
|
protected String counterpart;
|
||||||
|
@ -33,6 +37,7 @@ public class Message extends AbstractEntity {
|
||||||
protected long timeSent;
|
protected long timeSent;
|
||||||
protected int encryption;
|
protected int encryption;
|
||||||
protected int status;
|
protected int status;
|
||||||
|
protected int type;
|
||||||
protected boolean read = true;
|
protected boolean read = true;
|
||||||
|
|
||||||
protected transient Conversation conversation = null;
|
protected transient Conversation conversation = null;
|
||||||
|
@ -40,17 +45,17 @@ public class Message extends AbstractEntity {
|
||||||
public Message(Conversation conversation, String body, int encryption) {
|
public Message(Conversation conversation, String body, int encryption) {
|
||||||
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
||||||
conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
|
conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
|
||||||
Message.STATUS_UNSEND);
|
Message.STATUS_UNSEND,TYPE_TEXT);
|
||||||
this.conversation = conversation;
|
this.conversation = conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(Conversation conversation, String counterpart, String body, int encryption, int status) {
|
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;
|
this.conversation = conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(String uuid, String conversationUUid, String counterpart,
|
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.uuid = uuid;
|
||||||
this.conversationUuid = conversationUUid;
|
this.conversationUuid = conversationUUid;
|
||||||
this.counterpart = counterpart;
|
this.counterpart = counterpart;
|
||||||
|
@ -58,6 +63,7 @@ public class Message extends AbstractEntity {
|
||||||
this.timeSent = timeSent;
|
this.timeSent = timeSent;
|
||||||
this.encryption = encryption;
|
this.encryption = encryption;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,6 +76,7 @@ public class Message extends AbstractEntity {
|
||||||
values.put(TIME_SENT, timeSent);
|
values.put(TIME_SENT, timeSent);
|
||||||
values.put(ENCRYPTION, encryption);
|
values.put(ENCRYPTION, encryption);
|
||||||
values.put(STATUS, status);
|
values.put(STATUS, status);
|
||||||
|
values.put(TYPE, type);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +115,8 @@ public class Message extends AbstractEntity {
|
||||||
cursor.getString(cursor.getColumnIndex(BODY)),
|
cursor.getString(cursor.getColumnIndex(BODY)),
|
||||||
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
|
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
|
||||||
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
|
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) {
|
public void setConversation(Conversation conv) {
|
||||||
|
@ -150,4 +158,12 @@ public class Message extends AbstractEntity {
|
||||||
public void setEncryptedBody(String body) {
|
public void setEncryptedBody(String body) {
|
||||||
this.encryptedBody = body;
|
this.encryptedBody = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
private static DatabaseBackend instance = null;
|
private static DatabaseBackend instance = null;
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "history";
|
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) {
|
public DatabaseBackend(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
@ -50,7 +50,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
|
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
|
||||||
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
|
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
|
||||||
+ " TEXT, " + Message.BODY + " TEXT, " + Message.ENCRYPTION
|
+ " TEXT, " + Message.BODY + " TEXT, " + Message.ENCRYPTION
|
||||||
+ " NUMBER, " + Message.STATUS + " NUMBER," + "FOREIGN KEY("
|
+ " NUMBER, " + Message.STATUS + " NUMBER," +Message.TYPE +" NUMBER, FOREIGN KEY("
|
||||||
+ Message.CONVERSATION + ") REFERENCES "
|
+ Message.CONVERSATION + ") REFERENCES "
|
||||||
+ Conversation.TABLENAME + "(" + Conversation.UUID
|
+ Conversation.TABLENAME + "(" + Conversation.UUID
|
||||||
+ ") ON DELETE CASCADE);");
|
+ ") ON DELETE CASCADE);");
|
||||||
|
@ -72,6 +72,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
db.execSQL("update " + Account.TABLENAME
|
db.execSQL("update " + Account.TABLENAME
|
||||||
+ " set " + Account.OPTIONS + " = " + Account.OPTIONS + " | 8");
|
+ " 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) {
|
public static synchronized DatabaseBackend getInstance(Context context) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
|
||||||
|
|
||||||
public class FileBackend {
|
public class FileBackend {
|
||||||
|
@ -27,14 +28,18 @@ public class FileBackend {
|
||||||
this.context = context;
|
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 {
|
try {
|
||||||
InputStream is = context.getContentResolver().openInputStream(image);
|
InputStream is = context.getContentResolver().openInputStream(image);
|
||||||
String prefix = context.getFilesDir().getAbsolutePath();
|
File file = getImageFile(message);
|
||||||
String path = prefix+"/"+conversation.getAccount().getJid()+"/"+conversation.getContactJid();
|
|
||||||
String filename =new BigInteger(""+System.currentTimeMillis()).toString(32) + ".webp";
|
|
||||||
File file = new File(path+"/"+filename);
|
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
OutputStream os = new FileOutputStream(file);
|
OutputStream os = new FileOutputStream(file);
|
||||||
|
@ -73,4 +78,9 @@ public class FileBackend {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Bitmap getImageFromMessage(Message message) {
|
||||||
|
return BitmapFactory.decodeFile(getImageFile(message).getAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -60,6 +61,7 @@ import android.database.ContentObserver;
|
||||||
import android.database.DatabaseUtils;
|
import android.database.DatabaseUtils;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -387,6 +389,15 @@ public class XmppConnectionService extends Service {
|
||||||
return this.fileBackend;
|
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) {
|
protected Conversation findMuc(String name, Account account) {
|
||||||
for (Conversation conversation : this.conversations) {
|
for (Conversation conversation : this.conversations) {
|
||||||
|
|
|
@ -494,10 +494,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
selectedFragment.hidePgpPassphraseBox();
|
selectedFragment.hidePgpPassphraseBox();
|
||||||
}
|
}
|
||||||
} else if (requestCode == ATTACH_FILE) {
|
} else if (requestCode == ATTACH_FILE) {
|
||||||
FileBackend backend = xmppConnectionService.getFileBackend();
|
xmppConnectionService.attachImageToConversation(getSelectedConversation(), data.getData());
|
||||||
File file = backend.copyImageToPrivateStorage(getSelectedConversation(), data.getData());
|
|
||||||
Log.d(LOGTAG,"new file"+file.getAbsolutePath());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,6 @@ public class ConversationFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Log.d("gultsch", "clicked to decrypt");
|
|
||||||
if (askForPassphraseIntent != null) {
|
if (askForPassphraseIntent != null) {
|
||||||
try {
|
try {
|
||||||
getActivity().startIntentSenderForResult(
|
getActivity().startIntentSenderForResult(
|
||||||
|
@ -97,7 +96,7 @@ public class ConversationFragment extends Fragment {
|
||||||
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
||||||
0, 0);
|
0, 0);
|
||||||
} catch (SendIntentException e) {
|
} 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);
|
.findViewById(R.id.message_photo);
|
||||||
viewHolder.imageView.setImageBitmap(selfBitmap);
|
viewHolder.imageView.setImageBitmap(selfBitmap);
|
||||||
viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
|
viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
|
||||||
|
viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
|
||||||
break;
|
break;
|
||||||
case RECIEVED:
|
case RECIEVED:
|
||||||
view = (View) inflater.inflate(
|
view = (View) inflater.inflate(
|
||||||
|
@ -262,32 +262,40 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String body = item.getBody();
|
if (item.getType() == Message.TYPE_IMAGE) {
|
||||||
if (body != null) {
|
viewHolder.image.setVisibility(View.VISIBLE);
|
||||||
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
viewHolder.image.setImageBitmap(activity.xmppConnectionService.getFileBackend().getImageFromMessage(item));
|
||||||
viewHolder.messageBody
|
viewHolder.messageBody.setVisibility(View.GONE);
|
||||||
.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 {
|
} else {
|
||||||
viewHolder.indicator.setVisibility(View.GONE);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (item.getStatus() == Message.STATUS_UNSEND) {
|
if (item.getStatus() == Message.STATUS_UNSEND) {
|
||||||
viewHolder.time.setTypeface(null, Typeface.ITALIC);
|
viewHolder.time.setTypeface(null, Typeface.ITALIC);
|
||||||
|
@ -585,6 +593,7 @@ public class ConversationFragment extends Fragment {
|
||||||
|
|
||||||
private static class ViewHolder {
|
private static class ViewHolder {
|
||||||
|
|
||||||
|
protected ImageView image;
|
||||||
protected ImageView indicator;
|
protected ImageView indicator;
|
||||||
protected TextView time;
|
protected TextView time;
|
||||||
protected TextView messageBody;
|
protected TextView messageBody;
|
||||||
|
|
Loading…
Reference in a new issue