X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FRetrieveAccountsTask.java;h=8602ed1430f48845410597bf387bee1ac295c176;hp=94eaa1bdd59a849f4585c8f72d1572df48211465;hb=1aadcdeec93fc8892a8323735334890cd8859c80;hpb=2dbf35771643d7799bdc96fe9cd5c0a465f75c71 diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveAccountsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveAccountsTask.java index 94eaa1bd..8602ed14 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveAccountsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveAccountsTask.java @@ -23,8 +23,9 @@ import android.os.OperationCanceledException; import android.util.Log; import net.ktnx.mobileledger.R; +import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.LedgerAccount; -import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment; +import net.ktnx.mobileledger.ui.activity.MainActivity; import net.ktnx.mobileledger.utils.MLDB; import net.ktnx.mobileledger.utils.NetworkUtil; @@ -42,10 +43,10 @@ import java.util.regex.Pattern; public class RetrieveAccountsTask extends android.os.AsyncTask { int error; - WeakReference mContext; + WeakReference mContext; private SharedPreferences pref; - public RetrieveAccountsTask(WeakReference context) { + public RetrieveAccountsTask(WeakReference context) { mContext = context; error = 0; } @@ -55,119 +56,117 @@ public class RetrieveAccountsTask extends android.os.AsyncTask\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?"); + Pattern tr_end_re = Pattern.compile(""); + Pattern descriptions_line_re = + Pattern.compile("\\bdescriptionsSuggester\\s*=\\s*new\\b"); + Pattern description_items_re = Pattern.compile("\"value\":\"([^\"]+)\""); + int count = 0; + while ((line = buf.readLine()) != null) { + throwIfCancelled(); + + Matcher m = account_name_re.matcher(line); + if (m.find()) { + String acct_encoded = m.group(1); + String acct_name = URLDecoder.decode(acct_encoded, "UTF-8"); + acct_name = acct_name.replace("\"", ""); + Log.d("account-parser", acct_name); + + addAccount(db, acct_name); + publishProgress(++count); + + last_account_name = acct_name; + + continue; + } - Matcher tr_m = tr_re.matcher(line); - if (tr_m.find()) { - Log.d("account-parser", " - another account expected"); - last_account_name = null; - continue; - } + Matcher tr_m = tr_end_re.matcher(line); + if (tr_m.find()) { + Log.d("account-parser", " - another account expected"); + last_account_name = null; + continue; + } - if (last_account_name != null) { - m = value_re.matcher(line); - boolean match_found = false; - while (m.find()) { - throwIfCancelled(); - - match_found = true; - String value = m.group(1); - String currency = m.group(2); - if (currency == null) currency = ""; - value = value.replace(',', '.'); - Log.d("db", "curr=" + currency + ", value=" + value); - db.execSQL( - "insert or replace into account_values(account, currency, value, keep) values(?, ?, ?, 1);", - new Object[]{last_account_name, currency, - Float.valueOf(value) - }); - } - - if (match_found) continue; + if (last_account_name != null) { + m = account_value_re.matcher(line); + boolean match_found = false; + while (m.find()) { + throwIfCancelled(); + + match_found = true; + String value = m.group(1); + String currency = m.group(2); + if (currency == null) currency = ""; + value = value.replace(',', '.'); + Log.d("db", "curr=" + currency + ", value=" + value); + db.execSQL( + "insert or replace into account_values(account, currency, value, keep) values(?, ?, ?, 1);", + new Object[]{last_account_name, currency, + Float.valueOf(value) + }); } - m = descriptions_line_re.matcher(line); - if (m.find()) { - db.execSQL("update description_history set keep=0;"); - m = description_items_re.matcher(line); - while (m.find()) { - throwIfCancelled(); - - String description = m.group(1); - if (description.isEmpty()) continue; - - Log.d("db", String.format("Stored description: %s", - description)); - db.execSQL("insert or replace into description_history" + - "(description, description_upper, keep) " + - "values(?, ?, 1);", - new Object[]{description, description.toUpperCase() - }); - } - } + if (match_found) continue; } - db.execSQL("delete from account_values where keep=0;"); - db.execSQL("delete from accounts where keep=0;"); - db.setTransactionSuccessful(); - } - catch (OperationCanceledException e) { - Log.w("async", "Account retrieval cancelled"); - } - finally { - db.endTransaction(); + m = descriptions_line_re.matcher(line); + if (m.find()) { + db.execSQL("update description_history set keep=0;"); + m = description_items_re.matcher(line); + while (m.find()) { + throwIfCancelled(); + + String description = m.group(1); + if (description.isEmpty()) continue; + + Log.d("db", + String.format("Stored description: %s", description)); + db.execSQL("insert or replace into description_history" + + "(description, description_upper, keep) " + + "values(?, ?, 1);", + new Object[]{description, description.toUpperCase() + }); + } + } } + + db.execSQL("delete from account_values where keep=0;"); + db.execSQL("delete from accounts where keep=0;"); + db.setTransactionSuccessful(); + } + catch (OperationCanceledException e) { + Log.w("async", "Account retrieval cancelled"); + } + finally { + db.endTransaction(); } } } @@ -188,6 +187,10 @@ public class RetrieveAccountsTask extends android.os.AsyncTask