From a50a44d4c48eb901be5abc91321e1a18e61bb4a1 Mon Sep 17 00:00:00 2001 From: John-Yu Date: Mon, 25 May 2020 08:53:27 +0800 Subject: [PATCH] =?UTF-8?q?#876=20-=20Use=20different=20colors=20for=20bal?= =?UTF-8?q?ance,=20according=20to=20Accou=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 16 +++++----- .../android/app/GnuCashApplication.java | 12 ++----- .../android/export/ExportAsyncTask.java | 6 +++- .../gnucash/android/export/ExportParams.java | 8 +++-- .../export/csv/CsvTransactionsExporter.java | 14 ++------ .../gnucash/android/model/AccountType.java | 28 ++++++++++++++-- .../android/ui/account/AccountsActivity.java | 4 +-- .../ui/account/AccountsListFragment.java | 1 - .../android/ui/export/ExportFormFragment.java | 3 +- .../WidgetConfigurationActivity.java | 32 ++++++------------- .../android/ui/report/ReportsActivity.java | 12 +++---- .../main/res/layout/fragment_export_form.xml | 2 +- app/src/main/res/values/colors.xml | 2 ++ 13 files changed, 69 insertions(+), 71 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b1cd8add0..d7e265c36 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,9 +4,9 @@ apply plugin: 'com.android.application' apply plugin: 'io.fabric' def versionMajor = 2 -def versionMinor = 4 -def versionPatch = 1 -def versionBuild = 4 +def versionMinor = 5 +def versionPatch = 0 +def versionBuild = 0 static def buildTime() { def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'") @@ -203,7 +203,7 @@ dependencies { 'com.code-troopers.betterpickers:library:3.1.0', 'org.jraf:android-switch-backport:2.0.1@aar', 'com.github.PhilJay:MPAndroidChart:v2.1.3', - 'joda-time:joda-time:2.9.4', + 'joda-time:joda-time:2.10.6', 'com.google.android.gms:play-services-drive:9.6.1', 'io.github.kobakei:ratethisapp:1.1.3', 'com.squareup:android-times-square:1.6.5@aar', @@ -219,7 +219,7 @@ dependencies { 'androidx.fragment:fragment:1.3.0-alpha04' ) - debugImplementation 'com.facebook.stetho:stetho:1.5.0' + debugImplementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.jakewharton:butterknife:10.2.1' annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' @@ -230,7 +230,7 @@ dependencies { exclude module: 'httpclient' } - implementation('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') { + implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true } @@ -239,10 +239,10 @@ dependencies { testImplementation( 'junit:junit:4.12', - 'joda-time:joda-time:2.9.4', + 'joda-time:joda-time:2.10.6', 'org.assertj:assertj-core:1.7.1' ) - testImplementation 'org.robolectric:shadows-multidex:3.0' + testImplementation 'org.robolectric:shadows-multidex:4.3.1' androidTestImplementation( 'androidx.annotation:annotation:1.1.0', diff --git a/app/src/main/java/org/gnucash/android/app/GnuCashApplication.java b/app/src/main/java/org/gnucash/android/app/GnuCashApplication.java index cfcde2342..6d12db6cd 100644 --- a/app/src/main/java/org/gnucash/android/app/GnuCashApplication.java +++ b/app/src/main/java/org/gnucash/android/app/GnuCashApplication.java @@ -186,9 +186,7 @@ public static SplitsDbAdapter getSplitsDbAdapter() { return mSplitsDbAdapter; } - public static ScheduledActionDbAdapter getScheduledEventDbAdapter(){ - return mScheduledActionDbAdapter; - } + public static ScheduledActionDbAdapter getScheduledEventDbAdapter(){ return mScheduledActionDbAdapter; } public static CommoditiesDbAdapter getCommoditiesDbAdapter(){ return mCommoditiesDbAdapter; @@ -206,13 +204,9 @@ public static RecurrenceDbAdapter getRecurrenceDbAdapter() { return mRecurrenceDbAdapter; } - public static BudgetAmountsDbAdapter getBudgetAmountsDbAdapter(){ - return mBudgetAmountsDbAdapter; - } + public static BudgetAmountsDbAdapter getBudgetAmountsDbAdapter(){ return mBudgetAmountsDbAdapter; } - public static BooksDbAdapter getBooksDbAdapter(){ - return mBooksDbAdapter; - } + public static BooksDbAdapter getBooksDbAdapter(){ return mBooksDbAdapter; } /** * Returns the currently active database in the application diff --git a/app/src/main/java/org/gnucash/android/export/ExportAsyncTask.java b/app/src/main/java/org/gnucash/android/export/ExportAsyncTask.java index 4603ba1ab..fd4175600 100644 --- a/app/src/main/java/org/gnucash/android/export/ExportAsyncTask.java +++ b/app/src/main/java/org/gnucash/android/export/ExportAsyncTask.java @@ -17,6 +17,7 @@ package org.gnucash.android.export; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; @@ -90,6 +91,7 @@ public class ExportAsyncTask extends AsyncTask { /** * App context */ + @SuppressLint("StaticFieldLeak") private final Context mContext; private ProgressDialog mProgressDialog; @@ -139,9 +141,9 @@ protected void onPreExecute() { @Override protected Boolean doInBackground(ExportParams... params) { mExportParams = params[0]; - mExporter = getExporter(); try { + mExporter = getExporter(); mExportedFiles = mExporter.generateExport(); } catch (final Exception e) { Log.e(TAG, "Error exporting: " + e.getMessage()); @@ -176,6 +178,8 @@ protected Boolean doInBackground(ExportParams... params) { */ @Override protected void onPostExecute(Boolean exportSuccessful) { + super.onPostExecute(exportSuccessful); + if (exportSuccessful) { if (mContext instanceof Activity) reportSuccess(); diff --git a/app/src/main/java/org/gnucash/android/export/ExportParams.java b/app/src/main/java/org/gnucash/android/export/ExportParams.java index fe4b6ddea..597a5929d 100644 --- a/app/src/main/java/org/gnucash/android/export/ExportParams.java +++ b/app/src/main/java/org/gnucash/android/export/ExportParams.java @@ -39,8 +39,12 @@ public class ExportParams { * Options for the destination of the exported transctions file. * It could be stored on the {@link #SD_CARD} or exported through another program via {@link #SHARING} */ - public enum ExportTarget {SD_CARD("SD Card"), SHARING("External Service"), - DROPBOX("Dropbox"), GOOGLE_DRIVE("Google Drive"), OWNCLOUD("ownCloud"), + public enum ExportTarget { + SD_CARD("SD Card"), + SHARING("External Service"), + DROPBOX("Dropbox"), + GOOGLE_DRIVE("Google Drive"), + OWNCLOUD("ownCloud"), URI("Sync Service"); private String mDescription; ExportTarget(String description){ diff --git a/app/src/main/java/org/gnucash/android/export/csv/CsvTransactionsExporter.java b/app/src/main/java/org/gnucash/android/export/csv/CsvTransactionsExporter.java index e405c4fd2..b42f8ad14 100644 --- a/app/src/main/java/org/gnucash/android/export/csv/CsvTransactionsExporter.java +++ b/app/src/main/java/org/gnucash/android/export/csv/CsvTransactionsExporter.java @@ -53,17 +53,7 @@ public class CsvTransactionsExporter extends Exporter{ private char mCsvSeparator; - private DateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd", Locale.US); - - /** - * Construct a new exporter with export parameters - * @param params Parameters for the export - */ - public CsvTransactionsExporter(ExportParams params) { - super(params, null); - mCsvSeparator = params.getCsvSeparator(); - LOG_TAG = "GncXmlExporter"; - } + private static SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd", Locale.US); /** * Overloaded constructor. @@ -74,7 +64,7 @@ public CsvTransactionsExporter(ExportParams params) { public CsvTransactionsExporter(ExportParams params, SQLiteDatabase db) { super(params, db); mCsvSeparator = params.getCsvSeparator(); - LOG_TAG = "GncXmlExporter"; + LOG_TAG = "CSVTExporter"; } @Override diff --git a/app/src/main/java/org/gnucash/android/model/AccountType.java b/app/src/main/java/org/gnucash/android/model/AccountType.java index 0b228bb28..91785060c 100644 --- a/app/src/main/java/org/gnucash/android/model/AccountType.java +++ b/app/src/main/java/org/gnucash/android/model/AccountType.java @@ -192,13 +192,37 @@ public int getAmountColor(final boolean isCreditAmount) { // Credit amount and account like Assets, Bank, Cash..., or Debit amount and account like Expense/Income // RED - colorRes = R.color.debit_red; + // colorRes = R.color.debit_red; + if (!isExpenseOrIncomeAccount()) { + // It is not an Expense/Income account + + // RED + colorRes = R.color.debit_red; + + } else { + // It is an Expense/Income account + + // PURPLE + colorRes = R.color.debit_expense_income; + } } else { // Credit amount and account like Expense/Income, or Debit amount and account like Assets, Bank, Cash...) // GREEN - colorRes = R.color.credit_green; + // colorRes = R.color.credit_green; + if (!isExpenseOrIncomeAccount()) { + // It is not an Expense/Income account + + // GREEN + colorRes = R.color.credit_green; + + } else { + // It is an Expense/Income account + + // BLUE + colorRes = R.color.credit_expense_income; + } } return GnuCashApplication.getAppContext() diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index ae14c3290..988b8fa9d 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -400,7 +400,6 @@ private void init() { // Default preference not to show negative number in splits prefs.edit().putBoolean(getString(R.string.key_display_negative_signum_in_splits), false).apply(); - // Finish Activity finish(); @@ -450,8 +449,7 @@ public void onBackPressed() { // Get Preference about double back button press to exit boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), - true); + .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), true); if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { // BackPress button has already been pressed recently OR shall not use double back press to exit diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java index 24ee5b996..6708e5c06 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java @@ -197,7 +197,6 @@ public void onActivityCreated(Bundle savedInstanceState) { actionbar.setDisplayHomeAsUpEnabled(true); setHasOptionsMenu(true); - // specify an adapter (see also next example) mAccountRecyclerAdapter = new AccountRecyclerAdapter(null); mRecyclerView.setAdapter(mAccountRecyclerAdapter); diff --git a/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java b/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java index 0107a9b9f..c3e5d9965 100644 --- a/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java @@ -242,8 +242,7 @@ private void onRadioButtonClicked(View view){ } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_export_form, container, false); ButterKnife.bind(this, view); diff --git a/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java b/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java index bf606ac74..d702289a7 100644 --- a/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java @@ -71,21 +71,14 @@ public class WidgetConfigurationActivity extends Activity { private AccountsDbAdapter mAccountsDbAdapter; private int mAppWidgetId; - @BindView(R.id.input_accounts_spinner) - Spinner mAccountsSpinner; - @BindView(R.id.input_books_spinner) - Spinner mBooksSpinner; - @BindView(R.id.input_hide_account_balance) - CheckBox mHideAccountBalance; - @BindView(R.id.btn_save) - Button mOkButton; - @BindView(R.id.btn_cancel) - Button mCancelButton; - + @BindView(R.id.input_accounts_spinner) Spinner mAccountsSpinner; + @BindView(R.id.input_books_spinner) Spinner mBooksSpinner; + @BindView(R.id.input_hide_account_balance) CheckBox mHideAccountBalance; + @BindView(R.id.btn_save) Button mOkButton; + @BindView(R.id.btn_cancel) Button mCancelButton; private SimpleCursorAdapter mAccountsCursorAdapter; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -269,8 +262,7 @@ public static void updateWidget(final Context context, int appWidgetId) { } catch (IllegalArgumentException e) { Log.i("WidgetConfiguration", "Account not found, resetting widget " + appWidgetId); //if account has been deleted, let the user know - RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.widget_4x1); + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1); views.setTextViewText(R.id.account_name, context.getString(R.string.toast_account_deleted)); views.setTextViewText(R.id.transactions_summary, ""); //set it to simply open the app @@ -285,8 +277,7 @@ public static void updateWidget(final Context context, int appWidgetId) { return; } - final RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.widget_4x1); + final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1); views.setTextViewText(R.id.account_name, account.getName()); Money accountBalance = accountsDbAdapter.getAccountBalance(accountUID, -1, System.currentTimeMillis()); @@ -294,8 +285,7 @@ public static void updateWidget(final Context context, int appWidgetId) { if (hideAccountBalance) { views.setViewVisibility(R.id.transactions_summary, View.GONE); } else { - views.setTextViewText(R.id.transactions_summary, - accountBalance.formattedString(Locale.getDefault())); + views.setTextViewText(R.id.transactions_summary, accountBalance.formattedString(Locale.getDefault())); int color = accountBalance.isNegative() ? R.color.debit_red : R.color.credit_green; views.setTextColor(R.id.transactions_summary, ContextCompat.getColor(context, color)); } @@ -306,8 +296,7 @@ public static void updateWidget(final Context context, int appWidgetId) { accountViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); accountViewIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, accountUID); accountViewIntent.putExtra(UxArgument.BOOK_UID, bookUID); - PendingIntent accountPendingIntent = PendingIntent - .getActivity(context, appWidgetId, accountViewIntent, 0); + PendingIntent accountPendingIntent = PendingIntent.getActivity(context, appWidgetId, accountViewIntent, 0); views.setOnClickPendingIntent(R.id.widget_layout, accountPendingIntent); if (accountsDbAdapter.isPlaceholderAccount(accountUID)) { @@ -320,8 +309,7 @@ public static void updateWidget(final Context context, int appWidgetId) { newTransactionIntent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.TRANSACTION.name()); newTransactionIntent.putExtra(UxArgument.BOOK_UID, bookUID); newTransactionIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, accountUID); - PendingIntent pendingIntent = PendingIntent - .getActivity(context, appWidgetId, newTransactionIntent, 0); + PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, newTransactionIntent, 0); views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent); views.setViewVisibility(R.id.btn_view_account, View.GONE); } diff --git a/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java b/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java index d0f004390..a63875cf1 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java @@ -81,12 +81,9 @@ public class ReportsActivity extends BaseDrawerActivity implements AdapterView.O }; private static final String STATE_REPORT_TYPE = "STATE_REPORT_TYPE"; - @BindView(R.id.time_range_spinner) - Spinner mTimeRangeSpinner; - @BindView(R.id.report_account_type_spinner) - Spinner mAccountTypeSpinner; - @BindView(R.id.toolbar_spinner) - Spinner mReportsToolbarSpinner; + @BindView(R.id.time_range_spinner) Spinner mTimeRangeSpinner; + @BindView(R.id.report_account_type_spinner) Spinner mAccountTypeSpinner; + @BindView(R.id.toolbar_spinner) Spinner mReportsToolbarSpinner; private TransactionsDbAdapter mTransactionsDbAdapter; private AccountType mAccountType = AccountType.EXPENSE; @@ -194,8 +191,7 @@ public void onAttachFragment(@NonNull Fragment fragment) { */ private void loadFragment(BaseReportFragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager - .beginTransaction(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); diff --git a/app/src/main/res/layout/fragment_export_form.xml b/app/src/main/res/layout/fragment_export_form.xml index 2968519ae..9a6829c27 100644 --- a/app/src/main/res/layout/fragment_export_form.xml +++ b/app/src/main/res/layout/fragment_export_form.xml @@ -136,7 +136,7 @@ android:id="@+id/export_separator_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="12dp" + android:layout_marginStart="32dp" android:checkedButton="@id/radio_separator_comma_format" android:gravity="center_vertical" android:orientation="horizontal"> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9122dd7d7..a2777a6b6 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -17,6 +17,8 @@ #c11b17 #4cc552 + #FF9800 + #00BCD4 #FFAAAAAA #00000000 #ff33b5e5