mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-05 01:37:03 +01:00
UI refactoring of the DB management activity.
Added a method to delete the legacy DB only.
This commit is contained in:
parent
e230bd1d07
commit
1e6cb67edd
@ -295,7 +295,7 @@ public class GBApplication extends Application {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the entire Activity database and recreates it with empty tables.
|
||||
* Deletes both the old Activity database and the new one recreates it with empty tables.
|
||||
*
|
||||
* @return true on successful deletion
|
||||
*/
|
||||
@ -313,6 +313,20 @@ public class GBApplication extends Application {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the legacy (pre 0.12) Activity database
|
||||
*
|
||||
* @return true on successful deletion
|
||||
*/
|
||||
public static synchronized boolean deleteOldActivityDatabase(Context context) {
|
||||
DBHelper dbHelper = new DBHelper(context);
|
||||
boolean result = true;
|
||||
if (dbHelper.existsDB(DBConstants.DATABASE_NAME)) {
|
||||
result = getContext().deleteDatabase(DBConstants.DATABASE_NAME);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getPrefsFileVersion() {
|
||||
try {
|
||||
return Integer.parseInt(sharedPrefs.getString(PREFS_VERSION, "0")); //0 is legacy
|
||||
|
@ -11,6 +11,7 @@ import android.support.v4.app.NavUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -37,7 +38,9 @@ public class DbManagementActivity extends GBActivity {
|
||||
private Button exportDBButton;
|
||||
private Button importDBButton;
|
||||
private Button importOldActivityDataButton;
|
||||
private Button deleteOldActivityDBButton;
|
||||
private Button deleteDBButton;
|
||||
private TextView dbPath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -47,6 +50,9 @@ public class DbManagementActivity extends GBActivity {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(GBApplication.ACTION_QUIT);
|
||||
|
||||
dbPath = (TextView) findViewById(R.id.activity_db_management_path);
|
||||
dbPath.setText(getExternalPath());
|
||||
|
||||
exportDBButton = (Button) findViewById(R.id.exportDBButton);
|
||||
exportDBButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -70,6 +76,14 @@ public class DbManagementActivity extends GBActivity {
|
||||
}
|
||||
});
|
||||
|
||||
deleteOldActivityDBButton = (Button) findViewById(R.id.deleteOldActivityDB);
|
||||
deleteOldActivityDBButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
deleteOldActivityDbFile();
|
||||
}
|
||||
});
|
||||
|
||||
deleteDBButton = (Button) findViewById(R.id.emptyDBButton);
|
||||
deleteDBButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -79,6 +93,14 @@ public class DbManagementActivity extends GBActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private String getExternalPath() {
|
||||
try {
|
||||
return FileUtils.getExternalFilesDir().getAbsolutePath();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return "Cannot access export path. Please contact the developers.";
|
||||
}
|
||||
|
||||
private void exportDB() {
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
DBHelper helper = new DBHelper(this);
|
||||
@ -203,6 +225,29 @@ public class DbManagementActivity extends GBActivity {
|
||||
.show();
|
||||
}
|
||||
|
||||
private void deleteOldActivityDbFile() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setTitle("Delete old Activity Database?")
|
||||
.setMessage("Really delete the old activity database? Activity data that were not imported will be lost.")
|
||||
.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (GBApplication.deleteOldActivityDatabase(DbManagementActivity.this)) {
|
||||
GB.toast(DbManagementActivity.this, "Old Activity database successfully deleted.", Toast.LENGTH_SHORT, GB.INFO);
|
||||
} else {
|
||||
GB.toast(DbManagementActivity.this, "Old Activity database deletion failed.", Toast.LENGTH_SHORT, GB.INFO);
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -2,36 +2,48 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView"
|
||||
android:id="@+id/scrollView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<GridLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/db_management_intro"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/activity_db_management_import_export_explanation"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activity_db_management_path"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:columnCount="3"
|
||||
android:rowCount="15"
|
||||
android:alignmentMode="alignMargins">
|
||||
|
||||
android:gravity="fill_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<Button
|
||||
android:id="@+id/exportDBButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="0"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="6"
|
||||
android:layout_weight="1"
|
||||
|
||||
android:singleLine="false"
|
||||
android:text="Export DB" />
|
||||
|
||||
@ -39,31 +51,59 @@
|
||||
android:id="@+id/importDBButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="1"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="6"
|
||||
android:layout_weight="1"
|
||||
android:text="Import DB" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mergeOldActivityDataText"
|
||||
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" />
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="@string/activity_db_management_merge_old_explanation"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="fill_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<Button
|
||||
android:id="@+id/mergeOldActivityData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="0"
|
||||
android:layout_columnSpan="3"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="7"
|
||||
android:text="Merge old activity data" />
|
||||
android:layout_weight="1"
|
||||
android:text="Import old activity data" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/deleteOldActivityDB"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_weight="1"
|
||||
android:text="Delete old DB" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyDBText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="Warning! By pushing this button you will wipe your database and start from scratch."
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/emptyDBButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Empty DB" />
|
||||
|
||||
|
||||
</GridLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -299,4 +299,6 @@
|
||||
<string name="pref_summary_pebble_health_store_raw">If checked the data is stored \"as is\" and is available for later interpretation. NB: the database will be bigger in this case!</string>
|
||||
<string name="action_db_management">Database Management</string>
|
||||
<string name="title_activity_db_management">Database management</string>
|
||||
<string name="activity_db_management_import_export_explanation">The database operations use the following path on your device. \nThis path is accessible to other android applications and your computer. \nExpect to find your exported database (or place the database you want to import) there:</string>
|
||||
<string name="activity_db_management_merge_old_explanation">The activity data recorded with Gadgetbridge versions prior to 0.12 must be converted to a new format. \nYou can do this using the button below. Be aware that you must be connected to the device you want to associate the old activity data with! \nIf you already imported your data and are happy with the result, you may delete the old database.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user