+
+ static class AccountListLoader extends Thread {
+ MobileLedgerProfile profile;
+ AccountListLoader(MobileLedgerProfile profile) {
+ this.profile = profile;
+ }
+ @Override
+ public void run() {
+ Logger.debug("async-acc", "AccountListLoader::run() entered");
+ String profileUUID = profile.getUuid();
+ ArrayList<LedgerAccount> newList = new ArrayList<>();
+
+ String sql = "SELECT a.name from accounts a WHERE a.profile = ?";
+ sql += " ORDER BY a.name";
+
+ SQLiteDatabase db = App.getDatabase();
+ try (Cursor cursor = db.rawQuery(sql, new String[]{profileUUID})) {
+ while (cursor.moveToNext()) {
+ if (isInterrupted())
+ return;
+
+ final String accName = cursor.getString(0);
+// debug("accounts",
+// String.format("Read account '%s' from DB [%s]", accName,
+// profileUUID));
+ LedgerAccount acc = profile.loadAccount(db, accName);
+ if (acc.isVisible(newList))
+ newList.add(acc);
+ }
+ }
+
+ if (isInterrupted())
+ return;
+
+ Logger.debug("async-acc", "AccountListLoader::run() posting new list");
+ profile.accounts.postValue(newList);
+ }
+ }