X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FRetrieveAccountsTask.java;h=6e66453b38a6021bd54b8096d147db63e16c7e1e;hp=2c06849c87c74a1ff393a981cca0a391d1539cbd;hb=674b18d882411b94513d77c0aea39fd929a7a62b;hpb=f6c803b3c43e2601b3c5ed7f6b6a0e630a71cf6b
diff --git a/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java b/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java
index 2c06849c..6e66453b 100644
--- a/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java
+++ b/app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java
@@ -1,3 +1,20 @@
+/*
+ * Copyright © 2018 Damyan Ivanov.
+ * This file is part of Mobile-Ledger.
+ * Mobile-Ledger 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.
+ *
+ * Mobile-Ledger 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 Mobile-Ledger. If not, see .
+ */
+
package net.ktnx.mobileledger;
import android.content.SharedPreferences;
@@ -34,8 +51,6 @@ class RetrieveAccountsTask extends android.os.AsyncTask {
protected Void doInBackground(Void... params) {
try {
HttpURLConnection http = NetworkUtil.prepare_connection( pref, "add");
- http.setAllowUserInteraction(false);
- http.setRequestProperty("Accept-Charset", "UTF-8");
publishProgress(0);
try(MobileLedgerDatabase dbh = new MobileLedgerDatabase(mContext.get())) {
try(SQLiteDatabase db = dbh.getWritableDatabase()) {
@@ -163,9 +178,11 @@ class RetrieveAccountsTask extends android.os.AsyncTask {
do {
LedgerAccount acc = new LedgerAccount(name);
db.execSQL(
- "insert or replace into accounts(name, name_upper, level, parent_name, keep) "
- + "values(?, ?, ?, ?, 1)",
- new Object[]{name, name.toUpperCase(), acc.getLevel(), acc.getParentName()});
+ "update accounts set level = ?, keep = 1 where name = ?",
+ new Object[]{acc.getLevel(), name});
+ db.execSQL("insert into accounts(name, name_upper, parent_name, level) select ?,?,"
+ + "?,? " + "where (select changes() = 0)",
+ new Object[]{name, name.toUpperCase(), acc.getParentName(), acc.getLevel()});
name = acc.getParentName();
} while (name != null);
}