aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-19 01:14:30 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-19 01:14:30 +0200
commit5c0873c7cab8bdb95754f4a67839aa6ed5a3d2e8 (patch)
tree8783b29c032b4c0410943d411be404f036d9988e /src/eu/siacs/conversations/persistance
parent7ccbf0008a600cd00e3dea1b95890d7454509af3 (diff)
cleaned up debug log a little bit
Diffstat (limited to 'src/eu/siacs/conversations/persistance')
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java5
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java47
2 files changed, 40 insertions, 12 deletions
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index 68fc56cd..ad4555c2 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 7433946b..307a9e2c 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<String, Bitmap>(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();
+ }
}