Skip to content

Commit

Permalink
codinguser#876 - Use different colors for balance, according to Accou…
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Yu committed May 25, 2020
1 parent a9c14e7 commit a50a44d
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 71 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
Expand Down Expand Up @@ -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',
Expand All @@ -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'
Expand All @@ -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
}

Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class ExportAsyncTask extends AsyncTask<ExportParams, Void, Boolean> {
/**
* App context
*/
@SuppressLint("StaticFieldLeak")
private final Context mContext;

private ProgressDialog mProgressDialog;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/org/gnucash/android/model/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -285,17 +277,15 @@ 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());

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));
}
Expand All @@ -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)) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_export_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<resources>
<color name="debit_red">#c11b17</color>
<color name="credit_green">#4cc552</color>
<color name="debit_expense_income">#FF9800</color>
<color name="credit_expense_income">#00BCD4</color>
<color name="light_gray">#FFAAAAAA</color>
<color name="transparent">#00000000</color>
<color name="abs__holo_blue_light">#ff33b5e5</color>
Expand Down

0 comments on commit a50a44d

Please sign in to comment.