ListView for Transaction history
This commit is contained in:
parent
ec73925720
commit
ee8ba428d7
@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.NavUtils;
|
||||
@ -25,6 +26,7 @@ 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;
|
||||
@ -58,6 +60,7 @@ import com.nauk.moodl.DataManagers.DatabaseManager;
|
||||
import com.nauk.moodl.DataManagers.ExchangeManager.BinanceManager;
|
||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||
import com.nauk.moodl.LayoutManagers.TradeListAdapter;
|
||||
import com.nauk.moodl.LayoutManagers.TransactionListAdapter;
|
||||
import com.nauk.moodl.PlaceholderManager;
|
||||
import com.nauk.moodl.R;
|
||||
|
||||
@ -76,7 +79,7 @@ import static java.lang.Math.abs;
|
||||
public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
private ViewFlipper viewFlipper;
|
||||
private LinearLayout transactionLayout;
|
||||
private ListView transactionLayout;
|
||||
private ListView tradeLayout;
|
||||
private DatabaseManager databaseManager;
|
||||
//private String symbol;
|
||||
@ -94,6 +97,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
private PreferencesManager preferencesManager;
|
||||
private BinanceManager binanceManager;
|
||||
private TradeListAdapter tradeListAdapter;
|
||||
private TransactionListAdapter transactionListAdapter;
|
||||
private boolean flag_loading;
|
||||
|
||||
private boolean isSnapshotUpdated;
|
||||
@ -205,12 +209,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
setupActionBar();
|
||||
|
||||
drawTransactionList();
|
||||
|
||||
initializeButtons();
|
||||
initializeLineChart(lineChart);
|
||||
initializeCandleStickChart(candleStickChart);
|
||||
|
||||
TransactionUpdater transactionUpdater = new TransactionUpdater();
|
||||
transactionUpdater.execute();
|
||||
|
||||
updateInfoTab();
|
||||
|
||||
updateChartTab(DAY, 1);
|
||||
@ -898,6 +903,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
return transColor;
|
||||
}
|
||||
|
||||
private void drawTransactionList(ArrayList<Transaction> transactions)
|
||||
{
|
||||
transactionListAdapter = new TransactionListAdapter(this, transactions);
|
||||
|
||||
transactionLayout.setAdapter(transactionListAdapter);
|
||||
transactionLayout.setTextFilterEnabled(false);
|
||||
}
|
||||
|
||||
private void drawTradeList(ArrayList<com.nauk.moodl.DataManagers.CurrencyData.Trade> trades)
|
||||
{
|
||||
findViewById(R.id.tradeProgressBar).setVisibility(View.GONE);
|
||||
@ -930,43 +943,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
tradeLayout.setTextFilterEnabled(false);
|
||||
}
|
||||
|
||||
private void drawTransactionList()
|
||||
{
|
||||
transactionLayout.removeAllViews();
|
||||
|
||||
List<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
|
||||
|
||||
for(int i = 0; i < transactionList.size(); i++)
|
||||
{
|
||||
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);
|
||||
|
||||
dateTxtView.setText(getDate(transactionList.get(i).getTimestamp()));
|
||||
|
||||
LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout);
|
||||
deleteLayout.setTag(transactionList.get(i).getTransactionId());
|
||||
|
||||
deleteLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
preferencesManager.setMustUpdateSummary(true);
|
||||
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
|
||||
drawTransactionList();
|
||||
hasBeenModified = true;
|
||||
}
|
||||
});
|
||||
|
||||
amountTxtView.setText(String.valueOf(transactionList.get(i).getAmount()));
|
||||
valueTxtView.setText(numberConformer(transactionList.get(i).getPurchasedPrice() * transactionList.get(i).getAmount()));
|
||||
|
||||
setupSwipeView(view);
|
||||
|
||||
transactionLayout.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private static void expand(final View v) {
|
||||
v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT);
|
||||
final int targetHeight = v.getMeasuredHeight();
|
||||
@ -995,47 +971,23 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
v.startAnimation(a);
|
||||
}
|
||||
|
||||
private void setupSwipeView(View view)
|
||||
|
||||
|
||||
public class TransactionUpdater extends AsyncTask<Void, Integer, Void>
|
||||
{
|
||||
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.
|
||||
protected Void doInBackground(Void... voids) {
|
||||
|
||||
if(Looper.myLooper() == null)
|
||||
{
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
|
||||
//you are swiping.
|
||||
ArrayList<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
|
||||
drawTransactionList(transactionList);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@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.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class TradeAdder extends AsyncTask<Void, Integer, Void>
|
||||
|
@ -159,13 +159,13 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
||||
return currencyList;
|
||||
}
|
||||
|
||||
public List<Transaction> getCurrencyTransactions(String symbol)
|
||||
public ArrayList<Transaction> getCurrencyTransactions(String symbol)
|
||||
{
|
||||
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'";
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor resultatList = db.rawQuery(searchQuerry, null);
|
||||
|
||||
List<Transaction> transactionList = new ArrayList<>();
|
||||
ArrayList<Transaction> transactionList = new ArrayList<>();
|
||||
|
||||
while(resultatList.moveToNext())
|
||||
{
|
||||
|
@ -0,0 +1,196 @@
|
||||
package com.nauk.moodl.LayoutManagers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.nauk.moodl.Activities.CurrencyDetailsActivity;
|
||||
import com.nauk.moodl.DataManagers.CurrencyData.Transaction;
|
||||
import com.nauk.moodl.DataManagers.DatabaseManager;
|
||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||
import com.nauk.moodl.R;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
/**
|
||||
* Created by Guitoune on 24/04/2018.
|
||||
*/
|
||||
|
||||
public class TransactionListAdapter extends ArrayAdapter<Transaction> {
|
||||
|
||||
private Context context;
|
||||
|
||||
public TransactionListAdapter(Context context, ArrayList<Transaction> transactions)
|
||||
{
|
||||
super(context, android.R.layout.simple_list_item_1, transactions);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
Transaction transaction = getItem(position);
|
||||
|
||||
if(convertView == null)
|
||||
{
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_transaction_row, parent, false);
|
||||
}
|
||||
|
||||
TextView amountTxtView = convertView.findViewById(R.id.amountPurchased);
|
||||
TextView valueTxtView = convertView.findViewById(R.id.puchasedValue);
|
||||
TextView dateTxtView = convertView.findViewById(R.id.purchaseDate);
|
||||
|
||||
amountTxtView.setText(String.valueOf(transaction.getAmount()));
|
||||
valueTxtView.setText(numberConformer(transaction.getPurchasedPrice() * transaction.getAmount()));
|
||||
dateTxtView.setText(getDate(transaction.getTimestamp()));
|
||||
|
||||
LinearLayout deleteLayout = convertView.findViewById(R.id.deleteTransactionLayout);
|
||||
deleteLayout.setTag(transaction.getTransactionId());
|
||||
|
||||
deleteLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
DatabaseManager databaseManager = new DatabaseManager(context);
|
||||
preferencesManager.setMustUpdateSummary(true);
|
||||
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
|
||||
collapse((View) view.getParent().getParent().getParent().getParent());
|
||||
}
|
||||
});
|
||||
|
||||
setupSwipeView(convertView);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static void collapse(final View v) {
|
||||
final int initialHeight = v.getMeasuredHeight();
|
||||
|
||||
Animation a = new Animation()
|
||||
{
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
if(interpolatedTime == 1){
|
||||
v.setVisibility(View.GONE);
|
||||
}else{
|
||||
v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
|
||||
v.requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willChangeBounds() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// 1dp/ms
|
||||
a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
|
||||
v.startAnimation(a);
|
||||
}
|
||||
|
||||
private void setupSwipeView(View view)
|
||||
{
|
||||
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.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private String getDate(long timeStamp){
|
||||
|
||||
try{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault());
|
||||
Date netDate = (new Date(timeStamp));
|
||||
return sdf.format(netDate);
|
||||
}
|
||||
catch(Exception ex){
|
||||
return "xx";
|
||||
}
|
||||
}
|
||||
|
||||
private String numberConformer(double number)
|
||||
{
|
||||
String str;
|
||||
|
||||
if(abs(number) > 1)
|
||||
{
|
||||
str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
|
||||
}
|
||||
|
||||
if(!str.equals("Infinity"))
|
||||
{
|
||||
int counter = 0;
|
||||
int i = str.indexOf(".");
|
||||
if(i <= 0)
|
||||
{
|
||||
i = str.length();
|
||||
}
|
||||
for(i -= 1; i > 0; i--)
|
||||
{
|
||||
counter++;
|
||||
if(counter == 3)
|
||||
{
|
||||
str = str.substring(0, i) + " " + str.substring(i, str.length());
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
@ -600,18 +600,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:elevation="@dimen/cardview_elevation"/>
|
||||
|
||||
<ScrollView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5">
|
||||
|
||||
<LinearLayout
|
||||
<ListView
|
||||
android:id="@+id/listTransactions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:text="Trade history"
|
||||
|
@ -4,11 +4,6 @@
|
||||
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"
|
||||
@ -105,6 +100,4 @@
|
||||
<!-- Surface View End -->
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user