]> git.ktnx.net Git - mobile-ledger.git/commitdiff
parse and show ledger name
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 5 Jan 2019 15:48:10 +0000 (15:48 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 5 Jan 2019 15:48:10 +0000 (15:48 +0000)
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 5a65f57a6ee08ce2a555c78703980d9315c624d5..ad0641216b68b28cbb98292d04b1a082df2cec7b 100644 (file)
@@ -61,6 +61,7 @@ public class RetrieveTransactionsTask extends
     protected WeakReference<MainActivity> contextRef;
     protected int error;
     // %3A is '='
+    private Pattern ledger_title_re = Pattern.compile("<h1>([^<]+)</h1>");
     Pattern account_name_re = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\"");
     Pattern account_value_re = Pattern.compile(
             "<span class=\"[^\"]*\\bamount\\b[^\"]*\">\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?</span>");
@@ -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:
index ba0c5a649460bd719b9c921bd861ea47d0615087..beb8dd5438ba208511dede8ab7890ab7b88bffb6 100644 (file)
@@ -28,4 +28,5 @@ public final class Data {
     public static ObservableValue<List<String>> descriptions = new ObservableValue<>();
     public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0);
     public static ObservableValue<Date> lastUpdateDate = new ObservableValue<>();
+    public static ObservableValue<String> ledgerTitle = new ObservableValue<>();
 }
index 6e17983bf0b43b4f3dad5b516e1d76ad6ce470ec..0ed837197df4950e228cc90f30f073a96a3c7f49 100644 (file)
@@ -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);