Support for deleting/emptying the activity database

here
cpfeiffer 2015-12-08 23:42:58 +01:00
parent fe60d6aaf0
commit e642971b4c
3 changed files with 69 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -20,7 +20,7 @@
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:columnCount="3"
android:rowCount="15"
android:alignmentMode="alignMargins">
@ -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" />
<EditText
android:id="@+id/editContent"
@ -70,7 +71,7 @@
android:layout_width="match_parent"
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="9"
android:text="create test notification" />
@ -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" />
<Button
android:id="@+id/startCallButton"
@ -119,14 +121,15 @@
android:layout_column="1"
android:layout_gravity="fill_horizontal"
android:layout_row="4"
android:text="end call" />
android:text="end call"
android:layout_columnSpan="2" />
<Button
android:id="@+id/setMusicInfoButton"
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="5"
android:text="set music info" />
@ -136,7 +139,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="7"
android:text="reboot" />
@ -159,6 +162,14 @@
android:layout_gravity="fill_horizontal"
android:layout_row="6"
android:text="Import DB" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Empty DB"
android:id="@+id/emptyDBButton"
android:layout_row="6"
android:layout_column="2" />
</GridLayout>
</ScrollView>