From cd2ce61529771ef3054e4fa501ce64fcff9fa818 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 12 Apr 2019 18:08:05 +0300 Subject: [PATCH] developer menu item for wiping all local profile data --- .../mobileledger/model/MobileLedgerProfile.java | 16 ++++++++++++++++ .../ui/profiles/ProfileDetailFragment.java | 13 +++++++++++++ app/src/main/res/menu/profile_details.xml | 13 ++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 3db7850f..93a954f0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -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(); + } + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 8f3daed4..0021e2ce 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -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) { diff --git a/app/src/main/res/menu/profile_details.xml b/app/src/main/res/menu/profile_details.xml index ec883bd8..18d01233 100644 --- a/app/src/main/res/menu/profile_details.xml +++ b/app/src/main/res/menu/profile_details.xml @@ -1,5 +1,4 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + \ No newline at end of file -- 2.39.5