From 9973c4bf375d9df02f376cca6e6515dba6ec9a52 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 15 Apr 2018 16:40:59 +0200 Subject: [PATCH] Update watchlist interface (price fluctuation) --- .../coinfolio/Activities/HomeActivity.java | 20 --------- .../MarketCapitalization.java | 17 +++++--- .../HomeActivityFragments/Summary.java | 39 +++++++++++++++-- .../HomeActivityFragments/Watchlist.java | 43 +++++++++++++++++-- .../DataManagers/DatabaseManager.java | 2 + 5 files changed, 87 insertions(+), 34 deletions(-) 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 ae26f82..25fc772 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -166,26 +166,6 @@ public class HomeActivity extends AppCompatActivity { } }); - updateViewButtonIcon(); - - } - - private void updateViewButtonIcon() - { - ImageButton imgButton = findViewById(R.id.switch_button); - - imgButton.setBackgroundColor(this.getResources().getColor(R.color.buttonColor)); - - if(preferencesManager.getDetailOption()) - { - imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_unfold_less_black_24dp)); - preferencesManager.setDetailOption(true); - } - else - { - imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_details_black_24dp)); - preferencesManager.setDetailOption(false); - } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java index 4c19822..56e1134 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java @@ -6,6 +6,7 @@ import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.text.SpannableString; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -49,6 +50,8 @@ public class MarketCapitalization extends Fragment { { view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false); + setupDominantCurrenciesColors(); + marketCapManager = new MarketCapManager(getContext()); refreshLayout = view.findViewById(R.id.swiperefresh); @@ -64,8 +67,6 @@ public class MarketCapitalization extends Fragment { lastTimestamp = 0; - setupDominantCurrenciesColors(); - updateMarketCap(); return view; @@ -80,12 +81,12 @@ public class MarketCapitalization extends Fragment { dominantCurrenciesColors.put("XRP", -16744256); dominantCurrenciesColors.put("BCH", -1011696); dominantCurrenciesColors.put("LTC", -4671304); - dominantCurrenciesColors.put("ADA", -16773080); - dominantCurrenciesColors.put("NEO", -9390048); - dominantCurrenciesColors.put("XLM", -11509656); - dominantCurrenciesColors.put("XMR", -499712); dominantCurrenciesColors.put("EOS", -1513240); - dominantCurrenciesColors.put("IOT", -1513240); + dominantCurrenciesColors.put("ADA", -16773080); + dominantCurrenciesColors.put("XLM", -11509656); + dominantCurrenciesColors.put("MIOTA", -1513240); + dominantCurrenciesColors.put("NEO", -9390048); + dominantCurrenciesColors.put("XMR", -499712); dominantCurrenciesColors.put("DASH", -15175496); dominantCurrenciesColors.put("XEM", -7829368); dominantCurrenciesColors.put("TRX", -7829360); @@ -154,6 +155,7 @@ public class MarketCapitalization extends Fragment { otherCurrenciesDominance += marketCapManager.getDominance().get(key); colors.add(dominantCurrenciesColors.get(key)); } + entries.add(new PieEntry(100-otherCurrenciesDominance, "Others")); colors.add(-12369084); @@ -162,6 +164,7 @@ public class MarketCapitalization extends Fragment { set.setSliceSpace(1); set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + PieData data = new PieData(set); data.setValueTextSize(10); data.setValueFormatter(new PercentFormatter()); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java index 0086b15..b06ae5e 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java @@ -133,12 +133,11 @@ public class Summary extends Fragment { detailsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + updateViewButtonIcon(); switchView(); } }); - displayBalance(preferencesManager.isBalanceHidden()); - updateTitle(); generateSplashScreen(); @@ -148,6 +147,17 @@ public class Summary extends Fragment { return view; } + @Override + public void onResume() { + super.onResume(); + + updateAll(preferencesManager.mustUpdate()); + + updateViewButtonIcon(); + + displayBalance(preferencesManager.isBalanceHidden()); + } + private void updateAll(boolean mustUpdate) { if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || mustUpdate) @@ -491,8 +501,8 @@ public class Summary extends Fragment { { refreshLayout.setRefreshing(false); refreshCurrencyList(); - totalValue = totalValue; handler.removeCallbacks(updateRunnable); + adaptView(); } } @@ -517,6 +527,24 @@ public class Summary extends Fragment { callBack.onSuccess(result); } + private void updateViewButtonIcon() + { + ImageButton imgButton = getActivity().findViewById(R.id.switch_button); + + imgButton.setBackgroundColor(this.getResources().getColor(R.color.buttonColor)); + + if(preferencesManager.getDetailOption()) + { + imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_unfold_less_black_24dp)); + preferencesManager.setDetailOption(false); + } + else + { + imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_details_black_24dp)); + preferencesManager.setDetailOption(true); + } + } + private void displayBalance(boolean hideBalance) { updateTitle(); @@ -655,6 +683,11 @@ public class Summary extends Fragment { return null; } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + } } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java index 7174024..74d0a62 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java @@ -32,6 +32,9 @@ import org.json.JSONObject; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.util.Locale; + +import static java.lang.Math.abs; /** * Created by Tiji on 13/04/2018. @@ -132,12 +135,14 @@ public class Watchlist extends Fragment { { View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null); - ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%"); - ((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setText("$3"); + ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); + ((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); ((TextView) card.findViewById(R.id.currencyNameTextView)).setText(currency.getName()); - ((TextView) card.findViewById(R.id.currencySymbolTextView)).setText(currency.getSymbol()); + ((TextView) card.findViewById(R.id.currencySymbolTextView)).setText(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); ((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); - ((TextView) card.findViewById(R.id.currencyValueTextView)).setText("" + currency.getValue()); + ((TextView) card.findViewById(R.id.currencyValueTextView)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); + + updateColor(card, currency); card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); card.setOnClickListener(new View.OnClickListener() { @@ -157,6 +162,20 @@ public class Watchlist extends Fragment { } } + 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; @@ -227,4 +246,20 @@ public class Watchlist extends Fragment { return null; } } + + private String numberConformer(double number) + { + String str; + + if(abs(number) > 1) + { + str = String.format( Locale.UK, "%.2f", number); + } + else + { + str = String.format( Locale.UK, "%.4f", number); + } + + return str; + } } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index a94b503..7219f2d 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -5,6 +5,7 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; @@ -144,6 +145,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ while(resultatList.moveToNext()) { currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3))); + Log.d("coinfolio", "Database output : " + resultatList.getString(1)); } resultatList.close();