Fix buy fees display in the RecordTransactionActivity

- Fix fixed fees equation
This commit is contained in:
Tanguy Herbron 2018-08-17 03:09:45 +02:00
parent 89246e0919
commit 1f433ba708
4 changed files with 166 additions and 15 deletions

View File

@ -283,7 +283,7 @@ public class BuyFragment extends CustomRecordFragment {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(isFieldCorrectlyFilled(amoutEditText, false) && isFieldCorrectlyFilled(buyPriceEditText, false) && isFieldCorrectlyFilled(totalValueEditText, false))
if((isFieldCorrectlyFilled(amoutEditText, false) || isFieldCorrectlyFilled(totalValueEditText, false)) && isFieldCorrectlyFilled(buyPriceEditText, false))
{
double amount = Double.parseDouble(amoutEditText.getText().toString());
double purchasePrice = Double.parseDouble(buyPriceEditText.getText().toString());
@ -300,7 +300,7 @@ public class BuyFragment extends CustomRecordFragment {
amount = totalValue / purchasePrice;
}
if(fees_editText.getText().toString().equals("") || fees_editText.getText().toString().equals("0"))
if(fees_editText.getText().toString().equals("0") || (start == 0 && before == 1 && count == 0))
{
if(isAmountLastUpdated)
{
@ -314,7 +314,7 @@ public class BuyFragment extends CustomRecordFragment {
else
{
if(feesCurrencySpinner.getSelectedItemPosition() < 1)
if(feesCurrencySpinner.getSelectedItemPosition() < 2)
{
feeCurrency = fragmentPair.getFrom();
}
@ -325,13 +325,41 @@ public class BuyFragment extends CustomRecordFragment {
fees = getFees(feeCurrency, amount, purchasePrice);
if(isAmountLastUpdated)
if(feesCurrencySpinner.getSelectedItemPosition() % 2 == 0)
{
totalValueEditText.setText(String.valueOf(totalValue + fees));
if(isAmountLastUpdated)
{
totalValueEditText.setText(String.valueOf(totalValue + fees));
}
else
{
amoutEditText.setText(String.valueOf(amount - (fees / purchasePrice)));
}
}
else
{
amoutEditText.setText(String.valueOf(amount - (fees / purchasePrice )));
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));
}
}
}
}
}

View File

@ -1,15 +1,135 @@
<?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_height="match_parent"
android:background="@drawable/record_transaction_layout_background_sell">
<TextView
android:text="sell fragment"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
android:layout_margin="@dimen/margin"
android:orientation="vertical">
</RelativeLayout>
<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

@ -157,4 +157,6 @@
<string name="fixedFee">Pourcentage de %1$s</string>
<string name="percentageFee">%1$s fixe</string>
<string name="activity_sell_price">Prix de vente</string>
<string name="activity_sell_date">Date de vente</string>
</resources>

View File

@ -261,7 +261,6 @@
<string name="informations">Informations</string>
<string name="title_choose_coin">Choose a coin</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="exchange">Exchange</string>
<string name="pair">Pair</string>
<string name="total_value">Total value</string>
@ -272,5 +271,7 @@
<string name="fixedFee">%1$s percentage</string>
<string name="percentageFee">%1$s fixed</string>
<string name="activity_sell_price">Sell price</string>
<string name="activity_sell_date">Sell date</string>
</resources>