mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-02 21:17:32 +01:00
Support for deleting/emptying the activity database
This commit is contained in:
parent
fe60d6aaf0
commit
e642971b4c
@ -24,6 +24,7 @@ import java.util.concurrent.locks.Lock;
|
|||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBConstants;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||||
@ -222,4 +223,18 @@ public class GBApplication extends Application {
|
|||||||
blacklist.remove(packageName);
|
blacklist.remove(packageName);
|
||||||
saveBlackList();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
@ -48,8 +50,9 @@ public class DebugActivity extends Activity {
|
|||||||
private Button rebootButton;
|
private Button rebootButton;
|
||||||
private Button exportDBButton;
|
private Button exportDBButton;
|
||||||
private Button importDBButton;
|
private Button importDBButton;
|
||||||
private EditText editContent;
|
private Button deleteDBButton;
|
||||||
|
|
||||||
|
private EditText editContent;
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
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 = (Button) findViewById(R.id.rebootButton);
|
||||||
rebootButton.setOnClickListener(new View.OnClickListener() {
|
rebootButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@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() {
|
private void testNotification() {
|
||||||
Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
|
Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
|
||||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<GridLayout
|
<GridLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:columnCount="2"
|
android:columnCount="3"
|
||||||
android:rowCount="15"
|
android:rowCount="15"
|
||||||
android:alignmentMode="alignMargins">
|
android:alignmentMode="alignMargins">
|
||||||
|
|
||||||
@ -51,7 +51,8 @@
|
|||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="2"
|
android:layout_row="2"
|
||||||
android:text="send as E-Mail" />
|
android:text="send as E-Mail"
|
||||||
|
android:layout_columnSpan="2" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editContent"
|
android:id="@+id/editContent"
|
||||||
@ -70,7 +71,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_column="0"
|
android:layout_column="0"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="3"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="9"
|
android:layout_row="9"
|
||||||
android:text="create test notification" />
|
android:text="create test notification" />
|
||||||
@ -80,7 +81,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_column="0"
|
android:layout_column="0"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="3"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="8"
|
android:layout_row="8"
|
||||||
android:text="set time" />
|
android:text="set time" />
|
||||||
@ -101,7 +102,8 @@
|
|||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="3"
|
android:layout_row="3"
|
||||||
android:text="outgoing call" />
|
android:text="outgoing call"
|
||||||
|
android:layout_columnSpan="2" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/startCallButton"
|
android:id="@+id/startCallButton"
|
||||||
@ -119,14 +121,15 @@
|
|||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="4"
|
android:layout_row="4"
|
||||||
android:text="end call" />
|
android:text="end call"
|
||||||
|
android:layout_columnSpan="2" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/setMusicInfoButton"
|
android:id="@+id/setMusicInfoButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_column="0"
|
android:layout_column="0"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="3"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="5"
|
android:layout_row="5"
|
||||||
android:text="set music info" />
|
android:text="set music info" />
|
||||||
@ -136,7 +139,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_column="0"
|
android:layout_column="0"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="3"
|
||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="7"
|
android:layout_row="7"
|
||||||
android:text="reboot" />
|
android:text="reboot" />
|
||||||
@ -159,6 +162,14 @@
|
|||||||
android:layout_gravity="fill_horizontal"
|
android:layout_gravity="fill_horizontal"
|
||||||
android:layout_row="6"
|
android:layout_row="6"
|
||||||
android:text="Import DB" />
|
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>
|
</GridLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user