Add edit transaction option in details activity

This commit is contained in:
Tanguy Herbron 2018-04-27 16:25:51 +02:00
parent a082bb3d99
commit 680840b262
10 changed files with 135 additions and 44 deletions

View File

@ -21,12 +21,9 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.AbsListView;
@ -37,8 +34,6 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.binance.api.client.domain.account.Trade;
import com.daimajia.swipe.SwipeLayout;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.charts.LineChart;
@ -64,11 +59,9 @@ import com.nauk.moodl.LayoutManagers.TransactionListAdapter;
import com.nauk.moodl.PlaceholderManager;
import com.nauk.moodl.R;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -142,7 +135,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
finish();
return true;
}
return super.onOptionsItemSelected(item);
@ -983,7 +976,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Looper.prepare();
}
ArrayList<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
ArrayList<Transaction> transactionList = databaseManager.getCurrencyTransactionsForSymbol(currency.getSymbol());
drawTransactionList(transactionList);
return null;

View File

@ -3,12 +3,12 @@ package com.nauk.moodl.Activities;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.NavUtils;
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;
@ -17,6 +17,7 @@ import android.widget.TextView;
import android.widget.TimePicker;
import com.nauk.moodl.DataManagers.CurrencyData.Currency;
import com.nauk.moodl.DataManagers.CurrencyData.Transaction;
import com.nauk.moodl.DataManagers.DatabaseManager;
import com.nauk.moodl.DataManagers.PreferencesManager;
import com.nauk.moodl.R;
@ -42,6 +43,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
private PreferencesManager preferenceManager;
private EditText purchasedPriceEditText;
private Currency currency;
private int transactionId;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -63,13 +65,25 @@ public class RecordTransactionActivity extends AppCompatActivity {
amount *= -1;
}
if(transactionId != -1)
{
databaseManager.updateTransactionWithId(transactionId, amount, calendar.getTime(), purchasedPrice, fees);
}
else
{
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;
case android.R.id.home:
//NavUtils.navigateUpFromSameTask(this);
finish();
break;
default:
break;
}
@ -82,17 +96,11 @@ public class RecordTransactionActivity extends AppCompatActivity {
setContentView(R.layout.activity_record_transaction);
Intent intent = getIntent();
coin = intent.getStringExtra("coin");
symbol = intent.getStringExtra("symbol");
setTitle("Add " + coin + " transaction");
sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy");
calendar = Calendar.getInstance();
currency = new Currency(coin, symbol);
databaseManager = new DatabaseManager(this);
preferenceManager = new PreferencesManager(this);
@ -106,10 +114,33 @@ public class RecordTransactionActivity extends AppCompatActivity {
sellButton = findViewById(R.id.sellButton);
transferButton = findViewById(R.id.transfertButton);
//purchasedPrice.setText();
coin = intent.getStringExtra("coin");
Log.d("moodl", "1" + coin);
symbol = intent.getStringExtra("symbol");
transactionId = intent.getIntExtra("transactionId", -1);
if(transactionId != -1)
{
setTitle("Edit " + coin + " transaction");
DatabaseManager databaseManager = new DatabaseManager(this);
Transaction transaction = databaseManager.getCurrencyTransactionById(transactionId);
symbolTxtView.setText(transaction.getSymbol());
amountTxtView.setText(String.valueOf(transaction.getAmount()));
purchaseDate.setText(sdf.format(transaction.getTimestamp()));
feesTxtView.setText(String.valueOf(transaction.getFees()));
}
else
{
setTitle("Add " + coin + " transaction");
purchaseDate.setText(sdf.format(calendar.getTime()));
symbolTxtView.setText(symbol);
feesTxtView.setText(String.valueOf(0));
}
currency = new Currency(coin, symbol);
purchasedDateLayout.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -11,15 +11,17 @@ public class Transaction {
private double amount;
private long timestamp;
private double purchasedPrice;
private double fees;
private boolean isMined;
public Transaction(int transactionId, String symbol, double amount, long timestamp, double purchasedPrice)
public Transaction(int transactionId, String symbol, double amount, long timestamp, double purchasedPrice, double fees)
{
this.transactionId = transactionId;
this.symbol = symbol;
this.amount = amount;
this.timestamp = timestamp;
this.purchasedPrice = purchasedPrice;
this.fees = fees;
}
public int getTransactionId() {
@ -60,4 +62,12 @@ public class Transaction {
{
return purchasedPrice;
}
public double getFees() {
return fees;
}
public void setFees(double fees) {
this.fees = fees;
}
}

View File

@ -162,9 +162,43 @@ public class DatabaseManager extends SQLiteOpenHelper{
return currencyList;
}
public ArrayList<Transaction> getCurrencyTransactions(String symbol)
public void updateTransactionWithId(int transactionId, double amount, Date time, double purchasedPrice, double fees)
{
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'";
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(KEY_CURRENCY_BALANCE, amount);
cv.put(KEY_CURRENCY_DATE, time.getTime());
cv.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice);
cv.put(KEY_CURRENCY_FEES, fees);
db.update(TABLE_MANUAL_CURRENCIES, cv, KEY_CURRENCY_ID + "=" + transactionId, null);
}
public Transaction getCurrencyTransactionById(int id)
{
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE " + KEY_CURRENCY_ID + "='" + id + "'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor resultatList = db.rawQuery(searchQuerry, null);
Transaction transaction = null;
if(resultatList.moveToFirst())
{
transaction = new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5), resultatList.getDouble(7));
}
resultatList.close();
db.close();
return transaction;
}
public ArrayList<Transaction> getCurrencyTransactionsForSymbol(String symbol)
{
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE " + KEY_CURRENCY_SYMBOL + "='" + symbol.toUpperCase() + "'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor resultatList = db.rawQuery(searchQuerry, null);
@ -172,7 +206,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
while(resultatList.moveToNext())
{
transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5)));
transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5), resultatList.getDouble(7)));
}
resultatList.close();

View File

@ -1,8 +1,11 @@
package com.nauk.moodl.LayoutManagers;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -14,6 +17,8 @@ import android.widget.TextView;
import com.daimajia.swipe.SwipeLayout;
import com.nauk.moodl.Activities.CurrencyDetailsActivity;
import com.nauk.moodl.Activities.CurrencySelectionActivity;
import com.nauk.moodl.Activities.RecordTransactionActivity;
import com.nauk.moodl.DataManagers.CurrencyData.Transaction;
import com.nauk.moodl.DataManagers.DatabaseManager;
import com.nauk.moodl.DataManagers.PreferencesManager;
@ -43,7 +48,7 @@ public class TransactionListAdapter extends ArrayAdapter<Transaction> {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
Transaction transaction = getItem(position);
final Transaction transaction = getItem(position);
if(convertView == null)
{
@ -72,6 +77,22 @@ public class TransactionListAdapter extends ArrayAdapter<Transaction> {
}
});
LinearLayout editLayout = convertView.findViewById(R.id.editTransactionLayout);
editLayout.setTag(transaction.getTransactionId());
editLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = ((Activity) context).getTitle().toString();
name = name.substring(1, name.indexOf("|") - 1);
Intent intent = new Intent(context, RecordTransactionActivity.class);
intent.putExtra("coin", name);
intent.putExtra("symbol", transaction.getSymbol());
intent.putExtra("transactionId", transaction.getTransactionId());
context.startActivity(intent);
}
});
setupSwipeView(convertView);
return convertView;

View File

@ -18,6 +18,7 @@
<!--What you want to show-->
<LinearLayout
android:id="@+id/editTransactionLayout"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="match_parent"

View File

@ -9,8 +9,7 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:theme="@style/AppTheme.AppBarOverlay"
android:paddingTop="@dimen/fragment_padding"
android:background="@drawable/gradient_background_reverse">
<android.support.v7.widget.Toolbar

View File

@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:theme="@style/AppTheme.AppBarOverlay"
android:paddingTop="10dp"
android:paddingTop="@dimen/fragment_padding"
android:background="@drawable/gradient_background">
<android.support.design.widget.CollapsingToolbarLayout
@ -26,16 +26,6 @@
app:expandedTitleGravity="center"
app:titleEnabled="true">
<TextView
android:id="@+id/toolbarSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="20dp"
android:gravity="center"
android:textSize="20sp"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
@ -46,6 +36,16 @@
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/toolbarSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="20dp"
android:gravity="center"
android:textSize="20sp"
app:layout_collapseMode="parallax"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -76,9 +76,9 @@
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nauk.moodl.Activities.HomeActivity">
android:layout_width="wrap_content"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -9,7 +9,7 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingTop="@dimen/fragment_padding"
android:background="@drawable/gradient_background_reverse">
<android.support.v7.widget.Toolbar

View File

@ -3,7 +3,7 @@
<dimen name="cardViewSecondaryText">12sp</dimen>
<dimen name="cardViewChartSize">150dp</dimen>
<dimen name="app_bar_height">150dp</dimen>
<dimen name="app_bar_height">172dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="text_margin">16dp</dimen>
<dimen name="mainText">6dp</dimen>
@ -21,4 +21,6 @@
<dimen name="cardview_elevation">8dp</dimen>
<dimen name="toolbar_height">56dp</dimen>
<dimen name="toolbar_height_expand">70dp</dimen>
<dimen name="fragment_padding">15dp</dimen>
</resources>