diff --git a/app/src/main/java/org/gnucash/android/ui/report/ReportType.java b/app/src/main/java/org/gnucash/android/ui/report/ReportType.java index d9887e1db..f88cf45b6 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/ReportType.java +++ b/app/src/main/java/org/gnucash/android/ui/report/ReportType.java @@ -39,28 +39,36 @@ public enum ReportType { PIE_CHART(0), BAR_CHART(1), LINE_CHART(2), TEXT(3), NONE(4); + // #872 Use a list to be sure of the sort order which is not guaranted with a hashmap keys + List mReportNames = null; + Map mReportTypeMap = new HashMap<>(); + int mValue = 4; + /** + * Constructor + * + * @param index + */ ReportType(int index){ + mValue = index; + Context context = GnuCashApplication.getAppContext(); - switch (index){ - case 0: - mReportTypeMap.put(context.getString(R.string.title_pie_chart), PieChartFragment.class); - break; - case 1: - mReportTypeMap.put(context.getString(R.string.title_bar_chart), StackedBarChartFragment.class); - break; - case 2: - mReportTypeMap.put(context.getString(R.string.title_cash_flow_report), CashFlowLineChartFragment.class); - break; - case 3: - mReportTypeMap.put(context.getString(R.string.title_balance_sheet_report), BalanceSheetFragment.class); - break; - case 4: - break; - } + + // #872 Fill the map with all the items, in order to fill the Report Toolbar Spinner + mReportTypeMap.put(context.getString(R.string.title_pie_chart), + PieChartFragment.class); + + mReportTypeMap.put(context.getString(R.string.title_bar_chart), + StackedBarChartFragment.class); + + mReportTypeMap.put(context.getString(R.string.title_cash_flow_report), + CashFlowLineChartFragment.class); + + mReportTypeMap.put(context.getString(R.string.title_balance_sheet_report), + BalanceSheetFragment.class); } /** @@ -83,8 +91,54 @@ public enum ReportType { } } + public static ReportType getReportType(final String name) { + + Context context = GnuCashApplication.getAppContext(); + + if (name.equals(context.getString(R.string.title_pie_chart))) { + + return PIE_CHART; + + } else if (name.equals(context.getString(R.string.title_bar_chart))) { + + return BAR_CHART; + + } else if (name.equals(context.getString(R.string.title_cash_flow_report))) { + + return LINE_CHART; + + } else if (name.equals(context.getString(R.string.title_balance_sheet_report))) { + + return TEXT; + + } else { + + return NONE; + } + } + public List getReportNames(){ - return new ArrayList<>(mReportTypeMap.keySet()); + + Context context = GnuCashApplication.getAppContext(); + + if (mReportNames == null) { + // + + // + mReportNames = new ArrayList(); + + mReportNames.add(context.getString(R.string.title_pie_chart)); + mReportNames.add(context.getString(R.string.title_bar_chart)); + mReportNames.add(context.getString(R.string.title_cash_flow_report)); + mReportNames.add(context.getString(R.string.title_balance_sheet_report)); + + } else { + // n' pas + + // RAF + } + + return mReportNames; } public BaseReportFragment getFragment(String name){ diff --git a/app/src/main/java/org/gnucash/android/ui/report/barchart/StackedBarChartFragment.java b/app/src/main/java/org/gnucash/android/ui/report/barchart/StackedBarChartFragment.java index 5556c7896..ef501ea3f 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/barchart/StackedBarChartFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/report/barchart/StackedBarChartFragment.java @@ -81,7 +81,7 @@ public class StackedBarChartFragment extends BaseReportFragment { @Override public int getTitle() { - return R.string.title_cash_flow_report; + return R.string.title_bar_chart; } @Override diff --git a/app/src/main/res/layout/fragment_report_summary.xml b/app/src/main/res/layout/fragment_report_summary.xml index dfb9ab9dd..20c239edf 100644 --- a/app/src/main/res/layout/fragment_report_summary.xml +++ b/app/src/main/res/layout/fragment_report_summary.xml @@ -49,7 +49,7 @@ limitations under the License. android:layout_weight="1" android:drawableLeft="@drawable/ic_trending_up_white_24dp" android:drawableStart="@drawable/ic_trending_up_white_24dp" - android:text="@string/title_line_chart"/> + android:text="@string/title_cash_flow_report"/>