From b25e44d3ef82088305022d63977f2a4230c309ea Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 21:54:12 +0200 Subject: [PATCH] Fix transaction edition - Fee format was not displayed correctly in Buy and Sell tabs --- .../BuyFragment.java | 30 ++++++++++++++++++- .../SellFragment.java | 28 ++++++++++++++++- .../moodl/DataManagers/DatabaseManager.java | 15 +--------- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java index 15ed23b..767d472 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java @@ -64,7 +64,7 @@ public class BuyFragment extends CustomRecordFragment { private List symbolStrings; private int transactionId; - private Transaction transaction; + private static Transaction transaction; private boolean isAmountLastUpdated; @@ -523,6 +523,8 @@ public class BuyFragment extends CustomRecordFragment { public void updatePair(Pair pair) { + fragmentPair = pair; + currencyFeeAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); feesCurrencySpinner.setAdapter(currencyFeeAdapter); @@ -532,6 +534,32 @@ public class BuyFragment extends CustomRecordFragment { symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); currencyFeeAdapter.addAll(symbolStrings); currencyFeeAdapter.notifyDataSetChanged(); + + if(transaction != null) + { + if(transaction.getFeeCurrency().equals(fragmentPair.getFrom())) + { + if(transaction.getFeeFormat().equals("p")) + { + feesCurrencySpinner.setSelection(0); + } + else + { + feesCurrencySpinner.setSelection(1); + } + } + else + { + if(transaction.getFeeFormat().equals("p")) + { + feesCurrencySpinner.setSelection(2); + } + else + { + feesCurrencySpinner.setSelection(3); + } + } + } } @Override diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java index eed25f9..4976a63 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java @@ -63,7 +63,7 @@ public class SellFragment extends CustomRecordFragment { private List symbolStrings; private int transactionId; - private Transaction transaction; + private static Transaction transaction; private boolean isAmountLastUpdated; @@ -531,6 +531,32 @@ public class SellFragment extends CustomRecordFragment { symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); currencyFeeAdapter.addAll(symbolStrings); currencyFeeAdapter.notifyDataSetChanged(); + + if(transaction != null) + { + if(transaction.getFeeCurrency().equals(fragmentPair.getFrom())) + { + if(transaction.getFeeFormat().equals("p")) + { + feesCurrencySpinner.setSelection(0); + } + else + { + feesCurrencySpinner.setSelection(1); + } + } + else + { + if(transaction.getFeeFormat().equals("p")) + { + feesCurrencySpinner.setSelection(2); + } + else + { + feesCurrencySpinner.setSelection(3); + } + } + } } @Override diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java index 4309fc9..45bfa28 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -497,8 +497,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ Log.d("moodl", "Error while inserting transaction " + e.getMessage()); } - Log.d("mood", "Raw " + rawValues.toString()); - db.insert(TABLE_MANUAL_TRANSACTIONS, null, values); db.close(); } @@ -690,15 +688,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ if(resultatList.moveToFirst()) { - boolean deduct = false; - - if(!resultatList.isNull(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT))) - { - deduct = resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1; - } - - Log.d("moodl", "> " + resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE))); - transaction = new Transaction(resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_ID)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)) @@ -712,11 +701,9 @@ public class DatabaseManager extends SQLiteOpenHelper{ , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_DESTINATION)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_FEE_FORMAT)) - , deduct); + , resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1); } - Log.d("moodl", "> " + DatabaseUtils.dumpCurrentRowToString(resultatList)); - resultatList.close(); db.close();