Add fees for sent transaction

This commit is contained in:
Tanguy Herbron 2018-04-24 23:19:57 +02:00
parent ee8ba428d7
commit 19872f5609
9 changed files with 123 additions and 12 deletions

1
.idea/modules.xml generated
View File

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Moodl.iml" filepath="$PROJECT_DIR$/Moodl.iml" />
<module fileurl="file://E:\Github\Moodl\Moodl.iml" filepath="E:\Github\Moodl\Moodl.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>

View File

@ -23,14 +23,18 @@ public class RecordTransactionActivity extends AppCompatActivity {
private String coin;
private String symbol;
private EditText amountTxtView;
private TextView symbolTxtView;
private TextView purchasedDate;
private TextView feesTxtView;
private EditText amountTxtView;
private Button validateButton;
private Button receivedButton;
private Button sentButton;
private DatabaseManager databaseManager;
private Calendar calendar;
private SimpleDateFormat sdf;
private PreferencesManager preferenceManager;
private EditText purchasedPrice;
private EditText purchasedPriceEditText;
private Currency currency;
@Override
@ -53,13 +57,18 @@ public class RecordTransactionActivity extends AppCompatActivity {
databaseManager = new DatabaseManager(this);
preferenceManager = new PreferencesManager(this);
validateButton = findViewById(R.id.validateButton);
symbolTxtView = findViewById(R.id.currencySymbol);
amountTxtView = findViewById(R.id.currencyAmount);
feesTxtView = findViewById(R.id.feesTextView);
purchasedDate = findViewById(R.id.purchaseDate);
purchasedPrice = findViewById(R.id.purchasePrice);
purchasedPriceEditText = findViewById(R.id.purchasePrice);
validateButton = findViewById(R.id.validateButton);
receivedButton = findViewById(R.id.receivedButton);
sentButton = findViewById(R.id.sentButton);
//purchasedPrice.setText();
purchasedDate.setText(sdf.format(calendar.getTime()));
symbolTxtView.setText(symbol);
purchasedDate.setOnClickListener(new View.OnClickListener() {
@Override
@ -71,7 +80,16 @@ public class RecordTransactionActivity extends AppCompatActivity {
validateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime(), purchasedPrice.getText().toString());
double amount = Double.parseDouble(amountTxtView.getText().toString());
double purchasedPrice = Double.parseDouble(purchasedPriceEditText.getText().toString());
double fees = Double.parseDouble(feesTxtView.getText().toString());
if(!sentButton.isEnabled())
{
amount *= -1;
}
databaseManager.addCurrencyToManualCurrency(symbol, amount, calendar.getTime(), purchasedPrice, fees);
preferenceManager.setMustUpdateSummary(true);
Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -80,10 +98,30 @@ public class RecordTransactionActivity extends AppCompatActivity {
}
});
receivedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
receivedButton.setEnabled(false);
sentButton.setEnabled(true);
purchasedPriceEditText.setVisibility(View.VISIBLE);
feesTxtView.setVisibility(View.GONE);
}
});
sentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
receivedButton.setEnabled(true);
sentButton.setEnabled(false);
purchasedPriceEditText.setVisibility(View.GONE);
feesTxtView.setVisibility(View.VISIBLE);
}
});
currency.getTimestampPrice(this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() {
@Override
public void onSuccess(String price) {
purchasedPrice.setText(price);
purchasedPriceEditText.setText(price);
}
}, calendar.getTimeInMillis() / 1000);
}
@ -122,7 +160,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() {
@Override
public void onSuccess(String price) {
purchasedPrice.setText(price);
purchasedPriceEditText.setText(price);
}
}, calendar.getTimeInMillis() / 1000);
Log.d("moodl", "Time : " + calendar.getTimeInMillis());

View File

@ -34,6 +34,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
private static final String KEY_CURRENCY_DATE = "addDate";
private static final String KEY_CURRENCY_PURCHASED_PRICE = "purchasedPrice";
private static final String KEY_CURRENCY_IS_MINED = "isMined";
private static final String KEY_CURRENCY_FEES = "fees";
private static final String KEY_EXCHANGE_ID = "idExchange";
private static final String KEY_EXCHANGE_NAME = "name";
@ -60,7 +61,8 @@ public class DatabaseManager extends SQLiteOpenHelper{
+ KEY_CURRENCY_BALANCE + " TEXT,"
+ KEY_CURRENCY_DATE + " TEXT,"
+ KEY_CURRENCY_PURCHASED_PRICE + " REAL,"
+ KEY_CURRENCY_IS_MINED + " INTEGER"
+ KEY_CURRENCY_IS_MINED + " INTEGER,"
+ KEY_CURRENCY_FEES + " REAL"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_EXCHANGE_KEYS + "("
@ -125,7 +127,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
return currencyList;
}
public void addCurrencyToManualCurrency(String symbol, double balance, Date date, String purchasedPrice)
public void addCurrencyToManualCurrency(String symbol, double balance, Date date, double purchasedPrice, double fees)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
@ -134,6 +136,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
values.put(KEY_CURRENCY_BALANCE, balance);
values.put(KEY_CURRENCY_DATE, date.getTime());
values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice);
values.put(KEY_CURRENCY_FEES, fees);
db.insert(TABLE_MANUAL_CURRENCIES, null, values);
db.close();
@ -149,7 +152,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
while(resultatList.moveToNext())
{
currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3)));
currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3) - resultatList.getDouble(7)));
}
resultatList.close();

View File

@ -68,7 +68,7 @@ public class TransactionListAdapter extends ArrayAdapter<Transaction> {
DatabaseManager databaseManager = new DatabaseManager(context);
preferencesManager.setMustUpdateSummary(true);
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
collapse((View) view.getParent().getParent().getParent().getParent());
collapse((View) view.getParent().getParent().getParent());
}
});

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<color android:color="@color/green"/>
</item>
<item android:state_enabled="false">
<color android:color="@color/transparent_green"/>
</item>
</selector>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<color android:color="@color/red"/>
</item>
<item android:state_enabled="false">
<color android:color="@color/transparent_red"/>
</item>
</selector>

View File

@ -8,7 +8,37 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<Button
android:id="@+id/receivedButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="@string/receivedText"
android:background="@drawable/button_received"
android:layout_marginEnd="2.5dp"
android:enabled="false"
android:textColor="@color/white" />
<Button
android:id="@+id/sentButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="@string/sentText"
android:background="@drawable/button_sent"
android:layout_marginStart="2.5dp"
android:textColor="@color/white"
android:enabled="true" />
</LinearLayout>
<TextView
android:id="@+id/currencySymbol"
@ -36,6 +66,14 @@
android:layout_height="wrap_content"
android:hint="@string/activity_purchased_price"/>
<EditText
android:id="@+id/feesTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_fees"
android:visibility="gone"
android:text="0"/>
<Button
android:id="@+id/validateButton"
android:layout_width="match_parent"

View File

@ -38,4 +38,7 @@
<color name="summary_background">#F5F7FA</color>
<color name="decreaseCandle">#FFFF5754</color>
<color name="increaseCandle">#FF45B64A</color>
<color name="transparent_red">#22F55447</color>
<color name="transparent_green">#225DBF61</color>
<color name="transparent_white">#EEFFFFFF</color>
</resources>

View File

@ -64,6 +64,9 @@
<item>3</item>
</string-array>
<string name="receivedText">Received</string>
<string name="sentText">Sent</string>
<string-array name="multi_select_list_preference_default_value" />
<string name="pref_title_system_sync_settings">System sync settings</string>
@ -120,6 +123,7 @@
<string name="activity_add_amount">Amount</string>
<string name="activity_purchased_price">Purchased price</string>
<string name="activity_purchased_date">Purchased date</string>
<string name="activity_fees">Fees</string>
<string name="title_activity_currency_details">CurrencyDetailsActivity</string>
<string name="title_history">History charts</string>
<string name="title_watchlist">Watchlist</string>