]> git.ktnx.net Git - mobile-ledger.git/commitdiff
developer menu item for wiping all local profile data
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Apr 2019 15:08:05 +0000 (18:08 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Apr 2019 15:09:01 +0000 (18:09 +0300)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/res/menu/profile_details.xml

index 3db7850f986be606fb60bdd33cd269355df6ebf7..93a954f0a674bc95354eeb70d6c00831293f487b 100644 (file)
@@ -426,4 +426,20 @@ public final class MobileLedgerProfile {
 
         return result;
     }
+    public void wipeAllData() {
+        SQLiteDatabase db = MLDB.getDatabase();
+        db.beginTransaction();
+        try {
+            String[] pUuid = new String[]{uuid};
+            db.execSQL("delete from options where profile=?", pUuid);
+            db.execSQL("delete from accounts where profile=?", pUuid);
+            db.execSQL("delete from account_values where profile=?", pUuid);
+            db.execSQL("delete from transactions where profile=?", pUuid);
+            db.execSQL("delete from transaction_accounts where profile=?", pUuid);
+            db.setTransactionSuccessful();
+        }
+        finally {
+            db.endTransaction();
+        }
+    }
 }
index 8f3daed46ddb965d59c771210059f1749b3ed453..0021e2ce5cf308e2c3fd05188bf79e13fe621104 100644 (file)
@@ -38,6 +38,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
 import com.google.android.material.floatingactionbutton.FloatingActionButton;
 import com.google.android.material.textfield.TextInputLayout;
 
+import net.ktnx.mobileledger.BuildConfig;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
@@ -116,6 +117,18 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             return false;
         });
         menuDeleteProfile.setVisible((mProfile != null) && (Data.profiles.size() > 1));
+
+        if (BuildConfig.DEBUG) {
+            final MenuItem menuWipeProfileData = menu.findItem(R.id.menuWipeData);
+            menuWipeProfileData.setOnMenuItemClickListener(this::onWipeDataMenuClicked);
+            menuWipeProfileData.setVisible(mProfile != null);
+        }
+    }
+    private boolean onWipeDataMenuClicked(MenuItem item) {
+        // this is a development option, so no confirmation
+        mProfile.wipeAllData();
+        Data.profile.forceNotifyObservers();
+        return true;
     }
     @Override
     public void onCreate(Bundle savedInstanceState) {
index ec883bd8bc72d37d53e36cd441164dd38c0e1e5f..18d01233c639ef27dc230348af944f4fb5e8a706 100644 (file)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright © 2019 Damyan Ivanov.
   ~ This file is part of MoLe.
   ~ MoLe is free software: you can distribute it and/or modify it
@@ -17,7 +16,8 @@
   -->
 
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools">
 
     <item
         android:id="@+id/menuDelete"
         android:title="@string/delete_profile"
         android:titleCondensed="@string/delete"
         app:showAsAction="ifRoom" />
+    <item
+        android:id="@+id/menuWipeData"
+        android:title="Wipe profile data"
+        android:titleCondensed="Wipe"
+        app:showAsAction="never"
+        android:visible="false"
+        tools:ignore="HardcodedText" />
 </menu>
\ No newline at end of file