New features
- Created PlaceholderManager for a better readability - Added Pound (GBP) as a default currency option
This commit is contained in:
parent
749c7792ba
commit
26d3761d2c
@ -43,11 +43,11 @@ import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
|
||||
import com.nauk.coinfolio.DataManagers.DatabaseManager;
|
||||
import com.nauk.coinfolio.DataManagers.ExchangeManager.BinanceManager;
|
||||
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
||||
import com.nauk.coinfolio.PlaceholderManager;
|
||||
import com.nauk.coinfolio.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
@ -84,7 +84,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
private BarChart barChart;
|
||||
private PreferencesManager preferencesManager;
|
||||
private BinanceManager binanceManager;
|
||||
private CurrencyDetailsList currencyDetailsList;
|
||||
|
||||
private boolean displayLineChart;
|
||||
|
||||
@ -142,7 +141,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
databaseManager = new DatabaseManager(this);
|
||||
preferencesManager = new PreferencesManager(this);
|
||||
currencyDetailsList = new CurrencyDetailsList(this);
|
||||
|
||||
displayLineChart = true;
|
||||
|
||||
@ -549,9 +547,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
date = getDate(dataChartList.get(index).getTimestamp() * 1000);
|
||||
}
|
||||
|
||||
volumePlaceholder = getResources().getString(R.string.volumeDollarPlaceholder, numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()));
|
||||
pricePlaceholder = getResources().getString(R.string.priceDollarPlaceholder, numberConformer(e.getY()));
|
||||
timestampPlaceholder = getResources().getString(R.string.timestampPlaceholder, date);
|
||||
volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), this);
|
||||
pricePlaceholder = PlaceholderManager.getPriceString(numberConformer(e.getY()), this);
|
||||
timestampPlaceholder = PlaceholderManager.getTimestampString(date, this);
|
||||
|
||||
((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder);
|
||||
findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE);
|
||||
@ -726,8 +724,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
updateFluctuation(start, end);
|
||||
|
||||
((TextView) findViewById(R.id.txtViewPriceStart)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(start)));
|
||||
((TextView) findViewById(R.id.txtViewPriceNow)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(end)));
|
||||
((TextView) findViewById(R.id.txtViewPriceStart)).setText(PlaceholderManager.getValueString(numberConformer(start), this));
|
||||
((TextView) findViewById(R.id.txtViewPriceNow)).setText(PlaceholderManager.getValueString(numberConformer(end), this));
|
||||
|
||||
for(int i = 1; i < dataChartList.size(); i++)
|
||||
{
|
||||
@ -744,9 +742,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
((TextView) findViewById(R.id.totalVolume)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(totalVolume)));
|
||||
((TextView) findViewById(R.id.highestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(highestPrice)));
|
||||
((TextView) findViewById(R.id.lowestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(lowestPrice)));
|
||||
((TextView) findViewById(R.id.totalVolume)).setText(PlaceholderManager.getValueString(numberConformer(totalVolume), this));
|
||||
((TextView) findViewById(R.id.highestPrice)).setText(PlaceholderManager.getValueString(numberConformer(highestPrice), this));
|
||||
((TextView) findViewById(R.id.lowestPrice)).setText(PlaceholderManager.getValueString(numberConformer(lowestPrice), this));
|
||||
}
|
||||
|
||||
private void updateFluctuation(float start, float end)
|
||||
|
@ -73,7 +73,6 @@ import java.util.Locale;
|
||||
public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
private BottomNavigationView bottomNavigationView;
|
||||
|
||||
private ViewPager viewPager;
|
||||
|
||||
|
||||
|
@ -50,6 +50,7 @@ public class MarketCapitalization extends Fragment {
|
||||
private HashMap<String, Integer> dominantCurrenciesColors;
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
private long lastTimestamp;
|
||||
private String defaultCurrency;
|
||||
|
||||
private View view;
|
||||
|
||||
@ -68,12 +69,13 @@ public class MarketCapitalization extends Fragment {
|
||||
new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
updateMarketCap();
|
||||
updateMarketCap(false);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
lastTimestamp = 0;
|
||||
|
||||
ImageButton settingsButton = view.findViewById(R.id.settings_button);
|
||||
@ -86,7 +88,7 @@ public class MarketCapitalization extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
updateMarketCap();
|
||||
updateMarketCap(true);
|
||||
|
||||
return view;
|
||||
}
|
||||
@ -96,7 +98,16 @@ public class MarketCapitalization extends Fragment {
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
updateMarketCap();
|
||||
if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency()))
|
||||
{
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
updateMarketCap(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
updateMarketCap(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setupDominantCurrenciesColors()
|
||||
@ -120,9 +131,9 @@ public class MarketCapitalization extends Fragment {
|
||||
dominantCurrenciesColors.put("ETC", -10448784);
|
||||
}
|
||||
|
||||
private void updateMarketCap()
|
||||
private void updateMarketCap(boolean mustUpdate)
|
||||
{
|
||||
if(System.currentTimeMillis() / 1000 - lastTimestamp > 60)
|
||||
if(System.currentTimeMillis() / 1000 - lastTimestamp > 60 || mustUpdate)
|
||||
{
|
||||
if(!refreshLayout.isRefreshing())
|
||||
{
|
||||
@ -157,6 +168,48 @@ public class MarketCapitalization extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshDisplayedData()
|
||||
{
|
||||
setupTextViewMarketCap();
|
||||
|
||||
view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE);
|
||||
|
||||
List<PieEntry> entries = new ArrayList<>();
|
||||
|
||||
ArrayList<Integer> colors = new ArrayList<>();
|
||||
|
||||
float otherCurrenciesDominance = 0;
|
||||
|
||||
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
String key = (String) i.next();
|
||||
entries.add(new PieEntry(marketCapManager.getDominance().get(key), key));
|
||||
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
||||
colors.add(dominantCurrenciesColors.get(key));
|
||||
}
|
||||
|
||||
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
||||
colors.add(-12369084);
|
||||
|
||||
PieDataSet set = new PieDataSet(entries, "Market Cap Dominance");
|
||||
set.setColors(colors);
|
||||
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());
|
||||
|
||||
setupPieChart(data);
|
||||
|
||||
if(refreshLayout.isRefreshing())
|
||||
{
|
||||
refreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void countCompletedMarketCapRequest()
|
||||
{
|
||||
@ -164,44 +217,7 @@ public class MarketCapitalization extends Fragment {
|
||||
|
||||
if(marketCapCounter == 2)
|
||||
{
|
||||
setupTextViewMarketCap();
|
||||
|
||||
view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE);
|
||||
|
||||
List<PieEntry> entries = new ArrayList<>();
|
||||
|
||||
ArrayList<Integer> colors = new ArrayList<>();
|
||||
|
||||
float otherCurrenciesDominance = 0;
|
||||
|
||||
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
String key = (String) i.next();
|
||||
entries.add(new PieEntry(marketCapManager.getDominance().get(key), key));
|
||||
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
||||
colors.add(dominantCurrenciesColors.get(key));
|
||||
}
|
||||
|
||||
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
||||
colors.add(-12369084);
|
||||
|
||||
PieDataSet set = new PieDataSet(entries, "Market Cap Dominance");
|
||||
set.setColors(colors);
|
||||
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());
|
||||
|
||||
setupPieChart(data);
|
||||
|
||||
if(refreshLayout.isRefreshing())
|
||||
{
|
||||
refreshLayout.setRefreshing(false);
|
||||
}
|
||||
refreshDisplayedData();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,20 @@ import com.nauk.coinfolio.DataManagers.BalanceManager;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
||||
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
||||
import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator;
|
||||
import com.nauk.coinfolio.PlaceholderManager;
|
||||
import com.nauk.coinfolio.R;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
/**
|
||||
* Created by Tiji on 13/04/2018.
|
||||
@ -54,6 +61,7 @@ public class Summary extends Fragment {
|
||||
private HomeLayoutGenerator layoutGenerator;
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
private Dialog loadingDialog;
|
||||
private String defaultCurrency;
|
||||
|
||||
private TextView toolbarSubtitle;
|
||||
private CollapsingToolbarLayout toolbarLayout;
|
||||
@ -85,6 +93,8 @@ public class Summary extends Fragment {
|
||||
totalFluctuation = 0;
|
||||
lastTimestamp = 0;
|
||||
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
|
||||
handler = new Handler();
|
||||
updateRunnable = new Runnable() {
|
||||
@Override
|
||||
@ -180,7 +190,16 @@ public class Summary extends Fragment {
|
||||
|
||||
displayBalance(preferencesManager.isBalanceHidden());
|
||||
|
||||
updateAll(preferencesManager.mustUpdateSummary());
|
||||
if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency()))
|
||||
{
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
|
||||
updateAll(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
updateAll(preferencesManager.mustUpdateSummary());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAll(boolean mustUpdate)
|
||||
@ -240,13 +259,14 @@ public class Summary extends Fragment {
|
||||
Runnable newRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
if (balanceManager.getTotalBalance() != null)
|
||||
{
|
||||
final Currency currency = balanceManager.getTotalBalance().get(i);
|
||||
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()) > 0.001))
|
||||
{
|
||||
currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
|
||||
if (!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001)) {
|
||||
currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +373,7 @@ public class Summary extends Fragment {
|
||||
|
||||
if(preferencesManager.isBalanceHidden())
|
||||
{
|
||||
toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage)));
|
||||
toolbarLayout.setTitle(PlaceholderManager.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity()));
|
||||
toolbarSubtitle.setVisibility(View.GONE);
|
||||
|
||||
if(totalFluctuation > 0)
|
||||
@ -369,15 +389,7 @@ public class Summary extends Fragment {
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
toolbarLayout.setTitle(getResources().getString(R.string.currencyEurosPlaceholder, String.format("%.2f", totalValue)));
|
||||
break;
|
||||
default:
|
||||
toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, String.format("%.2f", totalValue)));
|
||||
break;
|
||||
}
|
||||
toolbarLayout.setTitle(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity()));
|
||||
toolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
|
||||
toolbarLayout.setExpandedTitleColor(Color.WHITE);
|
||||
|
||||
@ -394,33 +406,32 @@ public class Summary extends Fragment {
|
||||
|
||||
if(totalFluctuation == 0)
|
||||
{
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
toolbarSubtitle.setText(getResources().getString(R.string.currencyEurosPlaceholder, "0.00"));
|
||||
break;
|
||||
default:
|
||||
toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00"));
|
||||
break;
|
||||
}
|
||||
toolbarSubtitle.setText(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity()));
|
||||
toolbarSubtitle.setTextColor(-1275068417);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
toolbarSubtitle.setText(String.format("%.2f", totalFluctuation) + "€ (" + String.format("%.2f", totalFluctuationPercentage) + "%)");
|
||||
break;
|
||||
default:
|
||||
toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)");
|
||||
break;
|
||||
}
|
||||
toolbarSubtitle.setText(PlaceholderManager.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String numberConformer(double number)
|
||||
{
|
||||
String str;
|
||||
|
||||
if(abs(number) > 1)
|
||||
{
|
||||
str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
|
||||
{
|
||||
|
||||
@ -622,7 +633,7 @@ public class Summary extends Fragment {
|
||||
{
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
{
|
||||
balance.get(i).updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
||||
balance.get(i).updatePrice(getActivity(), defaultCurrency, new Currency.CurrencyCallBack() {
|
||||
@Override
|
||||
public void onSuccess(Currency currency) {
|
||||
countCoins(true, false);
|
||||
|
@ -70,7 +70,7 @@ public class Watchlist extends Fragment {
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
private long lastTimestamp;
|
||||
private PreferencesManager preferencesManager;
|
||||
private Toolbar toolbar;
|
||||
private String defaultCurrency;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
@ -82,6 +82,7 @@ public class Watchlist extends Fragment {
|
||||
preferencesManager = new PreferencesManager(getContext());
|
||||
|
||||
lastTimestamp = 0;
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
|
||||
watchlistManager = new WatchlistManager(getContext());
|
||||
|
||||
@ -93,7 +94,6 @@ public class Watchlist extends Fragment {
|
||||
updateWatchlist(false);
|
||||
}
|
||||
});
|
||||
toolbar = view.findViewById(R.id.toolbar);
|
||||
|
||||
Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist);
|
||||
addWatchlistButton.setOnClickListener(new View.OnClickListener() {
|
||||
@ -189,7 +189,15 @@ public class Watchlist extends Fragment {
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
updateWatchlist(preferencesManager.mustUpdateWatchlist());
|
||||
if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency()))
|
||||
{
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
updateWatchlist(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
updateWatchlist(preferencesManager.mustUpdateWatchlist());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWatchlist(boolean mustUpdate)
|
||||
@ -222,42 +230,47 @@ public class Watchlist extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateCards()
|
||||
{
|
||||
final List<View> watchlistViews = new ArrayList<View>();
|
||||
|
||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
|
||||
|
||||
Runnable newRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(final Currency currency : watchlistManager.getWatchlist())
|
||||
{
|
||||
watchlistViews.add(getCurrencyCardFor(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())
|
||||
{
|
||||
refreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void countWatchlist()
|
||||
{
|
||||
watchlistCounter++;
|
||||
|
||||
if(watchlistCounter >= watchlistManager.getWatchlist().size())
|
||||
{
|
||||
final List<View> watchlistViews = new ArrayList<View>();
|
||||
|
||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
|
||||
|
||||
Runnable newRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(final Currency currency : watchlistManager.getWatchlist())
|
||||
{
|
||||
watchlistViews.add(getCurrencyCardFor(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())
|
||||
{
|
||||
refreshLayout.setRefreshing(false);
|
||||
}
|
||||
generateCards();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,18 +233,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
});
|
||||
|
||||
bindPreferenceSummaryToValue(findPreference("default_currency"));
|
||||
findPreference("default_currency").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
|
||||
editor.putBoolean("refresh_default_currency", true);
|
||||
editor.apply();
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +128,6 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
||||
values.put(KEY_CURRENCY_BALANCE, balance);
|
||||
values.put(KEY_CURRENCY_DATE, date.getTime());
|
||||
values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice);
|
||||
//values.put(KEY_CURRENCY_PURCHASED_PRICE, something);
|
||||
|
||||
db.insert(TABLE_MANUAL_CURRENCIES, null, values);
|
||||
db.close();
|
||||
|
@ -9,6 +9,7 @@ import android.preference.PreferenceManager;
|
||||
|
||||
public class PreferencesManager {
|
||||
|
||||
private static int fragmentUpdated = 0;
|
||||
private static final String currencyListFile = "CustomCurrencies";
|
||||
private static final String preferencesFile = "Preferences";
|
||||
private SharedPreferences settingPreferences;
|
||||
@ -34,7 +35,20 @@ public class PreferencesManager {
|
||||
return preferencesList.getBoolean("DetailOption", true);
|
||||
}
|
||||
|
||||
public void disableRefreshDefaultCurrency()
|
||||
public boolean mustRefreshDefaultCurrency()
|
||||
{
|
||||
fragmentUpdated++;
|
||||
|
||||
if(fragmentUpdated == 3)
|
||||
{
|
||||
disableRefreshDefaultCurrency();
|
||||
fragmentUpdated = 0;
|
||||
}
|
||||
|
||||
return settingPreferences.getBoolean("refresh_default_currency", false);
|
||||
}
|
||||
|
||||
private void disableRefreshDefaultCurrency()
|
||||
{
|
||||
SharedPreferences.Editor editor = settingPreferences.edit();
|
||||
editor.putBoolean("refresh_default_currency", false);
|
||||
|
@ -26,6 +26,7 @@ import com.nauk.coinfolio.Activities.CurrencyDetailsActivity;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
|
||||
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
||||
import com.nauk.coinfolio.PlaceholderManager;
|
||||
import com.nauk.coinfolio.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
@ -64,7 +65,6 @@ public class HomeLayoutGenerator {
|
||||
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
||||
@Override
|
||||
public void onSuccess(Currency currency) {
|
||||
//setupLineChart(view, currency);
|
||||
ChartLoader chartLoader = new ChartLoader(view, currency);
|
||||
chartLoader.execute();
|
||||
}
|
||||
@ -206,39 +206,24 @@ public class HomeLayoutGenerator {
|
||||
double value = currency.getValue() * currency.getBalance();
|
||||
double percentage = value / totalValue * 100;
|
||||
DecimalFormat df = new DecimalFormat(".##");
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
((TextView) view.findViewById(R.id.currencyValueOwnedTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance())));
|
||||
((TextView) view.findViewById(R.id.currencyValueTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyEurosPlaceholder, numberConformer(currency.getValue())));
|
||||
((TextView) view.findViewById(R.id.currencyFluctuationTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
|
||||
break;
|
||||
default:
|
||||
((TextView) view.findViewById(R.id.currencyValueOwnedTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance())));
|
||||
((TextView) view.findViewById(R.id.currencyValueTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue())));
|
||||
((TextView) view.findViewById(R.id.currencyFluctuationTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
|
||||
|
||||
break;
|
||||
}
|
||||
((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(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol()));
|
||||
.setText(PlaceholderManager.getSymbolString(currency.getSymbol(), context));
|
||||
((TextView) view.findViewById(R.id.currencyOwnedTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol()));
|
||||
.setText(PlaceholderManager.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), context));
|
||||
((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView))
|
||||
.setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage())));
|
||||
.setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), context));
|
||||
|
||||
Drawable arrowDrawable = ((ImageView) view.findViewById(R.id.detailsArrow)).getDrawable();
|
||||
arrowDrawable.mutate();
|
||||
@ -251,7 +236,7 @@ public class HomeLayoutGenerator {
|
||||
progressBarDrawable.invalidateSelf();
|
||||
|
||||
((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage));
|
||||
((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, df.format(percentage)));
|
||||
((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderManager.getPercentageString(numberConformer(percentage), context));
|
||||
|
||||
if(isBalanceHidden)
|
||||
{
|
||||
|
135
app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java
Normal file
135
app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java
Normal file
@ -0,0 +1,135 @@
|
||||
package com.nauk.coinfolio;
|
||||
|
||||
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
||||
|
||||
/**
|
||||
* Created by Tiji on 19/04/2018.
|
||||
*/
|
||||
|
||||
public class PlaceholderManager {
|
||||
|
||||
public static String getValueString(String value, android.content.Context context)
|
||||
{
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
String formattedString = null;
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
formattedString = context.getResources().getString(R.string.currencyEurosPlaceholder, value);
|
||||
break;
|
||||
case "GBP":
|
||||
formattedString = context.getResources().getString(R.string.currencyPoundPlaceholder, value);
|
||||
break;
|
||||
default:
|
||||
formattedString = context.getResources().getString(R.string.currencyDollarPlaceholder, value);
|
||||
break;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
public static String getValuePercentageString(String value, String percentage, android.content.Context context)
|
||||
{
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
String formattedString = null;
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
formattedString = context.getResources().getString(R.string.fluctuationEurosPercentagePlaceholder, value, percentage);
|
||||
break;
|
||||
case "GBP":
|
||||
formattedString = context.getResources().getString(R.string.fluctuationPoundPercentagePlaceholder, value, percentage);
|
||||
break;
|
||||
default:
|
||||
formattedString = context.getResources().getString(R.string.fluctuationDollarPercentagePlaceholder, value, percentage);
|
||||
break;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
public static String getValueParenthesisString(String value, android.content.Context context)
|
||||
{
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
String formattedString = null;
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
formattedString = context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, value);
|
||||
break;
|
||||
case "GBP":
|
||||
formattedString = context.getResources().getString(R.string.currencyPoundParenthesisPlaceholder, value);
|
||||
break;
|
||||
default:
|
||||
formattedString = context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, value);
|
||||
break;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
public static String getPriceString(String value, android.content.Context context)
|
||||
{
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
String formattedString = null;
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
formattedString = context.getResources().getString(R.string.priceEurosPlaceholder, value);
|
||||
break;
|
||||
case "GBP":
|
||||
formattedString = context.getResources().getString(R.string.pricePoundPlaceholder, value);
|
||||
break;
|
||||
default:
|
||||
formattedString = context.getResources().getString(R.string.priceDollarPlaceholder, value);
|
||||
break;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
public static String getVolumeString(String value, android.content.Context context)
|
||||
{
|
||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
||||
String formattedString = null;
|
||||
|
||||
switch (preferencesManager.getDefaultCurrency())
|
||||
{
|
||||
case "EUR":
|
||||
formattedString = context.getResources().getString(R.string.volumeEurosPlaceholder, value);
|
||||
break;
|
||||
case "GBP":
|
||||
formattedString = context.getResources().getString(R.string.volumePoundPlaceholder, value);
|
||||
break;
|
||||
default:
|
||||
formattedString = context.getResources().getString(R.string.volumeDollarPlaceholder, value);
|
||||
break;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
public static String getSymbolString(String symbol, android.content.Context context)
|
||||
{
|
||||
return context.getResources().getString(R.string.currencySymbolPlaceholder, symbol);
|
||||
}
|
||||
|
||||
public static String getBalanceString(String balance, String symbol, android.content.Context context)
|
||||
{
|
||||
return context.getResources().getString(R.string.currencyBalancePlaceholder, balance, symbol);
|
||||
}
|
||||
|
||||
public static String getPercentageString(String value, android.content.Context context)
|
||||
{
|
||||
return context.getResources().getString(R.string.currencyPercentagePlaceholder, value);
|
||||
}
|
||||
|
||||
public static String getTimestampString(String date, android.content.Context context)
|
||||
{
|
||||
return context.getResources().getString(R.string.timestampPlaceholder, date);
|
||||
}
|
||||
}
|
@ -34,17 +34,19 @@
|
||||
|
||||
<string name="pref_title_default_currency">Default currency</string>
|
||||
<string-array name="pref_default_currencies_titles">
|
||||
<item>USD</item>
|
||||
<item>EUR</item>
|
||||
<item>BTC</item>
|
||||
<item>ETH</item>
|
||||
<item>Dollar (USD)</item>
|
||||
<item>Euro (EUR)</item>
|
||||
<item>Pound (GBP)</item>
|
||||
<!--<item>Bitcoin (BTC)</item>
|
||||
<item>Ethereum (ETH)</item>-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_default_currencies_values">
|
||||
<item>USD</item>
|
||||
<item>EUR</item>
|
||||
<item>BTC</item>
|
||||
<item>ETH</item>
|
||||
<item>GBP</item>
|
||||
<!--<item>BTC</item>
|
||||
<item>ETH</item>-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="list_preference_entries">
|
||||
@ -137,20 +139,31 @@
|
||||
<!--Cardview placeholders-->
|
||||
<string name="currencySymbolPlaceholder">(%1$s)</string>
|
||||
<string name="currencyBalancePlaceholder">%1$s%2$s</string>
|
||||
<string name="currencyPercentagePlaceholder">%1$s%%</string>
|
||||
<!--Dollar-->
|
||||
<string name="currencyDollarParenthesisPlaceholder">(US$%1$s)</string>
|
||||
<string name="currencyDollarPlaceholder">US$%1$s</string>
|
||||
<string name="fluctuationDollarPercentagePlaceholder">US$%1$s (%2$s%%)</string>
|
||||
<!--Euro-->
|
||||
<string name="currencyEurosParenthesisPlaceholder">(%1$s€)</string>
|
||||
<string name="currencyEurosPlaceholder">%1$s€</string>
|
||||
<string name="currencyPercentagePlaceholder">%1$s%%</string>
|
||||
<string name="fluctuationDollarPercentagePlaceholder">US$%1$s (%2$s%)</string>
|
||||
<string name="fluctuationEurosPercentagePlaceholder">%1$s€ (%2$s%)</string>
|
||||
<string name="fluctuationEurosPercentagePlaceholder">%1$s€ (%2$s%%)</string>
|
||||
<!--Pound-->
|
||||
<string name="currencyPoundParenthesisPlaceholder">(%1$s£)</string>
|
||||
<string name="currencyPoundPlaceholder">%1$s£</string>
|
||||
<string name="fluctuationPoundPercentagePlaceholder">%1$s£ (%2$s%%)</string>
|
||||
|
||||
<!--DetailsActivity placeholders-->
|
||||
<string name="timestampPlaceholder">Date\n%1$s</string>
|
||||
<!--Dollar-->
|
||||
<string name="volumeDollarPlaceholder">Volume\nUS$%1$s</string>
|
||||
<string name="priceDollarPlaceholder">Price\nUS$%1$s</string>
|
||||
<!--Euro-->
|
||||
<string name="volumeEurosPlaceholder">Volume\n%1$s€</string>
|
||||
<string name="priceEurosPlaceholder">Price\n%1$s€</string>
|
||||
<string name="timestampPlaceholder">Date\n%1$s</string>
|
||||
<!--Pound-->
|
||||
<string name="volumePoundPlaceholder">Volume\n%1$s£</string>
|
||||
<string name="pricePoundPlaceholder">Price\n%1$s£</string>
|
||||
|
||||
<string name="title_activity_main">MainActivity</string>
|
||||
|
||||
@ -158,10 +171,17 @@
|
||||
<string name="fingerprint_dialog_title">Verify your fingerprint to continue</string>
|
||||
|
||||
|
||||
<!--Marketcap placeholders-->
|
||||
<!--Dollar-->
|
||||
<string name="market_cap_dollar_textview">Total Market Capitalization :\nUS$%1$s</string>
|
||||
<string name="volume_dollar_market_cap_textview">24h volume :\nUS$%1$s</string>
|
||||
<!--Euro-->
|
||||
<string name="market_cap_euros_textview">Total Market Capitalization :\n%1$s€</string>
|
||||
<string name="volume_euros_market_cap_textview">24h volume :\n%1$s€</string>
|
||||
<!--Pound-->
|
||||
<string name="market_cap_pound_textview">Total Market Capitalization :\n%1$s£</string>
|
||||
<string name="volume_pound_market_cap_textview">24h volume :\n%1$s£</string>
|
||||
|
||||
<string name="title_activity_scrolling">ScrollingActivity</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user