Update watchlist interface (price fluctuation)
This commit is contained in:
parent
4393a7d592
commit
9973c4bf37
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -49,6 +50,8 @@ public class MarketCapitalization extends Fragment {
|
|||||||
{
|
{
|
||||||
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
||||||
|
|
||||||
|
setupDominantCurrenciesColors();
|
||||||
|
|
||||||
marketCapManager = new MarketCapManager(getContext());
|
marketCapManager = new MarketCapManager(getContext());
|
||||||
refreshLayout = view.findViewById(R.id.swiperefresh);
|
refreshLayout = view.findViewById(R.id.swiperefresh);
|
||||||
|
|
||||||
@ -64,8 +67,6 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
lastTimestamp = 0;
|
lastTimestamp = 0;
|
||||||
|
|
||||||
setupDominantCurrenciesColors();
|
|
||||||
|
|
||||||
updateMarketCap();
|
updateMarketCap();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
@ -80,12 +81,12 @@ public class MarketCapitalization extends Fragment {
|
|||||||
dominantCurrenciesColors.put("XRP", -16744256);
|
dominantCurrenciesColors.put("XRP", -16744256);
|
||||||
dominantCurrenciesColors.put("BCH", -1011696);
|
dominantCurrenciesColors.put("BCH", -1011696);
|
||||||
dominantCurrenciesColors.put("LTC", -4671304);
|
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("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("DASH", -15175496);
|
||||||
dominantCurrenciesColors.put("XEM", -7829368);
|
dominantCurrenciesColors.put("XEM", -7829368);
|
||||||
dominantCurrenciesColors.put("TRX", -7829360);
|
dominantCurrenciesColors.put("TRX", -7829360);
|
||||||
@ -154,6 +155,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
||||||
colors.add(dominantCurrenciesColors.get(key));
|
colors.add(dominantCurrenciesColors.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
||||||
colors.add(-12369084);
|
colors.add(-12369084);
|
||||||
|
|
||||||
@ -162,6 +164,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
set.setSliceSpace(1);
|
set.setSliceSpace(1);
|
||||||
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
||||||
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
||||||
|
|
||||||
PieData data = new PieData(set);
|
PieData data = new PieData(set);
|
||||||
data.setValueTextSize(10);
|
data.setValueTextSize(10);
|
||||||
data.setValueFormatter(new PercentFormatter());
|
data.setValueFormatter(new PercentFormatter());
|
||||||
|
@ -133,12 +133,11 @@ public class Summary extends Fragment {
|
|||||||
detailsButton.setOnClickListener(new View.OnClickListener() {
|
detailsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
updateViewButtonIcon();
|
||||||
switchView();
|
switchView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
displayBalance(preferencesManager.isBalanceHidden());
|
|
||||||
|
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
||||||
generateSplashScreen();
|
generateSplashScreen();
|
||||||
@ -148,6 +147,17 @@ public class Summary extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
updateAll(preferencesManager.mustUpdate());
|
||||||
|
|
||||||
|
updateViewButtonIcon();
|
||||||
|
|
||||||
|
displayBalance(preferencesManager.isBalanceHidden());
|
||||||
|
}
|
||||||
|
|
||||||
private void updateAll(boolean mustUpdate)
|
private void updateAll(boolean mustUpdate)
|
||||||
{
|
{
|
||||||
if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || mustUpdate)
|
if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || mustUpdate)
|
||||||
@ -491,8 +501,8 @@ public class Summary extends Fragment {
|
|||||||
{
|
{
|
||||||
refreshLayout.setRefreshing(false);
|
refreshLayout.setRefreshing(false);
|
||||||
refreshCurrencyList();
|
refreshCurrencyList();
|
||||||
totalValue = totalValue;
|
|
||||||
handler.removeCallbacks(updateRunnable);
|
handler.removeCallbacks(updateRunnable);
|
||||||
|
adaptView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,6 +527,24 @@ public class Summary extends Fragment {
|
|||||||
callBack.onSuccess(result);
|
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)
|
private void displayBalance(boolean hideBalance)
|
||||||
{
|
{
|
||||||
updateTitle();
|
updateTitle();
|
||||||
@ -655,6 +683,11 @@ public class Summary extends Fragment {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
super.onPostExecute(aVoid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,9 @@ import org.json.JSONObject;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static java.lang.Math.abs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Tiji on 13/04/2018.
|
* 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);
|
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
|
||||||
|
|
||||||
((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%");
|
((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage())));
|
||||||
((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setText("$3");
|
((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.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());
|
((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.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
card.setOnClickListener(new View.OnClickListener() {
|
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)
|
private String getIconUrl(String symbol)
|
||||||
{
|
{
|
||||||
String url;
|
String url;
|
||||||
@ -227,4 +246,20 @@ public class Watchlist extends Fragment {
|
|||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
||||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
|
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
|
||||||
@ -144,6 +145,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
|||||||
while(resultatList.moveToNext())
|
while(resultatList.moveToNext())
|
||||||
{
|
{
|
||||||
currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3)));
|
currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3)));
|
||||||
|
Log.d("coinfolio", "Database output : " + resultatList.getString(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
resultatList.close();
|
resultatList.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user