First reword of record activity

This commit is contained in:
Tanguy Herbron 2018-04-25 15:48:48 +02:00
parent 19872f5609
commit edbb27dd37
11 changed files with 227 additions and 97 deletions

View File

@ -2,8 +2,13 @@ package com.nauk.moodl.Activities;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.DatePicker; import android.widget.DatePicker;
@ -24,12 +29,13 @@ public class RecordTransactionActivity extends AppCompatActivity {
private String coin; private String coin;
private String symbol; private String symbol;
private TextView symbolTxtView; private TextView symbolTxtView;
private TextView purchasedDate; private TextInputLayout purchasedDateLayout;
private EditText purchaseDate;
private TextView feesTxtView; private TextView feesTxtView;
private EditText amountTxtView; private EditText amountTxtView;
private Button validateButton; private Button buyButton;
private Button receivedButton; private Button sellButton;
private Button sentButton; private Button transferButton;
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
private Calendar calendar; private Calendar calendar;
private SimpleDateFormat sdf; private SimpleDateFormat sdf;
@ -37,6 +43,39 @@ public class RecordTransactionActivity extends AppCompatActivity {
private EditText purchasedPriceEditText; private EditText purchasedPriceEditText;
private Currency currency; private Currency currency;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_record_action, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_record:
double amount = Double.parseDouble(amountTxtView.getText().toString());
double purchasedPrice = Double.parseDouble(purchasedPriceEditText.getText().toString());
double fees = Double.parseDouble(feesTxtView.getText().toString());
if(!sellButton.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);
startActivity(intent);
finish();
break;
default:
break;
}
return true;
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -60,61 +99,63 @@ public class RecordTransactionActivity extends AppCompatActivity {
symbolTxtView = findViewById(R.id.currencySymbol); symbolTxtView = findViewById(R.id.currencySymbol);
amountTxtView = findViewById(R.id.currencyAmount); amountTxtView = findViewById(R.id.currencyAmount);
feesTxtView = findViewById(R.id.feesTextView); feesTxtView = findViewById(R.id.feesTextView);
purchasedDate = findViewById(R.id.purchaseDate); purchasedDateLayout = findViewById(R.id.input_purchase_date);
purchaseDate = findViewById(R.id.purchaseDate);
purchasedPriceEditText = findViewById(R.id.purchasePrice); purchasedPriceEditText = findViewById(R.id.purchasePrice);
validateButton = findViewById(R.id.validateButton); buyButton = findViewById(R.id.buyButton);
receivedButton = findViewById(R.id.receivedButton); sellButton = findViewById(R.id.sellButton);
sentButton = findViewById(R.id.sentButton); transferButton = findViewById(R.id.transfertButton);
//purchasedPrice.setText(); //purchasedPrice.setText();
purchasedDate.setText(sdf.format(calendar.getTime())); purchaseDate.setText(sdf.format(calendar.getTime()));
symbolTxtView.setText(symbol); symbolTxtView.setText(symbol);
feesTxtView.setText(String.valueOf(0));
purchasedDate.setOnClickListener(new View.OnClickListener() { purchasedDateLayout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
createDatePicker(); createDatePicker();
} }
}); });
validateButton.setOnClickListener(new View.OnClickListener() { purchaseDate.setKeyListener(null);
purchaseDate.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
double amount = Double.parseDouble(amountTxtView.getText().toString()); createDatePicker();
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);
startActivity(intent);
finish();
} }
}); });
receivedButton.setOnClickListener(new View.OnClickListener() { buyButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
receivedButton.setEnabled(false); buyButton.setEnabled(false);
sentButton.setEnabled(true); sellButton.setEnabled(true);
purchasedPriceEditText.setVisibility(View.VISIBLE); transferButton.setEnabled(true);
feesTxtView.setVisibility(View.GONE); findViewById(R.id.input_purchase_price).setVisibility(View.VISIBLE);
findViewById(R.id.input_fees).setVisibility(View.GONE);
} }
}); });
sentButton.setOnClickListener(new View.OnClickListener() { sellButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
receivedButton.setEnabled(true); buyButton.setEnabled(true);
sentButton.setEnabled(false); sellButton.setEnabled(false);
purchasedPriceEditText.setVisibility(View.GONE); transferButton.setEnabled(true);
feesTxtView.setVisibility(View.VISIBLE); findViewById(R.id.input_purchase_price).setVisibility(View.GONE);
findViewById(R.id.input_fees).setVisibility(View.VISIBLE);
}
});
transferButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buyButton.setEnabled(true);
sellButton.setEnabled(true);
transferButton.setEnabled(false);
// Prepare transfer interface
} }
}); });
@ -136,7 +177,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
calendar.set(Calendar.YEAR, year); calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month); calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
purchasedDate.setText(sdf.format(calendar.getTime())); purchaseDate.setText(sdf.format(calendar.getTime()));
createTimePicker(); createTimePicker();
} }
}, },
@ -155,7 +196,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
public void onTimeSet(TimePicker view, int hour, int minute) { public void onTimeSet(TimePicker view, int hour, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.MINUTE, minute);
purchasedDate.setText(sdf.format(calendar.getTime())); purchaseDate.setText(sdf.format(calendar.getTime()));
currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() {
@Override @Override

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<solid android:color="@color/green"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/transparent_green"/>
<corners android:radius="3dp"/>
</shape>
</item>
</selector>

View File

@ -1,12 +0,0 @@
<?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,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<solid android:color="@color/red"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/transparent_red"/>
<corners android:radius="3dp"/>
</shape>
</item>
</selector>

View File

@ -1,12 +0,0 @@
<?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

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<solid android:color="@color/blue"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/transparent_blue"/>
<corners android:radius="3dp"/>
</shape>
</item>
</selector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
</vector>

View File

@ -17,23 +17,35 @@
android:layout_marginTop="5dp"> android:layout_marginTop="5dp">
<Button <Button
android:id="@+id/receivedButton" android:id="@+id/buyButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.5" android:layout_weight="0.3"
android:text="@string/receivedText" android:text="@string/buyText"
android:background="@drawable/button_received" android:background="@drawable/button_buy"
android:layout_marginEnd="2.5dp" android:layout_marginEnd="2.5dp"
android:enabled="false" android:enabled="false"
android:textColor="@color/white" /> android:textColor="@color/white" />
<Button <Button
android:id="@+id/sentButton" android:id="@+id/sellButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.5" android:layout_weight="0.3"
android:text="@string/sentText" android:text="@string/sellText"
android:background="@drawable/button_sent" android:background="@drawable/button_sell"
android:layout_marginStart="2.5dp"
android:layout_marginEnd="2.5dp"
android:textColor="@color/white"
android:enabled="true" />
<Button
android:id="@+id/transfertButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:text="@string/transferText"
android:background="@drawable/button_transfer"
android:layout_marginStart="2.5dp" android:layout_marginStart="2.5dp"
android:textColor="@color/white" android:textColor="@color/white"
android:enabled="true" /> android:enabled="true" />
@ -46,39 +58,62 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="25dp"/> android:textSize="25dp"/>
<EditText <android.support.design.widget.TextInputLayout
android:id="@+id/currencyAmount" android:id="@+id/input_currency_amount"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:hint="@string/activity_add_amount"/>
<TextView <EditText
android:id="@+id/purchaseDate" android:id="@+id/currencyAmount"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/activity_purchased_date" android:hint="@string/activity_add_amount"
android:layout_marginTop="10dp" android:inputType="numberDecimal"/>
android:layout_marginBottom="10dp" />
<EditText </android.support.design.widget.TextInputLayout>
android:id="@+id/purchasePrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_purchased_price"/>
<EditText <android.support.design.widget.TextInputLayout
android:id="@+id/feesTextView" android:id="@+id/input_purchase_date"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:hint="@string/activity_fees"
android:visibility="gone"
android:text="0"/>
<Button <EditText
android:id="@+id/validateButton" android:id="@+id/purchaseDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_purchased_date"
android:focusable="false"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_purchase_price"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/purchasePrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_purchased_price"
android:inputType="numberDecimal" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_fees"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Validate"/> android:visibility="gone">
<EditText
android:id="@+id/feesTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_fees"
android:inputType="numberDecimal" />
</android.support.design.widget.TextInputLayout>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_record"
android:icon="@drawable/ic_send_white_24dp"
android:title="@string/transaction_record"
app:showAsAction="always"/>
</menu>

View File

@ -41,4 +41,6 @@
<color name="transparent_red">#22F55447</color> <color name="transparent_red">#22F55447</color>
<color name="transparent_green">#225DBF61</color> <color name="transparent_green">#225DBF61</color>
<color name="transparent_white">#EEFFFFFF</color> <color name="transparent_white">#EEFFFFFF</color>
<color name="blue">#FF689afe</color>
<color name="transparent_blue">#22689afe</color>
</resources> </resources>

View File

@ -64,8 +64,11 @@
<item>3</item> <item>3</item>
</string-array> </string-array>
<string name="receivedText">Received</string> <string name="buyText">Buy</string>
<string name="sentText">Sent</string> <string name="sellText">Sell</string>
<string name="transferText">Transfer</string>
<string name="transaction_record">Save</string>
<string-array name="multi_select_list_preference_default_value" /> <string-array name="multi_select_list_preference_default_value" />