From 41d543229f3231469247e10ec6c197920c0e8bc4 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 12 Sep 2021 14:30:56 +0300 Subject: [PATCH] provide cloud backup functionality --- app/src/main/AndroidManifest.xml | 1 + .../ktnx/mobileledger/BackupsActivity.java | 4 +- .../{async => backup}/ConfigIO.java | 2 +- .../mobileledger/backup/ConfigReader.java | 76 ++++++++ .../mobileledger/backup/ConfigWriter.java | 56 ++++++ .../backup/MobileLedgerBackupAgent.java | 74 ++++++++ .../RawConfigReader.java} | 169 ++++++++---------- .../RawConfigWriter.java} | 112 +++++------- .../ui/profiles/ProfileDetailFragment.java | 3 + 9 files changed, 331 insertions(+), 166 deletions(-) rename app/src/main/java/net/ktnx/mobileledger/{async => backup}/ConfigIO.java (99%) create mode 100644 app/src/main/java/net/ktnx/mobileledger/backup/ConfigReader.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/backup/ConfigWriter.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/backup/MobileLedgerBackupAgent.java rename app/src/main/java/net/ktnx/mobileledger/{async/ConfigReader.java => backup/RawConfigReader.java} (80%) rename app/src/main/java/net/ktnx/mobileledger/{async/ConfigWriter.java => backup/RawConfigWriter.java} (59%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a8d20d90..e3ec6ee1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,7 @@ android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@drawable/app_icon_round" android:supportsRtl="true" + android:backupAgent="net.ktnx.mobileledger.backup.MobileLedgerBackupAgent" tools:ignore="GoogleAppIndexingWarning"> . */ -package net.ktnx.mobileledger.async; +package net.ktnx.mobileledger.backup; import android.content.Context; import android.net.Uri; diff --git a/app/src/main/java/net/ktnx/mobileledger/backup/ConfigReader.java b/app/src/main/java/net/ktnx/mobileledger/backup/ConfigReader.java new file mode 100644 index 00000000..7959da51 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/backup/ConfigReader.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2021 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + +package net.ktnx.mobileledger.backup; + +import android.content.Context; +import android.net.Uri; + +import net.ktnx.mobileledger.dao.ProfileDAO; +import net.ktnx.mobileledger.db.DB; +import net.ktnx.mobileledger.db.Profile; +import net.ktnx.mobileledger.model.Data; +import net.ktnx.mobileledger.utils.Misc; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class ConfigReader extends ConfigIO { + private final OnDoneListener onDoneListener; + private RawConfigReader r; + public ConfigReader(Context context, Uri uri, OnErrorListener onErrorListener, + OnDoneListener onDoneListener) throws FileNotFoundException { + super(context, uri, onErrorListener); + + this.onDoneListener = onDoneListener; + } + @Override + protected String getStreamMode() { + return "r"; + } + @Override + protected void initStream() { + RawConfigReader r = new RawConfigReader(new FileInputStream(pfd.getFileDescriptor())); + } + @Override + protected void processStream() throws IOException { + r.readConfig(); + r.restoreAll(); + String currentProfile = r.getCurrentProfile(); + + if (Data.getProfile() == null) { + Profile p = null; + final ProfileDAO dao = DB.get() + .getProfileDAO(); + if (currentProfile != null) + p = dao.getByUuidSync(currentProfile); + + if (p == null) + dao.getAnySync(); + + if (p != null) + Data.postCurrentProfile(p); + } + + if (onDoneListener != null) + Misc.onMainThread(onDoneListener::done); + } + abstract static public class OnDoneListener { + public abstract void done(); + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/backup/ConfigWriter.java b/app/src/main/java/net/ktnx/mobileledger/backup/ConfigWriter.java new file mode 100644 index 00000000..b1a2814e --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/backup/ConfigWriter.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2021 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + +package net.ktnx.mobileledger.backup; + +import android.content.Context; +import android.net.Uri; + +import net.ktnx.mobileledger.utils.Misc; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class ConfigWriter extends ConfigIO { + private final OnDoneListener onDoneListener; + private RawConfigWriter w; + public ConfigWriter(Context context, Uri uri, OnErrorListener onErrorListener, + OnDoneListener onDoneListener) throws FileNotFoundException { + super(context, uri, onErrorListener); + + this.onDoneListener = onDoneListener; + } + @Override + protected String getStreamMode() { + return "w"; + } + @Override + protected void initStream() { + w = new RawConfigWriter(new FileOutputStream(pfd.getFileDescriptor())); + } + @Override + protected void processStream() throws IOException { + w.writeConfig(); + + if (onDoneListener != null) + Misc.onMainThread(onDoneListener::done); + } + abstract static public class OnDoneListener { + public abstract void done(); + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/backup/MobileLedgerBackupAgent.java b/app/src/main/java/net/ktnx/mobileledger/backup/MobileLedgerBackupAgent.java new file mode 100644 index 00000000..ea09e514 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/backup/MobileLedgerBackupAgent.java @@ -0,0 +1,74 @@ +/* + * Copyright © 2021 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + +package net.ktnx.mobileledger.backup; + +import android.app.backup.BackupAgentHelper; +import android.app.backup.BackupDataInput; +import android.app.backup.BackupDataOutput; +import android.os.ParcelFileDescriptor; + +import net.ktnx.mobileledger.db.DB; +import net.ktnx.mobileledger.utils.Logger; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +class MobileLedgerBackupAgent extends BackupAgentHelper { + private static final int READ_BUF_LEN = 10; + public static String SETTINGS_KEY = "settings"; + @Override + public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, + ParcelFileDescriptor newState) throws IOException { + super.onBackup(oldState, data, newState); + backupSettings(data); + newState.close(); + } + private void backupSettings(BackupDataOutput data) throws IOException { + Logger.debug ("backup", "Starting cloud backup"); + ByteArrayOutputStream output = new ByteArrayOutputStream(4096); + RawConfigWriter saver = new RawConfigWriter(output); + saver.writeConfig(); + byte[] bytes = output.toByteArray(); + data.writeEntityHeader(SETTINGS_KEY, bytes.length); + data.writeEntityData(bytes, bytes.length); + Logger.debug("backup", "Done writing backup data"); + } + @Override + public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) + throws IOException { + Logger.debug("restore", "Starting cloud restore"); + if (data.readNextHeader()) { + String key = data.getKey(); + if (key.equals(SETTINGS_KEY)) { + restoreSettings(data); + } + } + } + private void restoreSettings(BackupDataInput data) throws IOException { + byte[] bytes = new byte[data.getDataSize()]; + data.readEntityData(bytes, 0, bytes.length); + RawConfigReader reader = new RawConfigReader(new ByteArrayInputStream(bytes)); + reader.readConfig(); + Logger.debug("restore", "Successfully read restore data. Wiping database"); + DB.get().deleteAllSync(); + Logger.debug("restore", "Database wiped"); + reader.restoreAll(); + Logger.debug("restore", "All data restored from the cloud"); + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/async/ConfigReader.java b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java similarity index 80% rename from app/src/main/java/net/ktnx/mobileledger/async/ConfigReader.java rename to app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java index a894f92f..45a593d7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/ConfigReader.java +++ b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java @@ -15,13 +15,12 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.async; +package net.ktnx.mobileledger.backup; -import android.content.Context; -import android.net.Uri; import android.util.JsonReader; import android.util.JsonToken; +import net.ktnx.mobileledger.backup.ConfigIO.Keys; import net.ktnx.mobileledger.dao.CurrencyDAO; import net.ktnx.mobileledger.dao.ProfileDAO; import net.ktnx.mobileledger.dao.TemplateHeaderDAO; @@ -31,41 +30,40 @@ import net.ktnx.mobileledger.db.Profile; import net.ktnx.mobileledger.db.TemplateAccount; import net.ktnx.mobileledger.db.TemplateHeader; import net.ktnx.mobileledger.db.TemplateWithAccounts; -import net.ktnx.mobileledger.model.Data; -import net.ktnx.mobileledger.utils.Misc; import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -public class ConfigReader extends ConfigIO { - private final OnDoneListener onDoneListener; - private JsonReader r; - public ConfigReader(Context context, Uri uri, OnErrorListener onErrorListener, - OnDoneListener onDoneListener) throws FileNotFoundException { - super(context, uri, onErrorListener); - - this.onDoneListener = onDoneListener; +public class RawConfigReader { + private final JsonReader r; + private List commodities; + private List profiles; + private List templates; + private String currentProfile; + public RawConfigReader(InputStream inputStream) { + r = new JsonReader(new BufferedReader(new InputStreamReader(inputStream))); + } + public List getCommodities() { + return commodities; } - @Override - protected String getStreamMode() { - return "r"; + public List getProfiles() { + return profiles; } - @Override - protected void initStream() { - r = new JsonReader(new BufferedReader( - new InputStreamReader(new FileInputStream(pfd.getFileDescriptor())))); + public List getTemplates() { + return templates; } - @Override - protected void processStream() throws IOException { - List commodities = null; - List profiles = null; - List templates = null; - String currentProfile = null; + public String getCurrentProfile() { + return currentProfile; + } + public void readConfig() throws IOException { + commodities = null; + profiles = null; + templates = null; + currentProfile = null; r.beginObject(); while (r.hasNext()) { String item = r.nextName(); @@ -75,13 +73,13 @@ public class ConfigReader extends ConfigIO { } switch (item) { case Keys.COMMODITIES: - commodities = readCommodities(r); + commodities = readCommodities(); break; case Keys.PROFILES: - profiles = readProfiles(r); + profiles = readProfiles(); break; case Keys.TEMPLATES: - templates = readTemplates(r); + templates = readTemplates(); break; case Keys.CURRENT_PROFILE: currentProfile = r.nextString(); @@ -91,65 +89,8 @@ public class ConfigReader extends ConfigIO { } } r.endObject(); - - restoreCommodities(commodities); - restoreProfiles(profiles); - restoreTemplates(templates); - - if (Data.getProfile() == null) { - Profile p = null; - final ProfileDAO dao = DB.get() - .getProfileDAO(); - if (currentProfile != null) - p = dao.getByUuidSync(currentProfile); - - if (p == null) - dao.getAnySync(); - - if (p != null) - Data.postCurrentProfile(p); - } - - if (onDoneListener != null) - Misc.onMainThread(onDoneListener::done); - } - private void restoreTemplates(List list) { - if (list == null) - return; - - TemplateHeaderDAO dao = DB.get() - .getTemplateDAO(); - - for (TemplateWithAccounts t : list) { - if (dao.getTemplateWithAccountsByUuidSync(t.header.getUuid()) == null) - dao.insertSync(t); - } - } - private void restoreProfiles(List list) { - if (list == null) - return; - - ProfileDAO dao = DB.get() - .getProfileDAO(); - - for (Profile p : list) { - if (dao.getByUuidSync(p.getUuid()) == null) - dao.insert(p); - } } - private void restoreCommodities(List list) { - if (list == null) - return; - - CurrencyDAO dao = DB.get() - .getCurrencyDAO(); - - for (Currency c : list) { - if (dao.getByNameSync(c.getName()) == null) - dao.insert(c); - } - } - private TemplateAccount readTemplateAccount(JsonReader r) throws IOException { + private TemplateAccount readTemplateAccount() throws IOException { r.beginObject(); TemplateAccount result = new TemplateAccount(0L, 0L, 0L); while (r.peek() != JsonToken.END_OBJECT) { @@ -256,7 +197,7 @@ public class ConfigReader extends ConfigIO { case Keys.ACCOUNTS: r.beginArray(); while (r.peek() == JsonToken.BEGIN_OBJECT) { - accounts.add(readTemplateAccount(r)); + accounts.add(readTemplateAccount()); } r.endArray(); break; @@ -271,7 +212,7 @@ public class ConfigReader extends ConfigIO { result.accounts = accounts; return result; } - private List readTemplates(JsonReader r) throws IOException { + private List readTemplates() throws IOException { List list = new ArrayList<>(); r.beginArray(); @@ -282,7 +223,7 @@ public class ConfigReader extends ConfigIO { return list; } - private List readCommodities(JsonReader r) throws IOException { + private List readCommodities() throws IOException { List list = new ArrayList<>(); r.beginArray(); @@ -322,7 +263,7 @@ public class ConfigReader extends ConfigIO { return list; } - private List readProfiles(JsonReader r) throws IOException { + private List readProfiles() throws IOException { List list = new ArrayList<>(); r.beginArray(); while (r.peek() == JsonToken.BEGIN_OBJECT) { @@ -392,7 +333,45 @@ public class ConfigReader extends ConfigIO { return list; } - abstract static public class OnDoneListener { - public abstract void done(); + public void restoreAll() { + restoreCommodities(); + restoreProfiles(); + restoreTemplates(); + } + private void restoreTemplates() { + if (templates == null) + return; + + TemplateHeaderDAO dao = DB.get() + .getTemplateDAO(); + + for (TemplateWithAccounts t : templates) { + if (dao.getTemplateWithAccountsByUuidSync(t.header.getUuid()) == null) + dao.insertSync(t); + } + } + private void restoreProfiles() { + if (profiles == null) + return; + + ProfileDAO dao = DB.get() + .getProfileDAO(); + + for (Profile p : profiles) { + if (dao.getByUuidSync(p.getUuid()) == null) + dao.insert(p); + } + } + private void restoreCommodities() { + if (commodities == null) + return; + + CurrencyDAO dao = DB.get() + .getCurrencyDAO(); + + for (Currency c : commodities) { + if (dao.getByNameSync(c.getName()) == null) + dao.insert(c); + } } } diff --git a/app/src/main/java/net/ktnx/mobileledger/async/ConfigWriter.java b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigWriter.java similarity index 59% rename from app/src/main/java/net/ktnx/mobileledger/async/ConfigWriter.java rename to app/src/main/java/net/ktnx/mobileledger/backup/RawConfigWriter.java index f72a2913..751a74a0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/ConfigWriter.java +++ b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigWriter.java @@ -15,12 +15,11 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.async; +package net.ktnx.mobileledger.backup; -import android.content.Context; -import android.net.Uri; import android.util.JsonWriter; +import net.ktnx.mobileledger.backup.ConfigIO.Keys; import net.ktnx.mobileledger.db.Currency; import net.ktnx.mobileledger.db.DB; import net.ktnx.mobileledger.db.Profile; @@ -28,73 +27,54 @@ import net.ktnx.mobileledger.db.TemplateAccount; import net.ktnx.mobileledger.db.TemplateWithAccounts; import net.ktnx.mobileledger.json.API; import net.ktnx.mobileledger.model.Data; -import net.ktnx.mobileledger.utils.Misc; import java.io.BufferedWriter; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.List; -public class ConfigWriter extends ConfigIO { - private final OnDoneListener onDoneListener; - private JsonWriter w; - public ConfigWriter(Context context, Uri uri, OnErrorListener onErrorListener, - OnDoneListener onDoneListener) throws FileNotFoundException { - super(context, uri, onErrorListener); - - this.onDoneListener = onDoneListener; - } - @Override - protected String getStreamMode() { - return "w"; - } - @Override - protected void initStream() { - w = new JsonWriter(new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(pfd.getFileDescriptor())))); +public class RawConfigWriter { + private final JsonWriter w; + public RawConfigWriter(OutputStream outputStream) { + w = new JsonWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); w.setIndent(" "); } - @Override - protected void processStream() throws IOException { + public void writeConfig() throws IOException { w.beginObject(); - writeCommodities(w); - writeProfiles(w); - writeCurrentProfile(w); - writeConfigTemplates(w); + writeCommodities(); + writeProfiles(); + writeCurrentProfile(); + writeConfigTemplates(); w.endObject(); w.flush(); - - if (onDoneListener != null) - Misc.onMainThread(onDoneListener::done); } - private void writeKey(JsonWriter w, String key, String value) throws IOException { + private void writeKey(String key, String value) throws IOException { if (value != null) w.name(key) .value(value); } - private void writeKey(JsonWriter w, String key, Integer value) throws IOException { + private void writeKey(String key, Integer value) throws IOException { if (value != null) w.name(key) .value(value); } - private void writeKey(JsonWriter w, String key, Long value) throws IOException { + private void writeKey(String key, Long value) throws IOException { if (value != null) w.name(key) .value(value); } - private void writeKey(JsonWriter w, String key, Float value) throws IOException { + private void writeKey(String key, Float value) throws IOException { if (value != null) w.name(key) .value(value); } - private void writeKey(JsonWriter w, String key, Boolean value) throws IOException { + private void writeKey(String key, Boolean value) throws IOException { if (value != null) w.name(key) .value(value); } - private void writeConfigTemplates(JsonWriter w) throws IOException { + private void writeConfigTemplates() throws IOException { List templates = DB.get() .getTemplateDAO() .getAllTemplatesWithAccountsSync(); @@ -113,17 +93,17 @@ public class ConfigWriter extends ConfigIO { .value(t.header.getName()); w.name(Keys.REGEX) .value(t.header.getRegularExpression()); - writeKey(w, Keys.TEST_TEXT, t.header.getTestText()); - writeKey(w, Keys.DATE_YEAR, t.header.getDateYear()); - writeKey(w, Keys.DATE_YEAR_GROUP, t.header.getDateYearMatchGroup()); - writeKey(w, Keys.DATE_MONTH, t.header.getDateMonth()); - writeKey(w, Keys.DATE_MONTH_GROUP, t.header.getDateMonthMatchGroup()); - writeKey(w, Keys.DATE_DAY, t.header.getDateDay()); - writeKey(w, Keys.DATE_DAY_GROUP, t.header.getDateDayMatchGroup()); - writeKey(w, Keys.TRANSACTION, t.header.getTransactionDescription()); - writeKey(w, Keys.TRANSACTION_GROUP, t.header.getTransactionDescriptionMatchGroup()); - writeKey(w, Keys.COMMENT, t.header.getTransactionComment()); - writeKey(w, Keys.COMMENT_GROUP, t.header.getTransactionCommentMatchGroup()); + writeKey(Keys.TEST_TEXT, t.header.getTestText()); + writeKey(ConfigIO.Keys.DATE_YEAR, t.header.getDateYear()); + writeKey(Keys.DATE_YEAR_GROUP, t.header.getDateYearMatchGroup()); + writeKey(Keys.DATE_MONTH, t.header.getDateMonth()); + writeKey(Keys.DATE_MONTH_GROUP, t.header.getDateMonthMatchGroup()); + writeKey(Keys.DATE_DAY, t.header.getDateDay()); + writeKey(Keys.DATE_DAY_GROUP, t.header.getDateDayMatchGroup()); + writeKey(Keys.TRANSACTION, t.header.getTransactionDescription()); + writeKey(Keys.TRANSACTION_GROUP, t.header.getTransactionDescriptionMatchGroup()); + writeKey(Keys.COMMENT, t.header.getTransactionComment()); + writeKey(Keys.COMMENT_GROUP, t.header.getTransactionCommentMatchGroup()); w.name(Keys.IS_FALLBACK) .value(t.header.isFallback()); if (t.accounts.size() > 0) { @@ -132,15 +112,15 @@ public class ConfigWriter extends ConfigIO { for (TemplateAccount a : t.accounts) { w.beginObject(); - writeKey(w, Keys.NAME, a.getAccountName()); - writeKey(w, Keys.NAME_GROUP, a.getAccountNameMatchGroup()); - writeKey(w, Keys.COMMENT, a.getAccountComment()); - writeKey(w, Keys.COMMENT_GROUP, a.getAccountCommentMatchGroup()); - writeKey(w, Keys.AMOUNT, a.getAmount()); - writeKey(w, Keys.AMOUNT_GROUP, a.getAmountMatchGroup()); - writeKey(w, Keys.NEGATE_AMOUNT, a.getNegateAmount()); - writeKey(w, Keys.CURRENCY, a.getCurrency()); - writeKey(w, Keys.CURRENCY_GROUP, a.getCurrencyMatchGroup()); + writeKey(Keys.NAME, a.getAccountName()); + writeKey(Keys.NAME_GROUP, a.getAccountNameMatchGroup()); + writeKey(Keys.COMMENT, a.getAccountComment()); + writeKey(Keys.COMMENT_GROUP, a.getAccountCommentMatchGroup()); + writeKey(Keys.AMOUNT, a.getAmount()); + writeKey(Keys.AMOUNT_GROUP, a.getAmountMatchGroup()); + writeKey(Keys.NEGATE_AMOUNT, a.getNegateAmount()); + writeKey(Keys.CURRENCY, a.getCurrency()); + writeKey(Keys.CURRENCY_GROUP, a.getCurrencyMatchGroup()); w.endObject(); } @@ -151,7 +131,7 @@ public class ConfigWriter extends ConfigIO { } w.endArray(); } - private void writeCommodities(JsonWriter w) throws IOException { + private void writeCommodities() throws IOException { List list = DB.get() .getCurrencyDAO() .getAllSync(); @@ -161,14 +141,14 @@ public class ConfigWriter extends ConfigIO { .beginArray(); for (Currency c : list) { w.beginObject(); - writeKey(w, Keys.NAME, c.getName()); - writeKey(w, Keys.POSITION, c.getPosition()); - writeKey(w, Keys.HAS_GAP, c.getHasGap()); + writeKey(Keys.NAME, c.getName()); + writeKey(Keys.POSITION, c.getPosition()); + writeKey(Keys.HAS_GAP, c.getHasGap()); w.endObject(); } w.endArray(); } - private void writeProfiles(JsonWriter w) throws IOException { + private void writeProfiles() throws IOException { List profiles = DB.get() .getProfileDAO() .getAllOrderedSync(); @@ -221,7 +201,7 @@ public class ConfigWriter extends ConfigIO { } w.endArray(); } - private void writeCurrentProfile(JsonWriter w) throws IOException { + private void writeCurrentProfile() throws IOException { Profile currentProfile = Data.getProfile(); if (currentProfile == null) return; @@ -229,8 +209,4 @@ public class ConfigWriter extends ConfigIO { w.name(Keys.CURRENT_PROFILE) .value(currentProfile.getUuid()); } - - abstract static public class OnDoneListener { - public abstract void done(); - } } 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 fce5967f..ab0d07d9 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 @@ -19,6 +19,7 @@ package net.ktnx.mobileledger.ui.profiles; import android.app.Activity; import android.app.AlertDialog; +import android.app.backup.BackupManager; import android.graphics.Typeface; import android.os.Bundle; import android.text.Editable; @@ -408,6 +409,8 @@ public class ProfileDetailFragment extends Fragment { dao.insertLast(profile, null); } + BackupManager.dataChanged(BuildConfig.APPLICATION_ID); + Activity activity = getActivity(); if (activity != null) activity.finish(); -- 2.39.2