diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java index 3685880..d136952 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java @@ -31,9 +31,9 @@ import com.nauk.moodl.Activities.HomeActivity; import com.nauk.moodl.Activities.SettingsActivity; import com.nauk.moodl.DataManagers.BalanceManager; import com.nauk.moodl.DataManagers.CurrencyData.Currency; +import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; import com.nauk.moodl.DataManagers.PreferencesManager; -import com.nauk.moodl.LayoutManagers.HomeLayoutGenerator; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -42,7 +42,6 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; @@ -56,7 +55,6 @@ public class Summary extends Fragment { private LinearLayout currencyLayout; private PreferencesManager preferencesManager; private BalanceManager balanceManager; - private HomeLayoutGenerator layoutGenerator; private SwipeRefreshLayout refreshLayout; private Dialog loadingDialog; private String defaultCurrency; @@ -85,7 +83,6 @@ public class Summary extends Fragment { preferencesManager = new PreferencesManager(getActivity()); balanceManager = new BalanceManager(getActivity()); - layoutGenerator = new HomeLayoutGenerator(getActivity()); currencyTickerList = new CurrencyTickerList(getActivity()); currencyLayout = fragmentView.findViewById(R.id.currencyListLayout); @@ -154,14 +151,16 @@ public class Summary extends Fragment { @Override public void run() { final List currencyView = new ArrayList<>(); + final List renderedCurrencies = new ArrayList<>(); if (balanceManager.getTotalBalance() != null) { for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { final Currency currency = balanceManager.getTotalBalance().get(i); - if (!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > preferencesManager.getMinimumAmount())) { - currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + if (!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { + //currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + renderedCurrencies.add(currency); } } } @@ -171,15 +170,18 @@ public class Summary extends Fragment { public void run() { currencyLayout.removeAllViews(); - for(int i = 0; i < currencyView.size(); i++) + for(int i = 0; i < renderedCurrencies.size(); i++) { - currencyLayout.addView(currencyView.get(i)); + //currencyLayout.addView(currencyView.get(i)); + currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), totalValue, preferencesManager.isBalanceHidden())); } if(loadingDialog.isShowing()) { loadingDialog.dismiss(); } + + handler.removeCallbacks(updateRunnable); } }); } @@ -302,6 +304,7 @@ public class Summary extends Fragment { coinCounter = 0; iconCounter = 0; detailsChecker = false; + tickersChecker = false; totalValue = 0; totalFluctuation = 0; @@ -309,7 +312,6 @@ public class Summary extends Fragment { private void adaptView() { - layoutRefresherRunnable.run(); } @@ -549,7 +551,6 @@ public class Summary extends Fragment { return null; } }.execute(); - handler.removeCallbacks(updateRunnable); } } @@ -619,16 +620,13 @@ public class Summary extends Fragment { { final Currency localCurrency = balanceManager.getTotalBalance().get(i); - if(balanceManager.getIconUrl(localCurrency.getSymbol()) != null) - { - getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new HomeActivity.IconCallBack() { - @Override - public void onSuccess(Bitmap bitmapIcon) { - localCurrency.setIcon(bitmapIcon); - countIcons(); - } - }); - } + getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new HomeActivity.IconCallBack() { + @Override + public void onSuccess(Bitmap bitmapIcon) { + localCurrency.setIcon(bitmapIcon); + countIcons(); + } + }); } return null; @@ -696,7 +694,6 @@ public class Summary extends Fragment { balanceManager.updateTotalBalance(new BalanceManager.VolleyCallBack() { @Override public void onSuccess() { - final List balance = balanceManager.getTotalBalance(); if(balanceManager.getTotalBalance().size() > 0) diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index cee11d7..940f48d 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -34,6 +34,7 @@ import com.nauk.moodl.Activities.HomeActivity; import com.nauk.moodl.Activities.SettingsActivity; import com.nauk.moodl.DataManagers.BalanceManager; import com.nauk.moodl.DataManagers.CurrencyData.Currency; +import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDetailsList; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; @@ -184,12 +185,6 @@ public class Watchlist extends Fragment { }); } - private void displayChartView() - { - expandH(view.findViewById(R.id.collapsableLayout)); - view.findViewById(R.id.LineChartView).invalidate(); - } - @Override public void onResume() { @@ -248,31 +243,17 @@ public class Watchlist extends Fragment { private void generateCards() { - final List watchlistViews = new ArrayList(); - ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews(); - Runnable newRunnable = new Runnable() { + getActivity().runOnUiThread(new Runnable() { @Override public void run() { - for(final Currency currency : watchlistManager.getWatchlist()) + for(Currency currency : watchlistManager.getWatchlist()) { - watchlistViews.add(getCurrencyCardFor(currency)); + ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(new CurrencyCardview(getContext(), currency)); } - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - for(int i = 0; i < watchlistViews.size(); i++) - { - ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(watchlistViews.get(i), 0); - } - } - }); } - }; - - newRunnable.run(); + }); if(refreshLayout.isRefreshing()) { @@ -290,104 +271,6 @@ public class Watchlist extends Fragment { } } - private View getCurrencyCardFor(final Currency currency) - { - final View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null); - - card.setTag(currency.getSymbol()); - - ((TextView) card.findViewById(R.id.currencyFluctuationTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getActivity())); - ((TextView) card.findViewById(R.id.currencyValueTextView)) - .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getActivity())); - - ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getActivity())); - ((TextView) card.findViewById(R.id.currencyNameTextView)) - .setText(currency.getName()); - ((TextView) card.findViewById(R.id.currencySymbolTextView)) - .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getActivity())); - ((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); - - ((LineChart) card.findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); - - Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable(); - arrowDrawable.mutate(); - arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - arrowDrawable.invalidateSelf(); - - Drawable progressDrawable = ((ProgressBar) card.findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable(); - progressDrawable.mutate(); - progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressDrawable.invalidateSelf(); - - card.findViewById(R.id.deleteCardWatchlist).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - collapseH(card); - DatabaseManager databaseManager = new DatabaseManager(getActivity()); - databaseManager.deleteCurrencyFromWatchlist(currency.getSymbol()); - } - }); - - updateColor(card, currency); - - card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(getActivity(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - getActivity().getApplicationContext().startActivity(intent); - } - }); - - card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - card.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) - { - collapseH(view.findViewById(R.id.collapsableLayout)); - } - else - { - view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); - view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); - - displayChartView(); - - if (currency.getHistoryMinutes() == null) { - currency.updateHistoryMinutes(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - if(currency.getHistoryMinutes() != null) - { - setupLineChart(view, 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 - { - displayChartView(); - view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); - view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); - } - } - } - }); - - return card; - } - private LineData generateData(Currency currency) { LineDataSet dataSet; @@ -427,42 +310,6 @@ public class Watchlist extends Fragment { return transColor ; } - private void setupLineChart(View view, final Currency currency) - { - LineChart lineChart = view.findViewById(R.id.LineChartView); - - lineChart.setDrawGridBackground(false); - lineChart.setDrawBorders(false); - lineChart.setDrawMarkers(false); - lineChart.setDoubleTapToZoomEnabled(false); - lineChart.setPinchZoom(false); - lineChart.setScaleEnabled(false); - lineChart.setDragEnabled(false); - lineChart.getDescription().setEnabled(false); - lineChart.getAxisLeft().setEnabled(false); - lineChart.getAxisRight().setEnabled(false); - lineChart.getLegend().setEnabled(false); - lineChart.getXAxis().setEnabled(false); - lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); - - lineChart.invalidate(); - } - - private void updateColor(View card, Currency currency) - { - if(currency.getDayFluctuation() >= 0) - { - ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setTextColor(getResources().getColor(R.color.increase)); - ((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setTextColor(getResources().getColor(R.color.increase)); - } - else - { - ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setTextColor(getResources().getColor(R.color.decrease)); - ((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setTextColor(getResources().getColor(R.color.decrease)); - } - } - private String getIconUrl(String symbol) { String url; @@ -547,17 +394,14 @@ public class Watchlist extends Fragment { currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(final Currency sucessCurrency) { - if(getIconUrl(sucessCurrency.getSymbol()) != null) - { - getBitmapFromURL(getIconUrl(sucessCurrency.getSymbol()), new HomeActivity.IconCallBack() { - @Override - public void onSuccess(Bitmap bitmapIcon) { - sucessCurrency.setIcon(bitmapIcon); - updateChartColor(currency); - countWatchlist(); - } - }); - } + getBitmapFromURL(getIconUrl(sucessCurrency.getSymbol()), new HomeActivity.IconCallBack() { + @Override + public void onSuccess(Bitmap bitmapIcon) { + sucessCurrency.setIcon(bitmapIcon); + updateChartColor(currency); + countWatchlist(); + } + }); } }); } diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/BalanceManager.java index 7b6d8e9..e6f7dcd 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/BalanceManager.java @@ -145,7 +145,7 @@ public class BalanceManager { for(int i = 0; i < hitBtcManagers.size(); i++) { - hitBtcManagers.get(i).updateBalance(new HitBtcManager.HitBtcCallBack() { + hitBtcManagers.get(i).updateGlobalBalance(new HitBtcManager.HitBtcCallBack() { @Override public void onSuccess() { countBalances(callBack); @@ -274,8 +274,16 @@ public class BalanceManager { String url; try { - JSONObject jsonObject = new JSONObject(currencyDetailsList.getCoinInfosHashmap().get(symbol)); - url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50"; + 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; diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java index caff4d5..4258b1b 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java @@ -96,6 +96,7 @@ public class Currency implements Parcelable { try { JSONObject jsonObject = new JSONObject(currencyDetails); url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50"; + } catch (NullPointerException e) { //Log.d(context.getResources().getString(R.string.debug), symbol + " has no icon URL"); url = null; diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java new file mode 100644 index 0000000..11c0535 --- /dev/null +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -0,0 +1,330 @@ +package com.nauk.moodl.DataManagers.CurrencyData; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.v7.widget.CardView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.data.Entry; +import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.data.LineDataSet; +import com.nauk.moodl.Activities.CurrencyDetailsActivity; +import com.nauk.moodl.DataManagers.PreferencesManager; +import com.nauk.moodl.PlaceholderManager; +import com.nauk.moodl.R; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +import static com.nauk.moodl.MoodlBox.collapseH; +import static com.nauk.moodl.MoodlBox.expandH; +import static com.nauk.moodl.MoodlBox.numberConformer; + +/** + * Created by Tiji on 12/05/2018. + */ + +public class CurrencyCardview extends CardView { + + public CurrencyCardview(@NonNull Context context) { + super(context); + } + + public CurrencyCardview(@NonNull final Context context, final Currency currency) + { + super (context); + + LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true); + + ((LineChart) findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); + + findViewById(R.id.masterLayout).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View view) { + PreferencesManager preferencesManager = new PreferencesManager(context); + + if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { + collapseH(view.findViewById(R.id.collapsableLayout)); + } else { + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); + expandH(view.findViewById(R.id.collapsableLayout)); + + if (currency.getHistoryMinutes() == null) { + currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + if(currency.getHistoryMinutes() != null) + { + setupLineChart(view, 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 + { + expandH(view.findViewById(R.id.collapsableLayout)); + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + } + } + } + }); + + updateCardViewInfos(currency); + + findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + + updateColor(currency); + } + + public CurrencyCardview(@NonNull final Context context, final Currency currency, float totalValue, boolean isBalanceHidden) + { + super(context); + + LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true); + + ((LineChart) findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); + + findViewById(R.id.masterLayout).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View view) { + PreferencesManager preferencesManager = new PreferencesManager(context); + + if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { + collapseH(view.findViewById(R.id.collapsableLayout)); + } else { + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); + expandH(view.findViewById(R.id.collapsableLayout)); + + if (currency.getHistoryMinutes() == null) { + currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + if(currency.getHistoryMinutes() != null) + { + setupLineChart(view, 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 + { + expandH(view.findViewById(R.id.collapsableLayout)); + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + } + } + } + }); + + updateCardViewInfos(currency, totalValue, isBalanceHidden); + + findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + + updateColor(currency); + } + + private void setupLineChart(View view, final Currency currency) + { + LineChart lineChart = findViewById(R.id.LineChartView); + + lineChart.setDrawGridBackground(false); + lineChart.setDrawBorders(false); + lineChart.setDrawMarkers(false); + lineChart.setDoubleTapToZoomEnabled(false); + lineChart.setPinchZoom(false); + lineChart.setScaleEnabled(false); + lineChart.setDragEnabled(false); + lineChart.getDescription().setEnabled(false); + lineChart.getAxisLeft().setEnabled(false); + lineChart.getAxisRight().setEnabled(false); + lineChart.getLegend().setEnabled(false); + lineChart.getXAxis().setEnabled(false); + lineChart.setViewPortOffsets(0, 0, 0, 0); + lineChart.setData(generateData(currency)); + } + + private void updateCardViewInfos(Currency currency) + { + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); + ((TextView) findViewById(R.id.currencyValueTextView)) + .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getContext())); + + ((ImageView) findViewById(R.id.currencyIcon)) + .setImageBitmap(currency.getIcon()); + ((TextView) findViewById(R.id.currencyNameTextView)) + .setText(currency.getName()); + ((TextView) findViewById(R.id.currencySymbolTextView)) + .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getContext())); + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); + + Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); + arrowDrawable.mutate(); + arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + arrowDrawable.invalidateSelf(); + + Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable(); + progressDrawable.mutate(); + progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressDrawable.invalidateSelf(); + } + + private void updateCardViewInfos(Currency currency, float totalValue, boolean isBalanceHidden) + { + double value = currency.getValue() * currency.getBalance(); + double percentage = value / totalValue * 100; + + ((TextView) findViewById(R.id.currencyValueOwnedTextView)) + .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext())); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); + ((TextView) findViewById(R.id.currencyValueTextView)) + .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getContext())); + + ((ImageView) findViewById(R.id.currencyIcon)) + .setImageBitmap(currency.getIcon()); + ((TextView) findViewById(R.id.currencyNameTextView)) + .setText(currency.getName()); + ((TextView) findViewById(R.id.currencySymbolTextView)) + .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getContext())); + ((TextView) findViewById(R.id.currencyOwnedTextView)) + .setText(PlaceholderManager.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext())); + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); + + Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable(); + arrowDrawable.mutate(); + arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + arrowDrawable.invalidateSelf(); + + Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable(); + progressDrawable.mutate(); + progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressDrawable.invalidateSelf(); + + Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); + progressBarDrawable.mutate(); + progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressBarDrawable.invalidateSelf(); + + ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); + ((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderManager.getPercentageString(numberConformer(percentage), getContext())); + + if(isBalanceHidden) + { + findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); + findViewById(R.id.percentageOwnedTextView).setVisibility(View.VISIBLE); + findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.GONE); + } + else + { + findViewById(R.id.currencyPortfolioDominance).setVisibility(View.INVISIBLE); + findViewById(R.id.percentageOwnedTextView).setVisibility(View.GONE); + findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.VISIBLE); + } + } + + private LineData generateData(Currency currency) + { + LineDataSet dataSet; + List dataChartList = currency.getHistoryMinutes(); + ArrayList values = new ArrayList<>(); + + for(int i = 0; i < dataChartList.size(); i+=10) + { + values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); + } + + dataSet = new LineDataSet(values, "History"); + dataSet.setDrawIcons(false); + dataSet.setColor(currency.getChartColor()); + dataSet.setLineWidth(1); + dataSet.setDrawFilled(true); + dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); + dataSet.setFormLineWidth(1); + dataSet.setFormSize(15); + dataSet.setDrawCircles(false); + dataSet.setDrawValues(false); + dataSet.setHighlightEnabled(false); + + return new LineData(dataSet); + } + + private void updateColor(Currency currency) + { + if(currency.getDayFluctuationPercentage() >= 0) + { + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(getResources().getColor(R.color.increase)); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(getResources().getColor(R.color.increase)); + } + else + { + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(getResources().getColor(R.color.decrease)); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(getResources().getColor(R.color.decrease)); + } + } + + private int getColorWithAplha(int color, float ratio) + { + int transColor; + int alpha = Math.round(Color.alpha(color) * ratio); + int r = Color.red(color); + int g = Color.green(color); + int b = Color.blue(color); + + transColor = Color.argb(alpha, r, g, b); + + return transColor ; + } +} diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java index 09085ab..8798d46 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -27,12 +27,12 @@ public class CurrencyDataRetriever { final static int HOURS = 1; final static int DAYS = 2; - private String minuteHistoryUrl = "https://min-api.cryptocompare.com/data/histominute"; - private String hourHistoryUrl = "https://min-api.cryptocompare.com/data/histohour"; - private String dayHistoryUrl = "https://min-api.cryptocompare.com/data/histoday"; - private String priceUrl = "https://min-api.cryptocompare.com/data/pricemultifull?fsyms="; - private String snapshotUrl = "https://www.cryptocompare.com/api/data/coinsnapshotfullbyid/?id="; - private String tickerUrl = "https://api.coinmarketcap.com/v2/ticker/"; + private final static String minuteHistoryUrl = "https://min-api.cryptocompare.com/data/histominute"; + private final static String hourHistoryUrl = "https://min-api.cryptocompare.com/data/histohour"; + private final static String dayHistoryUrl = "https://min-api.cryptocompare.com/data/histoday"; + private final static String priceUrl = "https://min-api.cryptocompare.com/data/pricemultifull?fsyms="; + private final static String snapshotUrl = "https://www.cryptocompare.com/api/data/coinsnapshotfullbyid/?id="; + private final static String tickerUrl = "https://api.coinmarketcap.com/v2/ticker/"; private RequestQueue requestQueue; @@ -157,8 +157,12 @@ public class CurrencyDataRetriever { requestQueue.add(stringRequest); } - public void updatePrice(final String symbolCurrencyFrom, String symbolCurrencyTo, final CurrencyCallBack callBack) + public void updatePrice(String symbolCurrencyFrom, String symbolCurrencyTo, final CurrencyCallBack callBack) { + if(symbolCurrencyFrom.equals("MIOTA")) + { + symbolCurrencyFrom = "IOT"; + } String requestUrl = priceUrl + symbolCurrencyFrom + "&tsyms=" + symbolCurrencyTo; StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java index 506167e..fcd7975 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java @@ -26,7 +26,7 @@ import java.util.regex.Pattern; public class CurrencyDetailsList { - final private static String DETAILURL = "https://www.cryptocompare.com/api/data/coinlist/"; + final private static String DETAILURL = "https://min-api.cryptocompare.com/data/all/coinlist"; private RequestQueue requestQueue; private LinkedHashMap coinInfosHashmap; private android.content.Context context; @@ -74,7 +74,18 @@ public class CurrencyDetailsList { StrictMode.setThreadPolicy(policy); JSONObject jsonObject = new JSONObject(tab[i]); - coinInfosHashmap.put(jsonObject.getString("Symbol"), tab[i]); + switch (jsonObject.getString("Symbol")) + { + case "IOT": + coinInfosHashmap.put("MIOTA", tab[i]); + break; + case "XRB": + coinInfosHashmap.put("NANO", tab[i]); + break; + default: + coinInfosHashmap.put(jsonObject.getString("Symbol"), tab[i]); + break; + } } catch (JSONException e) { Log.d(context.getResources().getString(R.string.debug), "ImageUrl not found."); } diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java index 6f22777..0affd0b 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java @@ -85,18 +85,7 @@ public class CurrencyTickerList { for(int i = 0; i < dataJsonArray.length(); i++) { JSONObject currencyJsonObject = dataJsonArray.getJSONObject(i); - switch (currencyJsonObject.getString("symbol")) - { - case "MIOTA": - currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), "IOT", currencyJsonObject.getInt("id"))); - break; - case "NANO": - currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), "XRB", currencyJsonObject.getInt("id"))); - break; - default: - currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id"))); - break; - } + currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id"))); } } catch (JSONException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java index ecea0bd..5e4f6f7 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java @@ -204,11 +204,10 @@ public class DatabaseManager extends SQLiteOpenHelper{ ArrayList transactionList = new ArrayList<>(); - resultatList.moveToLast(); - - do { + while (resultatList.moveToNext()) + { transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5), resultatList.getDouble(7))); - } while(resultatList.moveToPrevious()); + } resultatList.close(); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/ExchangeManager/HitBtcManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/ExchangeManager/HitBtcManager.java index 89e4af5..d4a0134 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/ExchangeManager/HitBtcManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/ExchangeManager/HitBtcManager.java @@ -31,9 +31,12 @@ public class HitBtcManager { private String publicKey; private String privateKey; final private String hitBalanceUrl = "https://api.hitbtc.com/api/2/account/balance"; + final private String hitTradingBalanceUrl = "https://api.hitbtc.com/api/2/trading/balance"; final private String tradeHistoryUrl = "https://api.hitbtc.com/api/2/history/trades?"; private RequestQueue requestQueue; private List pairSymbolList; + private boolean isTradingBalanceUpdated; + private boolean isBalanceUpdated; private List balance; private android.content.Context context; @@ -62,7 +65,97 @@ public class HitBtcManager { } - public void updateBalance(final HitBtcCallBack callBack) + private void mergeBalanceSymbols() + { + List mergedBalance = new ArrayList<>(); + + for(int i = 0; i < balance.size(); i++) + { + boolean updated = false; + + for(int j = 0; j < mergedBalance.size(); j++) + { + if(mergedBalance.get(j).getSymbol().equals(balance.get(i).getSymbol())) + { + mergedBalance.get(j).setBalance(mergedBalance.get(j).getBalance() + balance.get(i).getBalance()); + updated = true; + } + } + + if(!updated) + { + mergedBalance.add(balance.get(i)); + } + } + + balance = mergedBalance; + } + + public void updateGlobalBalance(final HitBtcCallBack masterCallBack) + { + isTradingBalanceUpdated = false; + isBalanceUpdated = false; + + balance = new ArrayList<>(); + + updateBalance(new HitBtcCallBack() { + @Override + public void onSuccess() { + isBalanceUpdated = true; + + if(isTradingBalanceUpdated) + { + mergeBalanceSymbols(); + masterCallBack.onSuccess(); + } + } + + @Override + public void onError(String error) { + masterCallBack.onError(error); + } + }); + + updateTradingBalance(new HitBtcCallBack() { + @Override + public void onSuccess() { + isTradingBalanceUpdated = true; + + if(isBalanceUpdated) + { + mergeBalanceSymbols(); + masterCallBack.onSuccess(); + } + } + + @Override + public void onError(String error) { + masterCallBack.onError(error); + } + }); + } + + private void updateTradingBalance(final HitBtcCallBack callBack) + { + JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitTradingBalanceUrl + , getResponseListener(callBack), getErrorResponseListener(callBack)) + { + @Override + public Map getHeaders() throws AuthFailureError { + Map headers = new HashMap<>(); + String credentials = publicKey + ":" + privateKey; + String auth = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); + headers.put("Content-Type", "application/json"); + headers.put("Authorization", auth); + + return headers; + } + }; + + requestQueue.add(arrayRequest); + } + + private void updateBalance(final HitBtcCallBack callBack) { JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl , getResponseListener(callBack), getErrorResponseListener(callBack)) @@ -109,8 +202,6 @@ public class HitBtcManager { private void parseBalance(JSONArray response) { - balance = new ArrayList<>(); - for(int i = 0; i < response.length(); i++) { try { @@ -120,7 +211,15 @@ public class HitBtcManager { if(available > 0 || reserved > 0) { - balance.add(new Currency(jsonObject.getString("currency"), available + reserved)); + switch (jsonObject.getString("currency")) + { + case "IOTA": + balance.add(new Currency("MIOTA", available + reserved)); + break; + default: + balance.add(new Currency(jsonObject.getString("currency"), available + reserved)); + break; + } } } catch (JSONException e) { diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java deleted file mode 100644 index c184d10..0000000 --- a/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java +++ /dev/null @@ -1,332 +0,0 @@ -package com.nauk.moodl.LayoutManagers; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.drawable.Drawable; -import android.support.v7.widget.CardView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.Transformation; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.data.LineDataSet; -import com.nauk.moodl.Activities.CurrencyDetailsActivity; -import com.nauk.moodl.DataManagers.CurrencyData.Currency; -import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDataChart; -import com.nauk.moodl.DataManagers.PreferencesManager; -import com.nauk.moodl.PlaceholderManager; -import com.nauk.moodl.R; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; - -import static com.nauk.moodl.MoodlBox.collapseH; -import static com.nauk.moodl.MoodlBox.expandH; -import static com.nauk.moodl.MoodlBox.numberConformer; - -/** - * Created by Tiji on 05/01/2018. - */ - -public class HomeLayoutGenerator { - - private android.content.Context context; - - public HomeLayoutGenerator(Context context) - { - this.context = context; - } - - public View getInfoLayout(final Currency currency, float totalValue, boolean isBalanceHidden) - { - View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null, true); - - ((LineChart) view.findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - PreferencesManager preferencesManager = new PreferencesManager(context); - - if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { - collapseH(view.findViewById(R.id.collapsableLayout)); - } else { - view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); - view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); - expandH(view.findViewById(R.id.collapsableLayout)); - - if (currency.getHistoryMinutes() == null) { - currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - if(currency.getHistoryMinutes() != null) - { - setupLineChart(view, 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 - { - expandH(view.findViewById(R.id.collapsableLayout)); - view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); - view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); - } - } - } - }); - - updateCardViewInfos(view, currency, totalValue, isBalanceHidden); - - view.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - }); - - updateColor(view, currency); - - return view; - } - - /*private class ChartLoader extends AsyncTask - { - private View view; - private Currency currency; - - ChartLoader(View view, Currency currency) - { - this.view = view; - this.currency = currency; - } - - @Override - protected void onPreExecute() { - super.onPreExecute(); - extendView(view); - } - - @Override - protected Void doInBackground(Void... voids) { - setupLineChart(view, currency); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - - view.findViewById(R.id.progressLineChart).setVisibility(View.GONE); - view.findViewById(R.id.LineChartView).setVisibility(View.VISIBLE); - view.findViewById(R.id.LineChartView).invalidate(); - } - } -*/ - private static void expand(final View v) { - v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); - final int targetHeight = v.getMeasuredHeight(); - - // Older versions of android (pre API 21) cancel animations for views with a height of 0. - v.getLayoutParams().height = 1; - v.setVisibility(View.VISIBLE); - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - v.getLayoutParams().height = interpolatedTime == 1 - ? CardView.LayoutParams.WRAP_CONTENT - : (int)(targetHeight * interpolatedTime); - v.requestLayout(); - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private static void collapse(final View v) { - final int initialHeight = v.getMeasuredHeight(); - - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if(interpolatedTime == 1){ - v.setVisibility(View.GONE); - }else{ - v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private void setupLineChart(View view, final Currency currency) - { - LineChart lineChart = view.findViewById(R.id.LineChartView); - - lineChart.setDrawGridBackground(false); - lineChart.setDrawBorders(false); - lineChart.setDrawMarkers(false); - lineChart.setDoubleTapToZoomEnabled(false); - lineChart.setPinchZoom(false); - lineChart.setScaleEnabled(false); - lineChart.setDragEnabled(false); - lineChart.getDescription().setEnabled(false); - lineChart.getAxisLeft().setEnabled(false); - lineChart.getAxisRight().setEnabled(false); - lineChart.getLegend().setEnabled(false); - lineChart.getXAxis().setEnabled(false); - lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); - } - - private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden) - { - double value = currency.getValue() * currency.getBalance(); - double percentage = value / totalValue * 100; - DecimalFormat df = new DecimalFormat(".##"); - - ((TextView) view.findViewById(R.id.currencyValueOwnedTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), context)); - ((TextView) view.findViewById(R.id.currencyValueTextView)) - .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), context)); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), context)); - - ((ImageView) view.findViewById(R.id.currencyIcon)) - .setImageBitmap(currency.getIcon()); - ((TextView) view.findViewById(R.id.currencyNameTextView)) - .setText(currency.getName()); - ((TextView) view.findViewById(R.id.currencySymbolTextView)) - .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), context)); - ((TextView) view.findViewById(R.id.currencyOwnedTextView)) - .setText(PlaceholderManager.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), context)); - ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), context)); - - Drawable arrowDrawable = ((ImageView) view.findViewById(R.id.detailsArrow)).getDrawable(); - arrowDrawable.mutate(); - arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - arrowDrawable.invalidateSelf(); - - Drawable progressDrawable = ((ProgressBar) view.findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable(); - progressDrawable.mutate(); - progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressDrawable.invalidateSelf(); - - Drawable progressBarDrawable = ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); - progressBarDrawable.mutate(); - progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - progressBarDrawable.invalidateSelf(); - - ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); - ((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderManager.getPercentageString(numberConformer(percentage), context)); - - if(isBalanceHidden) - { - view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); - view.findViewById(R.id.percentageOwnedTextView).setVisibility(View.VISIBLE); - view.findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.GONE); - } - else - { - view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.INVISIBLE); - view.findViewById(R.id.percentageOwnedTextView).setVisibility(View.GONE); - view.findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.VISIBLE); - } - } - - private void updateColor(View view, Currency currency) - { - if(currency.getDayFluctuationPercentage() >= 0) - { - ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) - .setTextColor(context.getResources().getColor(R.color.increase)); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setTextColor(context.getResources().getColor(R.color.increase)); - } - else - { - ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) - .setTextColor(context.getResources().getColor(R.color.decrease)); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setTextColor(context.getResources().getColor(R.color.decrease)); - } - } - - private LineData generateData(Currency currency) - { - LineDataSet dataSet; - List dataChartList = currency.getHistoryMinutes(); - ArrayList values = new ArrayList<>(); - - for(int i = 0; i < dataChartList.size(); i+=10) - { - values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); - } - - dataSet = new LineDataSet(values, "History"); - dataSet.setDrawIcons(false); - dataSet.setColor(currency.getChartColor()); - dataSet.setLineWidth(1); - dataSet.setDrawFilled(true); - dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); - dataSet.setFormLineWidth(1); - dataSet.setFormSize(15); - dataSet.setDrawCircles(false); - dataSet.setDrawValues(false); - dataSet.setHighlightEnabled(false); - - return new LineData(dataSet); - } - - private int getColorWithAplha(int color, float ratio) - { - int transColor; - int alpha = Math.round(Color.alpha(color) * ratio); - int r = Color.red(color); - int g = Color.green(color); - int b = Color.blue(color); - - transColor = Color.argb(alpha, r, g, b); - - return transColor ; - } -} diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index a4a35de..e86507f 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -2,6 +2,7 @@ + android:clickable="false" + android:orientation="vertical" + android:tag="mainLinear"> + android:orientation="horizontal" + android:baselineAligned="false"> + android:layout_margin="5dp" + android:orientation="vertical" + android:layout_weight="0.92"> + android:orientation="horizontal" + android:gravity="center"> - + + + + + + + + + + + android:gravity="start" + android:textColor="@color/secondaryTextViewColor" + android:textSize="@dimen/cardViewMainText" + android:layout_weight="0.5"/> - + - - - - - - - - - - - - - - - - - - - - - + android:background="@drawable/ic_delete_white_24dp" + android:clickable="false" + android:focusable="false"/> - + - + - + + + + + + + + + + + + + + android:visibility="gone"> - + + - - - - - - - - + android:src="@drawable/ic_keyboard_arrow_right_grey_48dp" + android:layout_gravity="center_vertical|end"/> - + diff --git a/app/src/main/res/layout/fragment_watchlist_homeactivity.xml b/app/src/main/res/layout/fragment_watchlist_homeactivity.xml index 4e0067f..5e2a1de 100644 --- a/app/src/main/res/layout/fragment_watchlist_homeactivity.xml +++ b/app/src/main/res/layout/fragment_watchlist_homeactivity.xml @@ -79,11 +79,6 @@ android:orientation="vertical" android:paddingTop="20dp"> - - - -