First reword of record activity
This commit is contained in:
parent
19872f5609
commit
edbb27dd37
@ -2,8 +2,13 @@ package com.nauk.moodl.Activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
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.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
@ -24,12 +29,13 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
||||
private String coin;
|
||||
private String symbol;
|
||||
private TextView symbolTxtView;
|
||||
private TextView purchasedDate;
|
||||
private TextInputLayout purchasedDateLayout;
|
||||
private EditText purchaseDate;
|
||||
private TextView feesTxtView;
|
||||
private EditText amountTxtView;
|
||||
private Button validateButton;
|
||||
private Button receivedButton;
|
||||
private Button sentButton;
|
||||
private Button buyButton;
|
||||
private Button sellButton;
|
||||
private Button transferButton;
|
||||
private DatabaseManager databaseManager;
|
||||
private Calendar calendar;
|
||||
private SimpleDateFormat sdf;
|
||||
@ -37,6 +43,39 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
||||
private EditText purchasedPriceEditText;
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -60,61 +99,63 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
||||
symbolTxtView = findViewById(R.id.currencySymbol);
|
||||
amountTxtView = findViewById(R.id.currencyAmount);
|
||||
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);
|
||||
validateButton = findViewById(R.id.validateButton);
|
||||
receivedButton = findViewById(R.id.receivedButton);
|
||||
sentButton = findViewById(R.id.sentButton);
|
||||
buyButton = findViewById(R.id.buyButton);
|
||||
sellButton = findViewById(R.id.sellButton);
|
||||
transferButton = findViewById(R.id.transfertButton);
|
||||
|
||||
//purchasedPrice.setText();
|
||||
purchasedDate.setText(sdf.format(calendar.getTime()));
|
||||
purchaseDate.setText(sdf.format(calendar.getTime()));
|
||||
symbolTxtView.setText(symbol);
|
||||
feesTxtView.setText(String.valueOf(0));
|
||||
|
||||
purchasedDate.setOnClickListener(new View.OnClickListener() {
|
||||
purchasedDateLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
createDatePicker();
|
||||
}
|
||||
});
|
||||
|
||||
validateButton.setOnClickListener(new View.OnClickListener() {
|
||||
purchaseDate.setKeyListener(null);
|
||||
|
||||
purchaseDate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
createDatePicker();
|
||||
}
|
||||
});
|
||||
|
||||
receivedButton.setOnClickListener(new View.OnClickListener() {
|
||||
buyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
receivedButton.setEnabled(false);
|
||||
sentButton.setEnabled(true);
|
||||
purchasedPriceEditText.setVisibility(View.VISIBLE);
|
||||
feesTxtView.setVisibility(View.GONE);
|
||||
buyButton.setEnabled(false);
|
||||
sellButton.setEnabled(true);
|
||||
transferButton.setEnabled(true);
|
||||
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
|
||||
public void onClick(View view) {
|
||||
receivedButton.setEnabled(true);
|
||||
sentButton.setEnabled(false);
|
||||
purchasedPriceEditText.setVisibility(View.GONE);
|
||||
feesTxtView.setVisibility(View.VISIBLE);
|
||||
buyButton.setEnabled(true);
|
||||
sellButton.setEnabled(false);
|
||||
transferButton.setEnabled(true);
|
||||
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.MONTH, month);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||
purchasedDate.setText(sdf.format(calendar.getTime()));
|
||||
purchaseDate.setText(sdf.format(calendar.getTime()));
|
||||
createTimePicker();
|
||||
}
|
||||
},
|
||||
@ -155,7 +196,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
||||
public void onTimeSet(TimePicker view, int hour, int minute) {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
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() {
|
||||
@Override
|
||||
|
18
app/src/main/res/drawable/button_buy.xml
Normal file
18
app/src/main/res/drawable/button_buy.xml
Normal 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>
|
@ -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>
|
18
app/src/main/res/drawable/button_sell.xml
Normal file
18
app/src/main/res/drawable/button_sell.xml
Normal 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>
|
@ -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>
|
18
app/src/main/res/drawable/button_transfer.xml
Normal file
18
app/src/main/res/drawable/button_transfer.xml
Normal 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>
|
9
app/src/main/res/drawable/ic_send_white_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_send_white_24dp.xml
Normal 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>
|
@ -17,23 +17,35 @@
|
||||
android:layout_marginTop="5dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/receivedButton"
|
||||
android:id="@+id/buyButton"
|
||||
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_weight="0.3"
|
||||
android:text="@string/buyText"
|
||||
android:background="@drawable/button_buy"
|
||||
android:layout_marginEnd="2.5dp"
|
||||
android:enabled="false"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/sentButton"
|
||||
android:id="@+id/sellButton"
|
||||
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_weight="0.3"
|
||||
android:text="@string/sellText"
|
||||
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:textColor="@color/white"
|
||||
android:enabled="true" />
|
||||
@ -46,39 +58,62 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="25dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/currencyAmount"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/input_currency_amount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_add_amount"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/purchaseDate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_purchased_date"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp" />
|
||||
<EditText
|
||||
android:id="@+id/currencyAmount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_add_amount"
|
||||
android:inputType="numberDecimal"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/purchasePrice"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_purchased_price"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/feesTextView"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/input_purchase_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_fees"
|
||||
android:visibility="gone"
|
||||
android:text="0"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:id="@+id/validateButton"
|
||||
<EditText
|
||||
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_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>
|
||||
|
||||
|
10
app/src/main/res/menu/menu_record_action.xml
Normal file
10
app/src/main/res/menu/menu_record_action.xml
Normal 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>
|
@ -41,4 +41,6 @@
|
||||
<color name="transparent_red">#22F55447</color>
|
||||
<color name="transparent_green">#225DBF61</color>
|
||||
<color name="transparent_white">#EEFFFFFF</color>
|
||||
<color name="blue">#FF689afe</color>
|
||||
<color name="transparent_blue">#22689afe</color>
|
||||
</resources>
|
@ -64,8 +64,11 @@
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<string name="receivedText">Received</string>
|
||||
<string name="sentText">Sent</string>
|
||||
<string name="buyText">Buy</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" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user