Skip to content

Commit

Permalink
Merge branch 'master' into close
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaligula0 authored Mar 27, 2024
2 parents 01c44f6 + 310a299 commit aec368d
Show file tree
Hide file tree
Showing 90 changed files with 2,865 additions and 228 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ dependencies {

debugImplementation 'com.facebook.stetho:stetho:1.5.0'

testImplementation 'org.robolectric:robolectric:4.9'
testImplementation 'org.robolectric:robolectric:4.11.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.22.0'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void validateEditTransactionFields(Transaction transaction) {
NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault());
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
onView(withId(R.id.input_transaction_amount)).check(matches(withText(formatter.format(balance.asDouble()))));
onView(withId(R.id.input_transaction_amount)).check(matches(withText(formatter.format(balance.toDouble()))));
onView(withId(R.id.input_date)).check(matches(withText(TransactionFormFragment.DATE_FORMATTER.format(transaction.getTimeMillis()))));
onView(withId(R.id.input_time)).check(matches(withText(TransactionFormFragment.TIME_FORMATTER.format(transaction.getTimeMillis()))));
onView(withId(R.id.input_description)).check(matches(withText(transaction.getNote())));
Expand Down Expand Up @@ -672,7 +672,7 @@ public void testLegacyIntentTransactionRecording() {
for (Transaction transaction : transactions) {
if (transaction.getDescription().equals("Power intents")) {
assertThat("Intents for sale").isEqualTo(transaction.getNote());
assertThat(4.99).isEqualTo(transaction.getBalance(TRANSACTIONS_ACCOUNT_UID).asDouble());
assertThat(4.99).isEqualTo(transaction.getBalance(TRANSACTIONS_ACCOUNT_UID).toDouble());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:name="org.gnucash.android.app.GnuCashApplication"
android:icon="@drawable/ic_launcher"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.GnucashTheme.NoActionBar"
android:allowBackup="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ public Money getAccountBalance(AccountType accountType, long startTimestamp, lon
public Money getAccountBalance(List<AccountType> accountTypes, long start, long end) {
Money balance = Money.createZeroInstance(GnuCashApplication.getDefaultCurrencyCode());
for (AccountType accountType : accountTypes) {
balance = balance.add(getAccountBalance(accountType, start, end));
balance = balance.plus(getAccountBalance(accountType, start, end));
}
return balance;
}
Expand Down Expand Up @@ -890,7 +890,7 @@ public Money getAccountsBalance(@NonNull List<String> accountUIDList, long start
? splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance)
: splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);

return balance.add(splitSum);
return balance.plus(splitSum);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ private String getRootAccountUID(String dbName) {
* Sets the first book in the database as active.
*/
private void setFirstBookAsActive() {
Book firstBook = getAllRecords().get(0);
List<Book> books = getAllRecords();
if (books.isEmpty()) {
Log.w(LOG_TAG, "No books.");
return;
}
Book firstBook = books.get(0);
firstBook.setActive(true);
addRecord(firstBook);
Log.w(LOG_TAG, "Book " + firstBook.getUID() + " set as active.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public Money getBudgetAmountSum(String accountUID) {
List<BudgetAmount> budgetAmounts = getBudgetAmounts(accountUID);
Money sum = Money.createZeroInstance(getAccountCurrencyCode(accountUID));
for (BudgetAmount budgetAmount : budgetAmounts) {
sum = sum.add(budgetAmount.getAmount());
sum = sum.plus(budgetAmount.getAmount());
}
return sum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ public Model getRecord(long id) {
*
* @return List of records in the database
*/
@NonNull
public List<Model> getAllRecords() {
List<Model> modelRecords = new ArrayList<>();
Cursor c = fetchAllRecords();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private Money calculateSplitBalance(List<String> accountUIDList, String currency
}
if (commodityCode.equals(currencyCode)) {
// currency matches
total = total.add(new Money(amount_num, amount_denom, currencyCode));
total = total.plus(new Money(amount_num, amount_denom, currencyCode));
//Log.d(getClass().getName(), "currency " + commodity + " sub - total " + total);
} else {
// there is a second currency involved
Expand All @@ -256,7 +256,7 @@ private Money calculateSplitBalance(List<String> accountUIDList, String currency
BigDecimal amount = Money.getBigDecimal(amount_num, amount_denom);
BigDecimal amountConverted = amount.multiply(new BigDecimal(price.first))
.divide(new BigDecimal(price.second), commodity.getSmallestFractionDigits(), BigDecimal.ROUND_HALF_EVEN);
total = total.add(new Money(amountConverted, commodity));
total = total.plus(new Money(amountConverted, commodity));
//Log.d(getClass().getName(), "currency " + commodity + " sub - total " + total);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gnucash.android.export.ExportParams;
import org.gnucash.android.export.Exporter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
import org.gnucash.android.model.TransactionType;
Expand Down Expand Up @@ -100,15 +101,23 @@ public List<String> generateExport() throws ExporterException {
*
* @param splits Splits to be written
*/
private void writeSplitsToCsv(@NonNull List<Split> splits, @NonNull CsvWriter writer) throws IOException {
private void writeSplitsToCsv(@NonNull List<Split> splits, @NonNull CsvWriter writer) throws IOException, Money.CurrencyMismatchException {
int index = 0;

Map<String, Account> uidAccountMap = new HashMap<>();

for (Split split : splits) {
if (index++ > 0) { // the first split is on the same line as the transactions. But after that, we
writer.write("" + mCsvSeparator + mCsvSeparator + mCsvSeparator + mCsvSeparator
+ mCsvSeparator + mCsvSeparator + mCsvSeparator + mCsvSeparator);
writer.write("" // Date
+ mCsvSeparator // Transaction ID
+ mCsvSeparator // Number
+ mCsvSeparator // Description
+ mCsvSeparator // Notes
+ mCsvSeparator // Commodity/Currency
+ mCsvSeparator // Void Reason
+ mCsvSeparator // Action
+ mCsvSeparator // Memo
);
}
writer.writeToken(split.getMemo());

Expand All @@ -135,7 +144,7 @@ private void writeSplitsToCsv(@NonNull List<Split> splits, @NonNull CsvWriter wr
} else {
writer.writeToken(null);
}
writer.writeEndToken(split.getQuantity().divide(split.getValue()).toLocaleString());
writer.writeEndToken(split.getQuantity().div(split.getValue().toDouble()).toLocaleString());
}
}

Expand Down Expand Up @@ -167,7 +176,7 @@ private void generateExport(final CsvWriter csvWriter) throws ExporterException
}

PreferencesHelper.setLastExportTime(TimestampHelper.getTimestampFromNow());
} catch (IOException e) {
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
throw new ExporterException(mExportParams, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void exportTransactions(XmlSerializer xmlSerializer, boolean exportTempl

// date entered, time when the transaction was actually created
Timestamp timeEntered = TimestampHelper.getTimestampFromUtcString(cursor.getString(cursor.getColumnIndexOrThrow("trans_date_posted")));
String dateEntered = GncXmlHelper.formatDate(timeEntered.getTime());
String dateEntered = GncXmlHelper.formatDate(timeEntered);
xmlSerializer.startTag(null, GncXmlHelper.TAG_DATE_ENTERED);
xmlSerializer.startTag(null, GncXmlHelper.TAG_TS_DATE);
xmlSerializer.text(dateEntered);
Expand Down Expand Up @@ -663,7 +663,7 @@ private void exportPrices(XmlSerializer xmlSerializer) throws IOException {
xmlSerializer.endTag(null, GncXmlHelper.TAG_COMMODITY_ID);
xmlSerializer.endTag(null, GncXmlHelper.TAG_PRICE_CURRENCY);
// time
String strDate = GncXmlHelper.formatDate(TimestampHelper.getTimestampFromUtcString(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.PriceEntry.COLUMN_DATE))).getTime());
String strDate = GncXmlHelper.formatDate(TimestampHelper.getTimestampFromUtcString(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.PriceEntry.COLUMN_DATE))));
xmlSerializer.startTag(null, GncXmlHelper.TAG_PRICE_TIME);
xmlSerializer.startTag(null, GncXmlHelper.TAG_TS_DATE);
xmlSerializer.text(strDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
* Collection of helper tags and methods for Gnc XML export
Expand Down Expand Up @@ -148,6 +149,7 @@ public abstract class GncXmlHelper {

public static final String RECURRENCE_VERSION = "1.0.0";
public static final String BOOK_VERSION = "2.0.0";
public static final TimeZone TZ_UTC = TimeZone.getTimeZone("UTC");
public static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
public static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

Expand All @@ -172,7 +174,16 @@ public abstract class GncXmlHelper {
* @param milliseconds Milliseconds since epoch
*/
public static String formatDate(long milliseconds) {
return TIME_FORMATTER.format(new Date(milliseconds));
return formatDate(new Date(milliseconds));
}

/**
* Formats dates for the GnuCash XML format
*
* @param date the date to format
*/
public static synchronized String formatDate(Date date) {
return TIME_FORMATTER.format(date);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.gnucash.android.ui.account;

import static org.gnucash.android.ui.colorpicker.ColorPickerDialog.COLOR_PICKER_DIALOG_TAG;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -46,12 +48,14 @@
import android.widget.EditText;
import android.widget.Spinner;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentResultListener;

import com.google.android.material.textfield.TextInputLayout;

Expand All @@ -65,7 +69,6 @@
import org.gnucash.android.model.Commodity;
import org.gnucash.android.model.Money;
import org.gnucash.android.ui.colorpicker.ColorPickerDialog;
import org.gnucash.android.ui.colorpicker.ColorPickerSwatch;
import org.gnucash.android.ui.colorpicker.ColorSquare;
import org.gnucash.android.ui.common.UxArgument;
import org.gnucash.android.ui.settings.PreferenceActivity;
Expand All @@ -87,12 +90,7 @@
* @author Ngewi Fet <[email protected]>
* @author Yongxin Wang <[email protected]>
*/
public class AccountFormFragment extends Fragment {

/**
* Tag for the color picker dialog fragment
*/
private static final String COLOR_PICKER_DIALOG_TAG = "color_picker_dialog";
public class AccountFormFragment extends Fragment implements FragmentResultListener {

/**
* EditText for the name of the account to be created/edited
Expand Down Expand Up @@ -223,16 +221,6 @@ public class AccountFormFragment extends Fragment {
@BindView(R.id.input_color_picker)
ColorSquare mColorSquare;

private final ColorPickerSwatch.OnColorSelectedListener mColorSelectedListener =
new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
mColorSquare.setBackgroundColor(color);
mSelectedColor = color;
}
};


/**
* Default constructor
* Required, else the app crashes on screen rotation
Expand Down Expand Up @@ -565,10 +553,19 @@ private void showColorPickerDialog() {
R.string.color_picker_default_title,
getAccountColorOptions(),
currentColor, 4, 12);
colorPickerDialogFragment.setOnColorSelectedListener(mColorSelectedListener);
fragmentManager.setFragmentResultListener(COLOR_PICKER_DIALOG_TAG, this, this);
colorPickerDialogFragment.show(fragmentManager, COLOR_PICKER_DIALOG_TAG);
}

@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
if (COLOR_PICKER_DIALOG_TAG.equals(requestKey)) {
int color = result.getInt(ColorPickerDialog.EXTRA_COLOR);
mColorSquare.setBackgroundColor(color);
mSelectedColor = color;
}
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView;
import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentResultListener;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.GridLayoutManager;
Expand Down Expand Up @@ -78,10 +81,11 @@
* @author Ngewi Fet <[email protected]>
*/
public class AccountsListFragment extends Fragment implements
Refreshable,
LoaderManager.LoaderCallbacks<Cursor>,
SearchView.OnQueryTextListener,
SearchView.OnCloseListener {
Refreshable,
LoaderManager.LoaderCallbacks<Cursor>,
SearchView.OnQueryTextListener,
SearchView.OnCloseListener,
FragmentResultListener {

AccountRecyclerAdapter mAccountRecyclerAdapter;
@BindView(R.id.account_recycler_view)
Expand Down Expand Up @@ -263,9 +267,11 @@ private void tryDeleteAccount(String accountUID) {
* @param accountUID Unique ID of account to be deleted after confirmation
*/
private void showConfirmationDialog(String accountUID) {
FragmentManager fm = getChildFragmentManager();
DeleteAccountDialogFragment alertFragment =
DeleteAccountDialogFragment.newInstance(accountUID);
alertFragment.show(getChildFragmentManager(), "delete_confirmation_dialog");
fm.setFragmentResultListener(DeleteAccountDialogFragment.TAG, this, this);
alertFragment.show(fm, DeleteAccountDialogFragment.TAG);
}

@Override
Expand Down Expand Up @@ -471,6 +477,13 @@ public Cursor loadInBackground() {
}
}

@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
if (DeleteAccountDialogFragment.TAG.equals(requestKey)) {
boolean refresh = result.getBoolean(Refreshable.EXTRA_REFRESH);
if (refresh) refresh();
}
}

class AccountRecyclerAdapter extends CursorRecyclerAdapter<AccountRecyclerAdapter.AccountViewHolder> {

Expand Down Expand Up @@ -532,7 +545,7 @@ public void onClick(View v) {
if (budgets.size() == 1) {
Budget budget = budgets.get(0);
Money balance = mAccountsDbAdapter.getAccountBalance(accountUID, budget.getStartofCurrentPeriod(), budget.getEndOfCurrentPeriod());
double budgetProgress = balance.divide(budget.getAmount(accountUID)).asBigDecimal().doubleValue() * 100;
double budgetProgress = balance.div(budget.getAmount(accountUID)).asBigDecimal().doubleValue() * 100;

holder.budgetIndicator.setVisibility(View.VISIBLE);
holder.budgetIndicator.setProgress((int) budgetProgress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
*/
public class DeleteAccountDialogFragment extends DialogFragment {

public static final String TAG = "delete_account_dialog";

/**
* Spinner for selecting the account to move the transactions to
*/
Expand Down Expand Up @@ -235,8 +237,12 @@ public void onClick(View v) {
//now kill them all!!
accountsDbAdapter.recursiveDeleteAccount(accountsDbAdapter.getID(mOriginAccountUID));

WidgetConfigurationActivity.updateAllWidgets(getActivity());
((Refreshable) getTargetFragment()).refresh();
WidgetConfigurationActivity.updateAllWidgets(v.getContext());

Bundle result = new Bundle();
result.putBoolean(Refreshable.EXTRA_REFRESH, true);
getParentFragmentManager().setFragmentResult(TAG, result);

dismiss();
}
});
Expand Down
Loading

0 comments on commit aec368d

Please sign in to comment.