Add swipte to delete in transaction history

SwipeLayout for transaction history per currency
FIX update balance when no coin
This commit is contained in:
Tanguy Herbron 2018-01-30 16:16:06 +01:00
parent 97c625efa7
commit 0faeb6c3d8
14 changed files with 290 additions and 12 deletions

2
.idea/modules.xml generated
View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/CrystalVault.iml" filepath="$PROJECT_DIR$/CrystalVault.iml" /> <module fileurl="file://$PROJECT_DIR$/Coinfolio.iml" filepath="$PROJECT_DIR$/Coinfolio.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules> </modules>
</component> </component>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 26 compileSdkVersion 26
defaultConfig { defaultConfig {
applicationId "com.nauk.coinfolio" applicationId "com.nauk.coinfoliobeta"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 26 targetSdkVersion 26
versionCode 1 versionCode 1
@ -31,6 +31,8 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:palette-v7: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' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

View File

@ -6,12 +6,17 @@ import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ViewFlipper; 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.DataManagers.DatabaseManager;
import com.nauk.coinfolio.R; import com.nauk.coinfolio.R;
@ -19,6 +24,7 @@ import org.w3c.dom.Text;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class CurrencyDetailsActivity extends AppCompatActivity { public class CurrencyDetailsActivity extends AppCompatActivity {
@ -59,7 +65,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
databaseManager = new DatabaseManager(this); databaseManager = new DatabaseManager(this);
viewFlipper = findViewById(R.id.vfCurrencyDetails); viewFlipper = findViewById(R.id.vfCurrencyDetails);
transactionLayout = findViewById(R.id.transactionsLinearLayout); transactionLayout = findViewById(R.id.listTransactions);
drawTransactionList(); drawTransactionList();
@ -71,9 +77,78 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
{ {
transactionLayout.removeAllViews(); transactionLayout.removeAllViews();
HashMap<Integer, Double> transactionList = databaseManager.getCurrencyTransactions(symbol); List<Transaction> 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<HashMap<Integer, Double>> transactionAdapter = new ArrayAdapter<HashMap<Integer, Double>>(CurrencyDetailsActivity.this, android.R.layout.simple_list_item_1, transactionList);
/*Iterator transactionsIterator = transactionList.keySet().iterator();
transactionList.se
while(transactionsIterator.hasNext()) while(transactionsIterator.hasNext())
{ {
@ -95,7 +170,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
}); });
transactionLayout.addView(txtView); transactionLayout.addView(txtView);
} }*/
} }

View File

@ -25,6 +25,7 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.daimajia.swipe.SwipeLayout;
import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.DataManagers.DatabaseManager;

View File

@ -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;
}
}

View File

@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log; import android.util.Log;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -110,17 +111,20 @@ public class DatabaseManager extends SQLiteOpenHelper{
return currencyList; return currencyList;
} }
public HashMap<Integer, Double> getCurrencyTransactions(String symbol) //public HashMap<Integer, Double> getCurrencyTransactions(String symbol)
public List<Transaction> getCurrencyTransactions(String symbol)
{ {
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'";
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
Cursor resultatList = db.rawQuery(searchQuerry, null); Cursor resultatList = db.rawQuery(searchQuerry, null);
HashMap<Integer, Double> transactionList = new HashMap<>(); //HashMap<Integer, Double> transactionList = new HashMap<>();
List<Transaction> transactionList = new ArrayList<>();
while(resultatList.moveToNext()) 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(); resultatList.close();

View File

@ -35,7 +35,7 @@ public class CurrencyAdapter extends ArrayAdapter<Currency> {
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
Currency currency = getItem(position); Currency currency = getItem(position);
if (convertView == null) { 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 currencyName = (TextView) convertView.findViewById(R.id.currencyName);
TextView currencySymbol = (TextView) convertView.findViewById(R.id.currencySymbol); TextView currencySymbol = (TextView) convertView.findViewById(R.id.currencySymbol);

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="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

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="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@ -37,7 +37,22 @@
</ScrollView> </ScrollView>
<ScrollView <RelativeLayout
android:id="@+id/rlTransactions"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/listTransactions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
<!--<ScrollView
android:id="@+id/svTransactions" android:id="@+id/svTransactions"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -50,7 +65,7 @@
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>-->
</ViewFlipper> </ViewFlipper>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_corners">
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/swipeLayout">
<!-- Bottom View Start-->
<LinearLayout
android:id="@+id/bottom_wrapper"
android:layout_width="100dp"
android:weightSum="1"
android:layout_height="match_parent"
android:orientation="horizontal">
<!--What you want to show-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@color/green">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_edit_white_24dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/deleteTransactionLayout"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@color/red">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_delete_white_24dp"/>
</LinearLayout>
</LinearLayout>
<!-- Bottom View End-->
<!-- Surface View Start -->
<LinearLayout
android:padding="5dp"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--What you want to show in SurfaceView-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:id="@+id/amountPurchased"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="Amount"/>
<TextView
android:id="@+id/puchasedValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="Value"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:id="@+id/purchaseDate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Date"
android:gravity="right"/>
</LinearLayout>
</LinearLayout>
<!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View File

@ -11,4 +11,6 @@
<color name="listBackground">#FFEEEEEE</color> <color name="listBackground">#FFEEEEEE</color>
<color name="listBackground2">#FFFFFFFF</color> <color name="listBackground2">#FFFFFFFF</color>
<color name="separationLine">#FF999999</color> <color name="separationLine">#FF999999</color>
<color name="red">#FFF44336</color>
<color name="green">#FF4CAF50</color>
</resources> </resources>