1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

This hopefully fixes the recreation of the old activity db

(I cannot reproduce or test it)
This commit is contained in:
cpfeiffer 2016-09-06 21:54:03 +02:00
parent f2b344349f
commit d011c437a2

View File

@ -6,6 +6,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast; import android.widget.Toast;
import java.io.File;
import nodomain.freeyourgadget.gadgetbridge.database.schema.ActivityDBCreationScript; import nodomain.freeyourgadget.gadgetbridge.database.schema.ActivityDBCreationScript;
import nodomain.freeyourgadget.gadgetbridge.database.schema.SchemaMigration; import nodomain.freeyourgadget.gadgetbridge.database.schema.SchemaMigration;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster; import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
@ -23,9 +25,11 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
private static final int DATABASE_VERSION = 7; private static final int DATABASE_VERSION = 7;
private static final String UPDATER_CLASS_NAME_PREFIX = "ActivityDBUpdate_"; private static final String UPDATER_CLASS_NAME_PREFIX = "ActivityDBUpdate_";
private final Context context;
public ActivityDatabaseHandler(Context context) { public ActivityDatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION); super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
} }
@Override @Override
@ -66,7 +70,16 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
return this; return this;
} }
public Context getContext() {
return context;
}
public boolean hasContent() { public boolean hasContent() {
File dbFile = getContext().getDatabasePath(getDatabaseName());
if (dbFile == null || !dbFile.exists()) {
return false;
}
try { try {
try (SQLiteDatabase db = this.getReadableDatabase()) { try (SQLiteDatabase db = this.getReadableDatabase()) {
try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, new String[]{KEY_TIMESTAMP}, null, null, null, null, null, "1")) { try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, new String[]{KEY_TIMESTAMP}, null, null, null, null, null, "1")) {