From 867ad7e441e63d3b7974f67dca8d11797e95a245 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 15 Dec 2018 19:36:27 +0000 Subject: [PATCH] helper method for getting transaction item (currency + amount) as string --- .../mobileledger/model/LedgerTransactionItem.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java index de430580..10842584 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java @@ -17,6 +17,8 @@ package net.ktnx.mobileledger.model; +import android.support.annotation.NonNull; + public class LedgerTransactionItem { private String accountName; private float amount; @@ -71,4 +73,17 @@ public class LedgerTransactionItem { public String getCurrency() { return currency; } + @NonNull + public String toString() { + if (!amountSet) return ""; + + StringBuilder sb = new StringBuilder(); + if (currency != null) { + sb.append(currency); + sb.append(' '); + } + sb.append(String.format("%,1.2f", amount)); + + return sb.toString(); + } } -- 2.39.5