From ffd103fad38d84e19f9ce8b22eb2845bb40adcd4 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 16:16:23 +0200 Subject: [PATCH 01/23] Fix transfer equation --- .../com/herbron/moodl/DataManagers/DatabaseManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 9e2d871..4309fc9 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -624,7 +624,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ if(resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1) { currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); } else { @@ -638,14 +638,14 @@ public class DatabaseManager extends SQLiteOpenHelper{ if(isBalanceRelated(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SOURCE)))) { currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); } else { if(isBalanceRelated(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_DESTINATION)))) { currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); } } } From 4c65596718deef503e8bfc5668ac7a0b1627ee56 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 18:12:35 +0200 Subject: [PATCH 02/23] Add transaction indicator --- .../CustomAdapters/TradeListAdapter.java | 4 +- .../TransactionListAdapter.java | 15 ++ .../res/layout/custom_transaction_row.xml | 211 ++++++++++-------- 3 files changed, 129 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java index 93c56c1..dc84a75 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java @@ -53,11 +53,11 @@ public class TradeListAdapter extends ArrayAdapter { if(trade.isBuyer()) { - tradeIndicator.setBackgroundColor(context.getColor(R.color.green)); + tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.green)); } else { - tradeIndicator.setBackgroundColor(context.getColor(R.color.red)); + tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.red)); } return convertView; diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java index df972de..b1864e3 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java @@ -88,6 +88,21 @@ public class TransactionListAdapter extends ArrayAdapter { } }); + View transactionIndicator = convertView.findViewById(R.id.transactionIndicator); + + switch (transaction.getType()) + { + case "b": + transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.increaseCandle)); + break; + case "s": + transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.decreaseCandle)); + break; + case "t": + transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.blue)); + break; + } + setupSwipeView(convertView); return convertView; diff --git a/app/src/main/res/layout/custom_transaction_row.xml b/app/src/main/res/layout/custom_transaction_row.xml index c2fd90e..7c96aaf 100644 --- a/app/src/main/res/layout/custom_transaction_row.xml +++ b/app/src/main/res/layout/custom_transaction_row.xml @@ -1,107 +1,120 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="50dp" + android:orientation="horizontal"> + + + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 10c3a0a67b3dcd66ad63e7c32ece24960c11e934 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 20:32:59 +0200 Subject: [PATCH 03/23] UI fix [RecordTransactionActivity] - Fix tab color when editing a transaction - Disable tab swiping - Fix crash when editing a sell transaction --- .../Activities/RecordTransactionActivity.java | 11 +- .../SellFragment.java | 208 +++++++++--------- .../layout/activity_record_transaction.xml | 2 +- 3 files changed, 117 insertions(+), 104 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java index 5c72977..4155211 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java @@ -37,6 +37,7 @@ import com.herbron.moodl.Activities.RecordTransactionFragments.SellFragment; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; import com.herbron.moodl.CustomAdapters.PairRecordListAdapter; import com.herbron.moodl.CustomLayouts.CustomRecordFragment; +import com.herbron.moodl.CustomLayouts.CustomViewPager; import com.herbron.moodl.DataManagers.CurrencyData.Currency; import com.herbron.moodl.DataManagers.CurrencyData.Transaction; import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; @@ -76,7 +77,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr private AutoCompleteTextView pair_autoCompleteTextView; private CustomTabLayout tabLayout; - private ViewPager viewPager; + private CustomViewPager viewPager; private RecordTransactionPageAdapter pageAdapter; @@ -246,7 +247,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr ((BuyFragment) pageAdapter.getItem(0)).updatePair(pair); - updatePairData(); + //updatePairData(); found = true; } @@ -255,6 +256,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr } tabLayout.getTabAt(0).select(); + ((TextView) tabLayout.getTabAt(0).getCustomView()).setTextColor(getResources().getColor(R.color.white)); break; case "s": @@ -294,7 +296,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr ((SellFragment) pageAdapter.getItem(1)).updatePair(pair); - updatePairData(); + //updatePairData(); found = true; } @@ -303,9 +305,11 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr } tabLayout.getTabAt(1).select(); + ((TextView) tabLayout.getTabAt(1).getCustomView()).setTextColor(getResources().getColor(R.color.white)); break; case "t": tabLayout.getTabAt(2).select(); + ((TextView) tabLayout.getTabAt(2).getCustomView()).setTextColor(getResources().getColor(R.color.white)); break; } } @@ -330,6 +334,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr pageAdapter = new RecordTransactionPageAdapter(getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(pageAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); + viewPager.setPagingEnabled(false); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { 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 d18ca60..eed25f9 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 @@ -133,6 +133,105 @@ public class SellFragment extends CustomRecordFragment { } }; + private TextWatcher feesTextWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + totalValueEditText.removeTextChangedListener(totalValueTextWatcher); + amoutEditText.removeTextChangedListener(amountTextWatcher); + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + if((isFieldCorrectlyFilled(amoutEditText, false) || isFieldCorrectlyFilled(totalValueEditText, false)) && isFieldCorrectlyFilled(sellPriceEditText, false)) + { + double amount = Double.parseDouble(amoutEditText.getText().toString()); + double purchasePrice = Double.parseDouble(sellPriceEditText.getText().toString()); + double fees; + double totalValue = Double.parseDouble(totalValueEditText.getText().toString()); + String feeCurrency; + + if(isAmountLastUpdated) + { + totalValue = amount * purchasePrice; + } + else + { + amount = totalValue / purchasePrice; + } + + if(fees_editText.getText().toString().equals("0") || (start == 0 && before == 1 && count == 0)) + { + if(isAmountLastUpdated) + { + totalValueEditText.setText(String.valueOf(amount * purchasePrice)); + } + else + { + amoutEditText.setText(String.valueOf(totalValue / purchasePrice)); + } + } + else + { + + if(feesCurrencySpinner.getSelectedItemPosition() < 2) + { + feeCurrency = fragmentPair.getFrom(); + } + else + { + feeCurrency = fragmentPair.getTo(); + } + + fees = getFees(feeCurrency, amount, purchasePrice); + + if(feesCurrencySpinner.getSelectedItemPosition() % 2 == 0) + { + if(isAmountLastUpdated) + { + totalValueEditText.setText(String.valueOf(totalValue - fees)); + } + else + { + amoutEditText.setText(String.valueOf(amount + (fees / purchasePrice))); + } + } + else + { + if(fragmentCurrency.getSymbol().equals(feeCurrency)) + { + if(isAmountLastUpdated) + { + totalValueEditText.setText(String.valueOf(totalValue - (fees * purchasePrice))); + } + else + { + amoutEditText.setText(String.valueOf((totalValue / purchasePrice) + fees)); + } + } + else + { + if(isAmountLastUpdated) + { + totalValueEditText.setText(String.valueOf(totalValue - fees)); + } + else + { + amoutEditText.setText(String.valueOf((totalValue + fees) / purchasePrice)); + } + } + } + } + } + } + + @Override + public void afterTextChanged(Editable s) { + totalValueEditText.addTextChangedListener(totalValueTextWatcher); + amoutEditText.addTextChangedListener(amountTextWatcher); + } + }; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -153,10 +252,8 @@ public class SellFragment extends CustomRecordFragment { private void initializeViewElements() { totalValueEditText = view.findViewById(R.id.totalValue_editText_sell); - totalValueEditText.addTextChangedListener(totalValueTextWatcher); amoutEditText = view.findViewById(R.id.amount_editText_sell); - amoutEditText.addTextChangedListener(amountTextWatcher); sellPriceEditText = view.findViewById(R.id.sellPrice_editText); sellDateEditText = view.findViewById(R.id.sellDate_editText); @@ -252,108 +349,19 @@ public class SellFragment extends CustomRecordFragment { }); fees_editText = view.findViewById(R.id.fees_editText_sell); - fees_editText.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - totalValueEditText.removeTextChangedListener(totalValueTextWatcher); - amoutEditText.removeTextChangedListener(amountTextWatcher); - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - if((isFieldCorrectlyFilled(amoutEditText, false) || isFieldCorrectlyFilled(totalValueEditText, false)) && isFieldCorrectlyFilled(sellPriceEditText, false)) - { - double amount = Double.parseDouble(amoutEditText.getText().toString()); - double purchasePrice = Double.parseDouble(sellPriceEditText.getText().toString()); - double fees; - double totalValue = Double.parseDouble(totalValueEditText.getText().toString()); - String feeCurrency; - - if(isAmountLastUpdated) - { - totalValue = amount * purchasePrice; - } - else - { - amount = totalValue / purchasePrice; - } - - if(fees_editText.getText().toString().equals("0") || (start == 0 && before == 1 && count == 0)) - { - if(isAmountLastUpdated) - { - totalValueEditText.setText(String.valueOf(amount * purchasePrice)); - } - else - { - amoutEditText.setText(String.valueOf(totalValue / purchasePrice)); - } - } - else - { - - if(feesCurrencySpinner.getSelectedItemPosition() < 2) - { - feeCurrency = fragmentPair.getFrom(); - } - else - { - feeCurrency = fragmentPair.getTo(); - } - - fees = getFees(feeCurrency, amount, purchasePrice); - - if(feesCurrencySpinner.getSelectedItemPosition() % 2 == 0) - { - if(isAmountLastUpdated) - { - totalValueEditText.setText(String.valueOf(totalValue - fees)); - } - else - { - amoutEditText.setText(String.valueOf(amount + (fees / purchasePrice))); - } - } - else - { - if(fragmentCurrency.getSymbol().equals(feeCurrency)) - { - if(isAmountLastUpdated) - { - totalValueEditText.setText(String.valueOf(totalValue - (fees * purchasePrice))); - } - else - { - amoutEditText.setText(String.valueOf((totalValue / purchasePrice) + fees)); - } - } - else - { - if(isAmountLastUpdated) - { - totalValueEditText.setText(String.valueOf(totalValue - fees)); - } - else - { - amoutEditText.setText(String.valueOf((totalValue + fees) / purchasePrice)); - } - } - } - } - } - } - - @Override - public void afterTextChanged(Editable s) { - totalValueEditText.addTextChangedListener(totalValueTextWatcher); - amoutEditText.addTextChangedListener(amountTextWatcher); - } - }); note_editText = view.findViewById(R.id.note_editText_sell); checkCallingIntent(); + + setupTextWatchers(); + } + + private void setupTextWatchers() + { + totalValueEditText.addTextChangedListener(totalValueTextWatcher); + amoutEditText.addTextChangedListener(amountTextWatcher); + fees_editText.addTextChangedListener(feesTextWatcher); } private double getFees(String feeCurrency, double amount, double purchasedPrice) diff --git a/app/src/main/res/layout/activity_record_transaction.xml b/app/src/main/res/layout/activity_record_transaction.xml index 699015d..8f111ec 100644 --- a/app/src/main/res/layout/activity_record_transaction.xml +++ b/app/src/main/res/layout/activity_record_transaction.xml @@ -126,7 +126,7 @@ app:tabMode="fixed" app:tabIndicatorColor="@color/transparent"/> - From b25e44d3ef82088305022d63977f2a4230c309ea Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 21:54:12 +0200 Subject: [PATCH 04/23] 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(); From d79a76f13bba2b7eb5971b7c8c17d2ffe5d85e8d Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 22:35:37 +0200 Subject: [PATCH 05/23] [DetailsActivity] Enable binance trade update - Add support for multiple binance accounts --- .../Transactions.java | 67 ++++++++++++------- .../moodl/DataManagers/BalanceManager.java | 5 +- .../ExchangeManager/BinanceManager.java | 2 +- .../BinanceUpdateNotifierInterface.java | 6 +- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java index 007e136..8d09c26 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java @@ -28,6 +28,7 @@ import com.herbron.moodl.CustomAdapters.TransactionListAdapter; import com.herbron.moodl.R; import java.util.ArrayList; +import java.util.List; /** * Created by Tiji on 13/05/2018. @@ -41,7 +42,7 @@ public class Transactions extends Fragment { private ListView tradeLayout; private ListView transactionLayout; private boolean flag_loading; - private BinanceManager binanceManager; + private List binanceManagerList; private DatabaseManager databaseManager; private TradeListAdapter tradeListAdapter; private ArrayList returnedTrades; @@ -55,7 +56,7 @@ public class Transactions extends Fragment { currency = getActivity().getIntent().getParcelableExtra("currency"); databaseManager = new DatabaseManager(getActivity().getBaseContext()); - //binanceManager = new BinanceManager(preferencesManager.getBinancePublicKey(), preferencesManager.getBinancePrivateKey()); + binanceManagerList = databaseManager.getBinanceAccounts(); tradeLayout = view.findViewById(R.id.listTrades); transactionLayout = view.findViewById(R.id.listTransactions); @@ -64,8 +65,8 @@ public class Transactions extends Fragment { TransactionUpdater transactionUpdater = new TransactionUpdater(); transactionUpdater.execute(); - /*TradeUpdater updater = new TradeUpdater(); - updater.execute();*/ + TradeUpdater updater = new TradeUpdater(); + updater.execute(); return view; } @@ -212,10 +213,16 @@ public class Transactions extends Fragment { private class TradeUpdater extends AsyncTask implements BinanceUpdateNotifierInterface { + private List trades; + private int nbResponse; + @Override protected void onPreExecute() { super.onPreExecute(); + + trades = new ArrayList<>(); + nbResponse = 0; } @Override @@ -228,7 +235,11 @@ public class Transactions extends Fragment { protected Void doInBackground(Void... params) { - binanceManager.updateTrades(currency.getSymbol()); + for(int i = 0; i < binanceManagerList.size(); i++) + { + binanceManagerList.get(i).addListener(this); + binanceManagerList.get(i).updateTrades(currency.getSymbol()); + } return null; } @@ -240,31 +251,37 @@ public class Transactions extends Fragment { } @Override - public void onBinanceTradesUpdated() { - ArrayList trades = binanceManager.getTrades(); - returnedTrades = new ArrayList<>(); + public void onBinanceTradesUpdated(List newTrades) { + trades.addAll(newTrades); - for(int i = trades.size() - 1; i >= 0 ; i--) + nbResponse++; + + if(nbResponse == binanceManagerList.size()) { - returnedTrades.add(trades.get(i)); - } + returnedTrades = new ArrayList<>(); - try { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - ArrayList trades = new ArrayList<>(); + for(int i = trades.size() - 1; i >= 0 ; i--) + { + returnedTrades.add(trades.get(i)); + } - for(int i = 0; i < 20 && i < returnedTrades.size(); i++) - { - trades.add(returnedTrades.get(i)); + try { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ArrayList trades = new ArrayList<>(); + + for(int i = 0; i < 20 && i < returnedTrades.size(); i++) + { + trades.add(returnedTrades.get(i)); + } + + drawTradeList(trades); } - - drawTradeList(trades); - } - }); - } catch (NullPointerException e) { - Log.d("moodl", "Transactions do not need to be updated anymore"); + }); + } catch (NullPointerException e) { + Log.d("moodl", "Transactions do not need to be updated anymore"); + } } } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java index 0ad3f03..8693f8c 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java @@ -1,6 +1,7 @@ package com.herbron.moodl.DataManagers; import com.herbron.moodl.Activities.HomeActivity; +import com.herbron.moodl.DataManagers.CurrencyData.Trade; import com.herbron.moodl.DataNotifiers.BinanceUpdateNotifierInterface; import com.herbron.moodl.DataManagers.CurrencyData.Currency; import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager; @@ -87,7 +88,7 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd for(int i = 0; i < binanceManagers.size(); i++) { - final BinanceManager binanceManager = binanceManagers.get(i); + BinanceManager binanceManager = binanceManagers.get(i); binanceManager.addListener(this); binanceManager.updateBalance(); } @@ -169,7 +170,7 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd } @Override - public void onBinanceTradesUpdated() { + public void onBinanceTradesUpdated(List trades) { } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java index f33d9bb..d6d1142 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java @@ -101,7 +101,7 @@ public class BinanceManager extends Exchange { for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList) { - binanceUpdateNotifierInterface.onBinanceTradesUpdated(); + binanceUpdateNotifierInterface.onBinanceTradesUpdated(trades); } } diff --git a/app/src/main/java/com/herbron/moodl/DataNotifiers/BinanceUpdateNotifierInterface.java b/app/src/main/java/com/herbron/moodl/DataNotifiers/BinanceUpdateNotifierInterface.java index 25920af..05bcafd 100644 --- a/app/src/main/java/com/herbron/moodl/DataNotifiers/BinanceUpdateNotifierInterface.java +++ b/app/src/main/java/com/herbron/moodl/DataNotifiers/BinanceUpdateNotifierInterface.java @@ -1,8 +1,12 @@ package com.herbron.moodl.DataNotifiers; +import com.herbron.moodl.DataManagers.CurrencyData.Trade; + +import java.util.List; + public interface BinanceUpdateNotifierInterface { - void onBinanceTradesUpdated(); + void onBinanceTradesUpdated(List trades); void onBinanceBalanceUpdateSuccess(); From e80c9f4046a8f9769eccfd12680152302dde5da0 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 20 Aug 2018 22:45:03 +0200 Subject: [PATCH 06/23] Code sorting --- .../{Charts.java => ChartsFragment.java} | 20 +++++++++---------- ...rmations.java => InformationFragment.java} | 2 +- ...actions.java => TransactionsFragment.java} | 4 ++-- .../moodl/DetailsActivityPagerAdapter.java | 12 +++++------ app/src/main/res/values/strings.xml | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) rename app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/{Charts.java => ChartsFragment.java} (97%) rename app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/{Informations.java => InformationFragment.java} (99%) rename app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/{Transactions.java => TransactionsFragment.java} (98%) diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java similarity index 97% rename from app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java rename to app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java index 5758398..29af91d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java @@ -49,7 +49,7 @@ import static com.herbron.moodl.MoodlBox.numberConformer; * Created by Tiji on 13/05/2018. */ -public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterface { +public class ChartsFragment extends Fragment implements CurrencyInfoUpdateNotifierInterface { private final static int HOUR = 0; private final static int DAY = 1; @@ -628,31 +628,31 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf switch (timeIntervalSpinner.getSelectedItemPosition()) { case 0: - updateChartTab(Charts.HOUR, 1); + updateChartTab(ChartsFragment.HOUR, 1); break; case 1: - updateChartTab(Charts.HOUR, 3); + updateChartTab(ChartsFragment.HOUR, 3); break; case 2: - updateChartTab(Charts.DAY, 1); + updateChartTab(ChartsFragment.DAY, 1); break; case 3: - updateChartTab(Charts.DAY, 3); + updateChartTab(ChartsFragment.DAY, 3); break; case 4: - updateChartTab(Charts.WEEK, 11); + updateChartTab(ChartsFragment.WEEK, 11); break; case 5: - updateChartTab(Charts.MONTH, 1); + updateChartTab(ChartsFragment.MONTH, 1); break; case 6: - updateChartTab(Charts.MONTH, 3); + updateChartTab(ChartsFragment.MONTH, 3); break; case 7: - updateChartTab(Charts.MONTH, 6); + updateChartTab(ChartsFragment.MONTH, 6); break; case 8: - updateChartTab(Charts.YEAR, 1); + updateChartTab(ChartsFragment.YEAR, 1); break; } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Informations.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java similarity index 99% rename from app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Informations.java rename to app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java index 5653191..88ba247 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Informations.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java @@ -26,7 +26,7 @@ import static com.herbron.moodl.MoodlBox.numberConformer; * Created by Tiji on 13/05/2018. */ -public class Informations extends Fragment { +public class InformationFragment extends Fragment { private Currency currency; private View view; diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java similarity index 98% rename from app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java rename to app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java index 8d09c26..192fb4f 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Transactions.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java @@ -34,7 +34,7 @@ import java.util.List; * Created by Tiji on 13/05/2018. */ -public class Transactions extends Fragment { +public class TransactionsFragment extends Fragment { private Currency currency; private View loadingFooter; @@ -280,7 +280,7 @@ public class Transactions extends Fragment { } }); } catch (NullPointerException e) { - Log.d("moodl", "Transactions do not need to be updated anymore"); + Log.d("moodl", "TransactionsFragment do not need to be updated anymore"); } } } diff --git a/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java b/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java index da76aec..271245f 100644 --- a/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java +++ b/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java @@ -4,9 +4,9 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; -import com.herbron.moodl.Activities.DetailsActivityFragments.Charts; -import com.herbron.moodl.Activities.DetailsActivityFragments.Informations; -import com.herbron.moodl.Activities.DetailsActivityFragments.Transactions; +import com.herbron.moodl.Activities.DetailsActivityFragments.ChartsFragment; +import com.herbron.moodl.Activities.DetailsActivityFragments.InformationFragment; +import com.herbron.moodl.Activities.DetailsActivityFragments.TransactionsFragment; /** * Created by Tiji on 13/05/2018. @@ -27,11 +27,11 @@ public class DetailsActivityPagerAdapter extends FragmentStatePagerAdapter { switch (position) { case 0: - return new Charts(); + return new ChartsFragment(); case 1: - return new Informations(); + return new InformationFragment(); case 2: - return new Transactions(); + return new TransactionsFragment(); default: return null; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25d563e..e45d473 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,7 +79,7 @@ Looking for trades… -- - + Drawer Dominance percentage Active cryptocurrencies From ac7fb545ecf082a2771e98d7f8abf93cbfa14668 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 21 Aug 2018 00:19:29 +0200 Subject: [PATCH 07/23] [DetailsActivity] Merge Transactions and Trades in the same list --- .../TransactionsFragment.java | 236 +++++++++++++----- .../CustomAdapters/TradeListAdapter.java | 2 +- .../TransactionListAdapter.java | 51 +++- app/src/main/res/layout/custom_trade_row.xml | 2 +- .../res/layout/custom_transaction_row.xml | 32 +-- .../detailsactivity_fragment_transactions.xml | 12 +- 6 files changed, 243 insertions(+), 92 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java index 192fb4f..2641b70 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java @@ -28,6 +28,8 @@ import com.herbron.moodl.CustomAdapters.TransactionListAdapter; import com.herbron.moodl.R; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -39,7 +41,7 @@ public class TransactionsFragment extends Fragment { private Currency currency; private View loadingFooter; private View view; - private ListView tradeLayout; + //private ListView tradeLayout; private ListView transactionLayout; private boolean flag_loading; private List binanceManagerList; @@ -57,7 +59,7 @@ public class TransactionsFragment extends Fragment { currency = getActivity().getIntent().getParcelableExtra("currency"); databaseManager = new DatabaseManager(getActivity().getBaseContext()); binanceManagerList = databaseManager.getBinanceAccounts(); - tradeLayout = view.findViewById(R.id.listTrades); + //tradeLayout = view.findViewById(R.id.listTrades); transactionLayout = view.findViewById(R.id.listTransactions); flag_loading = false; @@ -65,59 +67,137 @@ public class TransactionsFragment extends Fragment { TransactionUpdater transactionUpdater = new TransactionUpdater(); transactionUpdater.execute(); - TradeUpdater updater = new TradeUpdater(); - updater.execute(); - return view; } - private void loadingIndicatorGenerator() + private class TransactionUpdater extends AsyncTask implements BinanceUpdateNotifierInterface { - loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false); + private ArrayList displayedTransactions; + private int nbTradeAccountUpdated; + private int nbTransactionAccountUpdated; - Drawable drawable = ((ProgressBar) loadingFooter.findViewById(R.id.progressIndicator)).getIndeterminateDrawable(); - drawable.mutate(); - drawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - drawable.invalidateSelf(); + @Override + protected void onPreExecute() { + super.onPreExecute(); - tradeLayout.addFooterView(loadingFooter); - } + displayedTransactions = new ArrayList<>(); + nbTradeAccountUpdated = 0; + nbTransactionAccountUpdated = 0; + } - private void drawTradeList(ArrayList trades) - { - if(returnedTrades.size() > 20) + @Override + protected Void doInBackground(Void... voids) { + if(Looper.myLooper() == null) + { + Looper.prepare(); + } + + displayedTransactions.addAll(databaseManager.getCurrencyTransactionsForSymbol(currency.getSymbol())); + + for(int i = 0; i < binanceManagerList.size(); i++) + { + binanceManagerList.get(i).addListener(this); + binanceManagerList.get(i).updateTrades(currency.getSymbol()); + binanceManagerList.get(i).updateTransactions(currency.getSymbol()); + } + + if(nbTradeAccountUpdated == binanceManagerList.size()) + { + drawTransactionList(displayedTransactions); + } + + return null; + } + + @Override + public void onBinanceTradesUpdated(List trades) { + nbTradeAccountUpdated++; + + displayedTransactions.addAll(trades); + + if(nbTradeAccountUpdated == binanceManagerList.size()) + { + drawTransactionList(displayedTransactions); + } + } + + @Override + public void onBinanceBalanceUpdateSuccess() { + + } + + @Override + public void onBinanceBalanceUpdateError(int accountId, String error) { + + } + + private void drawTransactionList(ArrayList transactions) { - tradeLayout.setOnScrollListener(new AbsListView.OnScrollListener() { + Collections.sort(transactions, new Comparator() { @Override - public void onScrollStateChanged(AbsListView absListView, int i) { + public int compare(Object o1, Object o2) { + Long time1; + Long time2; - } - - @Override - public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0) + if(o1 instanceof Transaction) { - if(!flag_loading && tradeLayout.getCount() != returnedTrades.size() - 1) - { - flag_loading = true; - - TradeAdder tradeAdder = new TradeAdder(); - tradeAdder.execute(); - } + time1 = ((Transaction) o1).getTimestamp(); } + else + { + time1 = ((Trade) o1).getTime(); + } + + if(o2 instanceof Transaction) + { + time2 = ((Transaction) o2).getTimestamp(); + } + else + { + time2 = ((Trade) o2).getTime(); + } + + return time2.compareTo(time1); + } + }); + + TransactionListAdapter transactionListAdapter = new TransactionListAdapter(getActivity(), transactions); + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + transactionLayout.setAdapter(transactionListAdapter); + transactionLayout.setTextFilterEnabled(false); } }); } - - tradeListAdapter = new TradeListAdapter(getActivity().getBaseContext(), trades); - - tradeLayout.setAdapter(tradeListAdapter); - tradeLayout.setTextFilterEnabled(false); - - view.findViewById(R.id.tradeLoaderIndicator).setVisibility(View.GONE); } - private class TradeAdder extends AsyncTask + /*public class TransactionUpdater extends AsyncTask + { + @Override + protected Void doInBackground(Void... voids) { + + if(Looper.myLooper() == null) + { + Looper.prepare(); + } + + //binanceManager.updateTransactions(currency.getSymbol()); + + final ArrayList transactionList = databaseManager.getCurrencyTransactionsForSymbol(currency.getSymbol()); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + drawTransactionList(transactionList); + } + }); + + return null; + } + }*/ + + /*private class TradeAdder extends AsyncTask { @Override protected void onPreExecute() @@ -146,7 +226,7 @@ public class TransactionsFragment extends Fragment { tradeLayout.removeFooterView(loadingFooter); } }); - /*binanceManager.updateTrades(new BinanceManager.BinanceCallBack() { + binanceManager.updateTrades(new BinanceManager.BinanceCallBack() { @Override public void onSuccess() { ArrayList trades = binanceManager.getTrades(); @@ -173,13 +253,13 @@ public class TransactionsFragment extends Fragment { public void onError(String error) { } - }, currency.getSymbol(), tradeListAdapter.getItem(tradeListAdapter.getCount() - 1).getId());*/ + }, currency.getSymbol(), tradeListAdapter.getItem(tradeListAdapter.getCount() - 1).getId()); return null; } - } + }*/ - private void drawTransactionList(ArrayList transactions) + /*private void drawTransactionList(ArrayList transactions) { TransactionListAdapter transactionListAdapter = new TransactionListAdapter(getActivity(), transactions); @@ -187,30 +267,6 @@ public class TransactionsFragment extends Fragment { transactionLayout.setTextFilterEnabled(false); } - public class TransactionUpdater extends AsyncTask - { - @Override - protected Void doInBackground(Void... voids) { - - if(Looper.myLooper() == null) - { - Looper.prepare(); - } - - //binanceManager.updateTransactions(currency.getSymbol()); - - final ArrayList transactionList = databaseManager.getCurrencyTransactionsForSymbol(currency.getSymbol()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - drawTransactionList(transactionList); - } - }); - - return null; - } - } - private class TradeUpdater extends AsyncTask implements BinanceUpdateNotifierInterface { private List trades; @@ -276,7 +332,7 @@ public class TransactionsFragment extends Fragment { trades.add(returnedTrades.get(i)); } - drawTradeList(trades); + //drawTradeList(trades); } }); } catch (NullPointerException e) { @@ -294,5 +350,51 @@ public class TransactionsFragment extends Fragment { public void onBinanceBalanceUpdateError(int accountId, String error) { } + }*/ + + /*private void loadingIndicatorGenerator() + { + loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false); + + Drawable drawable = ((ProgressBar) loadingFooter.findViewById(R.id.progressIndicator)).getIndeterminateDrawable(); + drawable.mutate(); + drawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + drawable.invalidateSelf(); + + tradeLayout.addFooterView(loadingFooter); } + + private void drawTradeList(ArrayList trades) + { + if(returnedTrades.size() > 20) + { + tradeLayout.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0) + { + if(!flag_loading && tradeLayout.getCount() != returnedTrades.size() - 1) + { + flag_loading = true; + + TradeAdder tradeAdder = new TradeAdder(); + tradeAdder.execute(); + } + } + } + }); + } + + tradeListAdapter = new TradeListAdapter(getActivity().getBaseContext(), trades); + + tradeLayout.setAdapter(tradeListAdapter); + tradeLayout.setTextFilterEnabled(false); + + view.findViewById(R.id.tradeLoaderIndicator).setVisibility(View.GONE); + }*/ } diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java index dc84a75..f113531 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java @@ -41,7 +41,7 @@ public class TradeListAdapter extends ArrayAdapter { } TextView amountTxtView = convertView.findViewById(R.id.amountPurchased); - TextView purchasedPrice = convertView.findViewById(R.id.purchasedPrice); + TextView purchasedPrice = convertView.findViewById(R.id.purchasePrice); TextView tradePair = convertView.findViewById(R.id.pair); TextView dateTxtView = convertView.findViewById(R.id.tradeDate); View tradeIndicator = convertView.findViewById(R.id.tradeIndicator); diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java index b1864e3..562e93c 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,6 +15,7 @@ import android.widget.TextView; import com.daimajia.swipe.SwipeLayout; import com.herbron.moodl.Activities.RecordTransactionActivity; +import com.herbron.moodl.DataManagers.CurrencyData.Trade; import com.herbron.moodl.DataManagers.CurrencyData.Transaction; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.PreferencesManager; @@ -30,11 +32,11 @@ import static java.lang.Math.abs; * Created by Guitoune on 24/04/2018. */ -public class TransactionListAdapter extends ArrayAdapter { +public class TransactionListAdapter extends ArrayAdapter { private Context context; - public TransactionListAdapter(Context context, ArrayList transactions) + public TransactionListAdapter(Context context, ArrayList transactions) { super(context, android.R.layout.simple_list_item_1, transactions); this.context = context; @@ -43,12 +45,51 @@ public class TransactionListAdapter extends ArrayAdapter { @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - final Transaction transaction = getItem(position); - if(convertView == null) + if(getItem(position) instanceof Transaction) { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_transaction_row, parent, false); + return generateTransactionLayout(position, parent); } + else + { + return generateTradeLayout(position, parent); + } + } + + private View generateTradeLayout(int position, ViewGroup parent) + { + Trade trade = (Trade) getItem(position); + + View convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_trade_row, parent, false); + + TextView amountTxtView = convertView.findViewById(R.id.amountPurchased); + TextView purchasedPrice = convertView.findViewById(R.id.purchasePrice); + TextView tradePair = convertView.findViewById(R.id.pair); + TextView dateTxtView = convertView.findViewById(R.id.tradeDate); + View tradeIndicator = convertView.findViewById(R.id.tradeIndicator); + + amountTxtView.setText(String.valueOf(trade.getQty())); + purchasedPrice.setText(trade.getPrice()); + dateTxtView.setText(getDateFromTimestamp(trade.getTime())); + tradePair.setText(trade.getSymbol() + "/" + trade.getPairSymbol()); + + if(trade.isBuyer()) + { + tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.green)); + } + else + { + tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.red)); + } + + return convertView; + } + + private View generateTransactionLayout(int position, ViewGroup parent) + { + final Transaction transaction = (Transaction) getItem(position); + + View convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_transaction_row, parent, false); TextView amountTxtView = convertView.findViewById(R.id.amountPurchased); TextView valueTxtView = convertView.findViewById(R.id.puchasedValue); diff --git a/app/src/main/res/layout/custom_trade_row.xml b/app/src/main/res/layout/custom_trade_row.xml index cbab56d..3298b26 100644 --- a/app/src/main/res/layout/custom_trade_row.xml +++ b/app/src/main/res/layout/custom_trade_row.xml @@ -38,7 +38,7 @@ android:textSize="15dp"/> diff --git a/app/src/main/res/layout/custom_transaction_row.xml b/app/src/main/res/layout/custom_transaction_row.xml index 7c96aaf..67e3c1b 100644 --- a/app/src/main/res/layout/custom_transaction_row.xml +++ b/app/src/main/res/layout/custom_transaction_row.xml @@ -2,21 +2,21 @@ - - + android:orientation="vertical"> + android:layout_height="49dp" + android:orientation="horizontal"> - + + - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/detailsactivity_fragment_transactions.xml b/app/src/main/res/layout/detailsactivity_fragment_transactions.xml index 2d2560f..b2967aa 100644 --- a/app/src/main/res/layout/detailsactivity_fragment_transactions.xml +++ b/app/src/main/res/layout/detailsactivity_fragment_transactions.xml @@ -5,7 +5,15 @@ android:layout_height="match_parent" android:orientation="vertical"> - + + \ No newline at end of file From 518df666f400d77afb7b46588566f56ab46c639d Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 21 Aug 2018 02:00:09 +0200 Subject: [PATCH 08/23] Multiple fixs [DetailsActivity] - Fix crash when finishing the activity before all transactions and trades are updated [MarketCapitalizationActivity] - Fix some views not visible for little screens [RecordTransactionActivity] - Fix crash when editing a sell transaction --- .../TransactionsFragment.java | 19 +- .../MarketCapitalization.java | 8 +- .../BuyFragment.java | 4 +- .../SellFragment.java | 4 +- .../TransferFragment.java | 6 +- .../spinner_background_header.xml | 46 ++++ .../drawable/spinner_background_header.xml | 6 - .../homeactivity_fragment_marketcap.xml | 246 +++++++++--------- .../homeactivity_fragment_marketcap.xml | 245 ++++++++--------- .../record_transaction_fragment_buy.xml | 2 +- .../res/layout/spinner_dropdown_black.xml | 9 + 11 files changed, 334 insertions(+), 261 deletions(-) create mode 100644 app/src/main/res/drawable-v21/spinner_background_header.xml create mode 100644 app/src/main/res/layout/spinner_dropdown_black.xml diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java index 2641b70..61fba84 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java @@ -161,15 +161,18 @@ public class TransactionsFragment extends Fragment { } }); - TransactionListAdapter transactionListAdapter = new TransactionListAdapter(getActivity(), transactions); + if(getActivity() != null) + { + TransactionListAdapter transactionListAdapter = new TransactionListAdapter(getActivity(), transactions); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - transactionLayout.setAdapter(transactionListAdapter); - transactionLayout.setTextFilterEnabled(false); - } - }); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + transactionLayout.setAdapter(transactionListAdapter); + transactionLayout.setTextFilterEnabled(false); + } + }); + } } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index 4305c16..5cd2023 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -9,6 +9,7 @@ import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; +import android.support.v4.widget.NestedScrollView; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.graphics.Palette; import android.text.SpannableString; @@ -54,6 +55,7 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif private PreferencesManager preferencesManager; private CoinmarketCapAPIManager coinmarketCapAPIManager; private SwipeRefreshLayout refreshLayout; + private NestedScrollView nestedScrollView; private long lastTimestamp; private String defaultCurrency; private CryptocompareApiManager cryptocompareApiManager; @@ -89,6 +91,8 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif defaultCurrency = preferencesManager.getDefaultCurrency(); lastTimestamp = 0; + nestedScrollView = view.findViewById(R.id.nestedMarketCap); + setupRefreshLayout(); setupDrawerButton(); @@ -304,12 +308,12 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: - refreshLayout.setEnabled(false); + nestedScrollView.setEnabled(false); break; case MotionEvent.ACTION_MOVE: break; default: - refreshLayout.setEnabled(true); + nestedScrollView.setEnabled(true); break; } 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 767d472..6d7a1c2 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 @@ -296,8 +296,8 @@ public class BuyFragment extends CustomRecordFragment { }); feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText_buy); - currencyFeeAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); - currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + currencyFeeAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, new ArrayList<>()); + currencyFeeAdapter.setDropDownViewResource(R.layout.spinner_dropdown_black); feesCurrencySpinner.setAdapter(currencyFeeAdapter); deductHoldingsSwitch = view.findViewById(R.id.deductHoldingsBuy); 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 4976a63..f91ce8b 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 @@ -268,7 +268,7 @@ public class SellFragment extends CustomRecordFragment { feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText_sell); currencyFeeAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); - currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + currencyFeeAdapter.setDropDownViewResource(R.layout.spinner_dropdown_black); feesCurrencySpinner.setAdapter(currencyFeeAdapter); if(fragmentPair != null) @@ -522,6 +522,8 @@ public class SellFragment 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); diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java index d057a5b..b36deb2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java @@ -262,15 +262,15 @@ public class TransferFragment extends CustomRecordFragment { private void setupSpinnesr() { ArrayAdapter fromAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.from_transfer_options_string_array)); - fromAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + fromAdapter.setDropDownViewResource(R.layout.spinner_dropdown_black); fromSpinner.setAdapter(fromAdapter); ArrayAdapter toAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.to_transfer_options_string_array)); - toAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + toAdapter.setDropDownViewResource(R.layout.spinner_dropdown_black); toSpinner.setAdapter(toAdapter); ArrayAdapter feeAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.fees_options)); - feeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + feeAdapter.setDropDownViewResource(R.layout.spinner_dropdown_black); feeSpinner.setAdapter(feeAdapter); fromSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { diff --git a/app/src/main/res/drawable-v21/spinner_background_header.xml b/app/src/main/res/drawable-v21/spinner_background_header.xml new file mode 100644 index 0000000..7246389 --- /dev/null +++ b/app/src/main/res/drawable-v21/spinner_background_header.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/spinner_background_header.xml b/app/src/main/res/drawable/spinner_background_header.xml index 7246389..b6e1358 100644 --- a/app/src/main/res/drawable/spinner_background_header.xml +++ b/app/src/main/res/drawable/spinner_background_header.xml @@ -16,9 +16,6 @@ android:bottom="3dp"/> - @@ -38,9 +35,6 @@ android:bottom="3dp"/> - diff --git a/app/src/main/res/layout-v21/homeactivity_fragment_marketcap.xml b/app/src/main/res/layout-v21/homeactivity_fragment_marketcap.xml index 9d3726a..31351d3 100644 --- a/app/src/main/res/layout-v21/homeactivity_fragment_marketcap.xml +++ b/app/src/main/res/layout-v21/homeactivity_fragment_marketcap.xml @@ -50,173 +50,181 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@drawable/gradient_background"> - - - - + android:orientation="vertical" + android:paddingTop="20dp" + android:background="@drawable/list_background"> - - - - - - - - - + style="?android:attr/progressBarStyleLarge" + android:layout_gravity="center" + android:background="@drawable/circular_progress_bar" /> - + - + android:layout_height="350dp" + android:layout_marginTop="5dp"> + + + + + + + android:orientation="vertical" + android:layout_margin="10dp"> + + + + - - - - + android:orientation="horizontal" + android:baselineAligned="false"> + android:layout_weight="0.5" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + android:layout_weight="0.5" + android:orientation="vertical"> - - - - - - - - - - - - - + android:orientation="vertical" + android:layout_marginTop="5dp"> - + + + + + @@ -228,6 +236,6 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/homeactivity_fragment_marketcap.xml b/app/src/main/res/layout/homeactivity_fragment_marketcap.xml index 6fa469b..2628a9a 100644 --- a/app/src/main/res/layout/homeactivity_fragment_marketcap.xml +++ b/app/src/main/res/layout/homeactivity_fragment_marketcap.xml @@ -51,173 +51,180 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@drawable/gradient_background"> - - - - + android:orientation="vertical" + android:paddingTop="20dp"> - - - - - - - - - + style="?android:attr/progressBarStyleLarge" + android:layout_gravity="center" + android:background="@drawable/circular_progress_bar" /> - + - + android:layout_height="350dp" + android:layout_marginTop="5dp"> + + + + + + + android:orientation="vertical" + android:layout_margin="10dp"> + + + + - - - - + android:orientation="horizontal" + android:baselineAligned="false"> + android:layout_weight="0.5" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + android:layout_weight="0.5" + android:orientation="vertical"> - - - - - - - - - - - - - + android:orientation="vertical" + android:layout_marginTop="5dp"> - + + + + + @@ -229,6 +236,6 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/record_transaction_fragment_buy.xml b/app/src/main/res/layout/record_transaction_fragment_buy.xml index d883f0b..c13495f 100644 --- a/app/src/main/res/layout/record_transaction_fragment_buy.xml +++ b/app/src/main/res/layout/record_transaction_fragment_buy.xml @@ -100,7 +100,7 @@ android:id="@+id/feesCurrency_editText_buy" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_weight="1"/> + android:layout_weight="1" /> diff --git a/app/src/main/res/layout/spinner_dropdown_black.xml b/app/src/main/res/layout/spinner_dropdown_black.xml new file mode 100644 index 0000000..bf21419 --- /dev/null +++ b/app/src/main/res/layout/spinner_dropdown_black.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file From dd9f4d21419e6aff6a9c869a8d3695e65813bd88 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 22 Aug 2018 21:27:58 +0200 Subject: [PATCH 09/23] Rework labels in transaction history - Summary now updates after importing data - Fix crash when exiting the details activity too quickly --- .idea/assetWizardSettings.xml | 4 +- .../ChartsFragment.java | 18 ++--- .../InformationFragment.java | 27 ++++--- .../TransactionsFragment.java | 8 -- .../moodl/Activities/HomeActivity.java | 10 +-- .../MarketCapitalization.java | 8 +- .../HomeActivityFragments/Summary.java | 10 +-- .../Activities/RecordTransactionActivity.java | 29 ++----- .../BuyFragment.java | 11 ++- .../SellFragment.java | 10 +-- .../moodl/Activities/SettingsActivity.java | 4 + .../CustomAdapters/PairRecordListAdapter.java | 4 +- .../CustomAdapters/TradeListAdapter.java | 65 ---------------- .../TransactionListAdapter.java | 42 ++++++++++- .../CurrencyData/CurrencyCardview.java | 25 +++---- .../moodl/DataManagers/DatabaseManager.java | 8 +- .../PlaceholderUtils.java} | 25 ++++++- .../herbron/moodl/Utils/TransferUtils.java | 42 +++++++++++ .../drawable/ic_arrow_downward_white_24dp.xml | 5 ++ .../drawable/ic_arrow_upward_white_24dp.xml | 5 ++ app/src/main/res/layout/custom_trade_row.xml | 75 +++++++++---------- .../res/layout/custom_transaction_row.xml | 22 ++++-- app/src/main/res/values-fr/strings.xml | 10 +-- app/src/main/res/values/strings.xml | 6 ++ 24 files changed, 250 insertions(+), 223 deletions(-) delete mode 100644 app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java rename app/src/main/java/com/herbron/moodl/{PlaceholderManager.java => Utils/PlaceholderUtils.java} (89%) create mode 100644 app/src/main/java/com/herbron/moodl/Utils/TransferUtils.java create mode 100644 app/src/main/res/drawable/ic_arrow_downward_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_arrow_upward_white_24dp.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index ddc44c0..b34e12f 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -71,7 +71,7 @@ @@ -82,7 +82,7 @@ diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java index 29af91d..8aedb3d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/ChartsFragment.java @@ -36,7 +36,7 @@ import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDataChart; import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.CustomLayouts.CustomViewPager; import com.herbron.moodl.MoodlBox; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.util.ArrayList; @@ -252,8 +252,8 @@ public class ChartsFragment extends Fragment implements CurrencyInfoUpdateNotifi updateFluctuation(start, end); - ((TextView) view.findViewById(R.id.txtViewPriceStart)).setText(PlaceholderManager.getValueString(numberConformer(start), getActivity().getBaseContext())); - ((TextView) view.findViewById(R.id.txtViewPriceNow)).setText(PlaceholderManager.getValueString(numberConformer(end), getActivity().getBaseContext())); + ((TextView) view.findViewById(R.id.txtViewPriceStart)).setText(PlaceholderUtils.getValueString(numberConformer(start), getActivity().getBaseContext())); + ((TextView) view.findViewById(R.id.txtViewPriceNow)).setText(PlaceholderUtils.getValueString(numberConformer(end), getActivity().getBaseContext())); for(int i = 1; i < dataChartList.size(); i++) { @@ -270,9 +270,9 @@ public class ChartsFragment extends Fragment implements CurrencyInfoUpdateNotifi } } - ((TextView) view.findViewById(R.id.totalVolume)).setText(PlaceholderManager.getValueString(numberConformer(totalVolume), getActivity().getBaseContext())); - ((TextView) view.findViewById(R.id.highestPrice)).setText(PlaceholderManager.getValueString(numberConformer(highestPrice), getActivity().getBaseContext())); - ((TextView) view.findViewById(R.id.lowestPrice)).setText(PlaceholderManager.getValueString(numberConformer(lowestPrice), getActivity().getBaseContext())); + ((TextView) view.findViewById(R.id.totalVolume)).setText(PlaceholderUtils.getValueString(numberConformer(totalVolume), getActivity().getBaseContext())); + ((TextView) view.findViewById(R.id.highestPrice)).setText(PlaceholderUtils.getValueString(numberConformer(highestPrice), getActivity().getBaseContext())); + ((TextView) view.findViewById(R.id.lowestPrice)).setText(PlaceholderUtils.getValueString(numberConformer(lowestPrice), getActivity().getBaseContext())); } private void updateFluctuation(float start, float end) @@ -457,9 +457,9 @@ public class ChartsFragment extends Fragment implements CurrencyInfoUpdateNotifi date = getDateFromTimestamp(dataChartList.get(index).getTimestamp() * 1000); } - volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), getActivity().getBaseContext()); - pricePlaceholder = PlaceholderManager.getPriceString(numberConformer((lineChart.getHighlighted())[0].getY()), getActivity().getBaseContext()); - timestampPlaceholder = PlaceholderManager.getTimestampString(date, getActivity().getBaseContext()); + volumePlaceholder = PlaceholderUtils.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), getActivity().getBaseContext()); + pricePlaceholder = PlaceholderUtils.getPriceString(numberConformer((lineChart.getHighlighted())[0].getY()), getActivity().getBaseContext()); + timestampPlaceholder = PlaceholderUtils.getTimestampString(date, getActivity().getBaseContext()); ((TextView) view.findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); view.findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java index 88ba247..f29c6f1 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java @@ -17,7 +17,7 @@ import android.widget.TextView; import com.herbron.moodl.DataManagers.CurrencyData.Currency; import com.herbron.moodl.DataManagers.PreferencesManager; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import static com.herbron.moodl.MoodlBox.numberConformer; @@ -74,12 +74,15 @@ public class InformationFragment extends Fragment { { if(isTickerUpdated && isSnapshotUpdated) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - refreshInfoTab(); - } - }); + if(getActivity() != null) + { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + refreshInfoTab(); + } + }); + } } } @@ -120,12 +123,12 @@ public class InformationFragment extends Fragment { ((TextView) view.findViewById(R.id.txtViewDescription)) .setMovementMethod(LinkMovementMethod.getInstance()); ((TextView) view.findViewById(R.id.txtViewPercentageCoinEmited)) - .setText(PlaceholderManager.getEmitedPercentageString(numberConformer(currency.getMinedCoinSupply() / currency.getMaxCoinSupply() * 100), getActivity().getBaseContext())); + .setText(PlaceholderUtils.getEmitedPercentageString(numberConformer(currency.getMinedCoinSupply() / currency.getMaxCoinSupply() * 100), getActivity().getBaseContext())); if(currency.getMarketCapitalization() != 0) { ((TextView) view.findViewById(R.id.txtViewMarketCapitalization)) - .setText(PlaceholderManager.getValueString(numberConformer(currency.getMarketCapitalization()), getActivity().getBaseContext())); + .setText(PlaceholderUtils.getValueString(numberConformer(currency.getMarketCapitalization()), getActivity().getBaseContext())); view.findViewById(R.id.linearMarketCap).setVisibility(View.VISIBLE); } @@ -139,15 +142,15 @@ public class InformationFragment extends Fragment { if(currency.getMaxCoinSupply() == 0) { ((TextView) view.findViewById(R.id.txtViewTotalSupply)) - .setText(PlaceholderManager.getSymbolString(getString(R.string.infinity), getActivity())); + .setText(PlaceholderUtils.getSymbolString(getString(R.string.infinity), getActivity())); } else { ((TextView) view.findViewById(R.id.txtViewTotalSupply)) - .setText(PlaceholderManager.getSymbolString(numberConformer(currency.getMaxCoinSupply()), getActivity())); + .setText(PlaceholderUtils.getSymbolString(numberConformer(currency.getMaxCoinSupply()), getActivity())); } ((TextView) view.findViewById(R.id.txtViewCirculatingSupply)) - .setText(PlaceholderManager.getSymbolString(numberConformer(currency.getMinedCoinSupply()), getActivity())); + .setText(PlaceholderUtils.getSymbolString(numberConformer(currency.getMinedCoinSupply()), getActivity())); } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java index 61fba84..ecace94 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/TransactionsFragment.java @@ -1,20 +1,14 @@ package com.herbron.moodl.Activities.DetailsActivityFragments; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Looper; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AbsListView; import android.widget.ListView; -import android.widget.ProgressBar; import com.herbron.moodl.DataNotifiers.BinanceUpdateNotifierInterface; import com.herbron.moodl.DataManagers.CurrencyData.Currency; @@ -23,7 +17,6 @@ import com.herbron.moodl.DataManagers.CurrencyData.Transaction; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.ExchangeManager.BinanceManager; import com.herbron.moodl.DataManagers.PreferencesManager; -import com.herbron.moodl.CustomAdapters.TradeListAdapter; import com.herbron.moodl.CustomAdapters.TransactionListAdapter; import com.herbron.moodl.R; @@ -46,7 +39,6 @@ public class TransactionsFragment extends Fragment { private boolean flag_loading; private List binanceManagerList; private DatabaseManager databaseManager; - private TradeListAdapter tradeListAdapter; private ArrayList returnedTrades; @Override diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivity.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivity.java index 68e0d93..2174a5e 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivity.java @@ -3,13 +3,11 @@ package com.herbron.moodl.Activities; import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; -import android.graphics.Bitmap; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceActivity; -import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.design.widget.NavigationView; import android.support.v4.app.Fragment; @@ -19,14 +17,12 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDelegate; -import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.view.WindowManager; import android.widget.CompoundButton; -import android.widget.ImageView; import android.widget.Switch; import android.widget.TextView; @@ -38,7 +34,7 @@ import com.herbron.moodl.BalanceSwitchManagerInterface; import com.herbron.moodl.BalanceUpdateInterface; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.PreferencesManager; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import static com.herbron.moodl.MoodlBox.numberConformer; @@ -247,11 +243,11 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte if(preferencesManager.isBalanceHidden()) { - drawerBalanceTextView.setText(PlaceholderManager.getPercentageString(numberConformer(value), getApplicationContext())); + drawerBalanceTextView.setText(PlaceholderUtils.getPercentageString(numberConformer(value), getApplicationContext())); } else { - drawerBalanceTextView.setText(PlaceholderManager.getValueString(numberConformer(value), getApplicationContext())); + drawerBalanceTextView.setText(PlaceholderUtils.getValueString(numberConformer(value), getApplicationContext())); } } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index 5cd2023..b3a56a4 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -37,7 +37,7 @@ import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.CustomLayouts.CustomPieChart; import com.herbron.moodl.MoodlBox; import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.util.ArrayList; @@ -391,13 +391,13 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif private void updateDetails(double marketCap, double volume, String title, double percentage) { ((TextView) view.findViewById(R.id.textViewMarketCap)) - .setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(marketCap), getActivity().getBaseContext())); + .setText(PlaceholderUtils.getValueString(MoodlBox.numberConformer(marketCap), getActivity().getBaseContext())); ((TextView) view.findViewById(R.id.textViewVolume)) - .setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(volume), getActivity().getBaseContext())); + .setText(PlaceholderUtils.getValueString(MoodlBox.numberConformer(volume), getActivity().getBaseContext())); ((TextView) view.findViewById(R.id.textViewTitle)) .setText(title); ((TextView) view.findViewById(R.id.textViewDominancePercentage)) - .setText(PlaceholderManager.getPercentageString(MoodlBox.numberConformer(percentage), getActivity().getBaseContext())); + .setText(PlaceholderUtils.getPercentageString(MoodlBox.numberConformer(percentage), getActivity().getBaseContext())); } private SpannableString generateCenterSpannableText() { diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 16dffde..22806f2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -51,7 +51,7 @@ import com.herbron.moodl.BalanceSwitchManagerInterface; import com.herbron.moodl.DataNotifiers.BalanceUpdateNotifierInterface; import com.herbron.moodl.MoodlBox; import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.io.File; @@ -500,7 +500,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, public void updateBalanceDisplayedTitle(float totalFluctuationPercentage) { - toolbarLayout.setTitle(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); + toolbarLayout.setTitle(PlaceholderUtils.getValueString(numberConformer(totalValue), getActivity())); toolbarLayout.setCollapsedTitleTextColor(Color.WHITE); toolbarLayout.setExpandedTitleColor(Color.WHITE); @@ -517,18 +517,18 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, if(totalFluctuation == 0) { - toolbarSubtitle.setText(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); + toolbarSubtitle.setText(PlaceholderUtils.getValueString(numberConformer(totalValue), getActivity())); toolbarSubtitle.setTextColor(-1275068417); } else { - toolbarSubtitle.setText(PlaceholderManager.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity())); + toolbarSubtitle.setText(PlaceholderUtils.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity())); } } private void updateHideBalanceTitle(float totalFluctuationPercentage) { - toolbarLayout.setTitle(PlaceholderManager.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity())); + toolbarLayout.setTitle(PlaceholderUtils.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity())); toolbarSubtitle.setVisibility(View.GONE); if(totalFluctuation > 0) diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java index 4155211..c01e60d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java @@ -3,34 +3,23 @@ package com.herbron.moodl.Activities; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; -import android.opengl.Visibility; import android.os.AsyncTask; import android.os.Bundle; import android.support.design.widget.TabLayout; -import android.support.design.widget.TextInputLayout; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.View; -import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AutoCompleteTextView; -import android.widget.Button; -import android.widget.DatePicker; -import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.TimePicker; import com.herbron.moodl.Activities.RecordTransactionFragments.BuyFragment; import com.herbron.moodl.Activities.RecordTransactionFragments.SellFragment; @@ -44,7 +33,6 @@ import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; -import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface; import com.herbron.moodl.CustomAdapters.CoinRecordListAdapter; import com.herbron.moodl.CustomLayouts.CustomTabLayout; @@ -52,14 +40,11 @@ import com.herbron.moodl.CustomAdapters.ExchangeRecordListAdapter; import com.herbron.moodl.CustomAdapters.RecordTransactionPageAdapter; import com.herbron.moodl.MoodlBox; import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; -import java.util.Locale; public class RecordTransactionActivity extends AppCompatActivity implements CurrencyInfoUpdateNotifierInterface, CryptocompareNotifierInterface { @@ -187,7 +172,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr IconDownloaderTask iconDownloaderTask = new IconDownloaderTask(); iconDownloaderTask.execute(); coin_autoCompleteTextView.removeTextChangedListener(coinTextWatcher); - coin_autoCompleteTextView.setText(PlaceholderManager.getDenomination(currency.getName(), currency.getSymbol(), getBaseContext())); + coin_autoCompleteTextView.setText(PlaceholderUtils.getDenomination(currency.getName(), currency.getSymbol(), getBaseContext())); coin_autoCompleteTextView.setEnabled(false); if(globalTabLayouts.getVisibility() == View.GONE) @@ -242,7 +227,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr { pair = pairList.get(index); - pair_autoCompleteTextView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); + pair_autoCompleteTextView.setText(PlaceholderUtils.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); pair_autoCompleteTextView.setEnabled(true); ((BuyFragment) pageAdapter.getItem(0)).updatePair(pair); @@ -291,7 +276,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr { pair = pairList.get(index); - pair_autoCompleteTextView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); + pair_autoCompleteTextView.setText(PlaceholderUtils.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); pair_autoCompleteTextView.setEnabled(true); ((SellFragment) pageAdapter.getItem(1)).updatePair(pair); @@ -435,7 +420,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr public void onItemClick(AdapterView parent, View view, int position, long id) { pair = (Pair) pair_autoCompleteTextView.getAdapter().getItem(position); - pair_autoCompleteTextView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); + pair_autoCompleteTextView.setText(PlaceholderUtils.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); toolbar.requestFocus(); hideSoftKeyboard(RecordTransactionActivity.this); @@ -566,7 +551,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr public void onItemClick(AdapterView parent, View view, int position, long id) { currency = (Currency) coin_autoCompleteTextView.getAdapter().getItem(position); - coin_autoCompleteTextView.setText(PlaceholderManager.getDenomination(currency.getName(), currency.getSymbol(), getBaseContext())); + coin_autoCompleteTextView.setText(PlaceholderUtils.getDenomination(currency.getName(), currency.getSymbol(), getBaseContext())); toolbar.requestFocus(); hideSoftKeyboard(RecordTransactionActivity.this); @@ -685,7 +670,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr /*if(transactionId != -1) { - setTitle(PlaceholderManager.getEditTransactionString(coin, getBaseContext())); + setTitle(PlaceholderUtils.getEditTransactionString(coin, getBaseContext())); DatabaseManager databaseManager = new DatabaseManager(this); Transaction transaction = databaseManager.getCurrencyTransactionById(transactionId); 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 6d7a1c2..4bc3741 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 @@ -10,7 +10,6 @@ import android.support.design.widget.TextInputEditText; import android.support.v7.widget.AppCompatButton; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,7 +27,7 @@ import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; import com.herbron.moodl.DataManagers.PreferencesManager; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.text.SimpleDateFormat; @@ -452,8 +451,8 @@ public class BuyFragment extends CustomRecordFragment { private void updateAdapter() { symbolStrings = new ArrayList<>(); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); currencyFeeAdapter.clear(); currencyFeeAdapter.addAll(symbolStrings); @@ -530,8 +529,8 @@ public class BuyFragment extends CustomRecordFragment { feesCurrencySpinner.setAdapter(currencyFeeAdapter); symbolStrings = new ArrayList<>(); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); currencyFeeAdapter.addAll(symbolStrings); currencyFeeAdapter.notifyDataSetChanged(); 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 f91ce8b..c5d3caa 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 @@ -27,7 +27,7 @@ import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; import com.herbron.moodl.DataManagers.PreferencesManager; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.text.SimpleDateFormat; @@ -421,8 +421,8 @@ public class SellFragment extends CustomRecordFragment { private void updateAdapter() { symbolStrings = new ArrayList<>(); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); currencyFeeAdapter.clear(); currencyFeeAdapter.addAll(symbolStrings); @@ -529,8 +529,8 @@ public class SellFragment extends CustomRecordFragment { feesCurrencySpinner.setAdapter(currencyFeeAdapter); symbolStrings = new ArrayList<>(); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); - symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderUtils.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); currencyFeeAdapter.addAll(symbolStrings); currencyFeeAdapter.notifyDataSetChanged(); diff --git a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java index 3a5abf0..984e30a 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java @@ -44,6 +44,7 @@ import com.applandeo.listeners.OnSelectFileListener; import com.herbron.moodl.BuildConfig; import com.herbron.moodl.DataManagers.DataCrypter; import com.herbron.moodl.DataManagers.DatabaseManager; +import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.FingerprintToolkit.FingerprintDialogFragment; import com.herbron.moodl.FingerprintToolkit.FingerprintHandler; import com.herbron.moodl.MoodlBox; @@ -782,6 +783,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } } + + PreferencesManager preferencesManager = new PreferencesManager(getContext()); + preferencesManager.setMustUpdateSummary(true); } else { diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/PairRecordListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/PairRecordListAdapter.java index f91133d..c77dc76 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/PairRecordListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/PairRecordListAdapter.java @@ -11,7 +11,7 @@ import android.widget.Filter; import android.widget.TextView; import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.util.ArrayList; @@ -68,7 +68,7 @@ public class PairRecordListAdapter extends ArrayAdapter { TextView pairTxtView = convertView.findViewById(R.id.textView); pairTxtView.setTextColor(getContext().getResources().getColor(android.R.color.tab_indicator_text)); - pairTxtView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getContext())); + pairTxtView.setText(PlaceholderUtils.getPairString(pair.getFrom(), pair.getTo(), getContext())); return convertView; } diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java deleted file mode 100644 index f113531..0000000 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TradeListAdapter.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.herbron.moodl.CustomAdapters; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import com.herbron.moodl.DataManagers.CurrencyData.Trade; -import com.herbron.moodl.R; - -import java.util.ArrayList; - -import static com.herbron.moodl.MoodlBox.getDateFromTimestamp; - -/** - * Created by Guitoune on 24/04/2018. - */ - -public class TradeListAdapter extends ArrayAdapter { - - private Context context; - - public TradeListAdapter(Context context, ArrayList trades) - { - super(context, android.R.layout.simple_list_item_1, trades); - this.context = context; - } - - @NonNull - @Override - public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - Trade trade = getItem(position); - - if(convertView == null) - { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_trade_row, parent, false); - } - - TextView amountTxtView = convertView.findViewById(R.id.amountPurchased); - TextView purchasedPrice = convertView.findViewById(R.id.purchasePrice); - TextView tradePair = convertView.findViewById(R.id.pair); - TextView dateTxtView = convertView.findViewById(R.id.tradeDate); - View tradeIndicator = convertView.findViewById(R.id.tradeIndicator); - - amountTxtView.setText(String.valueOf(trade.getQty())); - purchasedPrice.setText(trade.getPrice()); - dateTxtView.setText(getDateFromTimestamp(trade.getTime())); - tradePair.setText(trade.getSymbol() + "/" + trade.getPairSymbol()); - - if(trade.isBuyer()) - { - tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.green)); - } - else - { - tradeIndicator.setBackgroundColor(context.getResources().getColor(R.color.red)); - } - - return convertView; - } -} diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java index 562e93c..1ec8278 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java @@ -20,6 +20,8 @@ import com.herbron.moodl.DataManagers.CurrencyData.Transaction; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.R; +import com.herbron.moodl.Utils.PlaceholderUtils; +import com.herbron.moodl.Utils.TransferUtils; import java.util.ArrayList; @@ -28,6 +30,8 @@ import static com.herbron.moodl.MoodlBox.getDateFromTimestamp; import static com.herbron.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; +import static com.herbron.moodl.Utils.TransferUtils.isBalanceRelated; + /** * Created by Guitoune on 24/04/2018. */ @@ -91,12 +95,12 @@ public class TransactionListAdapter extends ArrayAdapter { View convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_transaction_row, parent, false); - TextView amountTxtView = convertView.findViewById(R.id.amountPurchased); - TextView valueTxtView = convertView.findViewById(R.id.puchasedValue); - TextView dateTxtView = convertView.findViewById(R.id.purchaseDate); + TextView topLeftTextView = convertView.findViewById(R.id.transactionTLTV); + TextView bottomLeftTextView = convertView.findViewById(R.id.transactionBLTV); + TextView dateTxtView = convertView.findViewById(R.id.transactionDateTextView); + TextView amountTxtView = convertView.findViewById(R.id.transactionAmountTextView); amountTxtView.setText(String.valueOf(transaction.getAmount())); - valueTxtView.setText(numberConformer(transaction.getPrice() * transaction.getAmount())); dateTxtView.setText(getDateFromTimestamp(transaction.getTimestamp())); LinearLayout deleteLayout = convertView.findViewById(R.id.deleteTransactionLayout); @@ -135,12 +139,40 @@ public class TransactionListAdapter extends ArrayAdapter { { case "b": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.increaseCandle)); + topLeftTextView.setText(transaction.getSource()); + bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymbol(), transaction.getSymPair(), context)); break; case "s": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.decreaseCandle)); + topLeftTextView.setText(transaction.getSource()); + bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymPair(), transaction.getSymbol(), context)); break; case "t": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.blue)); + + if(isBalanceRelated(transaction.getDestination()) && isBalanceRelated(transaction.getSource())) + { + topLeftTextView.setText(context.getString(R.string.transferText)); + + bottomLeftTextView.setText(PlaceholderUtils.getFromToString(TransferUtils.getLabelFor(context, transaction.getSource()), TransferUtils.getLabelFor(context, transaction.getDestination()), context)); + } + else + { + if(isBalanceRelated(transaction.getDestination())) + { + topLeftTextView.setText(context.getString(R.string.depositText)); + bottomLeftTextView.setText(PlaceholderUtils.getFromString(TransferUtils.getLabelFor(context, transaction.getSource()), context)); + } + else + { + if(isBalanceRelated(transaction.getSource())) + { + topLeftTextView.setText(context.getString(R.string.withdrawText)); + bottomLeftTextView.setText(PlaceholderUtils.getToString(TransferUtils.getLabelFor(context, transaction.getDestination()), context)); + } + } + } + break; } @@ -149,6 +181,8 @@ public class TransactionListAdapter extends ArrayAdapter { return convertView; } + + private void setupSwipeView(View view) { SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index f660b1b..87f3e94 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -14,7 +14,6 @@ import android.support.v4.content.ContextCompat; import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -29,7 +28,7 @@ import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; import com.herbron.moodl.DataManagers.DatabaseManager; import com.herbron.moodl.DataManagers.PreferencesManager; import com.herbron.moodl.MoodlBox; -import com.herbron.moodl.PlaceholderManager; +import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; import java.util.ArrayList; @@ -219,18 +218,18 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti private void updateCardViewInfos(Currency currency) { ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); + .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); ((TextView) findViewById(R.id.currencyValueTextView)) - .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getContext())); + .setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext())); ((ImageView) findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) findViewById(R.id.currencyNameTextView)) .setText(currency.getName()); ((TextView) findViewById(R.id.currencySymbolTextView)) - .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getContext())); + .setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext())); ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); + .setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); @@ -257,22 +256,22 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti double percentage = value / totalValue * 100; ((TextView) findViewById(R.id.currencyValueOwnedTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext())); + .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext())); ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); + .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); ((TextView) findViewById(R.id.currencyValueTextView)) - .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getContext())); + .setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext())); ((ImageView) findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) findViewById(R.id.currencyNameTextView)) .setText(currency.getName()); ((TextView) findViewById(R.id.currencySymbolTextView)) - .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getContext())); + .setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext())); ((TextView) findViewById(R.id.currencyOwnedTextView)) - .setText(PlaceholderManager.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext())); + .setText(PlaceholderUtils.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext())); ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); + .setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); arrowDrawable.mutate(); @@ -290,7 +289,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti progressBarDrawable.invalidateSelf(); ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); - ((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderManager.getPercentageString(numberConformer(percentage), getContext())); + ((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderUtils.getPercentageString(numberConformer(percentage), getContext())); if(isBalanceHidden) { 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 45bfa28..7f50807 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -26,6 +26,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static com.herbron.moodl.Utils.TransferUtils.isBalanceRelated; + /** * Created by Guitoune on 14/01/2018. */ @@ -672,12 +674,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ return currencyList; } - private boolean isBalanceRelated(String str) - { - Set set = new HashSet<>(Arrays.asList(TransferFragment.EXCHANGE_CODE, TransferFragment.WALLET_CODE)); - return set.contains(str); - } - public Transaction getCurrencyTransactionById(int id) { String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_TRANSACTIONS + " WHERE " + KEY_TRANSACTION_ID + "='" + id + "'"; diff --git a/app/src/main/java/com/herbron/moodl/PlaceholderManager.java b/app/src/main/java/com/herbron/moodl/Utils/PlaceholderUtils.java similarity index 89% rename from app/src/main/java/com/herbron/moodl/PlaceholderManager.java rename to app/src/main/java/com/herbron/moodl/Utils/PlaceholderUtils.java index b3ad52a..085b67c 100644 --- a/app/src/main/java/com/herbron/moodl/PlaceholderManager.java +++ b/app/src/main/java/com/herbron/moodl/Utils/PlaceholderUtils.java @@ -1,8 +1,9 @@ -package com.herbron.moodl; +package com.herbron.moodl.Utils; import android.content.Context; import com.herbron.moodl.DataManagers.PreferencesManager; +import com.herbron.moodl.R; import java.util.ArrayList; import java.util.List; @@ -11,7 +12,7 @@ import java.util.List; * Created by Tiji on 19/04/2018. */ -public class PlaceholderManager { +public class PlaceholderUtils { public static String getValueString(String value, android.content.Context context) { @@ -182,4 +183,24 @@ public class PlaceholderManager { { return context.getResources().getString(R.string.timestampPlaceholder, date); } + + public static String getToString(String to, android.content.Context context) + { + return context.getResources().getString(R.string.toPlaceholder, to); + } + + public static String getFromString(String from, android.content.Context context) + { + return context.getResources().getString(R.string.fromPlaceholder, from); + } + + public static String getFromToString(String from, String to, android.content.Context context) + { + return context.getResources().getString(R.string.fromToPlaceholder, from, to); + } + + public static String getToPairString(String from, String to, Context context) + { + return context.getResources().getString(R.string.toPairPlaceholder, from, to); + } } diff --git a/app/src/main/java/com/herbron/moodl/Utils/TransferUtils.java b/app/src/main/java/com/herbron/moodl/Utils/TransferUtils.java new file mode 100644 index 0000000..93854af --- /dev/null +++ b/app/src/main/java/com/herbron/moodl/Utils/TransferUtils.java @@ -0,0 +1,42 @@ +package com.herbron.moodl.Utils; + +import android.content.Context; + +import com.herbron.moodl.Activities.RecordTransactionFragments.TransferFragment; +import com.herbron.moodl.R; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class TransferUtils { + + public static boolean isBalanceRelated(String str) + { + Set set = new HashSet<>(Arrays.asList(TransferFragment.EXCHANGE_CODE, TransferFragment.WALLET_CODE)); + return set.contains(str); + } + + public static String getLabelFor(Context context, String str) + { + switch (str) + { + case "stra:e": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[0].toLowerCase(); + case "stra:mw": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[1].toLowerCase(); + case "stra:m": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[2].toLowerCase(); + case "stra:smew": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[3].toLowerCase(); + case "stra:a": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[4].toLowerCase(); + case "stra:unk": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[5].toLowerCase(); + case "stra:fo": + return context.getResources().getStringArray(R.array.from_transfer_options_string_array)[6].toLowerCase(); + } + + return null; + } +} diff --git a/app/src/main/res/drawable/ic_arrow_downward_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_downward_white_24dp.xml new file mode 100644 index 0000000..4c58652 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_downward_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_upward_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_upward_white_24dp.xml new file mode 100644 index 0000000..fee89d2 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_upward_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/custom_trade_row.xml b/app/src/main/res/layout/custom_trade_row.xml index 3298b26..46e247e 100644 --- a/app/src/main/res/layout/custom_trade_row.xml +++ b/app/src/main/res/layout/custom_trade_row.xml @@ -2,7 +2,8 @@ + android:orientation="vertical" + android:background="#ffffffff"> - + android:layout_height="match_parent" + android:orientation="horizontal" + android:padding="5dp"> - - + android:layout_height="match_parent" + android:layout_weight="0.5" + android:orientation="vertical"> - + - + - - + + - + - + - diff --git a/app/src/main/res/layout/custom_transaction_row.xml b/app/src/main/res/layout/custom_transaction_row.xml index 67e3c1b..ca0f10c 100644 --- a/app/src/main/res/layout/custom_transaction_row.xml +++ b/app/src/main/res/layout/custom_transaction_row.xml @@ -79,13 +79,13 @@ android:orientation="vertical"> @@ -99,10 +99,20 @@ android:orientation="vertical"> + android:id="@+id/transactionAmountTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end" + android:gravity="end" + android:textSize="15dp"/> + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 117f162..6fbc86f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -6,7 +6,7 @@ Monnaie par défaut Achat Vente - Transfère + Transfert Enregistrer Réglages des échanges Activer la synchronisation @@ -118,19 +118,19 @@ - Site d'échange + Site d\'échange Mon portefeuille Minage - Le portefeuille de quelqu'un d'autre + Le portefeuille de quelqu\'un d\'autre Airdrop Autre / Inconnu Fork - Site d'échange + Site d\'échange Mon portefeuille - Le portefeuille de quelqu'un d'autre + Le portefeuille de quelqu\'un d\'autre Autre / Inconnu diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e45d473..581f285 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -299,5 +299,11 @@ This transaction is not valid Deduct from holdings Add to holdings + Withdraw + Deposit + From %1$s to %2$s + From %1$s + To %1$s + %1$s to %2$s From 2654b044b25bee031b55fa4279083b6e408933fd Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 24 Aug 2018 04:05:05 +0200 Subject: [PATCH 10/23] Minor fixs - Icon size fix - Fix details activity crash --- .../DetailsActivityFragments/InformationFragment.java | 6 ++++-- .../moodl/Activities/HomeActivityFragments/Summary.java | 2 +- app/src/main/res/layout-v21/cardview_currency.xml | 4 ++-- app/src/main/res/layout-v21/cardview_watchlist.xml | 4 ++-- app/src/main/res/layout/cardview_currency.xml | 4 ++-- app/src/main/res/layout/cardview_watchlist.xml | 4 ++-- app/src/main/res/layout/detailsactivity_fragment_charts.xml | 3 ++- app/src/main/res/values/dimens.xml | 2 ++ 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java index f29c6f1..595c241 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/InformationFragment.java @@ -9,6 +9,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -74,14 +75,15 @@ public class InformationFragment extends Fragment { { if(isTickerUpdated && isSnapshotUpdated) { - if(getActivity() != null) - { + try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { refreshInfoTab(); } }); + } catch (NullPointerException e) { + Log.d("moodl", "Information tab do not needs to be updated anymore"); } } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 22806f2..487f503 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -553,7 +553,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, public void onBalanceDataUpdated() { final List balance = balanceManager.getTotalBalance(); - if(balance.size() > 0) + if(balance != null && balance.size() > 0) { for(int i = 0; i < balance.size(); i++) { diff --git a/app/src/main/res/layout-v21/cardview_currency.xml b/app/src/main/res/layout-v21/cardview_currency.xml index eba4726..f7ccc19 100644 --- a/app/src/main/res/layout-v21/cardview_currency.xml +++ b/app/src/main/res/layout-v21/cardview_currency.xml @@ -29,8 +29,8 @@ @@ -128,7 +129,7 @@ android:paddingEnd="4dp" android:baselineAligned="false" android:gravity="bottom" - android:layout_alignParentBottom="true"> + android:layout_below="@id/mainMenuLayout"> 180dp 50dp + + 17dp From 4738a65dcc7e5bfe0ba2986a45e2ad4f716d972a Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 27 Aug 2018 02:48:16 +0200 Subject: [PATCH 11/23] [Untested] Fix balance deductions --- .idea/caches/build_file_checksums.ser | Bin 545 -> 540 bytes .../moodl/DataManagers/DatabaseManager.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ade57472755c33bf79039d6ed2cf8f39c522ab98..c7baaf739d989bc42cf5042f3ae94cae9fd2ff69 100644 GIT binary patch delta 75 zcmV-R0JQ(11e^qrm;`vmjm(jpwGt~sI$TwAWpZ;|M|Ej*Z*^{ElfD5qlTiUg8PyUh hQsgO{MjOF-z)RJ-5p)0%XL4a=Y-N*x0Tq)F0uh5M9IOBU delta 81 zcmV-X0IvU>1fc|wm;^R1jY^T6wUe0vL^7xp5}ld>Xcf?C5YOMJAn0@eFhe?ARdZ!> nb6i1WZE0?4b98cHbZ>H8E@yIKWNc+zlkfo>lZOEklkWj74Lu)t 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 7f50807..4abca59 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -603,6 +603,14 @@ public class DatabaseManager extends SQLiteOpenHelper{ currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); } + + if(resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1) + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)) + , -(resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_PURCHASE_PRICE)) + * resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) + + resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES))))); + } break; case "s": if(symbol.equals(feeSym)) @@ -615,6 +623,14 @@ public class DatabaseManager extends SQLiteOpenHelper{ currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); } + + if(resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1) + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)) + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_PURCHASE_PRICE)) + * resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) + - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + } break; case "t": if(isBalanceRelated(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SOURCE))) && isBalanceRelated(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_DESTINATION)))) From 76230123537f4c175f546d15df3dbe461b230336 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 27 Aug 2018 03:41:33 +0200 Subject: [PATCH 12/23] Fix total value calculus and allow fiat display - Fix Deduct switch not being updated when editing a transaction Previous commit tested and working --- .../HomeActivityFragments/Summary.java | 40 ++++++++++--------- .../BuyFragment.java | 1 + .../moodl/DataManagers/BalanceManager.java | 1 - .../CurrencyData/CurrencyCardview.java | 10 +++++ 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 487f503..8d8b967 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -213,7 +213,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { final Currency currency = balanceManager.getTotalBalance().get(i); - if (!currency.getSymbol().equals("USD") && (Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { + if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { //currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); renderedCurrencies.add(currency); } @@ -236,6 +236,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, loadingDialog.dismiss(); } + updateTitle(); + handler.removeCallbacks(updateRunnable); } }); @@ -371,9 +373,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, { coinCounter = 0; iconCounter = 0; - - totalValue = 0; - totalFluctuation = 0; } private void adaptView() @@ -466,8 +465,25 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, }); } + private void computeTotalValue() + { + totalValue = 0; + totalFluctuation = 0; + + for(int i = 0; i < currencyLayout.getChildCount(); i++) + { + if(currencyLayout.getChildAt(i) instanceof CurrencyCardview) + { + totalValue += ((CurrencyCardview) currencyLayout.getChildAt(i)).getOwnedValue(); + totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation(); + } + } + } + protected void updateTitle() { + computeTotalValue(); + float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100; if(preferencesManager.isBalanceHidden()) @@ -700,13 +716,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private void loadCurrency(Currency currency) { - if(!currency.getSymbol().equals("USD")) - { - currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); - currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); - totalValue += currency.getValue() * currency.getBalance(); - totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100); - } + currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); + currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); } @Override @@ -732,13 +743,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, balanceManager.getTotalBalance().set(i, localCurrency); } - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateTitle(); - } - }); - return null; } 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 4bc3741..1b97985 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 @@ -275,6 +275,7 @@ public class BuyFragment extends CustomRecordFragment { totalValueEditText.setText(String.valueOf(transaction.getAmount() * transaction.getPrice())); fees_editText.setText(String.valueOf(transaction.getFees())); note_editText.setText(transaction.getNote()); + deductHoldingsSwitch.setChecked(transaction.isDeducted()); } private void initializeViewElements() diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java index 8693f8c..7de9f43 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java @@ -30,7 +30,6 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd private int balanceCounter; - //NEW IMPLEMENTATION private List hitBtcManagers; private List binanceManagers; diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index 87f3e94..6fdee83 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -305,6 +305,16 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } } + public double getOwnedValue() + { + return currency.getValue() * currency.getBalance(); + } + + public double getFluctuation() + { + return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100); + } + private LineData generateData(Currency currency) { LineDataSet dataSet; From 9395ec742521c7c6791199be161932cf29f91320 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 27 Aug 2018 04:01:12 +0200 Subject: [PATCH 13/23] Fix transaction history not displaying correctly - Fix deducted transactions not being displayed - Fix pairs not displayed properly --- .../TransactionListAdapter.java | 4 +- .../moodl/DataManagers/DatabaseManager.java | 39 +++++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java index 1ec8278..503f6b3 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/TransactionListAdapter.java @@ -140,12 +140,12 @@ public class TransactionListAdapter extends ArrayAdapter { case "b": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.increaseCandle)); topLeftTextView.setText(transaction.getSource()); - bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymbol(), transaction.getSymPair(), context)); + bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymPair(), transaction.getSymbol(), context)); break; case "s": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.decreaseCandle)); topLeftTextView.setText(transaction.getSource()); - bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymPair(), transaction.getSymbol(), context)); + bottomLeftTextView.setText(PlaceholderUtils.getToPairString(transaction.getSymbol(), transaction.getSymPair(), context)); break; case "t": transactionIndicator.setBackgroundColor(context.getResources().getColor(R.color.blue)); 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 4abca59..d5edd77 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -725,7 +725,8 @@ public class DatabaseManager extends SQLiteOpenHelper{ public ArrayList getCurrencyTransactionsForSymbol(String symbol) { - String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_TRANSACTIONS + " WHERE " + KEY_TRANSACTION_SYMBOL + "='" + symbol.toUpperCase() + "'"; + String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_TRANSACTIONS + " WHERE " + KEY_TRANSACTION_SYMBOL + "='" + symbol.toUpperCase() + + "' OR " + KEY_TRANSACTION_PAIR + "='" + symbol.toUpperCase() + "' AND " + KEY_TRANSACTION_DEDUCT + "=1"; SQLiteDatabase db = this.getWritableDatabase(); Cursor resultatList = db.rawQuery(searchQuerry, null); @@ -733,16 +734,38 @@ public class DatabaseManager extends SQLiteOpenHelper{ while (resultatList.moveToNext()) { - boolean deduct = false; + String type = "t"; + String pair = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)); + String sym = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)); - if(!resultatList.isNull(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT))) + if(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)).equals(symbol.toUpperCase())) { - deduct = resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1; + type = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)); + } + else + { + if(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)).equals("s")) + { + type = "b"; + + pair = sym; + sym = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)); + } + else + { + if(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)).equals("b")) + { + type = "s"; + + pair = sym; + sym = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)); + } + } } transactionList.add(new Transaction(resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_ID)) - , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_PAIR)) + , sym + , pair , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) , resultatList.getLong(resultatList.getColumnIndex(KEY_TRANSACTION_DATE)) , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_PURCHASE_PRICE)) @@ -751,9 +774,9 @@ public class DatabaseManager extends SQLiteOpenHelper{ , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_FEE_CURRENCY)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SOURCE)) , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_DESTINATION)) - , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)) + , type , resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_FEE_FORMAT)) - , deduct)); + , resultatList.getInt(resultatList.getColumnIndex(KEY_TRANSACTION_DEDUCT)) == 1)); } resultatList.close(); From 2a4ba215e69f1106f6d1a83a78f50fcca0a098d8 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 28 Aug 2018 13:43:14 +0200 Subject: [PATCH 14/23] Fix 'infinity' balance percentage when hiding the balance --- .idea/caches/build_file_checksums.ser | Bin 540 -> 545 bytes .../HomeActivityFragments/Summary.java | 10 +++++++++- .../CurrencyData/CurrencyCardview.java | 6 ++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index c7baaf739d989bc42cf5042f3ae94cae9fd2ff69..ce3de474a50c71b4ce97aaf54f757eb2b9101f94 100644 GIT binary patch delta 81 zcmV-X0IvU>1fc|wm;``K8y}IJwUe0vL^7xp5}ld>Xcf?C5YOMJAn0@eFhe?ARdZ!> nb6i1WZE0?4b98cHbZ>H8E@yIKWNc+zlkfo>lZOEklkWj7|05qm delta 75 zcmV-R0JQ(11e^qrm;`vmjm(jpwGt~sI$TwAWpZ;|M|Ej*Z*^{ElfD5qlTiUg8PyUh hQsgO{MjOF-z)RJ-5p)0%XL4a=Y-N*x0Tq)F0uh5M9IOBU diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 8d8b967..595e631 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -228,7 +228,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, for(int i = 0; i < renderedCurrencies.size(); i++) { //currencyLayout.addView(currencyView.get(i)); - currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), totalValue, preferencesManager.isBalanceHidden())); + currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden())); } if(loadingDialog.isShowing()) @@ -478,6 +478,14 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation(); } } + + for(int i = 0; i < currencyLayout.getChildCount(); i++) + { + if(currencyLayout.getChildAt(i) instanceof CurrencyCardview) + { + ((CurrencyCardview) currencyLayout.getChildAt(i)).updateCardViewInfos(totalValue, preferencesManager.isBalanceHidden()); + } + } } protected void updateTitle() diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index 6fdee83..e84c227 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -126,7 +126,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti updateColor(currency); } - public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, float totalValue, boolean isBalanceHidden) + public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, boolean isBalanceHidden) { super(context); @@ -166,8 +166,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } }); - updateCardViewInfos(currency, totalValue, isBalanceHidden); - findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener); findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener); @@ -250,7 +248,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } } - private void updateCardViewInfos(Currency currency, float totalValue, boolean isBalanceHidden) + public void updateCardViewInfos(float totalValue, boolean isBalanceHidden) { double value = currency.getValue() * currency.getBalance(); double percentage = value / totalValue * 100; From b97b8e7645c337287020b6806f99d44db12f4162 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 29 Aug 2018 01:11:25 +0200 Subject: [PATCH 15/23] Add logos to exchange accounts list --- .idea/assetWizardSettings.xml | 40 ++++++++++++++++++- .../HomeActivityFragments/Summary.java | 4 +- .../ExchangeDescriptionListAdapter.java | 14 +++++++ .../res/drawable/exchange_logo_binance.xml | 13 ++++++ .../res/drawable/exchange_logo_hitbtc.xml | 23 +++++++++++ app/src/main/res/layout/exchange_cell.xml | 5 ++- app/src/main/res/layout/splash_screen.xml | 11 ++--- 7 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable/exchange_logo_binance.xml create mode 100644 app/src/main/res/drawable/exchange_logo_hitbtc.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index b34e12f..62e00cc 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -13,6 +13,36 @@ + @@ -81,9 +116,10 @@ diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 595e631..9d5ab3f 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -306,8 +306,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, } else { - TextView appNameTextView = splashLayout.findViewById(R.id.appNameTextView); - appNameTextView.setVisibility(View.VISIBLE); + /*ImageView appNameImageView = splashLayout.findViewById(R.id.appNameImageView); + appNameImageView.setVisibility(View.VISIBLE);*/ animatedLayout.setVisibility(View.GONE); } diff --git a/app/src/main/java/com/herbron/moodl/CustomAdapters/ExchangeDescriptionListAdapter.java b/app/src/main/java/com/herbron/moodl/CustomAdapters/ExchangeDescriptionListAdapter.java index bf33215..aa3fc74 100644 --- a/app/src/main/java/com/herbron/moodl/CustomAdapters/ExchangeDescriptionListAdapter.java +++ b/app/src/main/java/com/herbron/moodl/CustomAdapters/ExchangeDescriptionListAdapter.java @@ -18,6 +18,9 @@ import com.herbron.moodl.R; import java.util.ArrayList; +import static com.herbron.moodl.DataManagers.DatabaseManager.BINANCE_TYPE; +import static com.herbron.moodl.DataManagers.DatabaseManager.HITBTC_TYPE; + public class ExchangeDescriptionListAdapter extends ArrayAdapter { private Context context; @@ -42,10 +45,21 @@ public class ExchangeDescriptionListAdapter extends ArrayAdapter { TextView exchangeNameTextView = convertView.findViewById(R.id.exchange_name); TextView exchangeDescriptionTextView = convertView.findViewById(R.id.exchange_description); ImageView accountOffImageView = convertView.findViewById(R.id.exchange_account_off_imageView); + ImageView exchangeImageView = convertView.findViewById(R.id.exchange_icon_imageView); exchangeNameTextView.setText(exchange.getName()); exchangeDescriptionTextView.setText(exchange.getDescription()); + switch (exchange.getType()) + { + case BINANCE_TYPE: + exchangeImageView.setImageDrawable(context.getResources().getDrawable(R.drawable.exchange_logo_binance)); + break; + case HITBTC_TYPE: + exchangeImageView.setImageDrawable(context.getResources().getDrawable(R.drawable.exchange_logo_hitbtc)); + break; + } + if(!exchange.isEnabled()) { accountOffImageView.setVisibility(View.VISIBLE); diff --git a/app/src/main/res/drawable/exchange_logo_binance.xml b/app/src/main/res/drawable/exchange_logo_binance.xml new file mode 100644 index 0000000..b21e7b1 --- /dev/null +++ b/app/src/main/res/drawable/exchange_logo_binance.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/app/src/main/res/drawable/exchange_logo_hitbtc.xml b/app/src/main/res/drawable/exchange_logo_hitbtc.xml new file mode 100644 index 0000000..da03989 --- /dev/null +++ b/app/src/main/res/drawable/exchange_logo_hitbtc.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/exchange_cell.xml b/app/src/main/res/layout/exchange_cell.xml index 4097a60..776f56e 100644 --- a/app/src/main/res/layout/exchange_cell.xml +++ b/app/src/main/res/layout/exchange_cell.xml @@ -62,7 +62,7 @@ android:id="@+id/exchange_icon_imageView" android:layout_width="56dp" android:layout_height="56dp" - android:layout_marginEnd="@dimen/margin"/> + android:layout_margin="5dp"/> + android:foregroundGravity="center_vertical" + android:layout_marginTop="5dp"> + android:background="@color/colorPrimaryDark" + android:orientation="vertical"> - + android:src="@mipmap/ic_launcher_moodl"/> Date: Wed, 29 Aug 2018 01:12:47 +0200 Subject: [PATCH 16/23] Update version name for BETA --- .idea/caches/build_file_checksums.ser | Bin 545 -> 545 bytes app/build.gradle | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ce3de474a50c71b4ce97aaf54f757eb2b9101f94..8067773fbcdd12fe07eb24cf947c7cb4456005d8 100644 GIT binary patch delta 35 tcmV+;0Nnqf1fc|wm;{2)PD7ELcMxyvhQ9o!^O}QO_qqQd({__10sb~E5{3W( delta 35 tcmV+;0Nnqf1fc|wm;``K8y}IJcM$w3E^y7luZl@At__gGJ%y7a0si|G4!ZyV diff --git a/app/build.gradle b/app/build.gradle index e3946f2..a9ebb6c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.herbron.moodl" minSdkVersion 19 targetSdkVersion 27 - versionCode 6 - versionName "0.0.6" + versionCode 7 + versionName "0.1.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } From e6d69a01ce551ad3ca5880abe68397474446ee5c Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sat, 1 Sep 2018 23:30:19 +0200 Subject: [PATCH 17/23] Update chart color definition algorithm Everything comes now from the MoodlUtilBox --- .../MarketCapitalization.java | 5 ++--- .../HomeActivityFragments/Overview.java | 19 +++------------- .../HomeActivityFragments/Summary.java | 22 +------------------ .../HomeActivityFragments/Watchlist.java | 19 +++------------- .../main/java/com/herbron/moodl/MoodlBox.java | 15 +++++++++++++ 5 files changed, 24 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index b3a56a4..c0584e2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.List; import static com.herbron.moodl.MoodlBox.getColor; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; import static java.lang.Math.abs; /** @@ -265,10 +266,8 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { @Override public void onBitmapDownloaded(Bitmap bitmapIcon) { - Palette.Builder builder = Palette.from(bitmapIcon); - coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon); - coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); + coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(getIconDominantColor(getContext(), bitmapIcon)); countIcons(); diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java index c142429..9905a3e 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java @@ -30,6 +30,7 @@ import com.herbron.moodl.R; import java.util.List; import static com.herbron.moodl.MoodlBox.getDrawable; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** * Created by Administrator on 27/05/2018. @@ -121,20 +122,6 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface currencyLoader.execute(); } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(0)); - } - else - { - currency.setChartColor(12369084); - } - } - private void loadingIndicatorGenerator() { loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false); @@ -198,7 +185,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface @Override public void onBitmapDownloaded(Bitmap bitmap) { currency.setIcon(bitmap); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), bitmap)); countIcons(currencies[0]); } }); @@ -216,7 +203,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface icon = Bitmap.createScaledBitmap(icon, 50, 50, false); currency.setIcon(icon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), icon)); countIcons(currencies[0]); } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 9d5ab3f..fce352b 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -708,26 +708,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, super.onProgressUpdate(values); } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); - } - else - { - currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext())); - } - } - - private void loadCurrency(Currency currency) - { - currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); - currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); - } - @Override protected Void doInBackground(Void... params) { @@ -744,7 +724,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol())); - updateChartColor(localCurrency); + localCurrency.setChartColor(getIconDominantColor(baseContext, localCurrency.getIcon())); loadCurrency(localCurrency); diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java index 7368714..803043d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -43,6 +43,7 @@ import java.util.List; import static com.herbron.moodl.MoodlBox.collapseW; import static com.herbron.moodl.MoodlBox.expandW; import static com.herbron.moodl.MoodlBox.getColor; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** * Created by Tiji on 13/04/2018. @@ -380,20 +381,6 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac } } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); - } - else - { - currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext())); - } - } - public int getCurrencyId(String symbol) { int id = 0; @@ -454,7 +441,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac @Override public void onBitmapDownloaded(Bitmap bitmapIcon) { currency.setIcon(bitmapIcon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); countWatchlist(); } @@ -466,7 +453,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac icon = Bitmap.createScaledBitmap(icon, 50, 50, false); currency.setIcon(icon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), icon)); countWatchlist(); } } diff --git a/app/src/main/java/com/herbron/moodl/MoodlBox.java b/app/src/main/java/com/herbron/moodl/MoodlBox.java index ea6f231..87cbe61 100644 --- a/app/src/main/java/com/herbron/moodl/MoodlBox.java +++ b/app/src/main/java/com/herbron/moodl/MoodlBox.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.v7.graphics.Palette; import android.support.v7.widget.CardView; import android.util.Log; import android.view.View; @@ -297,4 +298,18 @@ public class MoodlBox { return url; } + + public static int getIconDominantColor(Context context, Bitmap icon) + { + if(icon != null) + { + Palette.Builder builder = Palette.from(icon); + + return builder.generate().getDominantColor(getColor(R.color.default_color, context)); + } + else + { + return getColor(R.color.default_color, context); + } + } } From 8ca63b5e85c58959afa3a48b3dc657868b75e03d Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sat, 1 Sep 2018 23:31:17 +0200 Subject: [PATCH 18/23] Rework icon loading - Icons are now downloaded after displaying the whole list --- .../HomeActivityFragments/Summary.java | 238 +++++++----------- .../CurrencyData/CurrencyCardview.java | 224 ++++++++++------- .../main/res/layout-v21/cardview_currency.xml | 2 +- .../res/layout-v21/cardview_watchlist.xml | 2 +- app/src/main/res/layout/cardview_currency.xml | 2 +- .../main/res/layout/cardview_watchlist.xml | 2 +- 6 files changed, 217 insertions(+), 253 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index fce352b..45ae4a0 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -3,6 +3,7 @@ package com.herbron.moodl.Activities.HomeActivityFragments; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Dialog; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -61,6 +62,7 @@ import java.util.Random; import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getDrawable; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; import static com.herbron.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; @@ -206,41 +208,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, layoutRefresherRunnable = new Runnable() { @Override public void run() { - final List renderedCurrencies = new ArrayList<>(); - - if (balanceManager.getTotalBalance() != null) - { - for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { - final Currency currency = balanceManager.getTotalBalance().get(i); - - if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { - //currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); - renderedCurrencies.add(currency); - } - } - } - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - currencyLayout.removeAllViews(); - - for(int i = 0; i < renderedCurrencies.size(); i++) - { - //currencyLayout.addView(currencyView.get(i)); - currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden())); - } - - if(loadingDialog.isShowing()) - { - loadingDialog.dismiss(); - } - - updateTitle(); - - handler.removeCallbacks(updateRunnable); - } - }); } }; } @@ -375,9 +342,44 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, iconCounter = 0; } - private void adaptView() + private void adaptView(float totalValue, float totalFluctuation) { - layoutRefresherRunnable.run(); + this.totalValue = totalValue; + this.totalFluctuation = totalFluctuation; + final List renderedCurrencies = new ArrayList<>(); + + if (balanceManager.getTotalBalance() != null) + { + for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { + final Currency currency = balanceManager.getTotalBalance().get(i); + + if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { + //currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + renderedCurrencies.add(currency); + } + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + currencyLayout.removeAllViews(); + + for(int i = 0; i < renderedCurrencies.size(); i++) + { + currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden())); + } + + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } + + updateTitle(); + + handler.removeCallbacks(updateRunnable); + } + }); } private void countCoins(boolean isCoin, boolean isDetails, boolean isTickers) @@ -401,46 +403,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, { if(balanceManager.getTotalBalance().size() == 0) { - countIcons(); + updateNoBalance(); } else { if(coinCounter >= balanceManager.getTotalBalance().size() && detailsChecker && tickersChecker) - { - IconDownloader iconDownloader = new IconDownloader(); - iconDownloader.execute(); - } - - } - } - } - - private void countIcons() - { - int offset = 0; - - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) - { - if(balanceManager.getTotalBalance().get(i).getSymbol().equals("USD")) - { - offset++; - } - } - - iconCounter++; - - if(balanceManager.getTotalBalance() != null) - { - if(balanceManager.getTotalBalance().size() == 0) - { - updateNoBalance(); - } - else - { - if(iconCounter == balanceManager.getTotalBalance().size() - offset) { UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator(); - uiHeavyLoadCalculator.execute(); + uiHeavyLoadCalculator.setOnUiEndListener(new UiHeavyLoadCalculator.OnUiEndListener() { + @Override + public void onEnd(float totalValue, float totalFluctuation) { + refreshLayout.setRefreshing(false); + + adaptView(totalValue, totalFluctuation); + } + }); + uiHeavyLoadCalculator.execute(getActivity().getBaseContext(), balanceManager, coinmarketCapAPIManager); } } } @@ -467,23 +445,11 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private void computeTotalValue() { - totalValue = 0; - totalFluctuation = 0; - for(int i = 0; i < currencyLayout.getChildCount(); i++) { if(currencyLayout.getChildAt(i) instanceof CurrencyCardview) { - totalValue += ((CurrencyCardview) currencyLayout.getChildAt(i)).getOwnedValue(); - totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation(); - } - } - - for(int i = 0; i < currencyLayout.getChildCount(); i++) - { - if(currencyLayout.getChildAt(i) instanceof CurrencyCardview) - { - ((CurrencyCardview) currencyLayout.getChildAt(i)).updateCardViewInfos(totalValue, preferencesManager.isBalanceHidden()); + ((CurrencyCardview) currencyLayout.getChildAt(i)).updateOwnedValues(totalValue, preferencesManager.isBalanceHidden()); } } } @@ -690,9 +656,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, countCoins(false, false, true); } - private class UiHeavyLoadCalculator extends AsyncTask + private static class UiHeavyLoadCalculator extends AsyncTask { + private float totalValue = 0; + private float totalFluctuation = 0; + + private BalanceManager balanceManager; + private CoinmarketCapAPIManager coinmarketCapAPIManager; + + private OnUiEndListener onUiEndListener; + + public void setOnUiEndListener(OnUiEndListener onUiEndListener) + { + this.onUiEndListener = onUiEndListener; + } + @Override protected void onPreExecute() { @@ -709,13 +688,18 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, } @Override - protected Void doInBackground(Void... params) + protected Void doInBackground(Object... params) { if(Looper.myLooper() == null) { Looper.prepare(); } + Context baseContext = (Context) params[0]; + + balanceManager = (BalanceManager) params[1]; + coinmarketCapAPIManager = (CoinmarketCapAPIManager) params[2]; + balanceManager.sortCoins(); for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) @@ -728,29 +712,30 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, loadCurrency(localCurrency); + totalValue += localCurrency.getValue() * localCurrency.getBalance(); + totalFluctuation += localCurrency.getValue() * localCurrency.getBalance() * (localCurrency.getDayFluctuationPercentage() / 100); + balanceManager.getTotalBalance().set(i, localCurrency); } return null; } + private void loadCurrency(Currency currency) + { + currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); + currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); + } + @Override protected void onPostExecute(Void result) { - refreshLayout.setRefreshing(false); - new AsyncTask() { + onUiEndListener.onEnd(totalValue, totalFluctuation); + } - @Override - protected Void doInBackground(Void... voids) { - if(Looper.myLooper() == null) - { - Looper.prepare(); - } - - adaptView(); - return null; - } - }.execute(); + public interface OnUiEndListener + { + void onEnd(float totalValue, float totalFluctuation); } } @@ -778,61 +763,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, } } - private class IconDownloader extends AsyncTask - { - @Override - protected void onPreExecute() - { - super.onPreExecute(); - } - - @Override - protected void onProgressUpdate(Integer... values) - { - super.onProgressUpdate(values); - } - - @Override - protected Void doInBackground(Void... params) - { - for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) - { - final Currency localCurrency = balanceManager.getTotalBalance().get(i); - - String iconUrl = MoodlBox.getIconUrl(localCurrency.getSymbol(), balanceManager.getCryptocompareApiManager()); - - if(iconUrl != null) - { - MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { - @Override - public void onBitmapDownloaded(Bitmap bitmapIcon) { - localCurrency.setIcon(bitmapIcon); - countIcons(); - } - }); - } - else - { - Drawable drawable = getDrawable(R.drawable.ic_panorama_fish_eye_24dp, getActivity().getBaseContext()); - - Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - - Canvas canvas = new Canvas(icon); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - - icon = Bitmap.createScaledBitmap(icon, 50, 50, false); - - localCurrency.setIcon(icon); - countIcons(); - } - } - - return null; - } - } - - private class DataUpdater extends AsyncTask { @Override diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index e84c227..1d38679 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -4,14 +4,19 @@ import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; +import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Build; +import android.os.Handler; +import android.os.Looper; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v7.widget.CardView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; @@ -26,7 +31,9 @@ import com.github.mikephil.charting.data.LineDataSet; import com.herbron.moodl.Activities.CurrencyDetailsActivity; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; import com.herbron.moodl.DataManagers.DatabaseManager; +import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager; import com.herbron.moodl.DataManagers.PreferencesManager; +import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface; import com.herbron.moodl.MoodlBox; import com.herbron.moodl.Utils.PlaceholderUtils; import com.herbron.moodl.R; @@ -36,6 +43,7 @@ import java.util.List; import static com.herbron.moodl.MoodlBox.collapseH; import static com.herbron.moodl.MoodlBox.expandH; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; import static com.herbron.moodl.MoodlBox.numberConformer; /** @@ -46,6 +54,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti private Currency currency; private Activity parentActivity; + private Context context; private OnClickListener detailsClickListener = new OnClickListener() { @Override @@ -67,6 +76,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti public CurrencyCardview(@NonNull Context context) { super(context); + this.context = context; } public CurrencyCardview(@NonNull final Context context, final Currency currency, final Activity activity) @@ -77,6 +87,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti this.currency = currency; this.parentActivity = activity; + this.context = context; LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true); @@ -84,32 +95,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti setupCardView(); - setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - PreferencesManager preferencesManager = new PreferencesManager(context); + setOnClickListeners(); - if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { - collapseH(view.findViewById(R.id.collapsableLayout)); - } else { - view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE); - view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); - expandH(view.findViewById(R.id.collapsableLayout)); - - if (currency.getHistoryMinutes() == null) { - currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency()); - } - else - { - expandH(view.findViewById(R.id.collapsableLayout)); - view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); - view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE); - } - } - } - }); - - updateCardViewInfos(currency); + updateCardviewInfos(); findViewById(R.id.deleteCardWatchlist).setOnClickListener(new OnClickListener() { @Override @@ -120,10 +108,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } }); - findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener); - findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener); + updateColor(); - updateColor(currency); + startIconUpdater(); } public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, boolean isBalanceHidden) @@ -134,6 +121,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti this.currency = currency; this.parentActivity = activity; + this.context = context; LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true); @@ -141,6 +129,68 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti setupCardView(); + setOnClickListeners(); + + updateCardviewInfos(); + + updateColor(); + + startIconUpdater(); + } + + private void startIconUpdater() + { + IconDownloader iconDownloader = new IconDownloader(); + iconDownloader.execute(context, currency); + iconDownloader.setOnBitmapDownloadedListener(new IconDownloader.OnBitmapDownloadedListener() { + @Override + public void onDownloaded(Bitmap icon) { + currency.setIcon(icon); + currency.setChartColor(getIconDominantColor(context, icon)); + + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + updateCurrencyColorRelatedLayouts(); + } + }); + } + }); + } + + private void updateCurrencyColorRelatedLayouts() + { + ((ImageView) findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); + + Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); + arrowDrawable.mutate(); + arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + arrowDrawable.invalidateSelf(); + + Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechart)).getIndeterminateDrawable(); + progressDrawable.mutate(); + progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressDrawable.invalidateSelf(); + + if(findViewById(R.id.currencyPortfolioDominance) != null) + { + Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); + progressBarDrawable.mutate(); + progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressBarDrawable.invalidateSelf(); + } + + LineChart lineChart = findViewById(R.id.LineChartView); + + if(currency.getHistoryMinutes() != null) + { + lineChart.setData(generateData()); + lineChart.invalidate(); + } + } + + private void setOnClickListeners() + { setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { @@ -150,7 +200,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti collapseH(view.findViewById(R.id.collapsableLayout)); } else { view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE); - view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); + view.findViewById(R.id.progressBarLinechart).setVisibility(View.VISIBLE); expandH(view.findViewById(R.id.collapsableLayout)); if (currency.getHistoryMinutes() == null) { @@ -159,7 +209,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti else { expandH(view.findViewById(R.id.collapsableLayout)); - view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); + view.findViewById(R.id.progressBarLinechart).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE); } } @@ -169,7 +219,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener); findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener); - updateColor(currency); } public Currency getCurrency() @@ -210,81 +259,33 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti lineChart.getLegend().setEnabled(false); lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); + lineChart.setData(generateData()); } - private void updateCardViewInfos(Currency currency) + private void updateCardviewInfos() { ((TextView) findViewById(R.id.currencyFluctuationTextView)) .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); ((TextView) findViewById(R.id.currencyValueTextView)) .setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext())); - ((ImageView) findViewById(R.id.currencyIcon)) - .setImageBitmap(currency.getIcon()); ((TextView) findViewById(R.id.currencyNameTextView)) .setText(currency.getName()); ((TextView) findViewById(R.id.currencySymbolTextView)) .setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext())); ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) .setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); - - Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); - - if(arrowDrawable != null) - { - arrowDrawable.mutate(); - arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - arrowDrawable.invalidateSelf(); - } - - Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable(); - - if(progressDrawable != null) - { - progressDrawable.mutate(); - progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressDrawable.invalidateSelf(); - } } - public void updateCardViewInfos(float totalValue, boolean isBalanceHidden) + public void updateOwnedValues(float totalValue, boolean isBalanceHidden) { double value = currency.getValue() * currency.getBalance(); double percentage = value / totalValue * 100; ((TextView) findViewById(R.id.currencyValueOwnedTextView)) .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext())); - ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); - ((TextView) findViewById(R.id.currencyValueTextView)) - .setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext())); - - ((ImageView) findViewById(R.id.currencyIcon)) - .setImageBitmap(currency.getIcon()); - ((TextView) findViewById(R.id.currencyNameTextView)) - .setText(currency.getName()); - ((TextView) findViewById(R.id.currencySymbolTextView)) - .setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext())); ((TextView) findViewById(R.id.currencyOwnedTextView)) .setText(PlaceholderUtils.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext())); - ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); - - Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); - arrowDrawable.mutate(); - arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - arrowDrawable.invalidateSelf(); - - Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable(); - progressDrawable.mutate(); - progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressDrawable.invalidateSelf(); - - Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); - progressBarDrawable.mutate(); - progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressBarDrawable.invalidateSelf(); ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); ((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderUtils.getPercentageString(numberConformer(percentage), getContext())); @@ -313,7 +314,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100); } - private LineData generateData(Currency currency) + private LineData generateData() { LineDataSet dataSet; List dataChartList = currency.getHistoryMinutes(); @@ -340,7 +341,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti return new LineData(dataSet); } - private void updateColor(Currency currency) + private void updateColor() { if(currency.getDayFluctuationPercentage() >= 0) { @@ -379,18 +380,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti @Override public void onHistoryDataUpdated() { - View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist); - View progressSummaryView = findViewById(R.id.progressBarLinechartSummary); + View progressView = findViewById(R.id.progressBarLinechart); - if(progressWatchlistView != null) - { - progressWatchlistView.setVisibility(View.GONE); - } - - if(progressSummaryView != null) - { - progressSummaryView.setVisibility(View.GONE); - } + progressView.setVisibility(View.GONE); findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE); @@ -404,4 +396,46 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti public void onPriceUpdated(Currency currency) { } + + private static class IconDownloader extends AsyncTask implements MoodlboxNotifierInterface + { + private Bitmap icon = null; + private OnBitmapDownloadedListener onBitmapDownloadedListener; + + public Bitmap getIcon() + { + return icon; + } + + public void setOnBitmapDownloadedListener(OnBitmapDownloadedListener onBitmapDownloadedListener) { + this.onBitmapDownloadedListener = onBitmapDownloadedListener; + } + + @Override + protected Void doInBackground(Object... objects) { + Context context = (Context) objects[0]; + Currency currency = (Currency) objects[1]; + + CryptocompareApiManager cryptocompareApiManager = CryptocompareApiManager.getInstance(context); + + String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager); + + if(iconUrl != null) + { + MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), context.getResources(), context, this); + } + + return null; + } + + @Override + public void onBitmapDownloaded(Bitmap bitmap) { + icon = bitmap; + onBitmapDownloadedListener.onDownloaded(bitmap); + } + + public interface OnBitmapDownloadedListener { + void onDownloaded(Bitmap icon); + } + } } diff --git a/app/src/main/res/layout-v21/cardview_currency.xml b/app/src/main/res/layout-v21/cardview_currency.xml index f7ccc19..51dde10 100644 --- a/app/src/main/res/layout-v21/cardview_currency.xml +++ b/app/src/main/res/layout-v21/cardview_currency.xml @@ -165,7 +165,7 @@ android:focusable="true"> Date: Sun, 2 Sep 2018 01:03:29 +0200 Subject: [PATCH 19/23] Add icon displaying animation --- .../CurrencyData/CurrencyCardview.java | 26 +++++++++++-------- .../main/res/layout-v21/cardview_currency.xml | 2 +- .../res/layout-v21/cardview_watchlist.xml | 2 +- app/src/main/res/layout/cardview_currency.xml | 2 +- .../main/res/layout/cardview_watchlist.xml | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index 1d38679..6640723 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -19,6 +19,12 @@ import android.support.v7.widget.CardView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.AnimationSet; +import android.view.animation.AnticipateInterpolator; +import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -52,6 +58,8 @@ import static com.herbron.moodl.MoodlBox.numberConformer; public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNotifierInterface { + private static final int FADE_IN_DURATION = 300; + private Currency currency; private Activity parentActivity; private Context context; @@ -160,7 +168,13 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti private void updateCurrencyColorRelatedLayouts() { - ((ImageView) findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); + Animation fadeIn = new AlphaAnimation(0, 1); + fadeIn.setInterpolator(new AccelerateInterpolator()); + fadeIn.setDuration(FADE_IN_DURATION); + + ImageView currencyIconImageView = findViewById(R.id.currencyIcon); + currencyIconImageView.setImageBitmap(currency.getIcon()); + currencyIconImageView.startAnimation(fadeIn); Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); arrowDrawable.mutate(); @@ -304,16 +318,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } } - public double getOwnedValue() - { - return currency.getValue() * currency.getBalance(); - } - - public double getFluctuation() - { - return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100); - } - private LineData generateData() { LineDataSet dataSet; diff --git a/app/src/main/res/layout-v21/cardview_currency.xml b/app/src/main/res/layout-v21/cardview_currency.xml index 51dde10..2a5f084 100644 --- a/app/src/main/res/layout-v21/cardview_currency.xml +++ b/app/src/main/res/layout-v21/cardview_currency.xml @@ -31,7 +31,7 @@ android:id="@+id/currencyIcon" android:layout_width="@dimen/currency_icon_cardview_size" android:layout_height="@dimen/currency_icon_cardview_size" - android:layout_margin="1dp" /> + android:layout_margin="1dp"/> + android:layout_margin="1dp"/> + android:layout_margin="1dp"/> + android:layout_margin="1dp"/> Date: Sun, 2 Sep 2018 01:54:48 +0200 Subject: [PATCH 20/23] Prepare suffix code for some inputs --- .../TextInputEditTextSuffix.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/src/main/java/com/herbron/moodl/CustomLayouts/TextInputEditTextSuffix.java diff --git a/app/src/main/java/com/herbron/moodl/CustomLayouts/TextInputEditTextSuffix.java b/app/src/main/java/com/herbron/moodl/CustomLayouts/TextInputEditTextSuffix.java new file mode 100644 index 0000000..8ea9d73 --- /dev/null +++ b/app/src/main/java/com/herbron/moodl/CustomLayouts/TextInputEditTextSuffix.java @@ -0,0 +1,51 @@ +package com.herbron.moodl.CustomLayouts; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.support.design.widget.TextInputEditText; +import android.text.TextPaint; +import android.util.AttributeSet; + +public class TextInputEditTextSuffix extends TextInputEditText { + + private TextPaint textPaint = new TextPaint(); + private String suffix = ""; + + public TextInputEditTextSuffix(Context context) { + super(context); + } + + public TextInputEditTextSuffix(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public TextInputEditTextSuffix(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if(!getText().toString().equals("")) + { + int suffixXPosition = (int) textPaint.measureText(getText().toString() + getPaddingLeft()); + canvas.drawText(suffix, Math.max(suffixXPosition, 0), getBaseline(), textPaint); + } + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + + textPaint.setColor(getCurrentTextColor()); + textPaint.setTextSize(getTextSize()); + textPaint.setTextAlign(Paint.Align.LEFT); + } + + public void setSuffix(String suffix) + { + this.suffix = suffix; + } +} From 1cb7c03d63838b416f5362bec5c10f061c34428d Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 2 Sep 2018 02:08:59 +0200 Subject: [PATCH 21/23] Remove useless code --- .../Activities/HomeActivityFragments/Summary.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 45ae4a0..17541e2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -85,7 +85,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private Handler handler; private Runnable updateRunnable; - private Runnable layoutRefresherRunnable; private int coinCounter; private int iconCounter; @@ -126,8 +125,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, initiateUpdateRunnable(); - initiateLayoutRefresherRunnable(); - refreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -203,15 +200,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, }; } - private void initiateLayoutRefresherRunnable() - { - layoutRefresherRunnable = new Runnable() { - @Override - public void run() { - } - }; - } - private void setupAddCurrencyButton(View fragmentView) { Button addCurrencyButton = fragmentView.findViewById(R.id.buttonAddTransaction); From cb428937d47ef3873ac4171ba12470332c6818b5 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 2 Oct 2018 15:36:56 +0200 Subject: [PATCH 22/23] Fix decode feature in the app (MUST BE CHECKED) --- .../java/com/herbron/moodl/DataManagers/DataCrypter.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java b/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java index 2abe2ce..006cd81 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java @@ -73,10 +73,12 @@ public class DataCrypter { IvParameterSpec ivParameterSpec = new IvParameterSpec(context.getString(R.string.ivKey).getBytes("UTF-8")); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - cipher.init(Cipher.ENCRYPT_MODE, aesKey, ivParameterSpec); + cipher.init(Cipher.DECRYPT_MODE, aesKey, ivParameterSpec); + + byte[] decryptedBytes = cipher.doFinal(data.getBytes("UTF-8")); - byte[] dataBytes = Base64.decode(data, Base64.DEFAULT); - decryptedData = new String(dataBytes, StandardCharsets.UTF_8); + //byte[] dataBytes = Base64.decode(data, Base64.DEFAULT); + decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8); } catch(NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException From aa8717946a83ed2813fa6c1807ad5453523b2e03 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 19 Nov 2018 16:43:42 +0100 Subject: [PATCH 23/23] Several fixes - CurrencySelectionActivity renamed to CurrencyListActivity - Allow refresh from the Update snackbar button in Summary after an error - Code cleaning - Typo --- .gitignore | 75 ++++++++++-- .idea/caches/build_file_checksums.ser | Bin 545 -> 545 bytes app/src/main/AndroidManifest.xml | 2 +- ...ctivity.java => CurrencyListActivity.java} | 112 +++++++++++------- .../HomeActivityFragments/Summary.java | 9 +- .../HomeActivityFragments/Watchlist.java | 40 +++---- .../CoinmarketCapAPIManager.java | 5 + .../main/java/com/herbron/moodl/MoodlBox.java | 62 ++++++---- .../homeactivity_fragment_watchlist.xml | 3 +- ...urrency.xml => activity_currency_list.xml} | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 14 files changed, 206 insertions(+), 114 deletions(-) rename app/src/main/java/com/herbron/moodl/Activities/{CurrencySelectionActivity.java => CurrencyListActivity.java} (65%) rename app/src/main/res/layout/{activity_add_currency.xml => activity_currency_list.xml} (95%) diff --git a/.gitignore b/.gitignore index e8267b1..a02421c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,69 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries .DS_Store -/build -/captures -.externalNativeBuild + +# Built application files *.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 8067773fbcdd12fe07eb24cf947c7cb4456005d8..92dcb68ae802120de4401d43f34c085dba3f0674 100644 GIT binary patch delta 36 ucmV+<0Neke1fc|wmj!0^prGK9oXilKOu3ogOJX7N!}Kxkrl|9icmb(cEfbyq delta 36 ucmV+<0Neke1fc|wmjz{l&rU;;oXij%j)#;VUxQ3reVEr{zV-l currencyNames = cryptocompareApiManager.getCurrenciesName(); - List currencySymbols = cryptocompareApiManager.getCurrenciesSymbol(); - - ArrayList currencyArrayList = new ArrayList<>(); - - for(int i = 0; i < currencyNames.size(); i++) - { - currencyArrayList.add(new Currency(currencyNames.get(i), currencySymbols.get(i))); - } - - adapter = new CoinWatchlistAdapter(this, currencyArrayList); + adapter = new CoinWatchlistAdapter(this, new ArrayList<>(coinmarketCapAPIManager.getTotalListing())); } private void setupList() @@ -93,26 +92,16 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear public void onItemClick(AdapterView adapterView, View view, int i, long l) { Currency selectedCurrency = (Currency) adapterView.getItemAtPosition(i); - if(isWatchList) - { - PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); - DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); + PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); + DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); - if(databaseManager.addCurrencyToWatchlist(selectedCurrency)) - { - preferencesManager.setMustUpdateWatchlist(true); - } - else - { - Toast.makeText(getApplicationContext(), getString(R.string.already_watchlisr), Toast.LENGTH_SHORT).show(); - } + if(databaseManager.addCurrencyToWatchlist(selectedCurrency)) + { + preferencesManager.setMustUpdateWatchlist(true); } else { - Intent intent = new Intent(CurrencySelectionActivity.this, RecordTransactionActivity.class); - intent.putExtra("coin", selectedCurrency.getName()); - intent.putExtra("symbol", selectedCurrency.getSymbol()); - startActivity(intent); + Toast.makeText(getApplicationContext(), getString(R.string.already_watchlist), Toast.LENGTH_SHORT).show(); } finish(); @@ -166,17 +155,20 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear private void detailsEvent() { - runOnUiThread(new Runnable() { - @Override - public void run() { - setupAdapter(); - setupList(); - setupSearchView(); + if(coinmarketCapAPIManager.isUpToDate() && cryptocompareApiManager.isDetailsUpToDate()) + { + runOnUiThread(new Runnable() { + @Override + public void run() { + setupAdapter(); + setupList(); + setupSearchView(); - expand(findViewById(R.id.listContainerLayout)); - findViewById(R.id.currencyListProgressBar).setVisibility(View.GONE); - } - }); + expand(findViewById(R.id.listContainerLayout)); + findViewById(R.id.currencyListProgressBar).setVisibility(View.GONE); + } + }); + } } @Override @@ -189,6 +181,26 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear } + @Override + public void onCurrenciesRetrieved(List currencyList) { + + } + + @Override + public void onTopCurrenciesUpdated() { + + } + + @Override + public void onMarketCapUpdated() { + + } + + @Override + public void onListingUpdated() { + detailsEvent(); + } + private class ListLoader extends AsyncTask { @Override @@ -211,9 +223,17 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear Looper.prepare(); } - if(!cryptocompareApiManager.isDetailsUpToDate()) + if(!cryptocompareApiManager.isDetailsUpToDate() || !coinmarketCapAPIManager.isUpToDate()) { - cryptocompareApiManager.updateDetails(); + if(!cryptocompareApiManager.isDetailsUpToDate()) + { + cryptocompareApiManager.updateDetails(); + } + + if(!coinmarketCapAPIManager.isUpToDate()) + { + coinmarketCapAPIManager.updateListing(); + } } else { diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 17541e2..57a00b8 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -72,13 +72,14 @@ import static java.lang.Math.abs; public class Summary extends Fragment implements BalanceSwitchManagerInterface, BalanceUpdateNotifierInterface, CryptocompareNotifierInterface, CoinmarketcapNotifierInterface { + + private LinearLayout currencyLayout; private PreferencesManager preferencesManager; private BalanceManager balanceManager; private SwipeRefreshLayout refreshLayout; private Dialog loadingDialog; private String defaultCurrency; - private CoinmarketCapAPIManager coinmarketCapAPIManager; private TextView toolbarSubtitle; private CollapsingToolbarLayout toolbarLayout; @@ -87,7 +88,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private Runnable updateRunnable; private int coinCounter; - private int iconCounter; private float totalValue; private boolean detailsChecker; private boolean tickersChecker; @@ -95,6 +95,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private long lastTimestamp; private BalanceUpdateInterface balanceUpdateInterface; + private CoinmarketCapAPIManager coinmarketCapAPIManager; private CryptocompareApiManager cryptocompareApiManager; @NonNull @@ -318,7 +319,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, .setAction(getString(R.string.update), new View.OnClickListener() { @Override public void onClick(View view) { - + updateAll(true); } }) .show(); @@ -327,7 +328,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private void resetCounters() { coinCounter = 0; - iconCounter = 0; } private void adaptView(float totalValue, float totalFluctuation) @@ -753,6 +753,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private class DataUpdater extends AsyncTask { + @Override protected Void doInBackground(Void... params) { diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java index 803043d..10ef21a 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -12,14 +12,14 @@ import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.graphics.Palette; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; -import com.herbron.moodl.Activities.CurrencySelectionActivity; +import com.herbron.moodl.Activities.CurrencyListActivity; import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface; import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; @@ -42,7 +42,6 @@ import java.util.List; import static com.herbron.moodl.MoodlBox.collapseW; import static com.herbron.moodl.MoodlBox.expandW; -import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** @@ -250,7 +249,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac disableEdition(); } - Intent selectionIntent = new Intent(getActivity(), CurrencySelectionActivity.class); + Intent selectionIntent = new Intent(getActivity(), CurrencyListActivity.class); selectionIntent.putExtra("isWatchList", true); startActivity(selectionIntent); } @@ -355,6 +354,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac public void run() { dragLinearLayout.removeAllViews(); view.findViewById(R.id.progressBarWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.buttonAddWatchlist).setVisibility(View.VISIBLE); for(Currency currency : watchlistManager.getWatchlist()) { @@ -390,6 +390,9 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac id = jsonObject.getInt("Id"); } catch (JSONException e) { e.printStackTrace(); + } catch (NullPointerException e) { + Log.d("moodl", "ID not found"); + e.printStackTrace(); } return id; @@ -435,27 +438,14 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac public void onPriceUpdated(Currency successCurrency) { String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager); - if(iconUrl != null) - { - MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { - @Override - public void onBitmapDownloaded(Bitmap bitmapIcon) { - currency.setIcon(bitmapIcon); - currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); - countWatchlist(); - - } - }); - } - else - { - Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); - icon = Bitmap.createScaledBitmap(icon, 50, 50, false); - - currency.setIcon(icon); - currency.setChartColor(getIconDominantColor(getContext(), icon)); - countWatchlist(); - } + MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { + @Override + public void onBitmapDownloaded(Bitmap bitmapIcon) { + currency.setIcon(bitmapIcon); + currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); + countWatchlist(); + } + }); } }); } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java index ea1bc67..0a12a9f 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java @@ -203,6 +203,11 @@ public class CoinmarketCapAPIManager { } } + public List getTotalListing() + { + return currencyTickerList; + } + public void updateTopCurrencies(final String toSymbol) { String requestString = topCurrenciesUrl + toSymbol; diff --git a/app/src/main/java/com/herbron/moodl/MoodlBox.java b/app/src/main/java/com/herbron/moodl/MoodlBox.java index 87cbe61..08cb719 100644 --- a/app/src/main/java/com/herbron/moodl/MoodlBox.java +++ b/app/src/main/java/com/herbron/moodl/MoodlBox.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v7.graphics.Palette; @@ -209,36 +210,51 @@ public class MoodlBox { public static void getBitmapFromURL(String src, String symbol, Resources resources, Context context, MoodlboxNotifierInterface callBack) { - String size = src.substring(src.lastIndexOf("=") + 1, src.length()); - String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png"; Bitmap result; - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - - result = BitmapFactory.decodeFile(filepath, options); - - if(result == null) + if(src != null) { - try { - java.net.URL url = new java.net.URL(src); - HttpURLConnection connection = (HttpURLConnection) url - .openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - result = BitmapFactory.decodeStream(input); + String size = src.substring(src.lastIndexOf("=") + 1, src.length()); + String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png"; - FileOutputStream out = new FileOutputStream(filepath); - result.compress(Bitmap.CompressFormat.PNG, 100, out); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inPreferredConfig = Bitmap.Config.ARGB_8888; - } catch (IOException e) { - Log.d("moodl", "Error while downloading " + symbol + " icon > " + e.getMessage()); - result = BitmapFactory.decodeResource(resources, - R.mipmap.ic_launcher_moodl); - result = Bitmap.createScaledBitmap(result, Integer.valueOf(size), Integer.valueOf(size), false); + result = BitmapFactory.decodeFile(filepath, options); + + if(result == null) + { + try { + java.net.URL url = new java.net.URL(src); + HttpURLConnection connection = (HttpURLConnection) url + .openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + result = BitmapFactory.decodeStream(input); + + FileOutputStream out = new FileOutputStream(filepath); + result.compress(Bitmap.CompressFormat.PNG, 100, out); + + } catch (IOException e) { + Log.d("moodl", "Error while downloading " + symbol + " icon > " + e.getMessage()); + Drawable defautlDrawable = resources.getDrawable(R.drawable.ic_panorama_fish_eye_24dp); + result = Bitmap.createBitmap(defautlDrawable.getIntrinsicWidth(), defautlDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + defautlDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + defautlDrawable.draw(canvas); + } } } + else + { + Log.d("moodl", "No URL for " + symbol); + Drawable defautlDrawable = resources.getDrawable(R.drawable.ic_panorama_fish_eye_24dp); + result = Bitmap.createBitmap(defautlDrawable.getIntrinsicWidth(), defautlDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + defautlDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + defautlDrawable.draw(canvas); + } callBack.onBitmapDownloaded(result); } diff --git a/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml b/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml index 3396bfe..b3bcd36 100644 --- a/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml +++ b/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml @@ -94,7 +94,8 @@ android:background="@drawable/button_dashed_background" android:layout_margin="10dp" android:textColor="@color/separationColor" - style="@style/Widget.AppCompat.Button.Borderless"/> + android:visibility="gone" + style="@style/Widget.AppCompat.Button.Borderless" /> diff --git a/app/src/main/res/layout/activity_add_currency.xml b/app/src/main/res/layout/activity_currency_list.xml similarity index 95% rename from app/src/main/res/layout/activity_add_currency.xml rename to app/src/main/res/layout/activity_currency_list.xml index f3fe515..a13e939 100644 --- a/app/src/main/res/layout/activity_add_currency.xml +++ b/app/src/main/res/layout/activity_currency_list.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.herbron.moodl.Activities.CurrencySelectionActivity"> + tools:context="com.herbron.moodl.Activities.CurrencyListActivity"> Impossible de résoudre l\'hôte Erreur inconnue Selectionner une monnaie - Monnaie déjà présente dans la liste suivie + Monnaie déjà présente dans la liste suivie Créer une sauvegarde Mauvais mot de passe Erreur diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 581f285..74b03f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -261,7 +261,7 @@ Can\'t resolve host Unexpected error Select a coin - Currency already in watchlist + Currency already in watchlist Create backup Wrong password Error diff --git a/build.gradle b/build.gradle index 04c6bc4..ce91d76 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cc87b0f..e1f6f58 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Jun 17 03:10:32 CEST 2018 +#Tue Oct 02 22:45:37 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip