Skip to content

Commit 36accb0

Browse files
committed
Assign colors to accounts when "Account color in reports" is checked.
Fixes #495
1 parent df9a06e commit 36accb0

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

app/src/main/java/org/gnucash/android/ui/report/BarChartFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ private BarData getData() {
229229
if (!accountToColorMap.containsKey(account.getUID())) {
230230
Integer color;
231231
if (mUseAccountColor) {
232-
color = account.getColor();
232+
color = (account.getColor() != Account.DEFAULT_COLOR)
233+
? account.getColor()
234+
: COLORS[accountToColorMap.size() % COLORS.length];
233235
} else {
234236
color = COLORS[accountToColorMap.size() % COLORS.length];
235237
}

app/src/main/java/org/gnucash/android/ui/report/PieChartFragment.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.gnucash.android.R;
4343
import org.gnucash.android.app.GnuCashApplication;
4444
import org.gnucash.android.db.AccountsDbAdapter;
45-
import org.gnucash.android.db.TransactionsDbAdapter;
4645
import org.gnucash.android.model.Account;
4746
import org.gnucash.android.model.AccountType;
4847

@@ -197,9 +196,15 @@ private PieData getData() {
197196
mReportStartTime, mReportEndTime).asDouble();
198197
if (balance > 0) {
199198
dataSet.addEntry(new Entry((float) balance, dataSet.getEntryCount()));
200-
colors.add(mUseAccountColor
201-
? account.getColor()
202-
: ReportsActivity.COLORS[(dataSet.getEntryCount() - 1) % ReportsActivity.COLORS.length]);
199+
int color;
200+
if (mUseAccountColor) {
201+
color = (account.getColor() != Account.DEFAULT_COLOR)
202+
? account.getColor()
203+
: ReportsActivity.COLORS[(dataSet.getEntryCount() - 1) % ReportsActivity.COLORS.length];
204+
} else {
205+
color = ReportsActivity.COLORS[(dataSet.getEntryCount() - 1) % ReportsActivity.COLORS.length];
206+
}
207+
colors.add(color);
203208
labels.add(account.getName());
204209
}
205210
}

app/src/main/java/org/gnucash/android/ui/report/ReportSummaryFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ private PieData getData() {
199199
Collections.singletonList(account.getUID()), start, end).asDouble();
200200
if (balance > 0) {
201201
dataSet.addEntry(new Entry((float) balance, dataSet.getEntryCount()));
202-
colors.add(account.getColor());
202+
colors.add(account.getColor() != Account.DEFAULT_COLOR
203+
? account.getColor()
204+
: ReportsActivity.COLORS[(dataSet.getEntryCount() - 1) % ReportsActivity.COLORS.length]);
203205
labels.add(account.getName());
204206
}
205207
}

0 commit comments

Comments
 (0)