diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 8aeb78c2a..11390e350 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -24,6 +24,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler; +import nodomain.freeyourgadget.gadgetbridge.database.DBConstants; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService; @@ -222,4 +223,18 @@ public class GBApplication extends Application { blacklist.remove(packageName); saveBlackList(); } + + /** + * Deletes the entire Activity database and recreates it with empty tables. + * @return true on successful deletion + */ + public static synchronized boolean deleteActivityDatabase() { + if (mActivityDatabaseHandler != null) { + mActivityDatabaseHandler.close(); + mActivityDatabaseHandler = null; + } + boolean result = getContext().deleteDatabase(DBConstants.DATABASE_NAME); + mActivityDatabaseHandler = new ActivityDatabaseHandler(getContext()); + return result; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index e5a90d0cf..18d3b526b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -1,10 +1,12 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.app.Activity; +import android.app.AlertDialog; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.database.sqlite.SQLiteOpenHelper; @@ -48,8 +50,9 @@ public class DebugActivity extends Activity { private Button rebootButton; private Button exportDBButton; private Button importDBButton; - private EditText editContent; + private Button deleteDBButton; + private EditText editContent; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -151,6 +154,14 @@ public class DebugActivity extends Activity { } }); + deleteDBButton = (Button) findViewById(R.id.emptyDBButton); + deleteDBButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + deleteActivityDatabase(); + } + }); + rebootButton = (Button) findViewById(R.id.rebootButton); rebootButton.setOnClickListener(new View.OnClickListener() { @Override @@ -224,6 +235,29 @@ public class DebugActivity extends Activity { } } + private void deleteActivityDatabase() { + AlertDialog dialog = new AlertDialog.Builder(this) + .setCancelable(true) + .setTitle("Delete Activity Data?") + .setMessage("Really delete the entire activity database? All your activity data will be lost.") + .setPositiveButton("Delete", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (GBApplication.deleteActivityDatabase()) { + GB.toast(DebugActivity.this, "Activity database successfully deleted.", Toast.LENGTH_SHORT, GB.INFO); + } else { + GB.toast(DebugActivity.this, "Activity database deletion failed.", Toast.LENGTH_SHORT, GB.INFO); + } + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }) + .show(); + } + private void testNotification() { Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 9452cc1dd..799b7ab5b 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -20,7 +20,7 @@ @@ -51,7 +51,8 @@ android:layout_column="1" android:layout_gravity="fill_horizontal" android:layout_row="2" - android:text="send as E-Mail" /> + android:text="send as E-Mail" + android:layout_columnSpan="2" /> @@ -80,7 +81,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" - android:layout_columnSpan="2" + android:layout_columnSpan="3" android:layout_gravity="fill_horizontal" android:layout_row="8" android:text="set time" /> @@ -101,7 +102,8 @@ android:layout_column="1" android:layout_gravity="fill_horizontal" android:layout_row="3" - android:text="outgoing call" /> + android:text="outgoing call" + android:layout_columnSpan="2" />