aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/persistance')
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java24
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java17
2 files changed, 31 insertions, 10 deletions
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index 51fd79e5..0991dd2d 100644
--- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -19,7 +19,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history";
- private static final int DATABASE_VERSION = 7;
+ private static final int DATABASE_VERSION = 8;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -50,10 +50,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ " TEXT, " + Conversation.CONTACT + " TEXT, "
+ Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID
+ " TEXT, " + Conversation.CREATED + " NUMBER, "
- + Conversation.STATUS + " NUMBER," + Conversation.MODE
- + " NUMBER," + "FOREIGN KEY(" + Conversation.ACCOUNT
- + ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID
- + ") ON DELETE CASCADE);");
+ + Conversation.STATUS + " NUMBER, " + Conversation.MODE
+ + " NUMBER, " + Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY("
+ + Conversation.ACCOUNT + ") REFERENCES " + Account.TABLENAME
+ + "(" + Account.UUID + ") ON DELETE CASCADE);");
db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
@@ -96,6 +96,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN "
+ Account.AVATAR + " TEXT");
}
+ if (oldVersion < 8 && newVersion >= 8) {
+ db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN "
+ + Conversation.ATTRIBUTES + " TEXT");
+ }
}
public static synchronized DatabaseBackend getInstance(Context context) {
@@ -206,6 +210,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) {
list.add(Account.fromCursor(cursor));
}
+ cursor.close();
return list;
}
@@ -221,13 +226,15 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String[] args = { account.getUuid() };
db.delete(Account.TABLENAME, Account.UUID + "=?", args);
}
-
+
public boolean hasEnabledAccounts() {
SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor= db.rawQuery("select count("+Account.UUID+") from "+Account.TABLENAME+" where not options & (1 <<1)", null);
+ Cursor cursor = db.rawQuery("select count(" + Account.UUID + ") from "
+ + Account.TABLENAME + " where not options & (1 <<1)", null);
cursor.moveToFirst();
int count = cursor.getInt(0);
- return (count>0);
+ cursor.close();
+ return (count > 0);
}
@Override
@@ -253,6 +260,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) {
roster.initContact(Contact.fromCursor(cursor));
}
+ cursor.close();
}
public void writeRoster(Roster roster) {
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 2b2aa86e..d86c0ee1 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -250,7 +250,10 @@ public class FileBackend {
if (!file.exists()) {
file = getJingleFileLegacy(message);
}
- Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath());
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inSampleSize = calcSampleSize(file, size);
+ Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath(),
+ options);
if (fullsize == null) {
throw new FileNotFoundException();
}
@@ -414,6 +417,17 @@ public class FileBackend {
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(context.getContentResolver()
.openInputStream(image), null, options);
+ return calcSampleSize(options, size);
+ }
+
+ private int calcSampleSize(File image, int size) {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(image.getAbsolutePath(), options);
+ return calcSampleSize(options, size);
+ }
+
+ private int calcSampleSize(BitmapFactory.Options options, int size) {
int height = options.outHeight;
int width = options.outWidth;
int inSampleSize = 1;
@@ -428,7 +442,6 @@ public class FileBackend {
}
}
return inSampleSize;
-
}
public Uri getJingleFileUri(Message message) {