aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java34
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java3
-rw-r--r--src/eu/siacs/conversations/services/ImageProvider.java97
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java14
4 files changed, 145 insertions, 3 deletions
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index c8c974dec..5a34dac61 100644
--- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -305,11 +305,43 @@ public class DatabaseBackend extends SQLiteOpenHelper {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = { uuid };
Cursor cursor = db.query(Contact.TABLENAME, null, Contact.UUID + "=?", args, null, null, null);
- if (cursor.getCount() == 0)
+ if (cursor.getCount() == 0) {
return null;
+ }
cursor.moveToFirst();
return Contact.fromCursor(cursor);
}
+ public Conversation findConversationByUuid(String conversationUuid) {
+ SQLiteDatabase db = this.getReadableDatabase();
+ String[] selectionArgs = { conversationUuid };
+ Cursor cursor = db.query(Conversation.TABLENAME, null, Conversation.UUID + "=?", selectionArgs, null, null, null);
+ if (cursor.getCount() == 0) {
+ return null;
+ }
+ cursor.moveToFirst();
+ return Conversation.fromCursor(cursor);
+ }
+
+ public Message findMessageByUuid(String messageUuid) {
+ SQLiteDatabase db = this.getReadableDatabase();
+ String[] selectionArgs = { messageUuid };
+ Cursor cursor = db.query(Message.TABLENAME, null, Message.UUID + "=?", selectionArgs, null, null, null);
+ if (cursor.getCount() == 0) {
+ return null;
+ }
+ cursor.moveToFirst();
+ return Message.fromCursor(cursor);
+ }
+ public Account findAccountByUuid(String accountUuid) {
+ SQLiteDatabase db = this.getReadableDatabase();
+ String[] selectionArgs = { accountUuid };
+ Cursor cursor = db.query(Account.TABLENAME, null, Account.UUID + "=?", selectionArgs, null, null, null);
+ if (cursor.getCount() == 0) {
+ return null;
+ }
+ cursor.moveToFirst();
+ return Account.fromCursor(cursor);
+ }
}
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 307a9e2c5..d830652df 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -14,8 +14,10 @@ import android.net.Uri;
import android.util.Log;
import android.util.LruCache;
+import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
public class FileBackend {
@@ -27,7 +29,6 @@ public class FileBackend {
public FileBackend(Context context) {
this.context = context;
-
int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
int cacheSize = maxMemory / 8;
thumbnailCache = new LruCache<String, Bitmap>(cacheSize) {
diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java
new file mode 100644
index 000000000..c1bae661e
--- /dev/null
+++ b/src/eu/siacs/conversations/services/ImageProvider.java
@@ -0,0 +1,97 @@
+package eu.siacs.conversations.services;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.persistance.DatabaseBackend;
+import eu.siacs.conversations.persistance.FileBackend;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+public class ImageProvider extends ContentProvider {
+
+ @Override
+ public ParcelFileDescriptor openFile(Uri uri, String mode)
+ throws FileNotFoundException {
+ DatabaseBackend databaseBackend = DatabaseBackend
+ .getInstance(getContext());
+ FileBackend fileBackend = new FileBackend(getContext());
+ String uuids = uri.getPath();
+ Log.d("xmppService", "uuids = " + uuids);
+ if (uuids == null) {
+ throw new FileNotFoundException();
+ }
+ String[] uuidsSplited = uuids.split("/");
+ if (uuidsSplited.length != 3) {
+ throw new FileNotFoundException();
+ }
+ String conversationUuid = uuidsSplited[1];
+ String messageUuid = uuidsSplited[2];
+
+ Conversation conversation = databaseBackend
+ .findConversationByUuid(conversationUuid);
+ if (conversation == null) {
+ throw new FileNotFoundException("conversation " + conversationUuid
+ + " could not be found");
+ }
+ Message message = databaseBackend.findMessageByUuid(messageUuid);
+ if (message == null) {
+ throw new FileNotFoundException("message " + messageUuid
+ + " could not be found");
+ }
+
+ Account account = databaseBackend.findAccountByUuid(conversation
+ .getAccountUuid());
+ if (account == null) {
+ throw new FileNotFoundException("account "
+ + conversation.getAccountUuid() + " cound not be found");
+ }
+ message.setConversation(conversation);
+ conversation.setAccount(account);
+
+ File file = fileBackend.getJingleFile(message);
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file,
+ ParcelFileDescriptor.MODE_READ_ONLY);
+ return pfd;
+ }
+
+ @Override
+ public int delete(Uri arg0, String arg1, String[] arg2) {
+ return 0;
+ }
+
+ @Override
+ public String getType(Uri arg0) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri arg0, ContentValues arg1) {
+ return null;
+ }
+
+ @Override
+ public boolean onCreate() {
+ return false;
+ }
+
+ @Override
+ public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
+ String arg4) {
+ return null;
+ }
+
+ @Override
+ public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
+ return 0;
+ }
+
+}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 6e1db2bf7..0604f1dbe 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -31,6 +31,7 @@ import android.content.SharedPreferences;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -197,7 +198,7 @@ public class ConversationFragment extends Fragment {
@Override
public View getView(int position, View view, ViewGroup parent) {
- Message item = getItem(position);
+ final Message item = getItem(position);
int type = getItemViewType(position);
ViewHolder viewHolder;
if (view == null) {
@@ -283,6 +284,17 @@ public class ConversationFragment extends Fragment {
viewHolder.image.setImageBitmap(thumbnail);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
+ viewHolder.image.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Uri uri = Uri.parse("content://eu.siacs.conversations.images/"+item.getConversationUuid()+"/"+item.getUuid());
+ Log.d("xmppService","staring intent with uri:"+uri.toString());
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(uri, "image/*");
+ startActivity(intent);
+ }
+ });
} catch (FileNotFoundException e) {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setText("error loading image file");