+ private void onQrScanned(String text) {
+ Logger.debug("qr", String.format("Got QR scan result [%s]", text));
+ Pattern p =
+ Pattern.compile("^(\\d+)\\*(\\d+)\\*(\\d+)-(\\d+)-(\\d+)\\*([:\\d]+)\\*([\\d.]+)$");
+ Matcher m = p.matcher(text);
+ if (m.matches()) {
+ float amount = Float.parseFloat(m.group(7));
+ viewModel.setDate(
+ new SimpleDate(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)),
+ Integer.parseInt(m.group(5))));
+
+ if (viewModel.accountsInInitialState()) {
+ {
+ NewTransactionModel.Item firstItem = viewModel.getItem(1);
+ if (firstItem == null) {
+ viewModel.addAccount(new LedgerTransactionAccount("разход:пазар"));
+ listAdapter.notifyItemInserted(viewModel.items.size() - 1);
+ }
+ else {
+ firstItem.setAccountName("разход:пазар");
+ firstItem.getAccount()
+ .resetAmount();
+ listAdapter.notifyItemChanged(1);
+ }
+ }
+ {
+ NewTransactionModel.Item secondItem = viewModel.getItem(2);
+ if (secondItem == null) {
+ viewModel.addAccount(
+ new LedgerTransactionAccount("актив:кеш:дам", -amount, null, null));
+ listAdapter.notifyItemInserted(viewModel.items.size() - 1);
+ }
+ else {
+ secondItem.setAccountName("актив:кеш:дам");
+ secondItem.getAccount()
+ .setAmount(-amount);
+ listAdapter.notifyItemChanged(2);
+ }
+ }
+ }
+ else {
+ viewModel.addAccount(new LedgerTransactionAccount("разход:пазар"));
+ viewModel.addAccount(
+ new LedgerTransactionAccount("актив:кеш:дам", -amount, null, null));
+ listAdapter.notifyItemRangeInserted(viewModel.items.size() - 1, 2);
+ }
+
+ listAdapter.checkTransactionSubmittable();
+ }
+ }