Update Sell tab in the RecordTransactionActivity allowing to register sell transaction

This commit is contained in:
Tanguy Herbron 2018-08-17 04:38:49 +02:00
parent 1f433ba708
commit 1efbaea351
9 changed files with 734 additions and 343 deletions

View File

@ -33,6 +33,7 @@ import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.herbron.moodl.Activities.RecordTransactionFragments.BuyFragment; import com.herbron.moodl.Activities.RecordTransactionFragments.BuyFragment;
import com.herbron.moodl.Activities.RecordTransactionFragments.SellFragment;
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
import com.herbron.moodl.CustomAdapters.PairRecordListAdapter; import com.herbron.moodl.CustomAdapters.PairRecordListAdapter;
import com.herbron.moodl.CustomLayouts.CustomRecordFragment; import com.herbron.moodl.CustomLayouts.CustomRecordFragment;
@ -150,6 +151,8 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
if(transactionId != -1) if(transactionId != -1)
{ {
List<Exchange> exchangeList;
List<Pair> pairList;
DatabaseManager databaseManager = new DatabaseManager(getBaseContext()); DatabaseManager databaseManager = new DatabaseManager(getBaseContext());
Transaction transaction = databaseManager.getCurrencyTransactionById(transactionId); Transaction transaction = databaseManager.getCurrencyTransactionById(transactionId);
List<Currency> denominationList = cryptocompareApiManager.getCurrenciesDenomination(); List<Currency> denominationList = cryptocompareApiManager.getCurrenciesDenomination();
@ -194,7 +197,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
switch (transaction.getType()) switch (transaction.getType())
{ {
case "b": case "b":
List<Exchange> exchangeList = cryptocompareApiManager.getExchangeList(currency.getSymbol()); exchangeList = cryptocompareApiManager.getExchangeList(currency.getSymbol());
while(index < exchangeList.size() && !found) while(index < exchangeList.size() && !found)
{ {
@ -214,7 +217,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
index++; index++;
} }
List<Pair> pairList = exchange.getPairsFor(currency.getSymbol()); pairList = exchange.getPairsFor(currency.getSymbol());
found = false; found = false;
index = 0; index = 0;
@ -242,6 +245,50 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
break; break;
case "s": 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(); tabLayout.getTabAt(1).select();
break; break;
case "t": case "t":

View File

@ -10,7 +10,6 @@ import android.support.design.widget.TextInputEditText;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatButton;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -48,7 +47,7 @@ public class BuyFragment extends CustomRecordFragment {
private static Spinner feesCurrencySpinner; private static Spinner feesCurrencySpinner;
private static View view; private static View view;
private ArrayAdapter<String> currencyAdapter; private ArrayAdapter<String> currencyFeeAdapter;
private SimpleDateFormat sdf; private SimpleDateFormat sdf;
private Calendar calendar; private Calendar calendar;
@ -179,10 +178,10 @@ public class BuyFragment extends CustomRecordFragment {
private void initializeViewElements() private void initializeViewElements()
{ {
totalValueEditText = view.findViewById(R.id.totalValue_editText); totalValueEditText = view.findViewById(R.id.totalValue_editText_buy);
totalValueEditText.addTextChangedListener(totalValueTextWatcher); totalValueEditText.addTextChangedListener(totalValueTextWatcher);
amoutEditText = view.findViewById(R.id.amount_editText); amoutEditText = view.findViewById(R.id.amount_editText_buy);
amoutEditText.addTextChangedListener(amountTextWatcher); amoutEditText.addTextChangedListener(amountTextWatcher);
buyPriceEditText = view.findViewById(R.id.buyPrice_editText); buyPriceEditText = view.findViewById(R.id.buyPrice_editText);
@ -195,11 +194,11 @@ public class BuyFragment extends CustomRecordFragment {
createDatePicker(); createDatePicker();
} }
}); });
feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText); feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText_buy);
currencyAdapter = new ArrayAdapter<String>(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); currencyFeeAdapter = new ArrayAdapter<String>(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>());
currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
feesCurrencySpinner.setAdapter(currencyAdapter); feesCurrencySpinner.setAdapter(currencyFeeAdapter);
if(fragmentPair != null) 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() { fees_editText.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 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(); checkCallingIntent();
} }
@ -443,9 +442,9 @@ public class BuyFragment extends CustomRecordFragment {
symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext()));
symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext()));
currencyAdapter.clear(); currencyFeeAdapter.clear();
currencyAdapter.addAll(symbolStrings); currencyFeeAdapter.addAll(symbolStrings);
currencyAdapter.notifyDataSetChanged(); currencyFeeAdapter.notifyDataSetChanged();
} }
private void createDatePicker() private void createDatePicker()
@ -511,30 +510,27 @@ public class BuyFragment extends CustomRecordFragment {
public void updatePair(Pair pair) public void updatePair(Pair pair)
{ {
currencyAdapter = new ArrayAdapter<String>(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); currencyFeeAdapter = new ArrayAdapter<String>(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>());
currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); currencyFeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
feesCurrencySpinner.setAdapter(currencyAdapter); feesCurrencySpinner.setAdapter(currencyFeeAdapter);
symbolStrings = new ArrayList<>(); symbolStrings = new ArrayList<>();
symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getFrom(), getSecureContext()));
symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext())); symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(pair.getTo(), getSecureContext()));
currencyAdapter.addAll(symbolStrings); currencyFeeAdapter.addAll(symbolStrings);
currencyAdapter.notifyDataSetChanged(); currencyFeeAdapter.notifyDataSetChanged();
} }
@Override @Override
public void onPairUpdated() { public void onPairUpdated() {
fragmentPair = pair; fragmentPair = pair;
fragmentCurrency.setOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() { fragmentCurrency.addOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() {
@Override @Override
public void onTimeStampPriceUpdated(String price) { public void onTimeStampPriceUpdated(String price) {
((TextInputEditText) view.findViewById(R.id.buyPrice_editText)).setText(price); ((TextInputEditText) view.findViewById(R.id.buyPrice_editText)).setText(price);
if(currencyAdapter != null) updatePair(fragmentPair);
{
updateAdapter();
}
} }
}); });

View File

@ -1,37 +1,550 @@
package com.herbron.moodl.Activities.RecordTransactionFragments; package com.herbron.moodl.Activities.RecordTransactionFragments;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; 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.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.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 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 { 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<String> 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<String> 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 @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 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; 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<String>(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 @Override
public void onCurrencyUpdated() { public void onCurrencyUpdated() {
fragmentCurrency = currency;
} }
@Override @Override
public void onExchangeUpdated() { public void onExchangeUpdated() {
fragmentExchange = exchange;
}
public void updatePair(Pair pair)
{
currencyFeeAdapter = new ArrayAdapter<String>(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 @Override
public void onPairUpdated() { 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);
} }
} }

View File

@ -44,7 +44,7 @@ public class Currency implements Parcelable {
private int rank; private int rank;
private String startDate; private String startDate;
private List<String> socialMediaLinks; private List<String> socialMediaLinks;
private OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener; private List<OnTimestampPriceUpdatedListener> onTimestampPriceUpdatedListenerList;
//private String proofType //private String proofType
private CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface; private CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface;
@ -82,8 +82,6 @@ public class Currency implements Parcelable {
this.currencyInfoUpdateNotifierInterface = currencyInfoUpdateNotifierInterface; 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) public void getTimestampPrice(android.content.Context context, String toSymbol, long timestamp)
{ {
dataRetriver = new CurrencyDataRetriever(context); dataRetriver = new CurrencyDataRetriever(context);
@ -96,9 +94,12 @@ public class Currency implements Parcelable {
public void onSuccess(String price) { public void onSuccess(String price) {
currencyInfoUpdateNotifierInterface.onTimestampPriceUpdated(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); }, timestamp);
@ -221,12 +222,6 @@ public class Currency implements Parcelable {
}, CurrencyDataRetriever.DAYS); }, CurrencyDataRetriever.DAYS);
} }
public void updateDetails(android.content.Context context, final CurrencyCallBack callBack)
{
dataRetriver = new CurrencyDataRetriever(context);
}
private int getDarkenColor(int color) private int getDarkenColor(int color)
{ {
int transColor; int transColor;
@ -542,8 +537,13 @@ public class Currency implements Parcelable {
void onTimeStampPriceUpdated(String price); 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);
} }
} }

View File

@ -1,135 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/record_transaction_layout_background_buy">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/amount_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_add_amount"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_buyPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5">
<android.support.design.widget.TextInputEditText
android:id="@+id/buyPrice_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_purchase_price"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_buyDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="@+id/buyDate_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_purchase_date"
android:focusable="false"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_totalValue"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/totalValue_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/total_value"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_fees"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<android.support.design.widget.TextInputEditText
android:id="@+id/fees_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_fees"/>
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="@+id/feesCurrency_editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_note"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/note_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/notes"
android:maxLines="4"
android:lines="4"
android:gravity="top"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/saveBuyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="@string/save"
android:layout_marginBottom="@dimen/mdtp_minimum_margin_top_bottom"
android:layout_gravity="end"
style="@style/Widget.AppCompat.Button.Colored"/>
</LinearLayout>
</ScrollView>

View File

@ -1,135 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/record_transaction_layout_background_sell">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/amount_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_add_amount"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_sellPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5">
<android.support.design.widget.TextInputEditText
android:id="@+id/sellPrice_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_sell_price"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_sellDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="@+id/sellDate_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_sell_date"
android:focusable="false"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_totalValue"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/totalValue_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/total_value"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_fees"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<android.support.design.widget.TextInputEditText
android:id="@+id/fees_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_fees"/>
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="@+id/feesCurrency_editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_note"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/note_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/notes"
android:maxLines="4"
android:lines="4"
android:gravity="top"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/saveSellButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="@string/save"
android:layout_marginBottom="@dimen/mdtp_minimum_margin_top_bottom"
android:layout_gravity="end"
style="@style/Widget.AppCompat.Button.Colored"/>
</LinearLayout>
</ScrollView>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/record_transaction_layout_background_transfer">
<TextView
android:text="transfer fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

View File

@ -11,12 +11,12 @@
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/input_amount" android:id="@+id/input_amount_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/amount_editText" android:id="@+id/amount_editText_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="numberDecimal" android:inputType="numberDecimal"
@ -63,12 +63,12 @@
</LinearLayout> </LinearLayout>
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/input_totalValue" android:id="@+id/input_totalValue_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/totalValue_editText" android:id="@+id/totalValue_editText_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="numberDecimal" android:inputType="numberDecimal"
@ -82,13 +82,13 @@
android:orientation="horizontal"> android:orientation="horizontal">
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/input_fees" android:id="@+id/input_fees_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0.7"> android:layout_weight="0.7">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/fees_editText" android:id="@+id/fees_editText_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="numberDecimal" android:inputType="numberDecimal"
@ -97,7 +97,7 @@
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<Spinner <Spinner
android:id="@+id/feesCurrency_editText" android:id="@+id/feesCurrency_editText_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"/> android:layout_weight="1"/>
@ -105,12 +105,12 @@
</LinearLayout> </LinearLayout>
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
android:id="@+id/input_note" android:id="@+id/input_note_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/note_editText" android:id="@+id/note_editText_buy"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/notes" android:hint="@string/notes"

View File

@ -1,15 +1,135 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/record_transaction_layout_background_sell"> android:background="@drawable/record_transaction_layout_background_sell">
<TextView <LinearLayout
android:text="sell fragment" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_amount_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/amount_editText_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_add_amount"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_sellPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5">
<android.support.design.widget.TextInputEditText
android:id="@+id/sellPrice_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_sell_price"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_sellDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="@+id/sellDate_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_sell_date"
android:focusable="false"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_totalValue_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/totalValue_editText_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/total_value"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_fees_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<android.support.design.widget.TextInputEditText
android:id="@+id/fees_editText_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/activity_fees"/>
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="@+id/feesCurrency_editText_sell"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_note_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/note_editText_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/notes"
android:maxLines="4"
android:lines="4"
android:gravity="top"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/saveSellButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:textColor="@color/white"
android:layout_centerVertical="true" android:text="@string/save"
android:layout_centerHorizontal="true"/> android:layout_marginBottom="@dimen/mdtp_minimum_margin_top_bottom"
android:layout_gravity="end"
style="@style/Widget.AppCompat.Button.Colored"/>
</RelativeLayout> </LinearLayout>
</ScrollView>