diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java index eb8e70e..f6cb615 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -3,23 +3,32 @@ package com.nauk.coinfolio.Activities; import android.content.ContentValues; import android.content.Intent; import android.graphics.Color; +import android.graphics.Rect; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; +import android.view.animation.BounceInterpolator; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.ViewFlipper; import com.daimajia.swipe.SwipeLayout; +import com.db.chart.animation.Animation; import com.db.chart.model.LineSet; +import com.db.chart.model.Point; import com.db.chart.renderer.AxisRenderer; +import com.db.chart.tooltip.Tooltip; +import com.db.chart.util.Tools; import com.db.chart.view.LineChartView; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; @@ -45,6 +54,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private DatabaseManager databaseManager; //private String symbol; private Currency currency; + private boolean hasBeenModified; + private Tooltip tip; + private int indexMax; + private int indexMin; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -66,6 +79,17 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } }; + @Override + public void onBackPressed() + { + Log.d(this.getResources().getString(R.string.debug), "Back pressed"); + Intent intent = new Intent(this, HomeActivity.class); + intent.putExtra("update", hasBeenModified); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + finish(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -80,23 +104,36 @@ public class CurrencyDetailsActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); - chartLayout = findViewById(R.id.chartLayout); + chartLayout = findViewById(R.id.chartsLayout); drawTransactionList(); - drawChart(); + if(currency.getDayPriceHistory().size() > 0) + { + drawChart(); + } + else + { + TextView errorTextView = new TextView(this); + errorTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500)); + errorTextView.setText("Not enough data"); + errorTextView.setTag("chart_layout"); + errorTextView.setGravity(Gravity.CENTER); + + chartLayout.addView(errorTextView); + } setTitle(currency.getName()); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - Log.d("coinfolio", "Color received : " + currency.getChartColor()); + hasBeenModified = false; } private void drawChart() { - LineChartView chartView = new LineChartView(this); + final LineChartView chartView = new LineChartView(this); LineSet lineSet = new LineSet(); double valMin; double valMax; @@ -105,8 +142,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity { String hour; String minute; - List dataChartList = currency.getDayPriceHistory(); + final List dataChartList = currency.getDayPriceHistory(); + indexMin = 0; + indexMax = 0; valMin = dataChartList.get(0).getOpen(); valMax = dataChartList.get(0).getOpen(); @@ -115,11 +154,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { if(valMax < dataChartList.get(i).getOpen()) { valMax = dataChartList.get(i).getOpen(); + indexMax = i; } if(valMin > dataChartList.get(i).getOpen()) { valMin = dataChartList.get(i).getOpen(); + indexMin = i; } } @@ -130,7 +171,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } chartView.setAxisBorderValues((float) valMin, (float) valMax); - chartView.setYLabels(AxisRenderer.LabelPosition.OUTSIDE); + chartView.setYLabels(AxisRenderer.LabelPosition.NONE); chartView.setYAxis(false); chartView.setXAxis(false); @@ -168,15 +209,48 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineSet.setFill(getColorWitchAlpha(currency.getChartColor(), 0.5f)); lineSet.setColor(currency.getChartColor()); - chartView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500)); + final LinearLayout.LayoutParams chartParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500); + chartParams.setMargins(0, 15, 0, 15); + + chartView.setLayoutParams(chartParams); + + tip = new Tooltip(this, R.layout.tooltip_layout, R.id.value); + + RelativeLayout.LayoutParams tipParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + + tip.setLayoutParams(tipParams); + tip.setVerticalAlignment(Tooltip.Alignment.BOTTOM_TOP); + tip.setDimensions((int) Tools.fromDpToPx(75), (int) Tools.fromDpToPx(25)); + tip.setClickable(false); + /*tip.setVerticalAlignment(Tooltip.Alignment.CENTER); + tip.setHorizontalAlignment(Tooltip.Alignment.CENTER); + tip.setDimensions((int) Tools.fromDpToPx(4), (int) Tools.fromDpToPx(4)); + tip.setClickable(false);*/ + + final Tooltip tip2 = tip; chartView.addData(lineSet); + chartView.setFadingEdgeLength(15); + chartView.setLongClickable(true); + + //tip.prepare(chartView.getEntriesArea(0).get(0), (float) dataChartList.get(0).getOpen()); + + chartView.setTooltips(tip); + chartView.setTooltips(tip2); + + Runnable launchAction = new Runnable() { + @Override + public void run() { + tip.prepare(chartView.getEntriesArea(0).get((int) indexMin/10), (float) dataChartList.get(indexMin).getOpen()); + tip2.prepare(chartView.getEntriesArea(0).get((int) indexMax/10), (float) dataChartList.get(indexMax).getOpen()); + chartView.showTooltip(tip, true); + //chartView.showTooltip(tip2, true); + } + }; + + chartView.show(new Animation().fromAlpha(0).withEndAction(launchAction)); chartLayout.addView(chartView); - - Log.d("coinfolio", "Color : " + currency.getChartColor()); - - chartView.show(); } private int getColorWitchAlpha(int color, float ratio) @@ -214,6 +288,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); Log.d(CurrencyDetailsActivity.this.getResources().getString(R.string.debug), "Id : " + view.getTag()); drawTransactionList(); + hasBeenModified = true; } }); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index c0ace0a..441c0f4 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -7,11 +7,14 @@ import android.graphics.BitmapFactory; import android.graphics.drawable.Icon; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.Snackbar; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; +import android.support.v7.widget.CardView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Gravity; @@ -21,6 +24,7 @@ import android.view.MenuItem; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -38,6 +42,7 @@ import com.nauk.coinfolio.R; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.util.ArrayList; import java.util.List; //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart @@ -67,6 +72,8 @@ public class HomeActivity extends AppCompatActivity { private PreferencesManager preferencesManager; private DatabaseManager databaseManager; private long lastTimestamp; + private Handler handler; + private Runnable updateRunnable; @Override protected void onCreate(Bundle savedInstanceState) { @@ -126,7 +133,7 @@ public class HomeActivity extends AppCompatActivity { new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - updateAll(); + updateAll(false); } } ); @@ -156,6 +163,41 @@ public class HomeActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); + handler = new Handler(); + + updateRunnable = new Runnable() { + @Override + public void run() { + if (refreshLayout.isRefreshing()) + { + refreshLayout.setRefreshing(false); + + Snackbar.make(findViewById(R.id.currencyListLayout), "Error while updating data", Snackbar.LENGTH_LONG) + .setAction("Update", new View.OnClickListener() { + @Override + public void onClick(View view) { + updateAll(true); + } + }) + .show(); + } + + if (loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + + Snackbar.make(findViewById(R.id.currencyListLayout), "Error while updating data", Snackbar.LENGTH_LONG) + .setAction("Update", new View.OnClickListener() { + @Override + public void onClick(View view) { + updateAll(true); + } + }) + .show(); + } + } + }; + updateViewButtonIcon(); lastTimestamp = 0; @@ -165,12 +207,16 @@ public class HomeActivity extends AppCompatActivity { protected void onResume() { super.onResume(); - if(System.currentTimeMillis()/1000 - lastTimestamp > 60) + Intent intent = getIntent(); + + updateAll(intent.getBooleanExtra("update", false)); + + /*if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || intent.getBooleanExtra("update", false)) { lastTimestamp = System.currentTimeMillis()/1000; updateAll(); - } + }*/ } @Override @@ -236,7 +282,7 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getDayPriceHistory() == null)) { - currencyLayout.addView(layoutGenerator.getInfoLayout(currency, currency.getChartColor())); + currencyLayout.addView(layoutGenerator.getInfoLayout(currency)); } } } @@ -246,13 +292,26 @@ public class HomeActivity extends AppCompatActivity { - private void updateAll() + private void updateAll(boolean mustUpdate) { - resetCounter(); - balanceManager.updateExchangeKeys(); - DataUpdater updater = new DataUpdater(); - updater.execute(); - refreshLayout.setRefreshing(true); + if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || mustUpdate) + { + lastTimestamp = System.currentTimeMillis() / 1000; + resetCounter(); + balanceManager.updateExchangeKeys(); + DataUpdater updater = new DataUpdater(); + updater.execute(); + refreshLayout.setRefreshing(true); + + handler.postDelayed(updateRunnable, 10000); + } + else + { + if(refreshLayout.isRefreshing()) + { + refreshLayout.setRefreshing(false); + } + } } private void resetCounter() @@ -283,84 +342,16 @@ public class HomeActivity extends AppCompatActivity { private void countIcons() { - float totalValue = 0; - float totalFluctuation = 0; - iconCounter++; - if(iconCounter == balanceManager.getTotalBalance().size()) + if(iconCounter == balanceManager.getTotalBalance().size() - 1) { - if(balanceManager.getTotalBalance() != null) { - if(coinCounter == balanceManager.getTotalBalance().size()-1 && iconChecker) + if(coinCounter == balanceManager.getTotalBalance().size() - 1 && iconChecker) { - refreshLayout.setRefreshing(false); - - balanceManager.sortCoins(); - - currencyLayout.removeAllViews(); - - //layoutGenerator.setCurrencyList(balanceManager.getTotalBalance()); - - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) - { - if(balanceManager.getTotalBalance().get(i).getIcon() != null) - { - //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); - - Palette.Builder builder = Palette.from(balanceManager.getTotalBalance().get(i).getIcon()); - - balanceManager.getTotalBalance().get(i).setChartColor(builder.generate().getDominantColor(0)); - - //layoutGenerator.addCurrencyToList(currency); - //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); - } - else - { - //currency.setChartColor(12369084); - balanceManager.getTotalBalance().get(i).setChartColor(12369084); - //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); - } - - if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && (balanceManager.getTotalBalance().get(i).getBalance() * balanceManager.getTotalBalance().get(i).getValue()) > 0.001) - { - balanceManager.getTotalBalance().get(i).setName(balanceManager.getCurrencyName(balanceManager.getTotalBalance().get(i).getSymbol())); - totalValue += balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance(); - totalFluctuation += (balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance()) * (balanceManager.getTotalBalance().get(i).getDayFluctuationPercentage() / 100); - //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); - //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); - currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0)); - } - - if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && balanceManager.getTotalBalance().get(i).getDayPriceHistory() == null) - { - //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); - //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); - currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0)); - } - } - - adaptView(); - - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); - - if(totalFluctuation > 0) - { - toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase)); - } - else - { - toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease)); - } - - toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation)); - - - if(loadingDialog.isShowing()) - { - loadingDialog.dismiss(); - } + UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator(); + uiHeavyLoadCalculator.execute(); } if(balanceManager.getTotalBalance().size() == 0) @@ -387,6 +378,31 @@ public class HomeActivity extends AppCompatActivity { } } } + else + { + if(balanceManager.getTotalBalance().size() == 0) + { + currencyLayout.removeAllViews(); + + refreshLayout.setRefreshing(false); + + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + toolbarLayout.setTitle("US$0.00"); + + toolbarSubtitle.setText("US$0.00"); + + toolbarSubtitle.setTextColor(-1275068417); + } + }); + } + } } private void countCoins(boolean isCoin, boolean isDetails) @@ -401,19 +417,32 @@ public class HomeActivity extends AppCompatActivity { iconChecker = true; } - if(coinCounter == balanceManager.getTotalBalance().size()-1) + if(balanceManager.getTotalBalance() != null) { - for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) + if(coinCounter == balanceManager.getTotalBalance().size()-1) { - final int index = i; + for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) + { + final int index = i; - getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()), new IconCallBack() { - @Override - public void onSuccess(Bitmap bitmapIcon) { - balanceManager.getTotalBalance().get(index).setIcon(bitmapIcon); - countIcons(); + if(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()) != null) + { + getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()), new IconCallBack() { + @Override + public void onSuccess(Bitmap bitmapIcon) { + balanceManager.getTotalBalance().get(index).setIcon(bitmapIcon); + countIcons(); + } + }); } - }); + } + } + else + { + if(balanceManager.getTotalBalance().size() == 0) + { + countIcons(); + } } } } @@ -460,6 +489,146 @@ public class HomeActivity extends AppCompatActivity { loadingDialog.show(); } + private class UiHeavyLoadCalculator extends AsyncTask + { + + private float totalValue; + private float totalFluctuation; + private float totalFluctuationPercentage; + + @Override + protected void onPreExecute() + { + super.onPreExecute(); + + totalValue = 0; + totalFluctuation = 0; + totalFluctuationPercentage = 0; + } + + @Override + protected void onProgressUpdate(Integer... values) + { + super.onProgressUpdate(values); + } + + @Override + protected Void doInBackground(Void... params) + { + final List cardList = new ArrayList<>(); + + Looper.prepare(); + + balanceManager.sortCoins(); + + //layoutGenerator.setCurrencyList(balanceManager.getTotalBalance()); + + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + { + final Currency localCurrency = balanceManager.getTotalBalance().get(i); + + if(localCurrency.getIcon() != null) + { + //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); + + Palette.Builder builder = Palette.from(localCurrency.getIcon()); + + localCurrency.setChartColor(builder.generate().getDominantColor(0)); + + //layoutGenerator.addCurrencyToList(currency); + //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); + } + else + { + //currency.setChartColor(12369084); + localCurrency.setChartColor(12369084); + //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); + } + + if(!localCurrency.getSymbol().equals("USD") && (localCurrency.getBalance() * localCurrency.getValue()) > 0.001) + { + localCurrency.setName(balanceManager.getCurrencyName(localCurrency.getSymbol())); + localCurrency.setId(balanceManager.getCurrencyId(localCurrency.getSymbol())); + totalValue += localCurrency.getValue() * localCurrency.getBalance(); + totalFluctuation += (localCurrency.getValue() * localCurrency.getBalance()) * (localCurrency.getDayFluctuationPercentage() / 100); + //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); + //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); + + cardList.add(layoutGenerator.getInfoLayout(localCurrency)); + } + + if(!localCurrency.getSymbol().equals("USD") && localCurrency.getDayPriceHistory() == null) + { + //balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()))); + //currencyLayout.addView(layoutGenerator.getInfoLayout(i)); + + cardList.add(layoutGenerator.getInfoLayout(localCurrency)); + } + + balanceManager.getTotalBalance().set(i, localCurrency); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + refreshLayout.setRefreshing(false); + currencyLayout.removeAllViews(); + + for(int i = 0; i < cardList.size(); i++) + { + currencyLayout.addView(cardList.get(i)); + } + + adaptView(); + } + }); + + toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); + + if(totalFluctuation > 0) + { + runOnUiThread(new Runnable() { + @Override + public void run() { + toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase)); + } + }); + } + else + { + runOnUiThread(new Runnable() { + @Override + public void run() { + toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease)); + } + }); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + + totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100; + + toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); + + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } + } + }); + + return null; + } + + @Override + protected void onPostExecute(Void result) + { + handler.removeCallbacks(updateRunnable); + } + } + private class DataUpdater extends AsyncTask { @Override @@ -490,12 +659,13 @@ public class HomeActivity extends AppCompatActivity { balance.get(i).updateDayPriceHistory(getApplicationContext(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { - currency.updateName(getApplicationContext(), new Currency.CurrencyCallBack() { + countCoins(true, false); + /*currency.updateName(getApplicationContext(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { countCoins(true, false); } - }); + });*/ } }); } @@ -515,10 +685,10 @@ public class HomeActivity extends AppCompatActivity { Snackbar.make(findViewById(R.id.currencyListLayout), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) .show(); refreshLayout.setRefreshing(false); - updateAll(); + updateAll(true); break; default: - updateAll(); + updateAll(true); } //updateAll(); } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index 94c167c..b18085c 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -41,6 +41,7 @@ public class RecordTransactionActivity extends AppCompatActivity { public void onClick(View view) { databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString())); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); + intent.putExtra("update", true); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); finish(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java index 1978bd1..f55b859 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -48,6 +48,7 @@ public class BalanceManager { private android.content.Context context; private Map iconUrlList; private Map coinList; + private Map coinIdList; private PreferencesManager preferenceManager; private DatabaseManager databaseManager; @@ -265,7 +266,16 @@ public class BalanceManager { public String getIconUrl(String symbol) { - return iconUrlList.get(symbol); + String url; + + try { + url = iconUrlList.get(symbol); + } catch (NullPointerException e) { + Log.d(context.getResources().getString(R.string.debug), symbol + " has no icon URL"); + url = null; + } + + return url; } public String getCurrencyName(String symbol) @@ -273,6 +283,11 @@ public class BalanceManager { return coinList.get(symbol); } + public int getCurrencyId(String symbol) + { + return coinIdList.get(symbol); + } + private void processDetailResult(String response, final IconCallBack callBack) { response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"Type\":100}")); @@ -280,6 +295,7 @@ public class BalanceManager { iconUrlList = new HashMap<>(); coinList = new HashMap<>(); + coinIdList = new HashMap<>(); for(int i = 0; i < tab.length; i++) { @@ -292,6 +308,8 @@ public class BalanceManager { iconUrlList.put(jsonObject.getString("Symbol"), "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50"); coinList.put(jsonObject.getString("Symbol"), jsonObject.getString("CoinName")); + + coinIdList.put(jsonObject.getString("Symbol"), jsonObject.getInt("Id")); } catch (JSONException e) { Log.d(context.getResources().getString(R.string.debug), "ImageUrl not found."); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java index a22f24d..a16027c 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java @@ -15,6 +15,7 @@ import static java.sql.Types.NULL; public class Currency implements Parcelable { + private int id; private String name; private String symbol; private double value; @@ -26,6 +27,21 @@ public class Currency implements Parcelable { private Bitmap icon; private int chartColor; + public Currency(Currency currency) + { + this.id = currency.id; + this.name = currency.name; + this.symbol = currency.symbol; + this.value = currency.value; + this.balance = currency.balance; + this.dayFluctuationPercentage = currency.getDayFluctuationPercentage(); + this.dayFluctuation = currency.getDayFluctuation(); + this.dayPriceHistory = currency.dayPriceHistory; + this.dataRetriver = currency.getDataRetriver(); + this.icon = currency.icon; + this.chartColor = currency.chartColor; + } + public Currency(String symbol, double balance) { this.symbol = symbol; @@ -88,6 +104,16 @@ public class Currency implements Parcelable { }); } + public void setId(int id) + { + this.id = id; + } + + public int getId() + { + return id; + } + public void setChartColor(int chartColor) { this.chartColor = chartColor; @@ -190,6 +216,7 @@ public class Currency implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(this.id); dest.writeString(this.name); dest.writeString(this.symbol); dest.writeDouble(this.value); @@ -202,6 +229,7 @@ public class Currency implements Parcelable { } protected Currency(Parcel in) { + this.id = in.readInt(); this.name = in.readString(); this.symbol = in.readString(); this.value = in.readDouble(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriver.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriver.java index 7ae848f..48a6428 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriver.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriver.java @@ -98,7 +98,7 @@ public class CurrencyDataRetriver { new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - + callBack.onSuccess(null); } }); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java index ea29d3f..9598248 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java @@ -19,12 +19,11 @@ import com.nauk.coinfolio.R; public class CurrencyAdapter extends ArrayAdapter { - private ArrayList Currencys, tempCurrency, suggestions; + private ArrayList tempCurrency, suggestions; private Context context; public CurrencyAdapter(Context context, ArrayList objects) { super(context, android.R.layout.simple_list_item_1, objects); - this.Currencys = objects; this.tempCurrency = new ArrayList(objects); this.suggestions = new ArrayList(objects); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index 3139711..f46c3cd 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -49,7 +49,7 @@ public class HomeLayoutGenerator { this.context = context; } - public CardView getInfoLayout(final Currency currency, int chartColor) + public CardView getInfoLayout(final Currency currency) //public CardView getInfoLayout(int index) { CardView mainCard = new CardView(context); @@ -132,7 +132,7 @@ public class HomeLayoutGenerator { mainLinear.addView(separatorLayout); - mainLinear.addView(generateChart(currency, chartLayout, chartColor)); + mainLinear.addView(generateChart(currency, chartLayout)); mainLinear.setClickable(false); @@ -180,13 +180,13 @@ public class HomeLayoutGenerator { } }*/ - private View generateChart(Currency currency, LinearLayout chartLayout, int chartColor) + private View generateChart(Currency currency, LinearLayout chartLayout) { View toReturn; if(currency.getDayPriceHistory() != null) { - LineChartView lineChartView = chartGenerator(currency.getDayPriceHistory(), chartColor); + LineChartView lineChartView = chartGenerator(currency.getDayPriceHistory(), currency.getChartColor()); chartLayout.setTag("chart_layout"); chartLayout.addView(lineChartView); lineChartView.show(); diff --git a/app/src/main/res/drawable/circular_progress_bar.xml b/app/src/main/res/drawable/circular_progress_bar.xml new file mode 100644 index 0000000..3c84667 --- /dev/null +++ b/app/src/main/res/drawable/circular_progress_bar.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 0c01066..be4d937 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -12,31 +12,58 @@ android:layout_height="match_parent" android:layout_marginBottom="56dp"> - + + + + + + + + + - + style="?android:attr/progressBarStyleLarge" + android:layout_gravity="center" + android:background="@drawable/circular_progress_bar" /> - - - - - + android:layout_height="match_parent"> - + + + + + + + --> + + + + + + \ No newline at end of file