From: Damyan Ivanov Date: Sat, 5 Jan 2019 15:48:10 +0000 (+0000) Subject: parse and show ledger name X-Git-Tag: v0.3~110 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=bb21e22f7b251a22cc830358e9f2c1d2911965c4;p=mobile-ledger.git parse and show ledger name --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 5a65f57a..ad064121 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -61,6 +61,7 @@ public class RetrieveTransactionsTask extends protected WeakReference contextRef; protected int error; // %3A is '=' + private Pattern ledger_title_re = Pattern.compile("

([^<]+)

"); Pattern account_name_re = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\""); Pattern account_value_re = Pattern.compile( "\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?"); @@ -125,6 +126,8 @@ public class RetrieveTransactionsTask extends String.format("HTTP error %d", http.getResponseCode())); db.beginTransaction(); try { + String ledgerTitle = null; + db.execSQL("UPDATE transactions set keep=0"); db.execSQL("update account_values set keep=0;"); db.execSQL("update accounts set keep=0;"); @@ -165,6 +168,13 @@ public class RetrieveTransactionsTask extends state = ParserState.EXPECTING_ACCOUNT_AMOUNT; L("→ expecting account amount"); } + else if (ledgerTitle == null) { + m = ledger_title_re.matcher(line); + if (m.find()) { + ledgerTitle = m.group(1); + Data.ledgerTitle.set(ledgerTitle); + } + } break; case EXPECTING_ACCOUNT_AMOUNT: diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index ba0c5a64..beb8dd54 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -28,4 +28,5 @@ public final class Data { public static ObservableValue> descriptions = new ObservableValue<>(); public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0); public static ObservableValue lastUpdateDate = new ObservableValue<>(); + public static ObservableValue ledgerTitle = new ObservableValue<>(); } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 6e17983b..0ed83719 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -139,6 +139,19 @@ public class MainActivity extends AppCompatActivity { scheduleTransactionListRetrieval(); } + + Data.ledgerTitle.addObserver(new Observer() { + @Override + public void update(Observable o, Object arg) { + runOnUiThread(() -> { + String title = Data.ledgerTitle.get(); + if (title == null) + toolbar.setSubtitle(""); + else + toolbar.setSubtitle(title); + }); + } + }); } public void fab_new_transaction_clicked(View view) { Intent intent = new Intent(this, NewTransactionActivity.class);