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 c8ec084..f5d17d2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java @@ -33,6 +33,7 @@ import android.widget.TextView; import android.widget.TimePicker; import com.herbron.moodl.Activities.RecordTransactionFragments.BuyFragment; +import com.herbron.moodl.Activities.RecordTransactionFragments.SellFragment; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; import com.herbron.moodl.CustomAdapters.PairRecordListAdapter; import com.herbron.moodl.CustomLayouts.CustomRecordFragment; @@ -150,6 +151,8 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr if(transactionId != -1) { + List exchangeList; + List pairList; DatabaseManager databaseManager = new DatabaseManager(getBaseContext()); Transaction transaction = databaseManager.getCurrencyTransactionById(transactionId); List denominationList = cryptocompareApiManager.getCurrenciesDenomination(); @@ -194,7 +197,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr switch (transaction.getType()) { case "b": - List exchangeList = cryptocompareApiManager.getExchangeList(currency.getSymbol()); + exchangeList = cryptocompareApiManager.getExchangeList(currency.getSymbol()); while(index < exchangeList.size() && !found) { @@ -214,7 +217,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr index++; } - List pairList = exchange.getPairsFor(currency.getSymbol()); + pairList = exchange.getPairsFor(currency.getSymbol()); found = false; index = 0; @@ -242,6 +245,50 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr break; case "s": + exchangeList = cryptocompareApiManager.getExchangeList(currency.getSymbol()); + + while(index < exchangeList.size() && !found) + { + if(exchangeList.get(index).getName().equals(transaction.getSource())) + { + exchange = exchangeList.get(index); + + exchange_autoCompleteTextView.setText(exchange.getName()); + exchange_autoCompleteTextView.setEnabled(true); + + updateExchangeData(); + + updatePairAdapter(); + found = true; + } + + index++; + } + + pairList = exchange.getPairsFor(currency.getSymbol()); + + found = false; + index = 0; + + while(index < pairList.size() && !found) + { + if(pairList.get(index).contains(currency.getSymbol()) && pairList.get(index).contains(transaction.getSymPair())) + { + pair = pairList.get(index); + + pair_autoCompleteTextView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getBaseContext())); + pair_autoCompleteTextView.setEnabled(true); + + ((SellFragment) pageAdapter.getItem(1)).updatePair(pair); + + updatePairData(); + + found = true; + } + + index++; + } + tabLayout.getTabAt(1).select(); break; case "t": 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 fb17037..ad94a15 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; @@ -48,7 +47,7 @@ public class BuyFragment extends CustomRecordFragment { private static Spinner feesCurrencySpinner; private static View view; - private ArrayAdapter currencyAdapter; + private ArrayAdapter currencyFeeAdapter; private SimpleDateFormat sdf; private Calendar calendar; @@ -179,10 +178,10 @@ public class BuyFragment extends CustomRecordFragment { private void initializeViewElements() { - totalValueEditText = view.findViewById(R.id.totalValue_editText); + totalValueEditText = view.findViewById(R.id.totalValue_editText_buy); totalValueEditText.addTextChangedListener(totalValueTextWatcher); - amoutEditText = view.findViewById(R.id.amount_editText); + amoutEditText = view.findViewById(R.id.amount_editText_buy); amoutEditText.addTextChangedListener(amountTextWatcher); buyPriceEditText = view.findViewById(R.id.buyPrice_editText); @@ -195,11 +194,11 @@ public class BuyFragment extends CustomRecordFragment { createDatePicker(); } }); - feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText); + feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText_buy); - currencyAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); - currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - feesCurrencySpinner.setAdapter(currencyAdapter); + currencyFeeAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); + currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + feesCurrencySpinner.setAdapter(currencyFeeAdapter); if(fragmentPair != null) { @@ -272,7 +271,7 @@ public class BuyFragment extends CustomRecordFragment { } }); - fees_editText = view.findViewById(R.id.fees_editText); + fees_editText = view.findViewById(R.id.fees_editText_buy); fees_editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -372,7 +371,7 @@ public class BuyFragment extends CustomRecordFragment { } }); - note_editText = view.findViewById(R.id.note_editText); + note_editText = view.findViewById(R.id.note_editText_buy); checkCallingIntent(); } @@ -443,9 +442,9 @@ public class BuyFragment extends CustomRecordFragment { symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); - currencyAdapter.clear(); - currencyAdapter.addAll(symbolStrings); - currencyAdapter.notifyDataSetChanged(); + currencyFeeAdapter.clear(); + currencyFeeAdapter.addAll(symbolStrings); + currencyFeeAdapter.notifyDataSetChanged(); } private void createDatePicker() @@ -511,30 +510,27 @@ public class BuyFragment extends CustomRecordFragment { public void updatePair(Pair pair) { - currencyAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); - currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - feesCurrencySpinner.setAdapter(currencyAdapter); + currencyFeeAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); + currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + feesCurrencySpinner.setAdapter(currencyFeeAdapter); symbolStrings = new ArrayList<>(); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); - currencyAdapter.addAll(symbolStrings); - currencyAdapter.notifyDataSetChanged(); + currencyFeeAdapter.addAll(symbolStrings); + currencyFeeAdapter.notifyDataSetChanged(); } @Override public void onPairUpdated() { fragmentPair = pair; - fragmentCurrency.setOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() { + fragmentCurrency.addOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() { @Override public void onTimeStampPriceUpdated(String price) { ((TextInputEditText) view.findViewById(R.id.buyPrice_editText)).setText(price); - if(currencyAdapter != null) - { - updateAdapter(); - } + updatePair(fragmentPair); } }); 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 7faf575..c7802d8 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 @@ -1,37 +1,550 @@ package com.herbron.moodl.Activities.RecordTransactionFragments; +import android.app.DatePickerDialog; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; +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; +import android.widget.ArrayAdapter; +import android.widget.DatePicker; +import android.widget.Spinner; +import android.widget.TimePicker; +import com.herbron.moodl.Activities.HomeActivity; import com.herbron.moodl.CustomLayouts.CustomRecordFragment; +import com.herbron.moodl.DataManagers.CurrencyData.Currency; +import com.herbron.moodl.DataManagers.CurrencyData.Transaction; +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.R; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; + public class SellFragment extends CustomRecordFragment { + private TextInputEditText amoutEditText; + private TextInputEditText sellPriceEditText; + private TextInputEditText sellDateEditText; + private TextInputEditText totalValueEditText; + private TextInputEditText fees_editText; + private TextInputEditText note_editText; + private AppCompatButton saveSellButton; + private static Spinner feesCurrencySpinner; + private static View view; + + private ArrayAdapter currencyFeeAdapter; + + private SimpleDateFormat sdf; + private Calendar calendar; + private PreferencesManager preferenceManager; + + private static Context context; + + private static Currency fragmentCurrency; + private static Exchange fragmentExchange; + private static Pair fragmentPair; + private List symbolStrings; + + private int transactionId; + private Transaction transaction; + + private boolean isAmountLastUpdated; + + private TextWatcher amountTextWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + totalValueEditText.removeTextChangedListener(totalValueTextWatcher); + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if(isFieldCorrectlyFilled(sellPriceEditText, false) && isFieldCorrectlyFilled(amoutEditText, false)) + { + if(Double.parseDouble(amoutEditText.getText().toString()) > 0) + { + Double totalValue = Double.parseDouble(sellPriceEditText.getText().toString()) * Double.parseDouble(s.toString()); + totalValueEditText.setText(String.format("%f", totalValue)); + } + else + { + totalValueEditText.setText("0"); + } + } + else + { + totalValueEditText.setText(""); + } + } + + @Override + public void afterTextChanged(Editable s) { + totalValueEditText.addTextChangedListener(totalValueTextWatcher); + isAmountLastUpdated = true; + } + }; + + private TextWatcher totalValueTextWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + amoutEditText.removeTextChangedListener(amountTextWatcher); + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if(isFieldCorrectlyFilled(sellPriceEditText, false) && isFieldCorrectlyFilled(totalValueEditText, false)) + { + if(Double.parseDouble(totalValueEditText.getText().toString()) > 0) + { + Double amount = Double.parseDouble(s.toString()) / Double.parseDouble(sellPriceEditText.getText().toString()); + amoutEditText.setText(String.format("%f", amount)); + } + else + { + amoutEditText.setText("0"); + } + } + else + { + amoutEditText.setText(""); + } + } + + @Override + public void afterTextChanged(Editable s) { + amoutEditText.addTextChangedListener(amountTextWatcher); + isAmountLastUpdated = false; + } + }; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_sell, container, false); + view = inflater.inflate(R.layout.fragment_sell, container, false); + + context = getActivity().getApplicationContext(); + + calendar = Calendar.getInstance(); + sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.UK); + + preferenceManager = new PreferencesManager(getContext()); + + initializeViewElements(); + return view; } + 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); + sellDateEditText.setText(sdf.format(calendar.getTime())); + + sellDateEditText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + createDatePicker(); + } + }); + 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); + feesCurrencySpinner.setAdapter(currencyFeeAdapter); + + if(fragmentPair != null) + { + updateAdapter(); + } + + saveSellButton = view.findViewById(R.id.saveSellButton); + saveSellButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(isFieldCorrectlyFilled(amoutEditText, true) && isFieldCorrectlyFilled(sellPriceEditText, true) && isFieldCorrectlyFilled(totalValueEditText, true)) + { + double amount = Double.parseDouble(amoutEditText.getText().toString()); + double purchasePrice = Double.parseDouble(sellPriceEditText.getText().toString()); + double fees; + String feeCurrency; + + if(feesCurrencySpinner.getSelectedItemPosition() < 1) + { + feeCurrency = fragmentPair.getFrom(); + } + else + { + feeCurrency = fragmentPair.getTo(); + } + + fees = getFees(feeCurrency, amount, purchasePrice); + + String note = note_editText.getText().toString(); + + DatabaseManager databaseManager = new DatabaseManager(getContext()); + + preferenceManager.setMustUpdateSummary(true); + + if(transactionId == -1) + { + databaseManager.addTransaction(fragmentCurrency.getSymbol() + , amount + , calendar.getTime() + , purchasePrice + , fees + , note + , fragmentPair.getFrom().equals(fragmentCurrency.getSymbol()) ? fragmentPair.getTo() : fragmentPair.getFrom() + , feeCurrency + , fragmentExchange.getName() + , "s" + , feesCurrencySpinner.getSelectedItemPosition() % 2 == 0 ? "p" : "f"); + + Intent intent = new Intent(getActivity(), HomeActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + } + else + { + databaseManager.updateTransactionWithId(transactionId + , amount + , calendar.getTime() + , purchasePrice + , fees + , note + , fragmentPair.getFrom().equals(fragmentCurrency.getSymbol()) ? fragmentPair.getTo() : fragmentPair.getFrom() + , feeCurrency + , fragmentExchange.getName() + , "s" + , feesCurrencySpinner.getSelectedItemPosition() % 2 == 0 ? "p" : "f"); + } + + getActivity().finish(); + } + } + }); + + 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(); + } + + private double getFees(String feeCurrency, double amount, double purchasedPrice) + { + double fees; + + if(fees_editText.getText().toString().equals("")) + { + fees = 0; + } + else + { + fees = Double.parseDouble(fees_editText.getText().toString()); + + if(feesCurrencySpinner.getSelectedItemPosition() % 2 == 0) + { + if(fragmentCurrency.getSymbol().equals(feeCurrency)) + { + fees = (100 * amount) / (100 + fees); + } + else + { + double base = (100 * purchasedPrice * amount) / (100 + fees); + + fees = purchasedPrice * amount - base; + } + } + } + + return fees; + } + + private void checkCallingIntent() + { + Intent intent = getActivity().getIntent(); + transactionId = intent.getIntExtra("transactionId", -1); + + if(transactionId != -1) + { + DatabaseManager databaseManager = new DatabaseManager(context); + transaction = databaseManager.getCurrencyTransactionById(transactionId); + + if(transaction.getType().equals("b")) + { + fillFields(); + } + } + } + + private void fillFields() + { + amoutEditText.setText(String.valueOf(transaction.getAmount())); + sellPriceEditText.setText(String.valueOf(transaction.getPrice())); + calendar.setTimeInMillis(transaction.getTimestamp()); + sellDateEditText.setText(sdf.format(calendar.getTime())); + totalValueEditText.setText(String.valueOf(transaction.getAmount() * transaction.getPrice())); + fees_editText.setText(String.valueOf(transaction.getFees())); + note_editText.setText(transaction.getNote()); + } + + private void updateAdapter() + { + symbolStrings = new ArrayList<>(); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); + + currencyFeeAdapter.clear(); + currencyFeeAdapter.addAll(symbolStrings); + currencyFeeAdapter.notifyDataSetChanged(); + } + + private static Context getSecureContext() + { + return context; + } + + private void createDatePicker() + { + DatePickerDialog datePickerDialog = new DatePickerDialog( + getContext(), + new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month); + calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); + sellDateEditText.setText(sdf.format(calendar.getTime())); + createTimePicker(); + } + }, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ); + + datePickerDialog.getDatePicker().setMaxDate(Calendar.getInstance().getTimeInMillis()); + datePickerDialog.show(); + } + + private void createTimePicker() + { + new android.app.TimePickerDialog( + getContext(), + new android.app.TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hour, int minute) { + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + sellDateEditText.setText(sdf.format(calendar.getTime())); + + if(fragmentCurrency != null) + { + fragmentCurrency.getTimestampPrice(getContext(), fragmentCurrency.getSymbol().equals(fragmentPair.getFrom()) ? fragmentPair.getTo() : fragmentPair.getFrom(),calendar.getTimeInMillis() / 1000); + } + } + }, + calendar.get(Calendar.HOUR_OF_DAY), + calendar.get(Calendar.MINUTE), + true + ).show(); + } + + private boolean isFieldCorrectlyFilled(TextInputEditText editText, boolean displayError) + { + String purchasedPriceText = editText.getText().toString(); + double purchasedPrice; + + try { + purchasedPrice = Double.parseDouble(purchasedPriceText); + + if(purchasedPrice < 0) + { + if(displayError) editText.setError(getResources().getString(R.string.field_negative)); + + return false; + } + } catch (NumberFormatException e) { + if(displayError) editText.setError(getResources().getString(R.string.field_nan)); + + return false; + } + + if(purchasedPriceText.equals("")) + { + if(displayError) editText.setError(getResources().getString(R.string.field_empty)); + + return false; + } + + return true; + } + @Override public void onCurrencyUpdated() { - + fragmentCurrency = currency; } @Override public void onExchangeUpdated() { + fragmentExchange = exchange; + } + public void updatePair(Pair 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); + + symbolStrings = new ArrayList<>(); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); + currencyFeeAdapter.addAll(symbolStrings); + currencyFeeAdapter.notifyDataSetChanged(); } @Override public void onPairUpdated() { + fragmentPair = pair; + fragmentCurrency.addOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() { + @Override + public void onTimeStampPriceUpdated(String price) { + ((TextInputEditText) view.findViewById(R.id.sellPrice_editText)).setText(price); + + updatePair(fragmentPair); + } + }); + + if(preferenceManager == null) + { + preferenceManager = new PreferencesManager(getSecureContext()); + } + + if(calendar == null) + { + calendar = Calendar.getInstance(); + } + + fragmentCurrency.getTimestampPrice(getSecureContext(), fragmentCurrency.getSymbol().equals(fragmentPair.getFrom()) ? fragmentPair.getTo() : fragmentPair.getFrom(), calendar.getTimeInMillis() / 1000); } } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java index e9e855d..673a444 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java @@ -44,7 +44,7 @@ public class Currency implements Parcelable { private int rank; private String startDate; private List socialMediaLinks; - private OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener; + private List onTimestampPriceUpdatedListenerList; //private String proofType private CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface; @@ -82,8 +82,6 @@ public class Currency implements Parcelable { this.currencyInfoUpdateNotifierInterface = currencyInfoUpdateNotifierInterface; } - //public Currency(int id, String symbol, String name, String algorithm, String proofType, ) - public void getTimestampPrice(android.content.Context context, String toSymbol, long timestamp) { dataRetriver = new CurrencyDataRetriever(context); @@ -96,9 +94,12 @@ public class Currency implements Parcelable { public void onSuccess(String price) { currencyInfoUpdateNotifierInterface.onTimestampPriceUpdated(price); - if(onTimestampPriceUpdatedListener != null) + if(onTimestampPriceUpdatedListenerList != null) { - onTimestampPriceUpdatedListener.onTimeStampPriceUpdated(price); + for(int i = 0; i < onTimestampPriceUpdatedListenerList.size(); i++) + { + onTimestampPriceUpdatedListenerList.get(i).onTimeStampPriceUpdated(price); + } } } }, timestamp); @@ -221,12 +222,6 @@ public class Currency implements Parcelable { }, CurrencyDataRetriever.DAYS); } - public void updateDetails(android.content.Context context, final CurrencyCallBack callBack) - { - dataRetriver = new CurrencyDataRetriever(context); - - } - private int getDarkenColor(int color) { int transColor; @@ -542,8 +537,13 @@ public class Currency implements Parcelable { void onTimeStampPriceUpdated(String price); } - public void setOnTimestampPriceUpdatedListener(OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener) + public void addOnTimestampPriceUpdatedListener(OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener) { - this.onTimestampPriceUpdatedListener = onTimestampPriceUpdatedListener; + if(onTimestampPriceUpdatedListenerList == null) + { + onTimestampPriceUpdatedListenerList = new ArrayList<>(); + } + + onTimestampPriceUpdatedListenerList.add(onTimestampPriceUpdatedListener); } } diff --git a/app/src/main/res/layout-v21/fragment_buy.xml b/app/src/main/res/layout-v21/fragment_buy.xml deleted file mode 100644 index cf04fa9..0000000 --- a/app/src/main/res/layout-v21/fragment_buy.xml +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout-v21/fragment_sell.xml b/app/src/main/res/layout-v21/fragment_sell.xml deleted file mode 100644 index d55f53d..0000000 --- a/app/src/main/res/layout-v21/fragment_sell.xml +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout-v21/fragment_transfer.xml b/app/src/main/res/layout-v21/fragment_transfer.xml deleted file mode 100644 index 8c13214..0000000 --- a/app/src/main/res/layout-v21/fragment_transfer.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_buy.xml b/app/src/main/res/layout/fragment_buy.xml index cf04fa9..123707f 100644 --- a/app/src/main/res/layout/fragment_buy.xml +++ b/app/src/main/res/layout/fragment_buy.xml @@ -11,12 +11,12 @@ android:orientation="vertical"> @@ -105,12 +105,12 @@ - - + android:layout_margin="@dimen/margin" + android:orientation="vertical"> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file