From 5c0873c7cab8bdb95754f4a67839aa6ed5a3d2e8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 19 Apr 2014 01:14:30 +0200 Subject: cleaned up debug log a little bit --- .../conversations/persistance/DatabaseBackend.java | 5 ++- .../conversations/persistance/FileBackend.java | 47 +++++++++++++++++----- 2 files changed, 40 insertions(+), 12 deletions(-) (limited to 'src/eu/siacs/conversations/persistance') diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 68fc56cde..ad4555c2e 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -207,6 +207,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { ContentValues values = contact.getContentValues(); if (!updatePresences) { values.remove(Contact.PRESENCES); + } else { + values.remove(Contact.DISPLAYNAME); + values.remove(Contact.PHOTOURI); + values.remove(Contact.SYSTEMACCOUNT); } db.update(Contact.TABLENAME, contact.getContentValues(), Contact.UUID + "=?", args); @@ -231,7 +235,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (cursor.getCount()>=1) { cursor.moveToFirst(); contact.setUuid(cursor.getString(0)); - //contact.setPresences(Presences.fromJsonString(cursor.getString(1))); updateContact(contact,false); } else { contact.setUuid(UUID.randomUUID().toString()); diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 7433946b2..307a9e2c5 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.persistance; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -10,6 +11,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.util.Log; import android.util.LruCache; import eu.siacs.conversations.entities.Conversation; @@ -25,7 +27,7 @@ public class FileBackend { public FileBackend(Context context) { this.context = context; - + int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 8; thumbnailCache = new LruCache(cacheSize) { @@ -45,7 +47,7 @@ public class FileBackend { String filename = message.getUuid() + ".webp"; return new JingleFile(path + "/" + filename); } - + private Bitmap resize(Bitmap originalBitmap, int size) { int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); @@ -59,8 +61,8 @@ public class FileBackend { scalledW = size; scalledH = (int) (h / ((double) w / size)); } - Bitmap scalledBitmap = Bitmap.createScaledBitmap( - originalBitmap, scalledW, scalledH, true); + Bitmap scalledBitmap = Bitmap.createScaledBitmap(originalBitmap, + scalledW, scalledH, true); return scalledBitmap; } else { return originalBitmap; @@ -78,9 +80,10 @@ public class FileBackend { Bitmap originalBitmap = BitmapFactory.decodeStream(is); is.close(); Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE); - boolean success = scalledBitmap.compress(Bitmap.CompressFormat.WEBP,75,os); + boolean success = scalledBitmap.compress( + Bitmap.CompressFormat.WEBP, 75, os); if (!success) { - //Log.d("xmppService", "couldnt compress"); + // Log.d("xmppService", "couldnt compress"); } os.close(); return file; @@ -96,16 +99,17 @@ public class FileBackend { } public Bitmap getImageFromMessage(Message message) { - return BitmapFactory - .decodeFile(getJingleFile(message).getAbsolutePath()); + return BitmapFactory.decodeFile(getJingleFile(message) + .getAbsolutePath()); } - public Bitmap getThumbnailFromMessage(Message message, int size) throws FileNotFoundException { + public Bitmap getThumbnailFromMessage(Message message, int size) + throws FileNotFoundException { Bitmap thumbnail = thumbnailCache.get(message.getUuid()); - if (thumbnail==null) { + if (thumbnail == null) { Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message) .getAbsolutePath()); - if (fullsize==null) { + if (fullsize == null) { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); @@ -113,4 +117,25 @@ public class FileBackend { } return thumbnail; } + + public void removeFiles(Conversation conversation) { + String prefix = context.getFilesDir().getAbsolutePath(); + String path = prefix + "/" + conversation.getAccount().getJid() + "/" + + conversation.getContactJid(); + File file = new File(path); + try { + this.deleteFile(file); + } catch (IOException e) { + Log.d("xmppService", + "error deleting file: " + file.getAbsolutePath()); + } + } + + private void deleteFile(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) + deleteFile(c); + } + f.delete(); + } } -- cgit v1.2.3