From 0faeb6c3d80a8cae8342803839dca6706be6d2ac Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 30 Jan 2018 16:16:06 +0100 Subject: [PATCH] Add swipte to delete in transaction history SwipeLayout for transaction history per currency FIX update balance when no coin --- .idea/modules.xml | 2 +- .idea/vcs.xml | 6 + app/build.gradle | 4 +- .../Activities/CurrencyDetailsActivity.java | 83 ++++++++++++- .../coinfolio/Activities/HomeActivity.java | 1 + .../CurrencyData/Transaction.java | 45 +++++++ .../DataManagers/DatabaseManager.java | 10 +- .../LayoutManagers/CurrencyAdapter.java | 2 +- .../res/drawable/ic_delete_white_24dp.xml | 9 ++ .../main/res/drawable/ic_edit_white_24dp.xml | 9 ++ .../res/layout/activity_currency_details.xml | 19 ++- ...custom_row.xml => custom_currency_row.xml} | 0 .../res/layout/custom_transaction_row.xml | 110 ++++++++++++++++++ app/src/main/res/values/colors.xml | 2 + 14 files changed, 290 insertions(+), 12 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java create mode 100644 app/src/main/res/drawable/ic_delete_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_edit_white_24dp.xml rename app/src/main/res/layout/{custom_row.xml => custom_currency_row.xml} (100%) create mode 100644 app/src/main/res/layout/custom_transaction_row.xml diff --git a/.idea/modules.xml b/.idea/modules.xml index fa9ddad..089a0e4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index f7567b8..5c71d36 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { - applicationId "com.nauk.coinfolio" + applicationId "com.nauk.coinfoliobeta" minSdkVersion 21 targetSdkVersion 26 versionCode 1 @@ -31,6 +31,8 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:palette-v7:26.1.0' + implementation 'com.android.support:recyclerview-v7:26.1.0' + implementation 'com.daimajia.swipelayout:library:1.2.0@aar' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java index d3bfe89..bbd97ae 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -6,12 +6,17 @@ import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.TextView; import android.widget.ViewFlipper; +import com.daimajia.swipe.SwipeLayout; +import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.R; @@ -19,6 +24,7 @@ import org.w3c.dom.Text; import java.util.HashMap; import java.util.Iterator; +import java.util.List; public class CurrencyDetailsActivity extends AppCompatActivity { @@ -59,7 +65,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); viewFlipper = findViewById(R.id.vfCurrencyDetails); - transactionLayout = findViewById(R.id.transactionsLinearLayout); + transactionLayout = findViewById(R.id.listTransactions); drawTransactionList(); @@ -71,9 +77,78 @@ public class CurrencyDetailsActivity extends AppCompatActivity { { transactionLayout.removeAllViews(); - HashMap transactionList = databaseManager.getCurrencyTransactions(symbol); + List transactionList = databaseManager.getCurrencyTransactions(symbol); - Iterator transactionsIterator = transactionList.keySet().iterator(); + for(int i = 0; i < transactionList.size(); i++) + { + Log.d("coinfoliobeta", "test"); + View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null); + TextView amountTxtView = view.findViewById(R.id.amountPurchased); + TextView valueTxtView = view.findViewById(R.id.puchasedValue); + TextView dateTxtView = view.findViewById(R.id.purchaseDate); + + LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout); + deleteLayout.setTag(transactionList.get(i).getTransactionId()); + + deleteLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); + Log.d(CurrencyDetailsActivity.this.getResources().getString(R.string.debug), "Id : " + view.getTag()); + drawTransactionList(); + } + }); + + amountTxtView.setText(transactionList.get(i).getAmount() + ""); + + SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); + + //set show mode. + swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); + + //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) + swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); + + swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onClose(SwipeLayout layout) { + //when the SurfaceView totally cover the BottomView. + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + //you are swiping. + } + + @Override + public void onStartOpen(SwipeLayout layout) { + + } + + @Override + public void onOpen(SwipeLayout layout) { + //when the BottomView totally show. + } + + @Override + public void onStartClose(SwipeLayout layout) { + + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + //when user's hand released. + } + }); + + transactionLayout.addView(view); + } + + //final ArrayAdapter> transactionAdapter = new ArrayAdapter>(CurrencyDetailsActivity.this, android.R.layout.simple_list_item_1, transactionList); + + /*Iterator transactionsIterator = transactionList.keySet().iterator(); + + transactionList.se while(transactionsIterator.hasNext()) { @@ -95,7 +170,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); transactionLayout.addView(txtView); - } + }*/ } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index 4244b4a..8a440c3 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -25,6 +25,7 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import com.daimajia.swipe.SwipeLayout; import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.DatabaseManager; diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java new file mode 100644 index 0000000..ac05f62 --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java @@ -0,0 +1,45 @@ +package com.nauk.coinfolio.DataManagers.CurrencyData; + +/** + * Created by Guitoune on 30/01/2018. + */ + +public class Transaction { + + private int transactionId; + private String symbol; + private double amount; + private double purchasedPrice; + private boolean isMined; + + public Transaction(int transactionId, String symbol, double amount) + { + this.transactionId = transactionId; + this.symbol = symbol; + this.amount = amount; + } + + public int getTransactionId() { + return transactionId; + } + + public void setTransactionId(int transactionId) { + this.transactionId = transactionId; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } +} diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 077a1ae..3bd4ad4 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; +import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import java.util.ArrayList; import java.util.HashMap; @@ -110,17 +111,20 @@ public class DatabaseManager extends SQLiteOpenHelper{ return currencyList; } - public HashMap getCurrencyTransactions(String symbol) + //public HashMap getCurrencyTransactions(String symbol) + public List getCurrencyTransactions(String symbol) { String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor resultatList = db.rawQuery(searchQuerry, null); - HashMap transactionList = new HashMap<>(); + //HashMap transactionList = new HashMap<>(); + List transactionList = new ArrayList<>(); while(resultatList.moveToNext()) { - transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); + //transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); + transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3))); } resultatList.close(); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java index 3cfcd35..ea29d3f 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java @@ -35,7 +35,7 @@ public class CurrencyAdapter extends ArrayAdapter { public View getView(int position, View convertView, ViewGroup parent) { Currency currency = getItem(position); if (convertView == null) { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_row, parent, false); + convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_currency_row, parent, false); } TextView currencyName = (TextView) convertView.findViewById(R.id.currencyName); TextView currencySymbol = (TextView) convertView.findViewById(R.id.currencySymbol); diff --git a/app/src/main/res/drawable/ic_delete_white_24dp.xml b/app/src/main/res/drawable/ic_delete_white_24dp.xml new file mode 100644 index 0000000..f9213d2 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_edit_white_24dp.xml b/app/src/main/res/drawable/ic_edit_white_24dp.xml new file mode 100644 index 0000000..35a774a --- /dev/null +++ b/app/src/main/res/drawable/ic_edit_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index fad4b5f..fc53091 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -37,7 +37,22 @@ - + + + + + + + + diff --git a/app/src/main/res/layout/custom_row.xml b/app/src/main/res/layout/custom_currency_row.xml similarity index 100% rename from app/src/main/res/layout/custom_row.xml rename to app/src/main/res/layout/custom_currency_row.xml diff --git a/app/src/main/res/layout/custom_transaction_row.xml b/app/src/main/res/layout/custom_transaction_row.xml new file mode 100644 index 0000000..a5f5319 --- /dev/null +++ b/app/src/main/res/layout/custom_transaction_row.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 991f12c..bbc7b0e 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -11,4 +11,6 @@ #FFEEEEEE #FFFFFFFF #FF999999 + #FFF44336 + #FF4CAF50