[DetailsActivity] Enable binance trade update
- Add support for multiple binance accounts
This commit is contained in:
parent
b25e44d3ef
commit
d79a76f13b
@ -28,6 +28,7 @@ import com.herbron.moodl.CustomAdapters.TransactionListAdapter;
|
|||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tiji on 13/05/2018.
|
* Created by Tiji on 13/05/2018.
|
||||||
@ -41,7 +42,7 @@ public class Transactions extends Fragment {
|
|||||||
private ListView tradeLayout;
|
private ListView tradeLayout;
|
||||||
private ListView transactionLayout;
|
private ListView transactionLayout;
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private BinanceManager binanceManager;
|
private List<BinanceManager> binanceManagerList;
|
||||||
private DatabaseManager databaseManager;
|
private DatabaseManager databaseManager;
|
||||||
private TradeListAdapter tradeListAdapter;
|
private TradeListAdapter tradeListAdapter;
|
||||||
private ArrayList<com.herbron.moodl.DataManagers.CurrencyData.Trade> returnedTrades;
|
private ArrayList<com.herbron.moodl.DataManagers.CurrencyData.Trade> returnedTrades;
|
||||||
@ -55,7 +56,7 @@ public class Transactions extends Fragment {
|
|||||||
|
|
||||||
currency = getActivity().getIntent().getParcelableExtra("currency");
|
currency = getActivity().getIntent().getParcelableExtra("currency");
|
||||||
databaseManager = new DatabaseManager(getActivity().getBaseContext());
|
databaseManager = new DatabaseManager(getActivity().getBaseContext());
|
||||||
//binanceManager = new BinanceManager(preferencesManager.getBinancePublicKey(), preferencesManager.getBinancePrivateKey());
|
binanceManagerList = databaseManager.getBinanceAccounts();
|
||||||
tradeLayout = view.findViewById(R.id.listTrades);
|
tradeLayout = view.findViewById(R.id.listTrades);
|
||||||
transactionLayout = view.findViewById(R.id.listTransactions);
|
transactionLayout = view.findViewById(R.id.listTransactions);
|
||||||
|
|
||||||
@ -64,8 +65,8 @@ public class Transactions extends Fragment {
|
|||||||
TransactionUpdater transactionUpdater = new TransactionUpdater();
|
TransactionUpdater transactionUpdater = new TransactionUpdater();
|
||||||
transactionUpdater.execute();
|
transactionUpdater.execute();
|
||||||
|
|
||||||
/*TradeUpdater updater = new TradeUpdater();
|
TradeUpdater updater = new TradeUpdater();
|
||||||
updater.execute();*/
|
updater.execute();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -212,10 +213,16 @@ public class Transactions extends Fragment {
|
|||||||
|
|
||||||
private class TradeUpdater extends AsyncTask<Void, Integer, Void> implements BinanceUpdateNotifierInterface
|
private class TradeUpdater extends AsyncTask<Void, Integer, Void> implements BinanceUpdateNotifierInterface
|
||||||
{
|
{
|
||||||
|
private List<Trade> trades;
|
||||||
|
private int nbResponse;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute()
|
protected void onPreExecute()
|
||||||
{
|
{
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
|
|
||||||
|
trades = new ArrayList<>();
|
||||||
|
nbResponse = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -228,7 +235,11 @@ public class Transactions extends Fragment {
|
|||||||
protected Void doInBackground(Void... params)
|
protected Void doInBackground(Void... params)
|
||||||
{
|
{
|
||||||
|
|
||||||
binanceManager.updateTrades(currency.getSymbol());
|
for(int i = 0; i < binanceManagerList.size(); i++)
|
||||||
|
{
|
||||||
|
binanceManagerList.get(i).addListener(this);
|
||||||
|
binanceManagerList.get(i).updateTrades(currency.getSymbol());
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -240,8 +251,13 @@ public class Transactions extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBinanceTradesUpdated() {
|
public void onBinanceTradesUpdated(List<Trade> newTrades) {
|
||||||
ArrayList<Trade> trades = binanceManager.getTrades();
|
trades.addAll(newTrades);
|
||||||
|
|
||||||
|
nbResponse++;
|
||||||
|
|
||||||
|
if(nbResponse == binanceManagerList.size())
|
||||||
|
{
|
||||||
returnedTrades = new ArrayList<>();
|
returnedTrades = new ArrayList<>();
|
||||||
|
|
||||||
for(int i = trades.size() - 1; i >= 0 ; i--)
|
for(int i = trades.size() - 1; i >= 0 ; i--)
|
||||||
@ -267,6 +283,7 @@ public class Transactions extends Fragment {
|
|||||||
Log.d("moodl", "Transactions do not need to be updated anymore");
|
Log.d("moodl", "Transactions do not need to be updated anymore");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBinanceBalanceUpdateSuccess() {
|
public void onBinanceBalanceUpdateSuccess() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.herbron.moodl.DataManagers;
|
package com.herbron.moodl.DataManagers;
|
||||||
|
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.Activities.HomeActivity;
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Trade;
|
||||||
import com.herbron.moodl.DataNotifiers.BinanceUpdateNotifierInterface;
|
import com.herbron.moodl.DataNotifiers.BinanceUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
@ -87,7 +88,7 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd
|
|||||||
|
|
||||||
for(int i = 0; i < binanceManagers.size(); i++)
|
for(int i = 0; i < binanceManagers.size(); i++)
|
||||||
{
|
{
|
||||||
final BinanceManager binanceManager = binanceManagers.get(i);
|
BinanceManager binanceManager = binanceManagers.get(i);
|
||||||
binanceManager.addListener(this);
|
binanceManager.addListener(this);
|
||||||
binanceManager.updateBalance();
|
binanceManager.updateBalance();
|
||||||
}
|
}
|
||||||
@ -169,7 +170,7 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBinanceTradesUpdated() {
|
public void onBinanceTradesUpdated(List<Trade> trades) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public class BinanceManager extends Exchange {
|
|||||||
|
|
||||||
for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList)
|
for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList)
|
||||||
{
|
{
|
||||||
binanceUpdateNotifierInterface.onBinanceTradesUpdated();
|
binanceUpdateNotifierInterface.onBinanceTradesUpdated(trades);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package com.herbron.moodl.DataNotifiers;
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Trade;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface BinanceUpdateNotifierInterface {
|
public interface BinanceUpdateNotifierInterface {
|
||||||
|
|
||||||
void onBinanceTradesUpdated();
|
void onBinanceTradesUpdated(List<Trade> trades);
|
||||||
|
|
||||||
void onBinanceBalanceUpdateSuccess();
|
void onBinanceBalanceUpdateSuccess();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user