Update code with new interfaces for a clearer code (I hope so...)
- Preview of the RecordTransactionActivity buying UI - MarketCapManager.java and CoinmarketCapAPIManager are now merged
This commit is contained in:
parent
10888c4c54
commit
92f08e00ed
@ -16,9 +16,9 @@ import android.widget.ListView;
|
|||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.LayoutManagers.CoinWatchlistAdapter;
|
import com.herbron.moodl.LayoutManagers.CoinWatchlistAdapter;
|
||||||
@ -27,12 +27,12 @@ import com.herbron.moodl.R;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CurrencySelectionActivity extends AppCompatActivity implements SearchView.OnQueryTextListener{
|
public class CurrencySelectionActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, CryptocompareNotifierInterface {
|
||||||
|
|
||||||
private CoinWatchlistAdapter adapter;
|
private CoinWatchlistAdapter adapter;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private android.widget.Filter filter;
|
private android.widget.Filter filter;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
private boolean isWatchList;
|
private boolean isWatchList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +44,8 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
|
|||||||
|
|
||||||
setContentView(R.layout.activity_add_currency);
|
setContentView(R.layout.activity_add_currency);
|
||||||
|
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(this);
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(this);
|
||||||
|
cryptocompareApiManager.addListener(this);
|
||||||
|
|
||||||
setTitle(getString(R.string.select_coin));
|
setTitle(getString(R.string.select_coin));
|
||||||
|
|
||||||
@ -67,8 +68,8 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
|
|||||||
|
|
||||||
private void setupAdapter()
|
private void setupAdapter()
|
||||||
{
|
{
|
||||||
List<String> currencyNames = currencyDetailsList.getCurrenciesName();
|
List<String> currencyNames = cryptocompareApiManager.getCurrenciesName();
|
||||||
List<String> currencySymbols = currencyDetailsList.getCurrenciesSymbol();
|
List<String> currencySymbols = cryptocompareApiManager.getCurrenciesSymbol();
|
||||||
|
|
||||||
ArrayList<Currency> currencyArrayList = new ArrayList<>();
|
ArrayList<Currency> currencyArrayList = new ArrayList<>();
|
||||||
|
|
||||||
@ -178,6 +179,16 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetailsUpdated() {
|
||||||
|
detailsEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExchangesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class ListLoader extends AsyncTask<Void, Integer, Void>
|
private class ListLoader extends AsyncTask<Void, Integer, Void>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -200,14 +211,9 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
|
|||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!currencyDetailsList.isUpToDate())
|
if(!cryptocompareApiManager.isDetailsUpToDate())
|
||||||
{
|
{
|
||||||
currencyDetailsList.update(new BalanceManager.IconCallBack() {
|
cryptocompareApiManager.updateDetails();
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
detailsEvent();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,7 @@ import com.github.mikephil.charting.data.LineData;
|
|||||||
import com.github.mikephil.charting.data.LineDataSet;
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
import com.github.mikephil.charting.highlight.Highlight;
|
import com.github.mikephil.charting.highlight.Highlight;
|
||||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDataChart;
|
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDataChart;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
@ -51,7 +52,7 @@ import static com.herbron.moodl.MoodlBox.numberConformer;
|
|||||||
* Created by Tiji on 13/05/2018.
|
* Created by Tiji on 13/05/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Charts extends Fragment {
|
public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterface {
|
||||||
|
|
||||||
private final static int HOUR = 0;
|
private final static int HOUR = 0;
|
||||||
private final static int DAY = 1;
|
private final static int DAY = 1;
|
||||||
@ -72,6 +73,8 @@ public class Charts extends Fragment {
|
|||||||
private Button lineChartButton;
|
private Button lineChartButton;
|
||||||
private Button candleStickChartButton;
|
private Button candleStickChartButton;
|
||||||
|
|
||||||
|
private Spinner timeIntervalSpinner;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||||
@ -80,6 +83,8 @@ public class Charts extends Fragment {
|
|||||||
|
|
||||||
currency = getActivity().getIntent().getParcelableExtra("currency");
|
currency = getActivity().getIntent().getParcelableExtra("currency");
|
||||||
|
|
||||||
|
currency.setListener(this);
|
||||||
|
|
||||||
lineChart = view.findViewById(R.id.chartPriceView);
|
lineChart = view.findViewById(R.id.chartPriceView);
|
||||||
candleStickChart = view.findViewById(R.id.chartCandleStickView);
|
candleStickChart = view.findViewById(R.id.chartCandleStickView);
|
||||||
lineChartButton = view.findViewById(R.id.lineChartButton);
|
lineChartButton = view.findViewById(R.id.lineChartButton);
|
||||||
@ -125,17 +130,17 @@ public class Charts extends Fragment {
|
|||||||
|
|
||||||
private void initializeSpinners()
|
private void initializeSpinners()
|
||||||
{
|
{
|
||||||
Spinner spinner = view.findViewById(R.id.timeIntervalSinner);
|
timeIntervalSpinner = view.findViewById(R.id.timeIntervalSinner);
|
||||||
|
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
|
||||||
R.array.time_interval_string_array, android.R.layout.simple_spinner_item);
|
R.array.time_interval_string_array, android.R.layout.simple_spinner_item);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
|
||||||
spinner.setAdapter(adapter);
|
timeIntervalSpinner.setAdapter(adapter);
|
||||||
|
|
||||||
spinner.setSelection(2);
|
timeIntervalSpinner.setSelection(2);
|
||||||
|
|
||||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
timeIntervalSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
updateCharts(i);
|
updateCharts(i);
|
||||||
@ -158,121 +163,31 @@ public class Charts extends Fragment {
|
|||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.HOUR, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.HOUR, 3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.DAY, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.DAY, 3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.WEEK, 11);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.MONTH, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.MONTH, 3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.MONTH, 6);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateChartTab(Charts.YEAR, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -684,4 +599,52 @@ public class Charts extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimestampPriveUpdated(String price) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHistoryDataUpdated() {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
switch (timeIntervalSpinner.getSelectedItemPosition())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
updateChartTab(Charts.HOUR, 1);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
updateChartTab(Charts.HOUR, 3);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
updateChartTab(Charts.DAY, 1);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
updateChartTab(Charts.DAY, 3);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
updateChartTab(Charts.WEEK, 11);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
updateChartTab(Charts.MONTH, 1);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
updateChartTab(Charts.MONTH, 3);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
updateChartTab(Charts.MONTH, 6);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
updateChartTab(Charts.YEAR, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPriceUpdated(Currency currency) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
|
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.CurrencyData.Trade;
|
import com.herbron.moodl.DataManagers.CurrencyData.Trade;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Transaction;
|
import com.herbron.moodl.DataManagers.CurrencyData.Transaction;
|
||||||
@ -209,7 +210,7 @@ public class Transactions extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TradeUpdater extends AsyncTask<Void, Integer, Void>
|
private class TradeUpdater extends AsyncTask<Void, Integer, Void> implements BinanceUpdateNotifierInterface
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute()
|
protected void onPreExecute()
|
||||||
@ -226,41 +227,8 @@ public class Transactions extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params)
|
protected Void doInBackground(Void... params)
|
||||||
{
|
{
|
||||||
binanceManager.updateTrades(new BinanceManager.BinanceCallBack() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
ArrayList<Trade> trades = binanceManager.getTrades();
|
|
||||||
returnedTrades = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i = trades.size() - 1; i >= 0 ; i--)
|
binanceManager.updateTrades(currency.getSymbol());
|
||||||
{
|
|
||||||
returnedTrades.add(trades.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ArrayList<Trade> trades = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i = 0; i < 20 && i < returnedTrades.size(); i++)
|
|
||||||
{
|
|
||||||
trades.add(returnedTrades.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
drawTradeList(trades);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
Log.d("moodl", "Transactions do not need to be updated anymore");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}, currency.getSymbol());
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -270,5 +238,44 @@ public class Transactions extends Fragment {
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBinanceTradesUpdated() {
|
||||||
|
ArrayList<Trade> trades = binanceManager.getTrades();
|
||||||
|
returnedTrades = new ArrayList<>();
|
||||||
|
|
||||||
|
for(int i = trades.size() - 1; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
returnedTrades.add(trades.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ArrayList<Trade> trades = new ArrayList<>();
|
||||||
|
|
||||||
|
for(int i = 0; i < 20 && i < returnedTrades.size(); i++)
|
||||||
|
{
|
||||||
|
trades.add(returnedTrades.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
drawTradeList(trades);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.d("moodl", "Transactions do not need to be updated anymore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBinanceBalanceUpdateSuccess() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBinanceBalanceUpdateError(int accountId, String error) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,9 +216,4 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
|
|||||||
drawerBalanceTextView.setText(PlaceholderManager.getValueString(numberConformer(value), getApplicationContext()));
|
drawerBalanceTextView.setText(PlaceholderManager.getValueString(numberConformer(value), getApplicationContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IconCallBack
|
|
||||||
{
|
|
||||||
void onSuccess(Bitmap bitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -27,19 +27,19 @@ import com.github.mikephil.charting.data.PieEntry;
|
|||||||
import com.github.mikephil.charting.formatter.PercentFormatter;
|
import com.github.mikephil.charting.formatter.PercentFormatter;
|
||||||
import com.github.mikephil.charting.highlight.Highlight;
|
import com.github.mikephil.charting.highlight.Highlight;
|
||||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
|
||||||
import com.herbron.moodl.DataManagers.MarketCapManager;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.LayoutManagers.CustomPieChart;
|
import com.herbron.moodl.LayoutManagers.CustomPieChart;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.PlaceholderManager;
|
import com.herbron.moodl.PlaceholderManager;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.herbron.moodl.MoodlBox.getColor;
|
import static com.herbron.moodl.MoodlBox.getColor;
|
||||||
@ -49,15 +49,14 @@ import static java.lang.Math.abs;
|
|||||||
* Created by Tiji on 13/04/2018.
|
* Created by Tiji on 13/04/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MarketCapitalization extends Fragment {
|
public class MarketCapitalization extends Fragment implements CryptocompareNotifierInterface, CoinmarketcapNotifierInterface {
|
||||||
|
|
||||||
private PreferencesManager preferencesManager;
|
private PreferencesManager preferencesManager;
|
||||||
private MarketCapManager marketCapManager;
|
private CoinmarketCapAPIManager coinmarketCapAPIManager;
|
||||||
private HashMap<String, Integer> dominantCurrenciesColors;
|
|
||||||
private SwipeRefreshLayout refreshLayout;
|
private SwipeRefreshLayout refreshLayout;
|
||||||
private long lastTimestamp;
|
private long lastTimestamp;
|
||||||
private String defaultCurrency;
|
private String defaultCurrency;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
private boolean isDetailsUpdated;
|
private boolean isDetailsUpdated;
|
||||||
private boolean isTopCurrenciesUpdated;
|
private boolean isTopCurrenciesUpdated;
|
||||||
private boolean isMarketpCapUpdated;
|
private boolean isMarketpCapUpdated;
|
||||||
@ -71,19 +70,15 @@ public class MarketCapitalization extends Fragment {
|
|||||||
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
||||||
|
|
||||||
preferencesManager = new PreferencesManager(getContext());
|
preferencesManager = new PreferencesManager(getContext());
|
||||||
marketCapManager = new MarketCapManager(getContext());
|
coinmarketCapAPIManager = CoinmarketCapAPIManager.getInstance(getContext());
|
||||||
|
coinmarketCapAPIManager.addListener(this);
|
||||||
|
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(getContext());
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
|
||||||
|
cryptocompareApiManager.addListener(this);
|
||||||
|
|
||||||
if(!currencyDetailsList.isUpToDate())
|
if(!cryptocompareApiManager.isDetailsUpToDate())
|
||||||
{
|
{
|
||||||
currencyDetailsList.update(new BalanceManager.IconCallBack() {
|
cryptocompareApiManager.updateDetails();
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
isDetailsUpdated = true;
|
|
||||||
countCompletedMarketCapRequest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -152,7 +147,6 @@ public class MarketCapitalization extends Fragment {
|
|||||||
{
|
{
|
||||||
updateMarketCap(false);
|
updateMarketCap(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMarketCap(boolean mustUpdate)
|
private void updateMarketCap(boolean mustUpdate)
|
||||||
@ -171,22 +165,9 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
lastTimestamp = System.currentTimeMillis() / 1000;
|
lastTimestamp = System.currentTimeMillis() / 1000;
|
||||||
|
|
||||||
marketCapManager.updateTopCurrencies(new MarketCapManager.VolleyCallBack() {
|
coinmarketCapAPIManager.updateTopCurrencies(preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess()
|
|
||||||
{
|
|
||||||
isTopCurrenciesUpdated = true;
|
|
||||||
countCompletedMarketCapRequest();
|
|
||||||
}
|
|
||||||
}, preferencesManager.getDefaultCurrency());
|
|
||||||
|
|
||||||
marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() {
|
coinmarketCapAPIManager.updateMarketCap(preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
isMarketpCapUpdated = true;
|
|
||||||
countCompletedMarketCapRequest();
|
|
||||||
}
|
|
||||||
}, preferencesManager.getDefaultCurrency());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -217,14 +198,14 @@ public class MarketCapitalization extends Fragment {
|
|||||||
private PieDataSet getMarketDominanceDataSet()
|
private PieDataSet getMarketDominanceDataSet()
|
||||||
{
|
{
|
||||||
List<PieEntry> entries = new ArrayList<>();
|
List<PieEntry> entries = new ArrayList<>();
|
||||||
List<Currency> topCurrencies = marketCapManager.getTopCurrencies();
|
List<Currency> topCurrencies = coinmarketCapAPIManager.getTopCurrencies();
|
||||||
ArrayList<Integer> colors = new ArrayList<>();
|
ArrayList<Integer> colors = new ArrayList<>();
|
||||||
|
|
||||||
float topCurrenciesDominance = 0;
|
float topCurrenciesDominance = 0;
|
||||||
|
|
||||||
for(int i = 0; i < topCurrencies.size(); i++)
|
for(int i = 0; i < topCurrencies.size(); i++)
|
||||||
{
|
{
|
||||||
PieEntry pieEntry = new PieEntry(topCurrencies.get(i).getDominance(marketCapManager.getMarketCap()), topCurrencies.get(i).getSymbol(), topCurrencies.get(i).getSymbol());
|
PieEntry pieEntry = new PieEntry(topCurrencies.get(i).getDominance(coinmarketCapAPIManager.getMarketCap()), topCurrencies.get(i).getSymbol(), topCurrencies.get(i).getSymbol());
|
||||||
|
|
||||||
if(pieEntry.getValue() < 3)
|
if(pieEntry.getValue() < 3)
|
||||||
{
|
{
|
||||||
@ -232,7 +213,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries.add(pieEntry);
|
entries.add(pieEntry);
|
||||||
topCurrenciesDominance += topCurrencies.get(i).getDominance(marketCapManager.getMarketCap());
|
topCurrenciesDominance += topCurrencies.get(i).getDominance(coinmarketCapAPIManager.getMarketCap());
|
||||||
colors.add(topCurrencies.get(i).getChartColor());
|
colors.add(topCurrencies.get(i).getChartColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +241,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
{
|
{
|
||||||
iconCounter++;
|
iconCounter++;
|
||||||
|
|
||||||
if(iconCounter >= marketCapManager.getTopCurrencies().size())
|
if(iconCounter >= coinmarketCapAPIManager.getTopCurrencies().size())
|
||||||
{
|
{
|
||||||
refreshDisplayedData();
|
refreshDisplayedData();
|
||||||
}
|
}
|
||||||
@ -268,24 +249,25 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
private void updateIcons()
|
private void updateIcons()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < marketCapManager.getTopCurrencies().size(); i++)
|
for(int i = 0; i < coinmarketCapAPIManager.getTopCurrencies().size(); i++)
|
||||||
{
|
{
|
||||||
final Currency localCurrency = marketCapManager.getTopCurrencies().get(i);
|
final Currency localCurrency = coinmarketCapAPIManager.getTopCurrencies().get(i);
|
||||||
final int index = i;
|
final int index = i;
|
||||||
|
|
||||||
String iconUrl = MoodlBox.getIconUrl(marketCapManager.getTopCurrencies().get(i).getSymbol(), 500, currencyDetailsList);
|
String iconUrl = MoodlBox.getIconUrl(coinmarketCapAPIManager.getTopCurrencies().get(i).getSymbol(), 500, cryptocompareApiManager);
|
||||||
|
|
||||||
if(iconUrl != null)
|
if(iconUrl != null)
|
||||||
{
|
{
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new MoodlboxNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||||
Palette.Builder builder = Palette.from(bitmapIcon);
|
Palette.Builder builder = Palette.from(bitmapIcon);
|
||||||
|
|
||||||
marketCapManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
|
coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
|
||||||
marketCapManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getContext())));
|
coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getContext())));
|
||||||
|
|
||||||
countIcons();
|
countIcons();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -310,11 +292,11 @@ public class MarketCapitalization extends Fragment {
|
|||||||
pieChart.setTouchEnabled(true);
|
pieChart.setTouchEnabled(true);
|
||||||
pieChart.setEntryLabelColor(Color.WHITE);
|
pieChart.setEntryLabelColor(Color.WHITE);
|
||||||
|
|
||||||
updateDetails(marketCapManager.getMarketCap(), marketCapManager.getDayVolume(), getString(R.string.global), 0);
|
updateDetails(coinmarketCapAPIManager.getMarketCap(), coinmarketCapAPIManager.getDayVolume(), getString(R.string.global), 0);
|
||||||
((TextView) view.findViewById(R.id.textViewActiveCrypto))
|
((TextView) view.findViewById(R.id.textViewActiveCrypto))
|
||||||
.setText(marketCapManager.getActive_crypto());
|
.setText(coinmarketCapAPIManager.getActive_crypto());
|
||||||
((TextView) view.findViewById(R.id.textViewActiveMarkets))
|
((TextView) view.findViewById(R.id.textViewActiveMarkets))
|
||||||
.setText(marketCapManager.getActive_markets());
|
.setText(coinmarketCapAPIManager.getActive_markets());
|
||||||
|
|
||||||
pieChart.setOnTouchListener(new View.OnTouchListener() {
|
pieChart.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -349,7 +331,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
if(!e.getData().equals("others"))
|
if(!e.getData().equals("others"))
|
||||||
{
|
{
|
||||||
Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData());
|
Currency currency = coinmarketCapAPIManager.getCurrencyFromSymbol((String) e.getData());
|
||||||
view.findViewById(R.id.currencyIcon).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.currencyIcon).setVisibility(View.VISIBLE);
|
||||||
view.findViewById(R.id.layoutPercentageDominance).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.layoutPercentageDominance).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@ -362,13 +344,13 @@ public class MarketCapitalization extends Fragment {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double othersMarketCap = marketCapManager.getMarketCap();
|
double othersMarketCap = coinmarketCapAPIManager.getMarketCap();
|
||||||
double othersVolume = marketCapManager.getDayVolume();
|
double othersVolume = coinmarketCapAPIManager.getDayVolume();
|
||||||
|
|
||||||
for(int i = 0; i < marketCapManager.getTopCurrencies().size(); i++)
|
for(int i = 0; i < coinmarketCapAPIManager.getTopCurrencies().size(); i++)
|
||||||
{
|
{
|
||||||
othersMarketCap -= marketCapManager.getTopCurrencies().get(i).getMarketCapitalization();
|
othersMarketCap -= coinmarketCapAPIManager.getTopCurrencies().get(i).getMarketCapitalization();
|
||||||
othersVolume -= marketCapManager.getTopCurrencies().get(i).getVolume24h();
|
othersVolume -= coinmarketCapAPIManager.getTopCurrencies().get(i).getVolume24h();
|
||||||
}
|
}
|
||||||
|
|
||||||
view.findViewById(R.id.currencyIcon).setVisibility(View.GONE);
|
view.findViewById(R.id.currencyIcon).setVisibility(View.GONE);
|
||||||
@ -390,7 +372,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
view.findViewById(R.id.layoutActiveCrypto).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.layoutActiveCrypto).setVisibility(View.VISIBLE);
|
||||||
view.findViewById(R.id.layoutActiveMarkets).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.layoutActiveMarkets).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
updateDetails(marketCapManager.getMarketCap(), marketCapManager.getDayVolume(), getString(R.string.global), 0);
|
updateDetails(coinmarketCapAPIManager.getMarketCap(), coinmarketCapAPIManager.getDayVolume(), getString(R.string.global), 0);
|
||||||
|
|
||||||
pieChart.setDrawCenterText(true);
|
pieChart.setDrawCenterText(true);
|
||||||
}
|
}
|
||||||
@ -419,4 +401,37 @@ public class MarketCapitalization extends Fragment {
|
|||||||
SpannableString spannableString = new SpannableString(getString(R.string.market_dominance));
|
SpannableString spannableString = new SpannableString(getString(R.string.market_dominance));
|
||||||
return spannableString;
|
return spannableString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetailsUpdated() {
|
||||||
|
isDetailsUpdated = true;
|
||||||
|
countCompletedMarketCapRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExchangesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCurrenciesRetrieved(List<Currency> currencyList) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTopCurrenciesUpdated() {
|
||||||
|
isTopCurrenciesUpdated = true;
|
||||||
|
countCompletedMarketCapRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMarketCapUpdated() {
|
||||||
|
isMarketpCapUpdated = true;
|
||||||
|
countCompletedMarketCapRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListingUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.herbron.moodl.Activities.HomeActivityFragments;
|
package com.herbron.moodl.Activities.HomeActivityFragments;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@ -18,13 +17,14 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.LayoutManagers.OverviewListAdapter;
|
import com.herbron.moodl.LayoutManagers.OverviewListAdapter;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,10 +35,10 @@ import static com.herbron.moodl.MoodlBox.getDrawable;
|
|||||||
* Created by Administrator on 27/05/2018.
|
* Created by Administrator on 27/05/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Overview extends Fragment {
|
public class Overview extends Fragment implements CoinmarketcapNotifierInterface {
|
||||||
|
|
||||||
private CurrencyTickerList currencyTickerList;
|
private CoinmarketCapAPIManager coinmarketCapAPIManager;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
private PreferencesManager preferenceManager;
|
private PreferencesManager preferenceManager;
|
||||||
private OverviewListAdapter overviewListAdapter;
|
private OverviewListAdapter overviewListAdapter;
|
||||||
|
|
||||||
@ -54,8 +54,10 @@ public class Overview extends Fragment {
|
|||||||
{
|
{
|
||||||
View fragmentView = inflater.inflate(R.layout.fragment_overview_homeactivity, container, false);
|
View fragmentView = inflater.inflate(R.layout.fragment_overview_homeactivity, container, false);
|
||||||
|
|
||||||
currencyTickerList = CurrencyTickerList.getInstance(getContext());
|
coinmarketCapAPIManager = CoinmarketCapAPIManager.getInstance(getContext());
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(getContext());
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
|
||||||
|
|
||||||
|
coinmarketCapAPIManager.addListener(this);
|
||||||
|
|
||||||
fragmentView.findViewById(R.id.toolbar).bringToFront();
|
fragmentView.findViewById(R.id.toolbar).bringToFront();
|
||||||
|
|
||||||
@ -92,6 +94,7 @@ public class Overview extends Fragment {
|
|||||||
return fragmentView;
|
return fragmentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setupDrawerButton(View view)
|
private void setupDrawerButton(View view)
|
||||||
{
|
{
|
||||||
ImageButton drawerButton = view.findViewById(R.id.drawer_button);
|
ImageButton drawerButton = view.findViewById(R.id.drawer_button);
|
||||||
@ -132,11 +135,6 @@ public class Overview extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UpdateCallBack
|
|
||||||
{
|
|
||||||
void onSuccess(List<Currency> currencyList);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadingIndicatorGenerator()
|
private void loadingIndicatorGenerator()
|
||||||
{
|
{
|
||||||
loadingFooter = LayoutInflater.from(getContext()).inflate(R.layout.listview_loading_indicator, null, false);
|
loadingFooter = LayoutInflater.from(getContext()).inflate(R.layout.listview_loading_indicator, null, false);
|
||||||
@ -144,6 +142,27 @@ public class Overview extends Fragment {
|
|||||||
listLayout.addFooterView(loadingFooter);
|
listLayout.addFooterView(loadingFooter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCurrenciesRetrieved(List<Currency> currencyList) {
|
||||||
|
IconDownloader iconDownloader = new IconDownloader();
|
||||||
|
iconDownloader.execute(currencyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTopCurrenciesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMarketCapUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListingUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class CurrencyLoader extends AsyncTask<Void, Void, Void>
|
private class CurrencyLoader extends AsyncTask<Void, Void, Void>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -155,14 +174,7 @@ public class Overview extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
currencyTickerList.getCurrenciesFrom(listLayout.getCount(), preferenceManager.getDefaultCurrency(), new UpdateCallBack() {
|
coinmarketCapAPIManager.getCurrenciesFrom(listLayout.getCount(), preferenceManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(List<Currency> currencyList)
|
|
||||||
{
|
|
||||||
IconDownloader iconDownloader = new IconDownloader();
|
|
||||||
iconDownloader.execute(currencyList);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,13 +188,13 @@ public class Overview extends Fragment {
|
|||||||
|
|
||||||
for(Currency currency : currencies[0])
|
for(Currency currency : currencies[0])
|
||||||
{
|
{
|
||||||
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), currencyDetailsList);
|
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager);
|
||||||
|
|
||||||
if(iconUrl != null)
|
if(iconUrl != null)
|
||||||
{
|
{
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getContext(), new MoodlboxNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmap) {
|
public void onBitmapDownloaded(Bitmap bitmap) {
|
||||||
currency.setIcon(bitmap);
|
currency.setIcon(bitmap);
|
||||||
updateChartColor(currency);
|
updateChartColor(currency);
|
||||||
countIcons(currencies[0]);
|
countIcons(currencies[0]);
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.BitmapFactory;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -33,23 +32,25 @@ import android.widget.Button;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.daasuu.ei.Ease;
|
import com.daasuu.ei.Ease;
|
||||||
import com.daasuu.ei.EasingInterpolator;
|
import com.daasuu.ei.EasingInterpolator;
|
||||||
import com.herbron.moodl.Activities.CurrencySelectionActivity;
|
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
|
||||||
import com.herbron.moodl.Activities.RecordTransactionActivity;
|
import com.herbron.moodl.Activities.RecordTransactionActivity;
|
||||||
import com.herbron.moodl.BalanceUpdateInterface;
|
import com.herbron.moodl.BalanceUpdateInterface;
|
||||||
|
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
|
||||||
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
import com.herbron.moodl.DataManagers.BalanceManager;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
|
||||||
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.BalanceSwitchManagerInterface;
|
import com.herbron.moodl.BalanceSwitchManagerInterface;
|
||||||
import com.herbron.moodl.DataNotifierInterface;
|
import com.herbron.moodl.DataNotifiers.BalanceUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.PlaceholderManager;
|
import com.herbron.moodl.PlaceholderManager;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ import static java.lang.Math.abs;
|
|||||||
* Created by Tiji on 13/04/2018.
|
* Created by Tiji on 13/04/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Summary extends Fragment implements BalanceSwitchManagerInterface, DataNotifierInterface {
|
public class Summary extends Fragment implements BalanceSwitchManagerInterface, BalanceUpdateNotifierInterface, CryptocompareNotifierInterface, CoinmarketcapNotifierInterface {
|
||||||
|
|
||||||
private LinearLayout currencyLayout;
|
private LinearLayout currencyLayout;
|
||||||
private PreferencesManager preferencesManager;
|
private PreferencesManager preferencesManager;
|
||||||
@ -75,7 +76,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
private SwipeRefreshLayout refreshLayout;
|
private SwipeRefreshLayout refreshLayout;
|
||||||
private Dialog loadingDialog;
|
private Dialog loadingDialog;
|
||||||
private String defaultCurrency;
|
private String defaultCurrency;
|
||||||
private CurrencyTickerList currencyTickerList;
|
private CoinmarketCapAPIManager coinmarketCapAPIManager;
|
||||||
|
|
||||||
private TextView toolbarSubtitle;
|
private TextView toolbarSubtitle;
|
||||||
private CollapsingToolbarLayout toolbarLayout;
|
private CollapsingToolbarLayout toolbarLayout;
|
||||||
@ -93,6 +94,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
private long lastTimestamp;
|
private long lastTimestamp;
|
||||||
|
|
||||||
private BalanceUpdateInterface balanceUpdateInterface;
|
private BalanceUpdateInterface balanceUpdateInterface;
|
||||||
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
@ -102,7 +104,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
|
|
||||||
preferencesManager = new PreferencesManager(getActivity());
|
preferencesManager = new PreferencesManager(getActivity());
|
||||||
balanceManager = new BalanceManager(getContext());
|
balanceManager = new BalanceManager(getContext());
|
||||||
currencyTickerList = CurrencyTickerList.getInstance(getActivity());
|
coinmarketCapAPIManager = CoinmarketCapAPIManager.getInstance(getActivity());
|
||||||
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getActivity());
|
||||||
|
|
||||||
currencyLayout = fragmentView.findViewById(R.id.currencyListLayout);
|
currencyLayout = fragmentView.findViewById(R.id.currencyListLayout);
|
||||||
refreshLayout = fragmentView.findViewById(R.id.swiperefreshsummary);
|
refreshLayout = fragmentView.findViewById(R.id.swiperefreshsummary);
|
||||||
@ -114,6 +117,9 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
|
|
||||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||||
|
|
||||||
|
cryptocompareApiManager.addListener(this);
|
||||||
|
coinmarketCapAPIManager.addListener(this);
|
||||||
|
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
|
|
||||||
initiateUpdateRunnable();
|
initiateUpdateRunnable();
|
||||||
@ -544,16 +550,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
displayBalance(preferencesManager.isBalanceHidden());
|
displayBalance(preferencesManager.isBalanceHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTickerListUpdated() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetailsUpdated() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBalanceDataUpdated() {
|
public void onBalanceDataUpdated() {
|
||||||
final List<Currency> balance = balanceManager.getTotalBalance();
|
final List<Currency> balance = balanceManager.getTotalBalance();
|
||||||
@ -562,10 +558,21 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < balance.size(); i++)
|
for(int i = 0; i < balance.size(); i++)
|
||||||
{
|
{
|
||||||
balance.get(i).updatePrice(getActivity(), defaultCurrency, new Currency.CurrencyCallBack() {
|
balance.get(i).updatePrice(getActivity(), defaultCurrency, new CurrencyInfoUpdateNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Currency currency) {
|
public void onTimestampPriveUpdated(String price) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHistoryDataUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPriceUpdated(Currency currency) {
|
||||||
countCoins(true, false, false);
|
countCoins(true, false, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -630,6 +637,36 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetailsUpdated() {
|
||||||
|
countCoins(false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExchangesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCurrenciesRetrieved(List<Currency> currencyList) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTopCurrenciesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMarketCapUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListingUpdated() {
|
||||||
|
countCoins(false, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
|
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -687,7 +724,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
{
|
{
|
||||||
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
||||||
|
|
||||||
localCurrency.setTickerId(currencyTickerList.getTickerIdForSymbol(localCurrency.getSymbol()));
|
localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol()));
|
||||||
|
|
||||||
updateChartColor(localCurrency);
|
updateChartColor(localCurrency);
|
||||||
|
|
||||||
@ -771,13 +808,13 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
{
|
{
|
||||||
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
||||||
|
|
||||||
String iconUrl = MoodlBox.getIconUrl(localCurrency.getSymbol(), balanceManager.getCurrencyDetailList());
|
String iconUrl = MoodlBox.getIconUrl(localCurrency.getSymbol(), balanceManager.getCryptocompareApiManager());
|
||||||
|
|
||||||
if(iconUrl != null)
|
if(iconUrl != null)
|
||||||
{
|
{
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new MoodlboxNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||||
localCurrency.setIcon(bitmapIcon);
|
localCurrency.setIcon(bitmapIcon);
|
||||||
countIcons();
|
countIcons();
|
||||||
}
|
}
|
||||||
@ -810,27 +847,23 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params)
|
protected Void doInBackground(Void... params)
|
||||||
{
|
{
|
||||||
if(!currencyTickerList.isUpToDate())
|
if(!coinmarketCapAPIManager.isUpToDate())
|
||||||
{
|
{
|
||||||
currencyTickerList.updateListing(new com.herbron.moodl.DataManagers.BalanceManager.IconCallBack() {
|
coinmarketCapAPIManager.updateListing();
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
countCoins(false, false, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
countCoins(false, false, true);
|
countCoins(false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
balanceManager.updateDetails(new com.herbron.moodl.DataManagers.BalanceManager.IconCallBack() {
|
if(!cryptocompareApiManager.isDetailsUpToDate())
|
||||||
@Override
|
{
|
||||||
public void onSuccess()
|
cryptocompareApiManager.updateDetails();
|
||||||
{
|
}
|
||||||
countCoins(false, true, false);
|
else
|
||||||
}
|
{
|
||||||
});
|
countCoins(false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
balanceManager.updateTotalBalance();
|
balanceManager.updateTotalBalance();
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import android.support.v4.view.GravityCompat;
|
|||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -21,22 +20,26 @@ import android.widget.Button;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
import com.herbron.moodl.Activities.CurrencySelectionActivity;
|
import com.herbron.moodl.Activities.CurrencySelectionActivity;
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
|
||||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.DataManagers.WatchlistManager;
|
import com.herbron.moodl.DataManagers.WatchlistManager;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
import com.jmedeisis.draglinearlayout.DragLinearLayout;
|
import com.jmedeisis.draglinearlayout.DragLinearLayout;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.herbron.moodl.MoodlBox.collapseW;
|
import static com.herbron.moodl.MoodlBox.collapseW;
|
||||||
import static com.herbron.moodl.MoodlBox.expandW;
|
import static com.herbron.moodl.MoodlBox.expandW;
|
||||||
import static com.herbron.moodl.MoodlBox.getColor;
|
import static com.herbron.moodl.MoodlBox.getColor;
|
||||||
@ -45,18 +48,18 @@ import static com.herbron.moodl.MoodlBox.getColor;
|
|||||||
* Created by Tiji on 13/04/2018.
|
* Created by Tiji on 13/04/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Watchlist extends Fragment {
|
public class Watchlist extends Fragment implements CryptocompareNotifierInterface {
|
||||||
|
|
||||||
private WatchlistManager watchlistManager;
|
private WatchlistManager watchlistManager;
|
||||||
private View view;
|
private View view;
|
||||||
private int watchlistCounter;
|
private int watchlistCounter;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
private SwipeRefreshLayout refreshLayout;
|
private SwipeRefreshLayout refreshLayout;
|
||||||
private DragLinearLayout dragLinearLayout;
|
private DragLinearLayout dragLinearLayout;
|
||||||
private long lastTimestamp;
|
private long lastTimestamp;
|
||||||
private PreferencesManager preferencesManager;
|
private PreferencesManager preferencesManager;
|
||||||
private String defaultCurrency;
|
private String defaultCurrency;
|
||||||
private CurrencyTickerList currencyTickerList;
|
private CoinmarketCapAPIManager coinmarketCapAPIManager;
|
||||||
private boolean tickerUpdated;
|
private boolean tickerUpdated;
|
||||||
private boolean detailsUpdated;
|
private boolean detailsUpdated;
|
||||||
private boolean editModeEnabled;
|
private boolean editModeEnabled;
|
||||||
@ -70,14 +73,15 @@ public class Watchlist extends Fragment {
|
|||||||
|
|
||||||
refreshLayout = view.findViewById(R.id.swiperefreshwatchlist);
|
refreshLayout = view.findViewById(R.id.swiperefreshwatchlist);
|
||||||
dragLinearLayout = view.findViewById(R.id.linearLayoutWatchlist);
|
dragLinearLayout = view.findViewById(R.id.linearLayoutWatchlist);
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(getContext());
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
|
||||||
preferencesManager = new PreferencesManager(getContext());
|
preferencesManager = new PreferencesManager(getContext());
|
||||||
databaseManager = new DatabaseManager(getContext());
|
databaseManager = new DatabaseManager(getContext());
|
||||||
|
|
||||||
lastTimestamp = 0;
|
lastTimestamp = 0;
|
||||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||||
currencyTickerList = CurrencyTickerList.getInstance(getActivity());
|
coinmarketCapAPIManager = CoinmarketCapAPIManager.getInstance(getActivity());
|
||||||
tickerUpdated = false;
|
tickerUpdated = false;
|
||||||
|
cryptocompareApiManager.addListener(this);
|
||||||
updateTickerList();
|
updateTickerList();
|
||||||
|
|
||||||
dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() {
|
dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() {
|
||||||
@ -115,30 +119,54 @@ public class Watchlist extends Fragment {
|
|||||||
|
|
||||||
private void updateTickerList()
|
private void updateTickerList()
|
||||||
{
|
{
|
||||||
AsyncTask<Void, Integer, Void> updater = new AsyncTask<Void, Integer, Void>() {
|
ListingUpdater listingUpdater = new ListingUpdater();
|
||||||
@Override
|
listingUpdater.execute();
|
||||||
protected Void doInBackground(Void... voids) {
|
}
|
||||||
if(!currencyTickerList.isUpToDate())
|
|
||||||
{
|
|
||||||
currencyTickerList.updateListing(new BalanceManager.IconCallBack() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
tickerUpdated = true;
|
|
||||||
checkUpdatedData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tickerUpdated = true;
|
|
||||||
checkUpdatedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
private class ListingUpdater extends AsyncTask<Void, Integer, Void> implements CoinmarketcapNotifierInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
|
||||||
|
coinmarketCapAPIManager.addListener(this);
|
||||||
|
|
||||||
|
if(!coinmarketCapAPIManager.isUpToDate())
|
||||||
|
{
|
||||||
|
coinmarketCapAPIManager.updateListing();
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
|
{
|
||||||
|
tickerUpdated = true;
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
checkUpdatedData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
updater.execute();
|
@Override
|
||||||
|
public void onCurrenciesRetrieved(List<Currency> currencyList) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTopCurrenciesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMarketCapUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListingUpdated() {
|
||||||
|
tickerUpdated = true;
|
||||||
|
checkUpdatedData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableEdition()
|
private void disableEdition()
|
||||||
@ -281,15 +309,9 @@ public class Watchlist extends Fragment {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
watchlistManager.updateWatchlist();
|
watchlistManager.updateWatchlist();
|
||||||
|
|
||||||
if(!currencyDetailsList.isUpToDate())
|
if(!cryptocompareApiManager.isDetailsUpToDate())
|
||||||
{
|
{
|
||||||
currencyDetailsList.update(new BalanceManager.IconCallBack() {
|
cryptocompareApiManager.updateDetails();
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
detailsUpdated = true;
|
|
||||||
checkUpdatedData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -358,24 +380,6 @@ public class Watchlist extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIconUrl(String symbol)
|
|
||||||
{
|
|
||||||
String url;
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
|
||||||
url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50";
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
Log.d(getContext().getResources().getString(R.string.debug), symbol + " has no icon URL");
|
|
||||||
url = null;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.d(getContext().getResources().getString(R.string.debug), "Url parsing error for " + symbol);
|
|
||||||
url = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateChartColor(Currency currency)
|
private void updateChartColor(Currency currency)
|
||||||
{
|
{
|
||||||
if(currency.getIcon() != null)
|
if(currency.getIcon() != null)
|
||||||
@ -395,7 +399,7 @@ public class Watchlist extends Fragment {
|
|||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
JSONObject jsonObject = new JSONObject(cryptocompareApiManager.getCoinInfosHashmap().get(symbol));
|
||||||
id = jsonObject.getInt("Id");
|
id = jsonObject.getInt("Id");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -404,6 +408,17 @@ public class Watchlist extends Fragment {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetailsUpdated() {
|
||||||
|
detailsUpdated = true;
|
||||||
|
checkUpdatedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExchangesUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class WatchlistUpdater extends AsyncTask<Void, Integer, Void>
|
private class WatchlistUpdater extends AsyncTask<Void, Integer, Void>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -416,22 +431,32 @@ public class Watchlist extends Fragment {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
for(final Currency currency : watchlistManager.getWatchlist())
|
for(final Currency currency : watchlistManager.getWatchlist())
|
||||||
{
|
{
|
||||||
currency.setTickerId(currencyTickerList.getTickerIdForSymbol(currency.getSymbol()));
|
currency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(currency.getSymbol()));
|
||||||
currency.setId(getCurrencyId(currency.getSymbol()));
|
currency.setId(getCurrencyId(currency.getSymbol()));
|
||||||
currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new CurrencyInfoUpdateNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final Currency sucessCurrency) {
|
public void onTimestampPriveUpdated(String price) {
|
||||||
|
|
||||||
String iconUrl = MoodlBox.getIconUrl(sucessCurrency.getSymbol(), currencyDetailsList);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHistoryDataUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPriceUpdated(Currency successCurrency) {
|
||||||
|
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager);
|
||||||
|
|
||||||
if(iconUrl != null)
|
if(iconUrl != null)
|
||||||
{
|
{
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, sucessCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getContext(), new MoodlboxNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||||
sucessCurrency.setIcon(bitmapIcon);
|
currency.setIcon(bitmapIcon);
|
||||||
updateChartColor(currency);
|
updateChartColor(currency);
|
||||||
countWatchlist();
|
countWatchlist();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -440,7 +465,7 @@ public class Watchlist extends Fragment {
|
|||||||
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl);
|
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl);
|
||||||
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
|
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
|
||||||
|
|
||||||
sucessCurrency.setIcon(icon);
|
currency.setIcon(icon);
|
||||||
updateChartColor(currency);
|
updateChartColor(currency);
|
||||||
countWatchlist();
|
countWatchlist();
|
||||||
}
|
}
|
||||||
|
@ -3,59 +3,47 @@ package com.herbron.moodl.Activities;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.support.v4.view.PagerAdapter;
|
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.graphics.Palette;
|
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TabWidget;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Transaction;
|
|
||||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.LayoutManagers.CoinSummaryListAdapter;
|
import com.herbron.moodl.LayoutManagers.CoinSummaryListAdapter;
|
||||||
import com.herbron.moodl.LayoutManagers.CustomTabLayout;
|
import com.herbron.moodl.LayoutManagers.CustomTabLayout;
|
||||||
import com.herbron.moodl.LayoutManagers.RecordTransactionPageAdapter;
|
import com.herbron.moodl.LayoutManagers.RecordTransactionPageAdapter;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.PlaceholderManager;
|
import com.herbron.moodl.PlaceholderManager;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static com.herbron.moodl.MoodlBox.getColor;
|
public class RecordTransactionActivity extends AppCompatActivity implements CurrencyInfoUpdateNotifierInterface {
|
||||||
|
|
||||||
public class RecordTransactionActivity extends AppCompatActivity {
|
|
||||||
|
|
||||||
private String coin;
|
private String coin;
|
||||||
private String symbol;
|
private String symbol;
|
||||||
@ -78,7 +66,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
|||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
private ImageView currencyIconImageView;
|
private ImageView currencyIconImageView;
|
||||||
|
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
|
|
||||||
private SearchView mainSearchView;
|
private SearchView mainSearchView;
|
||||||
|
|
||||||
@ -231,13 +219,15 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cryptocompareApiManager.updateExchangeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupAutoCompleteTextView()
|
private void setupAutoCompleteTextView()
|
||||||
{
|
{
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(this);
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(this);
|
||||||
|
|
||||||
CoinSummaryListAdapter adapter = new CoinSummaryListAdapter(this, R.layout.custom_summary_coin_row, new ArrayList<>(currencyDetailsList.getCurrenciesDenomination()));
|
CoinSummaryListAdapter adapter = new CoinSummaryListAdapter(this, R.layout.custom_summary_coin_row, new ArrayList<>(cryptocompareApiManager.getCurrenciesDenomination()));
|
||||||
|
|
||||||
AutoCompleteTextView coin_autoCompleteTextView = findViewById(R.id.coin_autoCompleteTextView);
|
AutoCompleteTextView coin_autoCompleteTextView = findViewById(R.id.coin_autoCompleteTextView);
|
||||||
coin_autoCompleteTextView.setThreshold(0);
|
coin_autoCompleteTextView.setThreshold(0);
|
||||||
@ -282,6 +272,8 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
|||||||
toolbar.requestFocus();
|
toolbar.requestFocus();
|
||||||
hideSoftKeyboard(RecordTransactionActivity.this);
|
hideSoftKeyboard(RecordTransactionActivity.this);
|
||||||
|
|
||||||
|
currency.setListener(RecordTransactionActivity.this);
|
||||||
|
|
||||||
RecordTransactionActivity.this.currency = currency;
|
RecordTransactionActivity.this.currency = currency;
|
||||||
|
|
||||||
IconDownloaderTask iconDownloaderTask = new IconDownloaderTask();
|
IconDownloaderTask iconDownloaderTask = new IconDownloaderTask();
|
||||||
@ -290,23 +282,39 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimestampPriveUpdated(String price) {
|
||||||
|
purchasedPriceEditText.setText(price);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHistoryDataUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPriceUpdated(Currency currency) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class IconDownloaderTask extends AsyncTask<Void, Void, Void> {
|
private class IconDownloaderTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), 500, currencyDetailsList);
|
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), 500, cryptocompareApiManager);
|
||||||
|
|
||||||
if(iconUrl != null)
|
if(iconUrl != null)
|
||||||
{
|
{
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getBaseContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getBaseContext(), new MoodlboxNotifierInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
currencyIconImageView.setImageBitmap(bitmapIcon);
|
currencyIconImageView.setImageBitmap(bitmapIcon);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -469,12 +477,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
|
|||||||
calendar.set(Calendar.MINUTE, minute);
|
calendar.set(Calendar.MINUTE, minute);
|
||||||
purchaseDate.setText(sdf.format(calendar.getTime()));
|
purchaseDate.setText(sdf.format(calendar.getTime()));
|
||||||
|
|
||||||
currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() {
|
currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(),calendar.getTimeInMillis() / 1000);
|
||||||
@Override
|
|
||||||
public void onSuccess(String price) {
|
|
||||||
purchasedPriceEditText.setText(price);
|
|
||||||
}
|
|
||||||
}, calendar.getTimeInMillis() / 1000);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
calendar.get(Calendar.HOUR_OF_DAY),
|
calendar.get(Calendar.HOUR_OF_DAY),
|
||||||
|
@ -4,18 +4,40 @@ import android.os.Bundle;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
public class BuyFragment extends Fragment {
|
public class BuyFragment extends Fragment implements CryptocompareNotifierInterface {
|
||||||
|
|
||||||
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_buy, container, false);
|
View view = inflater.inflate(R.layout.fragment_buy, container, false);
|
||||||
|
|
||||||
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
|
||||||
|
|
||||||
|
cryptocompareApiManager.addListener(this);
|
||||||
|
|
||||||
|
cryptocompareApiManager.updateExchangeList();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetailsUpdated() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExchangesUpdated() {
|
||||||
|
Log.d("moodl", "Received ! " + cryptocompareApiManager.getExchangeList().get(0).getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.herbron.moodl;
|
||||||
|
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
|
||||||
|
public interface CurrencyInfoUpdateNotifierInterface {
|
||||||
|
|
||||||
|
void onTimestampPriveUpdated(String price);
|
||||||
|
|
||||||
|
void onHistoryDataUpdated();
|
||||||
|
|
||||||
|
void onPriceUpdated(Currency currency);
|
||||||
|
|
||||||
|
}
|
@ -1,41 +1,31 @@
|
|||||||
package com.herbron.moodl.DataManagers;
|
package com.herbron.moodl.DataManagers;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.android.volley.RequestQueue;
|
|
||||||
import com.android.volley.toolbox.Volley;
|
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.Activities.HomeActivity;
|
||||||
|
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.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.ExchangeManager.BinanceManager;
|
import com.herbron.moodl.DataManagers.ExchangeManager.BinanceManager;
|
||||||
import com.herbron.moodl.DataManagers.ExchangeManager.HitBtcManager;
|
import com.herbron.moodl.DataManagers.ExchangeManager.HitBtcManager;
|
||||||
import com.herbron.moodl.DataNotifierInterface;
|
import com.herbron.moodl.DataNotifiers.BalanceUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.DataNotifiers.HitBTCUpdateNotifierInterface;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tiji on 25/12/2017.
|
* Created by Tiji on 25/12/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BalanceManager {
|
public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpdateNotifierInterface {
|
||||||
|
|
||||||
private RequestQueue requestQueue;
|
|
||||||
private List<Currency> binanceBalance;
|
|
||||||
private List<Currency> hitBalance;
|
|
||||||
private List<Currency> manualBalances;
|
private List<Currency> manualBalances;
|
||||||
private List<Currency> totalBalance;
|
private List<Currency> totalBalance;
|
||||||
private android.content.Context context;
|
private android.content.Context context;
|
||||||
private LinkedHashMap<String, String> coinInfosHashmap;
|
|
||||||
private PreferencesManager preferenceManager;
|
|
||||||
private DatabaseManager databaseManager;
|
private DatabaseManager databaseManager;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
|
|
||||||
private int balanceCounter;
|
private int balanceCounter;
|
||||||
|
|
||||||
@ -43,30 +33,26 @@ public class BalanceManager {
|
|||||||
private List<HitBtcManager> hitBtcManagers;
|
private List<HitBtcManager> hitBtcManagers;
|
||||||
private List<BinanceManager> binanceManagers;
|
private List<BinanceManager> binanceManagers;
|
||||||
|
|
||||||
private DataNotifierInterface dataNotifierInterface;
|
private BalanceUpdateNotifierInterface balanceUpdateNotifierInterface;
|
||||||
|
|
||||||
public BalanceManager(android.content.Context context)
|
public BalanceManager(android.content.Context context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
preferenceManager = new PreferencesManager(context);
|
|
||||||
requestQueue = Volley.newRequestQueue(context);
|
|
||||||
binanceBalance = new ArrayList<Currency>();
|
|
||||||
hitBalance = new ArrayList<Currency>();
|
|
||||||
manualBalances = new ArrayList<Currency>();
|
manualBalances = new ArrayList<Currency>();
|
||||||
databaseManager = new DatabaseManager(context);
|
databaseManager = new DatabaseManager(context);
|
||||||
hitBtcManagers = new ArrayList<>();
|
hitBtcManagers = new ArrayList<>();
|
||||||
binanceManagers = new ArrayList<>();
|
binanceManagers = new ArrayList<>();
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(context);
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(context);
|
||||||
|
|
||||||
balanceCounter = 0;
|
balanceCounter = 0;
|
||||||
|
|
||||||
setListener((DataNotifierInterface) ((HomeActivity) context).getHoldingsFragment());
|
setListener((BalanceUpdateNotifierInterface) ((HomeActivity) context).getHoldingsFragment());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(DataNotifierInterface dataNotifierInterface)
|
public void setListener(BalanceUpdateNotifierInterface balanceUpdateNotifierInterface)
|
||||||
{
|
{
|
||||||
this.dataNotifierInterface = dataNotifierInterface;
|
this.balanceUpdateNotifierInterface = balanceUpdateNotifierInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateExchangeKeys()
|
public void updateExchangeKeys()
|
||||||
@ -102,18 +88,8 @@ public class BalanceManager {
|
|||||||
for(int i = 0; i < binanceManagers.size(); i++)
|
for(int i = 0; i < binanceManagers.size(); i++)
|
||||||
{
|
{
|
||||||
final BinanceManager binanceManager = binanceManagers.get(i);
|
final BinanceManager binanceManager = binanceManagers.get(i);
|
||||||
binanceManager.updateBalance(new BinanceManager.BinanceCallBack() {
|
binanceManager.addListener(this);
|
||||||
@Override
|
binanceManager.updateBalance();
|
||||||
public void onSuccess() {
|
|
||||||
countBalances();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String error) {
|
|
||||||
databaseManager.disableExchangeAccount(binanceManager.getId());
|
|
||||||
dataNotifierInterface.onBalanceError(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,18 +100,8 @@ public class BalanceManager {
|
|||||||
for(int i = 0; i < hitBtcManagers.size(); i++)
|
for(int i = 0; i < hitBtcManagers.size(); i++)
|
||||||
{
|
{
|
||||||
final HitBtcManager hitBtcManager = hitBtcManagers.get(i);
|
final HitBtcManager hitBtcManager = hitBtcManagers.get(i);
|
||||||
hitBtcManagers.get(i).updateGlobalBalance(new HitBtcManager.HitBtcCallBack() {
|
hitBtcManager.addListener(this);
|
||||||
@Override
|
hitBtcManager.updateGlobalBalance();
|
||||||
public void onSuccess() {
|
|
||||||
countBalances();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String error) {
|
|
||||||
databaseManager.disableExchangeAccount(hitBtcManager.getId());
|
|
||||||
dataNotifierInterface.onBalanceError(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +139,7 @@ public class BalanceManager {
|
|||||||
|
|
||||||
mergeBalanceTotal(manualBalances);
|
mergeBalanceTotal(manualBalances);
|
||||||
|
|
||||||
dataNotifierInterface.onBalanceDataUpdated();
|
balanceUpdateNotifierInterface.onBalanceDataUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeBalanceTotal(List<Currency> balance)
|
private void mergeBalanceTotal(List<Currency> balance)
|
||||||
@ -202,13 +168,31 @@ public class BalanceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface VolleyCallBack {
|
@Override
|
||||||
void onSuccess();
|
public void onBinanceTradesUpdated() {
|
||||||
void onError(String error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IconCallBack {
|
@Override
|
||||||
void onSuccess();
|
public void onBinanceBalanceUpdateSuccess() {
|
||||||
|
countBalances();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBinanceBalanceUpdateError(int accountId, String error) {
|
||||||
|
databaseManager.disableExchangeAccount(accountId);
|
||||||
|
balanceUpdateNotifierInterface.onBalanceError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHitBTCBalanceUpdateSuccess() {
|
||||||
|
countBalances();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHitBTCBalanceUpdateError(int accountId, String error) {
|
||||||
|
databaseManager.disableExchangeAccount(accountId);
|
||||||
|
balanceUpdateNotifierInterface.onBalanceError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sortCoins()
|
public void sortCoins()
|
||||||
@ -227,47 +211,9 @@ public class BalanceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDetails(final IconCallBack callBack)
|
public CryptocompareApiManager getCryptocompareApiManager()
|
||||||
{
|
{
|
||||||
if(!currencyDetailsList.isUpToDate())
|
return cryptocompareApiManager;
|
||||||
{
|
|
||||||
currencyDetailsList.update(callBack);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
callBack.onSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIconUrl(String symbol)
|
|
||||||
{
|
|
||||||
String url;
|
|
||||||
|
|
||||||
try {
|
|
||||||
switch (symbol)
|
|
||||||
{
|
|
||||||
case "IOTA":
|
|
||||||
url = "https://www.cryptocompare.com/media/1383540/iota_logo.png?width=50";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
|
||||||
url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
Log.d(context.getResources().getString(R.string.debug), symbol + " has no icon URL");
|
|
||||||
url = null;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.d(context.getResources().getString(R.string.debug), "Url parsing error for " + symbol);
|
|
||||||
url = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CurrencyDetailsList getCurrencyDetailList()
|
|
||||||
{
|
|
||||||
return currencyDetailsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrencyName(String symbol)
|
public String getCurrencyName(String symbol)
|
||||||
@ -275,7 +221,7 @@ public class BalanceManager {
|
|||||||
String currencyName = null;
|
String currencyName = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
JSONObject jsonObject = new JSONObject(cryptocompareApiManager.getCoinInfosHashmap().get(symbol));
|
||||||
currencyName = jsonObject.getString("CoinName");
|
currencyName = jsonObject.getString("CoinName");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -291,7 +237,7 @@ public class BalanceManager {
|
|||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
JSONObject jsonObject = new JSONObject(cryptocompareApiManager.getCoinInfosHashmap().get(symbol));
|
||||||
id = jsonObject.getInt("Id");
|
id = jsonObject.getInt("Id");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -301,32 +247,4 @@ public class BalanceManager {
|
|||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortDetails()
|
|
||||||
{
|
|
||||||
LinkedHashMap<String, String> sortedHashmap = new LinkedHashMap<>();
|
|
||||||
List<String> listInfos = new ArrayList<>(coinInfosHashmap.values());
|
|
||||||
List<String> listSymbols = new ArrayList<>(coinInfosHashmap.keySet());
|
|
||||||
|
|
||||||
for(int i = 0; i < coinInfosHashmap.keySet().size(); i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = new JSONObject(listInfos.get(i));
|
|
||||||
int index = jsonObject.getInt("SortOrder");
|
|
||||||
|
|
||||||
listInfos.add(index, listInfos.get(i));
|
|
||||||
listSymbols.add(index, listSymbols.get(i));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < listInfos.size(); i++)
|
|
||||||
{
|
|
||||||
sortedHashmap.put(listSymbols.get(i), listInfos.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
coinInfosHashmap = sortedHashmap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -48,6 +50,8 @@ public class Currency implements Parcelable {
|
|||||||
private List<String> socialMediaLinks;
|
private List<String> socialMediaLinks;
|
||||||
//private String proofType
|
//private String proofType
|
||||||
|
|
||||||
|
private CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface;
|
||||||
|
|
||||||
public Currency() {}
|
public Currency() {}
|
||||||
|
|
||||||
public Currency(String symbol, double balance)
|
public Currency(String symbol, double balance)
|
||||||
@ -76,9 +80,14 @@ public class Currency implements Parcelable {
|
|||||||
this.tickerId = tickerId;
|
this.tickerId = tickerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface)
|
||||||
|
{
|
||||||
|
this.currencyInfoUpdateNotifierInterface = currencyInfoUpdateNotifierInterface;
|
||||||
|
}
|
||||||
|
|
||||||
//public Currency(int id, String symbol, String name, String algorithm, String proofType, )
|
//public Currency(int id, String symbol, String name, String algorithm, String proofType, )
|
||||||
|
|
||||||
public void getTimestampPrice(android.content.Context context, String toSymbol, final PriceCallBack callBack, long timestamp)
|
public void getTimestampPrice(android.content.Context context, String toSymbol, long timestamp)
|
||||||
{
|
{
|
||||||
dataRetriver = new CurrencyDataRetriever(context);
|
dataRetriver = new CurrencyDataRetriever(context);
|
||||||
|
|
||||||
@ -88,12 +97,12 @@ public class Currency implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String price) {
|
public void onSuccess(String price) {
|
||||||
callBack.onSuccess(price);
|
currencyInfoUpdateNotifierInterface.onTimestampPriveUpdated(price);
|
||||||
}
|
}
|
||||||
}, timestamp);
|
}, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePrice(android.content.Context context, String toSymbol, final CurrencyCallBack callBack)
|
public void updatePrice(android.content.Context context, String toSymbol, final CurrencyInfoUpdateNotifierInterface callBack)
|
||||||
{
|
{
|
||||||
dataRetriver = new CurrencyDataRetriever(context);
|
dataRetriver = new CurrencyDataRetriever(context);
|
||||||
|
|
||||||
@ -107,12 +116,12 @@ public class Currency implements Parcelable {
|
|||||||
setDayFluctuationPercentage(currencyInfo.getDayFluctuationPercentage());
|
setDayFluctuationPercentage(currencyInfo.getDayFluctuationPercentage());
|
||||||
}
|
}
|
||||||
|
|
||||||
callBack.onSuccess(Currency.this);
|
callBack.onPriceUpdated(currencyInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHistoryMinutes(android.content.Context context, String toSymbol, final CurrencyCallBack callBack)
|
public void updateHistoryMinutes(android.content.Context context, String toSymbol)
|
||||||
{
|
{
|
||||||
dataRetriver = new CurrencyDataRetriever(context);
|
dataRetriver = new CurrencyDataRetriever(context);
|
||||||
|
|
||||||
@ -121,7 +130,7 @@ public class Currency implements Parcelable {
|
|||||||
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
||||||
setHistoryMinutes(dataChart);
|
setHistoryMinutes(dataChart);
|
||||||
|
|
||||||
callBack.onSuccess(Currency.this);
|
currencyInfoUpdateNotifierInterface.onHistoryDataUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -178,7 +187,7 @@ public class Currency implements Parcelable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHistoryHours(android.content.Context context, String toSymbol, final CurrencyCallBack callBack)
|
public void updateHistoryHours(android.content.Context context, String toSymbol)
|
||||||
{
|
{
|
||||||
dataRetriver = new CurrencyDataRetriever(context);
|
dataRetriver = new CurrencyDataRetriever(context);
|
||||||
dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() {
|
dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() {
|
||||||
@ -186,7 +195,7 @@ public class Currency implements Parcelable {
|
|||||||
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
||||||
setHistoryHours(dataChart);
|
setHistoryHours(dataChart);
|
||||||
|
|
||||||
callBack.onSuccess(Currency.this);
|
currencyInfoUpdateNotifierInterface.onHistoryDataUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -194,7 +203,7 @@ public class Currency implements Parcelable {
|
|||||||
}, CurrencyDataRetriever.HOURS);
|
}, CurrencyDataRetriever.HOURS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHistoryDays(android.content.Context context, String toSymbol, final CurrencyCallBack callBack)
|
public void updateHistoryDays(android.content.Context context, String toSymbol)
|
||||||
{
|
{
|
||||||
dataRetriver = new CurrencyDataRetriever(context);
|
dataRetriver = new CurrencyDataRetriever(context);
|
||||||
dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() {
|
dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() {
|
||||||
@ -202,7 +211,7 @@ public class Currency implements Parcelable {
|
|||||||
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
public void onSuccess(List<CurrencyDataChart> dataChart) {
|
||||||
setHistoryDays(dataChart);
|
setHistoryDays(dataChart);
|
||||||
|
|
||||||
callBack.onSuccess(Currency.this);
|
currencyInfoUpdateNotifierInterface.onHistoryDataUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,7 @@ import com.github.mikephil.charting.data.Entry;
|
|||||||
import com.github.mikephil.charting.data.LineData;
|
import com.github.mikephil.charting.data.LineData;
|
||||||
import com.github.mikephil.charting.data.LineDataSet;
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
import com.herbron.moodl.Activities.CurrencyDetailsActivity;
|
import com.herbron.moodl.Activities.CurrencyDetailsActivity;
|
||||||
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
@ -43,7 +44,7 @@ import static com.herbron.moodl.MoodlBox.numberConformer;
|
|||||||
* Created by Tiji on 12/05/2018.
|
* Created by Tiji on 12/05/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CurrencyCardview extends CardView {
|
public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNotifierInterface {
|
||||||
|
|
||||||
private Currency currency;
|
private Currency currency;
|
||||||
|
|
||||||
@ -55,6 +56,8 @@ public class CurrencyCardview extends CardView {
|
|||||||
{
|
{
|
||||||
super (context);
|
super (context);
|
||||||
|
|
||||||
|
currency.setListener(this);
|
||||||
|
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
|
|
||||||
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
|
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
|
||||||
@ -76,23 +79,7 @@ public class CurrencyCardview extends CardView {
|
|||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
expandH(view.findViewById(R.id.collapsableLayout));
|
||||||
|
|
||||||
if (currency.getHistoryMinutes() == null) {
|
if (currency.getHistoryMinutes() == null) {
|
||||||
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
if(currency.getHistoryMinutes() != null)
|
|
||||||
{
|
|
||||||
setupLineChart(currency);
|
|
||||||
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -142,6 +129,8 @@ public class CurrencyCardview extends CardView {
|
|||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
currency.setListener(this);
|
||||||
|
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
|
|
||||||
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
|
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
|
||||||
@ -163,23 +152,7 @@ public class CurrencyCardview extends CardView {
|
|||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
expandH(view.findViewById(R.id.collapsableLayout));
|
||||||
|
|
||||||
if (currency.getHistoryMinutes() == null) {
|
if (currency.getHistoryMinutes() == null) {
|
||||||
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency());
|
||||||
@Override
|
|
||||||
public void onSuccess(Currency currency) {
|
|
||||||
if(currency.getHistoryMinutes() != null)
|
|
||||||
{
|
|
||||||
setupLineChart(currency);
|
|
||||||
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -386,4 +359,39 @@ public class CurrencyCardview extends CardView {
|
|||||||
|
|
||||||
return transColor ;
|
return transColor ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimestampPriveUpdated(String price) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHistoryDataUpdated() {
|
||||||
|
setupLineChart(currency);
|
||||||
|
|
||||||
|
View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist);
|
||||||
|
View progressSummaryView = findViewById(R.id.progressBarLinechartSummary);
|
||||||
|
|
||||||
|
if(progressWatchlistView != null)
|
||||||
|
{
|
||||||
|
progressWatchlistView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(progressSummaryView != null)
|
||||||
|
{
|
||||||
|
progressSummaryView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if(currency.getHistoryMinutes() == null)
|
||||||
|
{
|
||||||
|
findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPriceUpdated(Currency currency) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,202 +0,0 @@
|
|||||||
package com.herbron.moodl.DataManagers.CurrencyData;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.android.volley.Request;
|
|
||||||
import com.android.volley.RequestQueue;
|
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
|
||||||
import com.android.volley.toolbox.Volley;
|
|
||||||
import com.herbron.moodl.Activities.HomeActivityFragments.Overview;
|
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Guitoune on 22/04/2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class CurrencyTickerList {
|
|
||||||
|
|
||||||
final private static String LISTINGURL = "https://api.coinmarketcap.com/v2/listings/";
|
|
||||||
final private static String TICKERLISTURL1 = "https://api.coinmarketcap.com/v2/ticker/?start=";
|
|
||||||
private RequestQueue requestQueue;
|
|
||||||
private List<Currency> currencyTickerList;
|
|
||||||
private static CurrencyTickerList INSTANCE;
|
|
||||||
private boolean upToDate;
|
|
||||||
|
|
||||||
private CurrencyTickerList(Context context)
|
|
||||||
{
|
|
||||||
requestQueue = Volley.newRequestQueue(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized CurrencyTickerList getInstance(Context context)
|
|
||||||
{
|
|
||||||
if(INSTANCE == null)
|
|
||||||
{
|
|
||||||
INSTANCE = new CurrencyTickerList(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUpToDate()
|
|
||||||
{
|
|
||||||
if(currencyTickerList == null)
|
|
||||||
{
|
|
||||||
upToDate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return upToDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getCurrenciesFrom(int indexFrom, final String toSymbol, Overview.UpdateCallBack callBack)
|
|
||||||
{
|
|
||||||
String requetsString = TICKERLISTURL1 + indexFrom + "&limit=50&convert=" + toSymbol;
|
|
||||||
|
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, requetsString,
|
|
||||||
new Response.Listener<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(String response) {
|
|
||||||
if (response.length() > 0)
|
|
||||||
{
|
|
||||||
processTickersResult(response, toSymbol, callBack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requestQueue.add(strRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateListing(final BalanceManager.IconCallBack callBack)
|
|
||||||
{
|
|
||||||
currencyTickerList = new ArrayList<>();
|
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, LISTINGURL,
|
|
||||||
new Response.Listener<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(String response) {
|
|
||||||
if (response.length() > 0) {
|
|
||||||
processTickerListResult(response, callBack);
|
|
||||||
}
|
|
||||||
upToDate = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
upToDate = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requestQueue.add(strRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTickerIdForSymbol(String symbol)
|
|
||||||
{
|
|
||||||
int tickerId = 0;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while(!currencyTickerList.get(i).getSymbol().equals(symbol) && currencyTickerList.size() > i+1)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currencyTickerList.get(i).getSymbol().equals(symbol))
|
|
||||||
{
|
|
||||||
tickerId = currencyTickerList.get(i).getTickerId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return tickerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processTickersResult(String response, String toSymbol, Overview.UpdateCallBack callBack)
|
|
||||||
{
|
|
||||||
List<Currency> currencyList = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject masterJsonObject = new JSONObject(response);
|
|
||||||
|
|
||||||
if(masterJsonObject.keys().hasNext())
|
|
||||||
{
|
|
||||||
JSONObject currencyJsonObject = masterJsonObject.getJSONObject(masterJsonObject.keys().next());
|
|
||||||
Iterator<?> keys = currencyJsonObject.keys();
|
|
||||||
|
|
||||||
while(keys.hasNext())
|
|
||||||
{
|
|
||||||
String key = keys.next().toString();
|
|
||||||
JSONObject subCurrencyJsonObject = currencyJsonObject.getJSONObject(key);
|
|
||||||
Currency newCurrency = new Currency(subCurrencyJsonObject.getString("name"), subCurrencyJsonObject.getString("symbol"), subCurrencyJsonObject.getInt("id"));
|
|
||||||
newCurrency.setRank(subCurrencyJsonObject.getInt("rank"));
|
|
||||||
JSONObject quoteJsonObject = subCurrencyJsonObject.getJSONObject("quotes");
|
|
||||||
JSONObject symJsonObject = quoteJsonObject.getJSONObject(toSymbol);
|
|
||||||
newCurrency.setValue(symJsonObject.getDouble("price"));
|
|
||||||
newCurrency.setDayFluctuationPercentage((float) symJsonObject.getDouble("percent_change_24h"));
|
|
||||||
newCurrency.setDayFluctuation(newCurrency.getDayFluctuationPercentage() * newCurrency.getValue() / 100);
|
|
||||||
|
|
||||||
currencyList.add(newCurrency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
callBack.onSuccess(currencyList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processTickerListResult(String response, BalanceManager.IconCallBack callBack)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
JSONObject dataJsonObject = new JSONObject(response);
|
|
||||||
JSONArray dataJsonArray = dataJsonObject.getJSONArray("data");
|
|
||||||
|
|
||||||
for(int i = 0; i < dataJsonArray.length(); i++)
|
|
||||||
{
|
|
||||||
JSONObject currencyJsonObject = dataJsonArray.getJSONObject(i);
|
|
||||||
currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id")));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
/*response = response.substring(16, response.length() - 2);
|
|
||||||
String[] strTable = response.split(Pattern.quote("},"));
|
|
||||||
|
|
||||||
for(int i = 0; i < strTable.length; i++)
|
|
||||||
{
|
|
||||||
strTable[i] += "}";
|
|
||||||
Log.d("moodl", "TICKER " + i + " " + strTable[i]);
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = new JSONObject(strTable[i]);
|
|
||||||
Log.d("moodl", "TICKER JSON " + i + " " + jsonObject);
|
|
||||||
switch (jsonObject.getString("symbol"))
|
|
||||||
{
|
|
||||||
case "MIOTA":
|
|
||||||
coinTickersHashmap.put("IOT", strTable[i]);
|
|
||||||
break;
|
|
||||||
case "NANO":
|
|
||||||
coinTickersHashmap.put("XRB", strTable[i]);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
coinTickersHashmap.put(jsonObject.getString("symbol"), strTable[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
callBack.onSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +1,12 @@
|
|||||||
package com.herbron.moodl.DataManagers.ExchangeManager;
|
package com.herbron.moodl.DataManagers.ExchangeManager;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.binance.api.client.BinanceApiClientFactory;
|
import com.binance.api.client.BinanceApiClientFactory;
|
||||||
import com.binance.api.client.BinanceApiRestClient;
|
import com.binance.api.client.BinanceApiRestClient;
|
||||||
import com.binance.api.client.domain.account.Account;
|
import com.binance.api.client.domain.account.Account;
|
||||||
import com.binance.api.client.domain.account.AssetBalance;
|
import com.binance.api.client.domain.account.AssetBalance;
|
||||||
import com.binance.api.client.domain.account.Trade;
|
import com.binance.api.client.domain.account.Trade;
|
||||||
import com.binance.api.client.exception.BinanceApiException;
|
import com.binance.api.client.exception.BinanceApiException;
|
||||||
|
import com.herbron.moodl.DataNotifiers.BinanceUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -23,6 +22,8 @@ public class BinanceManager extends Exchange {
|
|||||||
private ArrayList<com.herbron.moodl.DataManagers.CurrencyData.Trade> trades;
|
private ArrayList<com.herbron.moodl.DataManagers.CurrencyData.Trade> trades;
|
||||||
private static List<String> pairSymbolList;
|
private static List<String> pairSymbolList;
|
||||||
|
|
||||||
|
private List<BinanceUpdateNotifierInterface> binanceUpdateNotifierInterfaceList;
|
||||||
|
|
||||||
public BinanceManager(Exchange exchange)
|
public BinanceManager(Exchange exchange)
|
||||||
{
|
{
|
||||||
super(exchange.id, exchange.name, exchange.type, exchange.description, exchange.publicKey, exchange.privateKey, exchange.isEnabled);
|
super(exchange.id, exchange.name, exchange.type, exchange.description, exchange.publicKey, exchange.privateKey, exchange.isEnabled);
|
||||||
@ -30,6 +31,16 @@ public class BinanceManager extends Exchange {
|
|||||||
createPairSymbolList();
|
createPairSymbolList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addListener(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface)
|
||||||
|
{
|
||||||
|
if(binanceUpdateNotifierInterfaceList == null)
|
||||||
|
{
|
||||||
|
binanceUpdateNotifierInterfaceList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
binanceUpdateNotifierInterfaceList.add(binanceUpdateNotifierInterface);
|
||||||
|
}
|
||||||
|
|
||||||
private void createPairSymbolList()
|
private void createPairSymbolList()
|
||||||
{
|
{
|
||||||
pairSymbolList = new ArrayList<>();
|
pairSymbolList = new ArrayList<>();
|
||||||
@ -40,7 +51,7 @@ public class BinanceManager extends Exchange {
|
|||||||
pairSymbolList.add("USDT");
|
pairSymbolList.add("USDT");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBalance(BinanceCallBack callBack)
|
public void updateBalance()
|
||||||
{
|
{
|
||||||
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey);
|
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey);
|
||||||
|
|
||||||
@ -57,20 +68,26 @@ public class BinanceManager extends Exchange {
|
|||||||
if(Double.parseDouble(assets.get(i).getFree()) > 0 || Double.parseDouble(assets.get(i).getLocked()) > 0)
|
if(Double.parseDouble(assets.get(i).getFree()) > 0 || Double.parseDouble(assets.get(i).getLocked()) > 0)
|
||||||
{
|
{
|
||||||
//balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked())));
|
//balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked())));
|
||||||
if(!assets.get(i).getAsset().equals("VEN"))
|
if(!assets.get(i).getAsset().equals("VET"))
|
||||||
{
|
{
|
||||||
balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked())));
|
balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callBack.onSuccess();
|
for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
binanceUpdateNotifierInterface.onBinanceBalanceUpdateSuccess();
|
||||||
|
}
|
||||||
} catch (BinanceApiException e) {
|
} catch (BinanceApiException e) {
|
||||||
callBack.onError(e.getMessage());
|
for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
binanceUpdateNotifierInterface.onBinanceBalanceUpdateError(id, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTrades(BinanceCallBack callBack, String symbol)
|
public void updateTrades(String symbol)
|
||||||
{
|
{
|
||||||
trades = new ArrayList<>();
|
trades = new ArrayList<>();
|
||||||
|
|
||||||
@ -82,7 +99,10 @@ public class BinanceManager extends Exchange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callBack.onSuccess();
|
for(BinanceUpdateNotifierInterface binanceUpdateNotifierInterface : binanceUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
binanceUpdateNotifierInterface.onBinanceTradesUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTrades(BinanceCallBack callBack, String symbol, long fromId)
|
public void updateTrades(BinanceCallBack callBack, String symbol, long fromId)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.herbron.moodl.DataManagers.ExchangeManager;
|
package com.herbron.moodl.DataManagers.ExchangeManager;
|
||||||
|
|
||||||
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Exchange {
|
public class Exchange {
|
||||||
|
|
||||||
protected int id;
|
protected int id;
|
||||||
@ -9,6 +13,7 @@ public class Exchange {
|
|||||||
protected String publicKey;
|
protected String publicKey;
|
||||||
protected String privateKey;
|
protected String privateKey;
|
||||||
protected boolean isEnabled;
|
protected boolean isEnabled;
|
||||||
|
private List<Pair> pairs;
|
||||||
|
|
||||||
public Exchange(int id, String name, int type, String description, String publicKey, String privateKey, boolean isEnabled)
|
public Exchange(int id, String name, int type, String description, String publicKey, String privateKey, boolean isEnabled)
|
||||||
{
|
{
|
||||||
@ -21,6 +26,12 @@ public class Exchange {
|
|||||||
this.isEnabled = isEnabled;
|
this.isEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Exchange(String name, List<Pair> pairs)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.pairs = pairs;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnabled()
|
public boolean isEnabled()
|
||||||
{
|
{
|
||||||
return isEnabled;
|
return isEnabled;
|
||||||
|
@ -11,6 +11,7 @@ import com.android.volley.VolleyError;
|
|||||||
import com.android.volley.toolbox.JsonArrayRequest;
|
import com.android.volley.toolbox.JsonArrayRequest;
|
||||||
import com.android.volley.toolbox.Volley;
|
import com.android.volley.toolbox.Volley;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
import com.herbron.moodl.DataNotifiers.HitBTCUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -39,6 +40,8 @@ public class HitBtcManager extends Exchange {
|
|||||||
private List<Currency> balance;
|
private List<Currency> balance;
|
||||||
private android.content.Context context;
|
private android.content.Context context;
|
||||||
|
|
||||||
|
private List<HitBTCUpdateNotifierInterface> hitBTCUpdateNotifierInterfaceList;
|
||||||
|
|
||||||
public HitBtcManager(android.content.Context context, Exchange exchange)
|
public HitBtcManager(android.content.Context context, Exchange exchange)
|
||||||
{
|
{
|
||||||
super(exchange.id, exchange.name, exchange.type, exchange.description, exchange.publicKey, exchange.privateKey, exchange.isEnabled);
|
super(exchange.id, exchange.name, exchange.type, exchange.description, exchange.publicKey, exchange.privateKey, exchange.isEnabled);
|
||||||
@ -47,6 +50,16 @@ public class HitBtcManager extends Exchange {
|
|||||||
requestQueue = Volley.newRequestQueue(context);
|
requestQueue = Volley.newRequestQueue(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addListener(HitBTCUpdateNotifierInterface hitBTCUpdateNotifierInterface)
|
||||||
|
{
|
||||||
|
if(hitBTCUpdateNotifierInterfaceList == null)
|
||||||
|
{
|
||||||
|
hitBTCUpdateNotifierInterfaceList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
hitBTCUpdateNotifierInterfaceList.add(hitBTCUpdateNotifierInterface);
|
||||||
|
}
|
||||||
|
|
||||||
private void createPairSymbolList()
|
private void createPairSymbolList()
|
||||||
{
|
{
|
||||||
pairSymbolList = new ArrayList<>();
|
pairSymbolList = new ArrayList<>();
|
||||||
@ -57,11 +70,6 @@ public class HitBtcManager extends Exchange {
|
|||||||
pairSymbolList.add("USDT");
|
pairSymbolList.add("USDT");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTrades(final HitBtcCallBack callBack, String symbol, String pairSymbol)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeBalanceSymbols()
|
private void mergeBalanceSymbols()
|
||||||
{
|
{
|
||||||
List<Currency> mergedBalance = new ArrayList<>();
|
List<Currency> mergedBalance = new ArrayList<>();
|
||||||
@ -88,7 +96,7 @@ public class HitBtcManager extends Exchange {
|
|||||||
balance = mergedBalance;
|
balance = mergedBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateGlobalBalance(final HitBtcCallBack masterCallBack)
|
public void updateGlobalBalance()
|
||||||
{
|
{
|
||||||
isTradingBalanceUpdated = false;
|
isTradingBalanceUpdated = false;
|
||||||
isBalanceUpdated = false;
|
isBalanceUpdated = false;
|
||||||
@ -103,13 +111,20 @@ public class HitBtcManager extends Exchange {
|
|||||||
if(isTradingBalanceUpdated)
|
if(isTradingBalanceUpdated)
|
||||||
{
|
{
|
||||||
mergeBalanceSymbols();
|
mergeBalanceSymbols();
|
||||||
masterCallBack.onSuccess();
|
|
||||||
|
for(HitBTCUpdateNotifierInterface hitBTCUpdateNotifierInterface : hitBTCUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
hitBTCUpdateNotifierInterface.onHitBTCBalanceUpdateSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(String error) {
|
public void onError(String error) {
|
||||||
masterCallBack.onError(error);
|
for(HitBTCUpdateNotifierInterface hitBTCUpdateNotifierInterface : hitBTCUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
hitBTCUpdateNotifierInterface.onHitBTCBalanceUpdateError(id, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,13 +136,20 @@ public class HitBtcManager extends Exchange {
|
|||||||
if(isBalanceUpdated)
|
if(isBalanceUpdated)
|
||||||
{
|
{
|
||||||
mergeBalanceSymbols();
|
mergeBalanceSymbols();
|
||||||
masterCallBack.onSuccess();
|
|
||||||
|
for(HitBTCUpdateNotifierInterface hitBTCUpdateNotifierInterface : hitBTCUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
hitBTCUpdateNotifierInterface.onHitBTCBalanceUpdateSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(String error) {
|
public void onError(String error) {
|
||||||
masterCallBack.onError(error);
|
for(HitBTCUpdateNotifierInterface hitBTCUpdateNotifierInterface : hitBTCUpdateNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
hitBTCUpdateNotifierInterface.onHitBTCBalanceUpdateError(id, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,352 @@
|
|||||||
|
package com.herbron.moodl.DataManagers.InfoAPIManagers;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.volley.Request;
|
||||||
|
import com.android.volley.RequestQueue;
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
import com.android.volley.toolbox.Volley;
|
||||||
|
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Guitoune on 22/04/2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CoinmarketCapAPIManager {
|
||||||
|
|
||||||
|
final private static String LISTINGURL = "https://api.coinmarketcap.com/v2/listings/";
|
||||||
|
final private static String TICKERLISTURL1 = "https://api.coinmarketcap.com/v2/ticker/?start=";
|
||||||
|
|
||||||
|
|
||||||
|
private static final String topCurrenciesUrl = "https://api.coinmarketcap.com/v2/ticker/?limit=9&convert=";
|
||||||
|
private static final String marketCapUrl = "https://api.coinmarketcap.com/v2/global/?convert=";
|
||||||
|
|
||||||
|
private RequestQueue requestQueue;
|
||||||
|
private List<Currency> currencyTickerList;
|
||||||
|
private static CoinmarketCapAPIManager INSTANCE;
|
||||||
|
private boolean upToDate;
|
||||||
|
|
||||||
|
private List<Currency> topCurrencies;
|
||||||
|
private long marketCap;
|
||||||
|
private long dayVolume;
|
||||||
|
private String active_crypto;
|
||||||
|
private String active_markets;
|
||||||
|
|
||||||
|
private List<CoinmarketcapNotifierInterface> coinmarketcapNotifierInterfaceList;
|
||||||
|
|
||||||
|
private CoinmarketCapAPIManager(Context context)
|
||||||
|
{
|
||||||
|
requestQueue = Volley.newRequestQueue(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized CoinmarketCapAPIManager getInstance(Context context)
|
||||||
|
{
|
||||||
|
if(INSTANCE == null)
|
||||||
|
{
|
||||||
|
INSTANCE = new CoinmarketCapAPIManager(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(CoinmarketcapNotifierInterface coinmarketcapNotifierInterface)
|
||||||
|
{
|
||||||
|
if(coinmarketcapNotifierInterfaceList == null)
|
||||||
|
{
|
||||||
|
coinmarketcapNotifierInterfaceList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
coinmarketcapNotifierInterfaceList.add(coinmarketcapNotifierInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUpToDate()
|
||||||
|
{
|
||||||
|
if(currencyTickerList == null)
|
||||||
|
{
|
||||||
|
upToDate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return upToDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCurrenciesFrom(int indexFrom, final String toSymbol)
|
||||||
|
{
|
||||||
|
String requetsString = TICKERLISTURL1 + indexFrom + "&limit=50&convert=" + toSymbol;
|
||||||
|
|
||||||
|
StringRequest strRequest = new StringRequest(Request.Method.GET, requetsString,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
if (response.length() > 0)
|
||||||
|
{
|
||||||
|
processTickersResult(response, toSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestQueue.add(strRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateListing()
|
||||||
|
{
|
||||||
|
currencyTickerList = new ArrayList<>();
|
||||||
|
StringRequest strRequest = new StringRequest(Request.Method.GET, LISTINGURL,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
if (response.length() > 0) {
|
||||||
|
processTickerListResult(response);
|
||||||
|
}
|
||||||
|
upToDate = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
upToDate = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestQueue.add(strRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTickerIdForSymbol(String symbol)
|
||||||
|
{
|
||||||
|
int tickerId = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while(!currencyTickerList.get(i).getSymbol().equals(symbol) && currencyTickerList.size() > i+1)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currencyTickerList.get(i).getSymbol().equals(symbol))
|
||||||
|
{
|
||||||
|
tickerId = currencyTickerList.get(i).getTickerId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tickerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processTickersResult(String response, String toSymbol)
|
||||||
|
{
|
||||||
|
List<Currency> currencyList = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject masterJsonObject = new JSONObject(response);
|
||||||
|
|
||||||
|
if(masterJsonObject.keys().hasNext())
|
||||||
|
{
|
||||||
|
JSONObject currencyJsonObject = masterJsonObject.getJSONObject(masterJsonObject.keys().next());
|
||||||
|
Iterator<?> keys = currencyJsonObject.keys();
|
||||||
|
|
||||||
|
while(keys.hasNext())
|
||||||
|
{
|
||||||
|
String key = keys.next().toString();
|
||||||
|
JSONObject subCurrencyJsonObject = currencyJsonObject.getJSONObject(key);
|
||||||
|
Currency newCurrency = new Currency(subCurrencyJsonObject.getString("name"), subCurrencyJsonObject.getString("symbol"), subCurrencyJsonObject.getInt("id"));
|
||||||
|
newCurrency.setRank(subCurrencyJsonObject.getInt("rank"));
|
||||||
|
JSONObject quoteJsonObject = subCurrencyJsonObject.getJSONObject("quotes");
|
||||||
|
JSONObject symJsonObject = quoteJsonObject.getJSONObject(toSymbol);
|
||||||
|
newCurrency.setValue(symJsonObject.getDouble("price"));
|
||||||
|
newCurrency.setDayFluctuationPercentage((float) symJsonObject.getDouble("percent_change_24h"));
|
||||||
|
newCurrency.setDayFluctuation(newCurrency.getDayFluctuationPercentage() * newCurrency.getValue() / 100);
|
||||||
|
|
||||||
|
currencyList.add(newCurrency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CoinmarketcapNotifierInterface coinmarketcapNotifierInterface : coinmarketcapNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
coinmarketcapNotifierInterface.onCurrenciesRetrieved(currencyList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processTickerListResult(String response)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSONObject dataJsonObject = new JSONObject(response);
|
||||||
|
JSONArray dataJsonArray = dataJsonObject.getJSONArray("data");
|
||||||
|
|
||||||
|
for(int i = 0; i < dataJsonArray.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject currencyJsonObject = dataJsonArray.getJSONObject(i);
|
||||||
|
currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id")));
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CoinmarketcapNotifierInterface coinmarketcapNotifierInterface : coinmarketcapNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
coinmarketcapNotifierInterface.onListingUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTopCurrencies(final String toSymbol)
|
||||||
|
{
|
||||||
|
String requestString = topCurrenciesUrl + toSymbol;
|
||||||
|
|
||||||
|
topCurrencies = new ArrayList<>();
|
||||||
|
|
||||||
|
StringRequest strRequest = new StringRequest(Request.Method.GET, requestString,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
if (response.length() > 0) {
|
||||||
|
processTopCurrencies(response, toSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CoinmarketcapNotifierInterface coinmarketcapNotifierInterface : coinmarketcapNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
coinmarketcapNotifierInterface.onTopCurrenciesUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestQueue.add(strRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMarketCap(final String toSymbol)
|
||||||
|
{
|
||||||
|
String requestString = marketCapUrl + toSymbol;
|
||||||
|
|
||||||
|
StringRequest strRequest = new StringRequest(Request.Method.GET, requestString,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
if (response.length() > 0) {
|
||||||
|
processMarketCapData(response, toSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(CoinmarketcapNotifierInterface coinmarketcapNotifierInterface : coinmarketcapNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
coinmarketcapNotifierInterface.onMarketCapUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestQueue.add(strRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processMarketCapData(String response, String toSymbol)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
|
JSONObject dataJsonObject = jsonObject.getJSONObject("data");
|
||||||
|
JSONObject quotesJsonObject = dataJsonObject.getJSONObject("quotes");
|
||||||
|
JSONObject valuesJsonObject = quotesJsonObject.getJSONObject(toSymbol);
|
||||||
|
|
||||||
|
active_crypto = dataJsonObject.getString("active_cryptocurrencies");
|
||||||
|
active_markets = dataJsonObject.getString("active_markets");
|
||||||
|
marketCap = valuesJsonObject.getLong("total_market_cap");
|
||||||
|
dayVolume = valuesJsonObject.getLong("total_volume_24h");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActive_crypto()
|
||||||
|
{
|
||||||
|
return active_crypto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActive_markets()
|
||||||
|
{
|
||||||
|
return active_markets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Currency> getTopCurrencies()
|
||||||
|
{
|
||||||
|
return topCurrencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDayVolume()
|
||||||
|
{
|
||||||
|
return dayVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processTopCurrencies(String response, String toSymbol)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSONObject masterJsonObject = new JSONObject(response);
|
||||||
|
|
||||||
|
if(masterJsonObject.keys().hasNext())
|
||||||
|
{
|
||||||
|
JSONObject currencyJsonObject = masterJsonObject.getJSONObject(masterJsonObject.keys().next());
|
||||||
|
Iterator<?> keys = currencyJsonObject.keys();
|
||||||
|
|
||||||
|
while(keys.hasNext())
|
||||||
|
{
|
||||||
|
String key = keys.next().toString();
|
||||||
|
JSONObject subCurrencyJsonObject = currencyJsonObject.getJSONObject(key);
|
||||||
|
Currency newCurrency = new Currency(subCurrencyJsonObject.getString("name"), subCurrencyJsonObject.getString("symbol"), subCurrencyJsonObject.getInt("id"));
|
||||||
|
JSONObject quoteJsonObject = subCurrencyJsonObject.getJSONObject("quotes");
|
||||||
|
JSONObject symJsonObject = quoteJsonObject.getJSONObject(toSymbol);
|
||||||
|
newCurrency.setMarketCapitalization(symJsonObject.getDouble("market_cap"));
|
||||||
|
newCurrency.setVolume24h(symJsonObject.getDouble("volume_24h"));
|
||||||
|
|
||||||
|
topCurrencies.add(newCurrency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Currency getCurrencyFromSymbol(String symbol)
|
||||||
|
{
|
||||||
|
Currency returnedCurrency = null;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(symbol.equals(topCurrencies.get(index).getSymbol()))
|
||||||
|
{
|
||||||
|
returnedCurrency = topCurrencies.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
} while(index < topCurrencies.size() && returnedCurrency == null);
|
||||||
|
|
||||||
|
|
||||||
|
return returnedCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMarketCap()
|
||||||
|
{
|
||||||
|
return marketCap;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.herbron.moodl.DataManagers.CurrencyData;
|
package com.herbron.moodl.DataManagers.InfoAPIManagers;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
@ -10,12 +10,16 @@ import com.android.volley.Response;
|
|||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.android.volley.toolbox.Volley;
|
import com.android.volley.toolbox.Volley;
|
||||||
import com.herbron.moodl.DataManagers.BalanceManager;
|
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -24,30 +28,64 @@ import java.util.regex.Pattern;
|
|||||||
* Created by Tiji on 11/04/2018.
|
* Created by Tiji on 11/04/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CurrencyDetailsList {
|
public class CryptocompareApiManager {
|
||||||
|
|
||||||
final private static String DETAILURL = "https://min-api.cryptocompare.com/data/all/coinlist";
|
final private static String DETAILURL = "https://min-api.cryptocompare.com/data/all/coinlist";
|
||||||
|
final private static String EXCHANGEURL = "https://min-api.cryptocompare.com/data/all/exchanges";
|
||||||
private RequestQueue requestQueue;
|
private RequestQueue requestQueue;
|
||||||
private LinkedHashMap<String, String> coinInfosHashmap;
|
private LinkedHashMap<String, String> coinInfosHashmap;
|
||||||
private static CurrencyDetailsList INSTANCE;
|
private List<Exchange> exchangeList;
|
||||||
private boolean upToDate;
|
private static CryptocompareApiManager INSTANCE;
|
||||||
|
private boolean exchangesUpToDate;
|
||||||
|
private boolean detailsUpToDate;
|
||||||
|
|
||||||
private CurrencyDetailsList(Context context)
|
private List<CryptocompareNotifierInterface> cryptocompareNotifierInterfaceList;
|
||||||
|
|
||||||
|
private CryptocompareApiManager(Context context)
|
||||||
{
|
{
|
||||||
requestQueue = Volley.newRequestQueue(context);
|
requestQueue = Volley.newRequestQueue(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized CurrencyDetailsList getInstance(Context context)
|
public static synchronized CryptocompareApiManager getInstance(Context context)
|
||||||
{
|
{
|
||||||
if(INSTANCE == null)
|
if(INSTANCE == null)
|
||||||
{
|
{
|
||||||
INSTANCE = new CurrencyDetailsList(context);
|
INSTANCE = new CryptocompareApiManager(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final BalanceManager.IconCallBack callBack)
|
public void addListener(CryptocompareNotifierInterface cryptocompareNotifierInterface)
|
||||||
|
{
|
||||||
|
if(cryptocompareNotifierInterfaceList == null)
|
||||||
|
{
|
||||||
|
cryptocompareNotifierInterfaceList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
cryptocompareNotifierInterfaceList.add(cryptocompareNotifierInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateExchangeList()
|
||||||
|
{
|
||||||
|
StringRequest stringRequest = new StringRequest(Request.Method.GET, EXCHANGEURL,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
processExchangeResult(response);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestQueue.add(stringRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDetails()
|
||||||
{
|
{
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, DETAILURL,
|
StringRequest strRequest = new StringRequest(Request.Method.GET, DETAILURL,
|
||||||
new Response.Listener<String>() {
|
new Response.Listener<String>() {
|
||||||
@ -55,7 +93,7 @@ public class CurrencyDetailsList {
|
|||||||
public void onResponse(String response) {
|
public void onResponse(String response) {
|
||||||
|
|
||||||
if (response.length() > 0) {
|
if (response.length() > 0) {
|
||||||
processDetailResult(response, callBack);
|
processDetailResult(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -69,17 +107,72 @@ public class CurrencyDetailsList {
|
|||||||
requestQueue.add(strRequest);
|
requestQueue.add(strRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpToDate()
|
public boolean isExchangesUpToDate()
|
||||||
|
{
|
||||||
|
if(exchangeList == null)
|
||||||
|
{
|
||||||
|
exchangesUpToDate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exchangesUpToDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDetailsUpToDate()
|
||||||
{
|
{
|
||||||
if(coinInfosHashmap == null)
|
if(coinInfosHashmap == null)
|
||||||
{
|
{
|
||||||
upToDate = false;
|
detailsUpToDate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return upToDate;
|
return detailsUpToDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processDetailResult(String response, final BalanceManager.IconCallBack callBack)
|
private void processExchangeResult(String response)
|
||||||
|
{
|
||||||
|
exchangeList = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject mainJsonObject = new JSONObject(response);
|
||||||
|
Iterator<String> exchangeIterator = mainJsonObject.keys();
|
||||||
|
|
||||||
|
while(exchangeIterator.hasNext())
|
||||||
|
{
|
||||||
|
String exchangeKey = exchangeIterator.next();
|
||||||
|
JSONObject exchangeJsonObject = mainJsonObject.getJSONObject(exchangeKey);
|
||||||
|
Iterator<String> pairIterator = exchangeJsonObject.keys();
|
||||||
|
|
||||||
|
while(pairIterator.hasNext())
|
||||||
|
{
|
||||||
|
String pairKey = pairIterator.next();
|
||||||
|
JSONArray pairJsonArray = exchangeJsonObject.getJSONArray(pairKey);
|
||||||
|
|
||||||
|
List<Pair> pairList = new ArrayList<>();
|
||||||
|
|
||||||
|
for(int i = 0; i < pairJsonArray.length(); i++)
|
||||||
|
{
|
||||||
|
pairList.add(new Pair(pairKey, pairJsonArray.get(i).toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
exchangeList.add(new Exchange(exchangeKey, pairList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CryptocompareNotifierInterface cryptocompareNotifierInterface : cryptocompareNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
cryptocompareNotifierInterface.onExchangesUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.d("moodl", "Error while processing exchange result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Exchange> getExchangeList()
|
||||||
|
{
|
||||||
|
return exchangeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processDetailResult(String response)
|
||||||
{
|
{
|
||||||
response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"BaseImageUrl\""));
|
response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"BaseImageUrl\""));
|
||||||
String[] tab = response.split(Pattern.quote("},"));
|
String[] tab = response.split(Pattern.quote("},"));
|
||||||
@ -113,9 +206,12 @@ public class CurrencyDetailsList {
|
|||||||
|
|
||||||
sortDetails();
|
sortDetails();
|
||||||
|
|
||||||
upToDate = true;
|
detailsUpToDate = true;
|
||||||
|
|
||||||
callBack.onSuccess();
|
for(CryptocompareNotifierInterface cryptocompareNotifierInterface : cryptocompareNotifierInterfaceList)
|
||||||
|
{
|
||||||
|
cryptocompareNotifierInterface.onDetailsUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortDetails()
|
private void sortDetails()
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.herbron.moodl.DataManagers.InfoAPIManagers;
|
||||||
|
|
||||||
|
public class Pair {
|
||||||
|
|
||||||
|
private String from;
|
||||||
|
private String to;
|
||||||
|
|
||||||
|
public Pair(String from, String to)
|
||||||
|
{
|
||||||
|
this.from = from;
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String symbol)
|
||||||
|
{
|
||||||
|
return symbol.equals(from) || symbol.equals(to);
|
||||||
|
}
|
||||||
|
}
|
@ -1,182 +0,0 @@
|
|||||||
package com.herbron.moodl.DataManagers;
|
|
||||||
|
|
||||||
import com.android.volley.Request;
|
|
||||||
import com.android.volley.RequestQueue;
|
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
|
||||||
import com.android.volley.toolbox.Volley;
|
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Guitoune on 02/03/2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class MarketCapManager {
|
|
||||||
|
|
||||||
private static final String topCurrenciesUrl = "https://api.coinmarketcap.com/v2/ticker/?limit=9&convert=";
|
|
||||||
private static final String marketCapUrl = "https://api.coinmarketcap.com/v2/global/?convert=";
|
|
||||||
private RequestQueue requestQueue;
|
|
||||||
private List<Currency> topCurrencies;
|
|
||||||
private long marketCap;
|
|
||||||
private long dayVolume;
|
|
||||||
private String active_crypto;
|
|
||||||
private String active_markets;
|
|
||||||
|
|
||||||
public MarketCapManager(android.content.Context context)
|
|
||||||
{
|
|
||||||
requestQueue = Volley.newRequestQueue(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTopCurrencies(final VolleyCallBack callBack, final String toSymbol)
|
|
||||||
{
|
|
||||||
String requestString = topCurrenciesUrl + toSymbol;
|
|
||||||
|
|
||||||
topCurrencies = new ArrayList<>();
|
|
||||||
|
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, requestString,
|
|
||||||
new Response.Listener<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(String response) {
|
|
||||||
if (response.length() > 0) {
|
|
||||||
processTopCurrencies(response, toSymbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
callBack.onSuccess();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requestQueue.add(strRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateMarketCap(final VolleyCallBack callBack, final String toSymbol)
|
|
||||||
{
|
|
||||||
String requestString = marketCapUrl + toSymbol;
|
|
||||||
|
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, requestString,
|
|
||||||
new Response.Listener<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(String response) {
|
|
||||||
if (response.length() > 0) {
|
|
||||||
processMarketCapData(response, toSymbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
callBack.onSuccess();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requestQueue.add(strRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processMarketCapData(String response, String toSymbol)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = new JSONObject(response);
|
|
||||||
JSONObject dataJsonObject = jsonObject.getJSONObject("data");
|
|
||||||
JSONObject quotesJsonObject = dataJsonObject.getJSONObject("quotes");
|
|
||||||
JSONObject valuesJsonObject = quotesJsonObject.getJSONObject(toSymbol);
|
|
||||||
|
|
||||||
active_crypto = dataJsonObject.getString("active_cryptocurrencies");
|
|
||||||
active_markets = dataJsonObject.getString("active_markets");
|
|
||||||
marketCap = valuesJsonObject.getLong("total_market_cap");
|
|
||||||
dayVolume = valuesJsonObject.getLong("total_volume_24h");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getActive_crypto()
|
|
||||||
{
|
|
||||||
return active_crypto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getActive_markets()
|
|
||||||
{
|
|
||||||
return active_markets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Currency> getTopCurrencies()
|
|
||||||
{
|
|
||||||
return topCurrencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDayVolume()
|
|
||||||
{
|
|
||||||
return dayVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processTopCurrencies(String response, String toSymbol)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
JSONObject masterJsonObject = new JSONObject(response);
|
|
||||||
|
|
||||||
if(masterJsonObject.keys().hasNext())
|
|
||||||
{
|
|
||||||
JSONObject currencyJsonObject = masterJsonObject.getJSONObject(masterJsonObject.keys().next());
|
|
||||||
Iterator<?> keys = currencyJsonObject.keys();
|
|
||||||
|
|
||||||
while(keys.hasNext())
|
|
||||||
{
|
|
||||||
String key = keys.next().toString();
|
|
||||||
JSONObject subCurrencyJsonObject = currencyJsonObject.getJSONObject(key);
|
|
||||||
Currency newCurrency = new Currency(subCurrencyJsonObject.getString("name"), subCurrencyJsonObject.getString("symbol"), subCurrencyJsonObject.getInt("id"));
|
|
||||||
JSONObject quoteJsonObject = subCurrencyJsonObject.getJSONObject("quotes");
|
|
||||||
JSONObject symJsonObject = quoteJsonObject.getJSONObject(toSymbol);
|
|
||||||
newCurrency.setMarketCapitalization(symJsonObject.getDouble("market_cap"));
|
|
||||||
newCurrency.setVolume24h(symJsonObject.getDouble("volume_24h"));
|
|
||||||
|
|
||||||
topCurrencies.add(newCurrency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Currency getCurrencyFromSymbol(String symbol)
|
|
||||||
{
|
|
||||||
Currency returnedCurrency = null;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(symbol.equals(topCurrencies.get(index).getSymbol()))
|
|
||||||
{
|
|
||||||
returnedCurrency = topCurrencies.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
} while(index < topCurrencies.size() && returnedCurrency == null);
|
|
||||||
|
|
||||||
|
|
||||||
return returnedCurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMarketCap()
|
|
||||||
{
|
|
||||||
return marketCap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface VolleyCallBack
|
|
||||||
{
|
|
||||||
void onSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.herbron.moodl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Administrator on 17/06/2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface DataNotifierInterface {
|
|
||||||
|
|
||||||
void onTickerListUpdated();
|
|
||||||
|
|
||||||
void onDetailsUpdated();
|
|
||||||
|
|
||||||
void onBalanceDataUpdated();
|
|
||||||
|
|
||||||
void onBalanceError(String error);
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Administrator on 17/06/2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface BalanceUpdateNotifierInterface {
|
||||||
|
|
||||||
|
void onBalanceDataUpdated();
|
||||||
|
|
||||||
|
void onBalanceError(String error);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
public interface BinanceUpdateNotifierInterface {
|
||||||
|
|
||||||
|
void onBinanceTradesUpdated();
|
||||||
|
|
||||||
|
void onBinanceBalanceUpdateSuccess();
|
||||||
|
|
||||||
|
void onBinanceBalanceUpdateError(int accountId, String error);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CoinmarketcapNotifierInterface {
|
||||||
|
|
||||||
|
void onCurrenciesRetrieved(List<Currency> currencyList);
|
||||||
|
|
||||||
|
void onTopCurrenciesUpdated();
|
||||||
|
|
||||||
|
void onMarketCapUpdated();
|
||||||
|
|
||||||
|
void onListingUpdated();
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
public interface CryptocompareNotifierInterface {
|
||||||
|
|
||||||
|
void onDetailsUpdated();
|
||||||
|
|
||||||
|
void onExchangesUpdated();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
public interface HitBTCUpdateNotifierInterface {
|
||||||
|
|
||||||
|
void onHitBTCBalanceUpdateSuccess();
|
||||||
|
|
||||||
|
void onHitBTCBalanceUpdateError(int accountId, String error);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.herbron.moodl.DataNotifiers;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
public interface MoodlboxNotifierInterface {
|
||||||
|
|
||||||
|
void onBitmapDownloaded(Bitmap bitmap);
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ import android.widget.LinearLayout;
|
|||||||
|
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -22,14 +22,14 @@ import java.util.List;
|
|||||||
public class OverviewListAdapter extends ArrayAdapter<Currency> {
|
public class OverviewListAdapter extends ArrayAdapter<Currency> {
|
||||||
|
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
private CurrencyDetailsList currencyDetailsList;
|
private CryptocompareApiManager cryptocompareApiManager;
|
||||||
|
|
||||||
public OverviewListAdapter(Context context, List<Currency> currencies, Activity activity)
|
public OverviewListAdapter(Context context, List<Currency> currencies, Activity activity)
|
||||||
{
|
{
|
||||||
super(context, android.R.layout.simple_expandable_list_item_1, currencies);
|
super(context, android.R.layout.simple_expandable_list_item_1, currencies);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
|
||||||
currencyDetailsList = CurrencyDetailsList.getInstance(getContext());
|
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -38,7 +38,7 @@ public class OverviewListAdapter extends ArrayAdapter<Currency> {
|
|||||||
{
|
{
|
||||||
Currency currency = getItem(position);
|
Currency currency = getItem(position);
|
||||||
|
|
||||||
currencyDetailsList.getCurrencyDetailsFromSymbol(currency.getSymbol());
|
cryptocompareApiManager.getCurrencyDetailsFromSymbol(currency.getSymbol());
|
||||||
|
|
||||||
CurrencyCardview currencyCardview = new CurrencyCardview(getContext(), currency, activity);
|
CurrencyCardview currencyCardview = new CurrencyCardview(getContext(), currency, activity);
|
||||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
@ -13,8 +12,8 @@ import android.view.View;
|
|||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
|
|
||||||
import com.herbron.moodl.Activities.HomeActivity;
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -207,7 +206,7 @@ public class MoodlBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getBitmapFromURL(String src, String symbol, Resources resources, Context context, HomeActivity.IconCallBack callBack)
|
public static void getBitmapFromURL(String src, String symbol, Resources resources, Context context, MoodlboxNotifierInterface callBack)
|
||||||
{
|
{
|
||||||
String size = src.substring(src.lastIndexOf("=") + 1, src.length());
|
String size = src.substring(src.lastIndexOf("=") + 1, src.length());
|
||||||
String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png";
|
String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png";
|
||||||
@ -240,7 +239,7 @@ public class MoodlBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callBack.onSuccess(result);
|
callBack.onBitmapDownloaded(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getColor(int id, Context context)
|
public static int getColor(int id, Context context)
|
||||||
@ -275,9 +274,9 @@ public class MoodlBox {
|
|||||||
return drawable;
|
return drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIconUrl(String symbol, CurrencyDetailsList currencyDetailsList)
|
public static String getIconUrl(String symbol, CryptocompareApiManager cryptocompareApiManager)
|
||||||
{
|
{
|
||||||
return getIconUrl(symbol, 50, currencyDetailsList);
|
return getIconUrl(symbol, 50, cryptocompareApiManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float convertDpToPx(float dp, Resources resources)
|
public static float convertDpToPx(float dp, Resources resources)
|
||||||
@ -285,12 +284,12 @@ public class MoodlBox {
|
|||||||
return dp * resources.getDisplayMetrics().density;
|
return dp * resources.getDisplayMetrics().density;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIconUrl(String symbol, int size, CurrencyDetailsList currencyDetailsList)
|
public static String getIconUrl(String symbol, int size, CryptocompareApiManager cryptocompareApiManager)
|
||||||
{
|
{
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol));
|
JSONObject jsonObject = new JSONObject(cryptocompareApiManager.getCoinInfosHashmap().get(symbol));
|
||||||
url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=" + size;
|
url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=" + size;
|
||||||
} catch (JSONException | NullPointerException e) {
|
} catch (JSONException | NullPointerException e) {
|
||||||
url = null;
|
url = null;
|
||||||
|
@ -1,15 +1,157 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@drawable/record_transaction_layout_background_buy">
|
android:background="@drawable/record_transaction_layout_background_buy">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:text="buy fragment"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:layout_margin="@dimen/margin"
|
||||||
android:layout_centerVertical="true"
|
android:orientation="vertical">
|
||||||
android:layout_centerHorizontal="true"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_exchangeName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/exchangeName_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/exchange"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_exchangePair"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/exchangePair_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/pair"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_amount"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/amount_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/activity_add_amount"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_buyPrice"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1.5">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/buyPrice_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/activity_purchase_price"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_buyDate"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/buyDate_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/activity_purchase_date"
|
||||||
|
android:focusable="false"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_totalValue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/totalValue_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/total_value"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_fees"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.15">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/fees_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/activity_fees"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/feesUnit_Spinner"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.85"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_note"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/note_editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/notes"
|
||||||
|
android:maxLines="4"
|
||||||
|
android:lines="4"
|
||||||
|
android:gravity="top"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatButton
|
||||||
|
android:id="@+id/saveExchangeButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:text="@string/save"
|
||||||
|
android:layout_marginBottom="@dimen/mdtp_minimum_margin_top_bottom"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
style="@style/Widget.AppCompat.Button.Colored"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
@ -16,8 +16,8 @@
|
|||||||
<string name="pref_title_gdax_publickey">Clé public</string>
|
<string name="pref_title_gdax_publickey">Clé public</string>
|
||||||
<string name="pref_title_gdax_privatekey">Clé privée</string>
|
<string name="pref_title_gdax_privatekey">Clé privée</string>
|
||||||
<string name="activity_add_amount">Montant</string>
|
<string name="activity_add_amount">Montant</string>
|
||||||
<string name="activity_purchased_price">Prix d\'achat</string>
|
<string name="activity_purchase_price">Prix d\'achat</string>
|
||||||
<string name="activity_purchased_date">Date d\'achat</string>
|
<string name="activity_purchase_date">Date d\'achat</string>
|
||||||
<string name="activity_fees">Frais</string>
|
<string name="activity_fees">Frais</string>
|
||||||
<string name="title_history">Historique</string>
|
<string name="title_history">Historique</string>
|
||||||
<string name="title_infos">Informations</string>
|
<string name="title_infos">Informations</string>
|
||||||
|
@ -127,8 +127,8 @@
|
|||||||
|
|
||||||
<!--Add transaction activity-->
|
<!--Add transaction activity-->
|
||||||
<string name="activity_add_amount">Amount</string>
|
<string name="activity_add_amount">Amount</string>
|
||||||
<string name="activity_purchased_price">Purchased price</string>
|
<string name="activity_purchase_price">Purchase price</string>
|
||||||
<string name="activity_purchased_date">Purchased date</string>
|
<string name="activity_purchase_date">Purchase date</string>
|
||||||
<string name="activity_fees">Fees</string>
|
<string name="activity_fees">Fees</string>
|
||||||
<string name="title_activity_currency_details" translatable="false">CurrencyDetailsActivity</string>
|
<string name="title_activity_currency_details" translatable="false">CurrencyDetailsActivity</string>
|
||||||
<string name="title_history">History charts</string>
|
<string name="title_history">History charts</string>
|
||||||
@ -261,6 +261,9 @@
|
|||||||
<string name="title_choose_coin">Choose a coin</string>
|
<string name="title_choose_coin">Choose a coin</string>
|
||||||
|
|
||||||
<!-- TODO: Remove or change this placeholder text -->
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
<string name="exchange">Exchange</string>
|
||||||
|
<string name="pair">Pair</string>
|
||||||
|
<string name="total_value">Total value</string>
|
||||||
|
<string name="notes">Notes</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user