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 2cabb4d..df8577b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -16,7 +16,6 @@ import android.support.v4.app.NavUtils; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; @@ -300,7 +299,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { updateChartTab(DAY, 1); break; case "3d": - currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { + currency.updateHistoryHours(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -313,7 +312,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "1w": - currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { + currency.updateHistoryHours(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -326,7 +325,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "1M": - currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { + currency.updateHistoryHours(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -339,7 +338,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "3M": - currency.updateHistoryDays(this, new Currency.CurrencyCallBack() { + currency.updateHistoryDays(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -352,7 +351,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "6M": - currency.updateHistoryDays(this, new Currency.CurrencyCallBack() { + currency.updateHistoryDays(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -365,7 +364,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "1y": - currency.updateHistoryDays(this, new Currency.CurrencyCallBack() { + currency.updateHistoryDays(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -550,8 +549,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { date = getDate(dataChartList.get(index).getTimestamp() * 1000); } - volumePlaceholder = getResources().getString(R.string.volumePlaceholder, numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY())); - pricePlaceholder = getResources().getString(R.string.pricePlaceholder, numberConformer(e.getY())); + 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); ((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); 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 c19a544..cb69a10 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -121,7 +121,10 @@ public class HomeActivity extends AppCompatActivity { viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - //bottomNavigationView.getMenu().getItem(position).setChecked(true); + if(!bottomNavigationView.getMenu().getItem(position).isChecked()) + { + bottomNavigationView.getMenu().getItem(position).setChecked(true); + } if(position % 2 == 0) { 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 386b2f2..14b104d 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 @@ -25,6 +25,7 @@ import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.PercentFormatter; import com.nauk.coinfolio.Activities.SettingsActivity; import com.nauk.coinfolio.DataManagers.MarketCapManager; +import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.R; import java.text.DecimalFormat; @@ -44,6 +45,7 @@ public class MarketCapitalization extends Fragment { private int marketCapCounter; + private PreferencesManager preferencesManager; private MarketCapManager marketCapManager; private HashMap dominantCurrenciesColors; private SwipeRefreshLayout refreshLayout; @@ -54,6 +56,7 @@ public class MarketCapitalization extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + preferencesManager = new PreferencesManager(getContext()); view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false); setupDominantCurrenciesColors(); @@ -92,6 +95,8 @@ public class MarketCapitalization extends Fragment { public void onResume() { super.onResume(); + + updateMarketCap(); } private void setupDominantCurrenciesColors() @@ -141,7 +146,7 @@ public class MarketCapitalization extends Fragment { public void onSuccess() { countCompletedMarketCapRequest(); } - }); + }, preferencesManager.getDefaultCurrency()); } else { @@ -249,8 +254,20 @@ public class MarketCapitalization extends Fragment { symbols.setGroupingSeparator(' '); formatter.setDecimalFormatSymbols(symbols); - ((TextView) view.findViewById(R.id.marketCapTextView)).setText(getActivity().getResources().getString(R.string.market_cap_textview, formatter.format(marketCapManager.getMarketCap()))); - - ((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap)).setText(getActivity().getResources().getString(R.string.volume_market_cap_textview, formatter.format(marketCapManager.getDayVolume()))); + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + ((TextView) view.findViewById(R.id.marketCapTextView)) + .setText(getActivity().getResources().getString(R.string.market_cap_euros_textview, formatter.format(marketCapManager.getMarketCap()))); + ((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap)) + .setText(getActivity().getResources().getString(R.string.volume_euros_market_cap_textview, formatter.format(marketCapManager.getDayVolume()))); + break; + default: + ((TextView) view.findViewById(R.id.marketCapTextView)) + .setText(getActivity().getResources().getString(R.string.market_cap_dollar_textview, formatter.format(marketCapManager.getMarketCap()))); + ((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap)) + .setText(getActivity().getResources().getString(R.string.volume_dollar_market_cap_textview, formatter.format(marketCapManager.getDayVolume()))); + break; + } } } 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 654fc49..160151a 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 @@ -8,7 +8,9 @@ import android.graphics.Color; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; +import android.support.annotation.NonNull; import android.support.design.widget.CollapsingToolbarLayout; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; @@ -50,7 +52,6 @@ public class Summary extends Fragment { private PreferencesManager preferencesManager; private BalanceManager balanceManager; private HomeLayoutGenerator layoutGenerator; - private View view; private SwipeRefreshLayout refreshLayout; private Dialog loadingDialog; @@ -67,17 +68,18 @@ public class Summary extends Fragment { protected float totalFluctuation; private long lastTimestamp; + @NonNull @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - view = inflater.inflate(R.layout.fragment_summary_homeactivity, container, false); + View fragmentView = inflater.inflate(R.layout.fragment_summary_homeactivity, container, false); - currencyLayout = view.findViewById(R.id.currencyListLayout); + currencyLayout = fragmentView.findViewById(R.id.currencyListLayout); preferencesManager = new PreferencesManager(getActivity()); balanceManager = new BalanceManager(getActivity()); layoutGenerator = new HomeLayoutGenerator(getActivity()); - refreshLayout = view.findViewById(R.id.swiperefreshsummary); - toolbarSubtitle = view.findViewById(R.id.toolbarSubtitle); + refreshLayout = fragmentView.findViewById(R.id.swiperefreshsummary); + toolbarSubtitle = fragmentView.findViewById(R.id.toolbarSubtitle); totalValue = 0; totalFluctuation = 0; @@ -114,12 +116,12 @@ public class Summary extends Fragment { ); handler.postDelayed(updateRunnable, 10000); - toolbarLayout = view.findViewById(R.id.toolbar_layout); + toolbarLayout = fragmentView.findViewById(R.id.toolbar_layout); toolbarLayout.setForegroundGravity(Gravity.CENTER); - Button addCurrencyButton = view.findViewById(R.id.buttonAddTransaction); + Button addCurrencyButton = fragmentView.findViewById(R.id.buttonAddTransaction); - ImageButton settingsButton = view.findViewById(R.id.settings_button); + ImageButton settingsButton = fragmentView.findViewById(R.id.settings_button); settingsButton.setOnClickListener(new View.OnClickListener() { @Override @@ -142,7 +144,7 @@ public class Summary extends Fragment { generateSplashScreen(); - return view; + return fragmentView; } private void generateSplashScreen() @@ -176,9 +178,9 @@ public class Summary extends Fragment { public void onResume() { super.onResume(); - updateAll(preferencesManager.mustUpdateSummary()); - displayBalance(preferencesManager.isBalanceHidden()); + + updateAll(preferencesManager.mustUpdateSummary()); } private void updateAll(boolean mustUpdate) @@ -197,7 +199,6 @@ public class Summary extends Fragment { resetCounters(); DataUpdater updater = new DataUpdater(); updater.execute(); - } else { @@ -236,7 +237,7 @@ public class Summary extends Fragment { final List currencyView = new ArrayList<>(); - Runnable newRunnabmle = new Runnable() { + Runnable newRunnable = new Runnable() { @Override public void run() { for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) @@ -261,7 +262,7 @@ public class Summary extends Fragment { } }; - newRunnabmle.run(); + newRunnable.run(); } private void countCoins(boolean isCoin, boolean isDetails) @@ -293,7 +294,6 @@ public class Summary extends Fragment { } } - private void countIcons() { int offset = 0; @@ -351,8 +351,6 @@ public class Summary extends Fragment { { float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100; - - if(preferencesManager.isBalanceHidden()) { toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage))); @@ -371,7 +369,15 @@ public class Summary extends Fragment { } else { - toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, String.format("%.2f", totalValue))); + 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.setCollapsedTitleTextColor(Color.WHITE); toolbarLayout.setExpandedTitleColor(Color.WHITE); @@ -388,13 +394,29 @@ public class Summary extends Fragment { if(totalFluctuation == 0) { - toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); + 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.setTextColor(-1275068417); } else { - toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); + 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; + } } } } @@ -600,7 +622,7 @@ public class Summary extends Fragment { { for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) { - balance.get(i).updatePrice(getActivity(), new Currency.CurrencyCallBack() { + balance.get(i).updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { countCoins(true, false); @@ -622,27 +644,34 @@ public class Summary extends Fragment { public void onError(String error) { - /*switch (error) + View view = getActivity().findViewById(R.id.snackbar_placer); + + switch (error) { case "com.android.volley.AuthFailureError": preferencesManager.disableHitBTC(); - Snackbar.make(findViewById(R.id.viewFlipperSummary), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) + Snackbar.make(view, "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) .show(); + refreshLayout.setRefreshing(false); + updateAll(true); break; case "API-key format invalid.": preferencesManager.disableBinance(); - Snackbar.make(findViewById(R.id.viewFlipperSummary), "Binance synchronization error : Invalid keys", Snackbar.LENGTH_LONG) + Snackbar.make(view, "Binance synchronization error : Invalid keys", Snackbar.LENGTH_LONG) .show(); + updateAll(true); break; default: - Snackbar.make(findViewById(R.id.viewFlipperSummary), "Unexpected error", Snackbar.LENGTH_LONG) + Snackbar.make(view, "Unexpected error", Snackbar.LENGTH_LONG) .show(); + Log.d("coinfolio", error); + updateAll(true); - }*/ + } } }); 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 0a73f8a..66755f7 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 @@ -237,64 +237,7 @@ public class Watchlist extends Fragment { public void run() { for(final Currency currency : watchlistManager.getWatchlist()) { - View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null); - - ((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(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); - ((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); - ((TextView) card.findViewById(R.id.currencyValueTextView)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); - - Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable(); - arrowDrawable.mutate(); - arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - arrowDrawable.invalidateSelf(); - - updateColor(card, currency); - - 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) - { - collapseView(view); - } - else - { - if (currency.getHistoryMinutes() == null) { - currency.updateHistoryMinutes(getActivity(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - extendView(view); - setupLineChart(view, currency); - } - }); - } - else - { - extendView(view); - } - } - } - }); - - 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); - } - }); - - if(currency.getHistoryMinutes() != null) - { - setupLineChart(card, currency); - } - - watchlistViews.add(card); + watchlistViews.add(getCurrencyCardFor(currency)); } getActivity().runOnUiThread(new Runnable() { @@ -317,6 +260,86 @@ public class Watchlist extends Fragment { } } } + + private View getCurrencyCardFor(final Currency currency) + { + View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null); + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + ((TextView) card.findViewById(R.id.currencyFluctuationTextView)) + .setText(getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); + ((TextView) card.findViewById(R.id.currencyValueTextView)) + .setText(getResources().getString(R.string.currencyEurosPlaceholder, numberConformer(currency.getValue()))); + break; + default : + ((TextView) card.findViewById(R.id.currencyFluctuationTextView)) + .setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); + ((TextView) card.findViewById(R.id.currencyValueTextView)) + .setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); + break; + } + + ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)) + .setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); + ((TextView) card.findViewById(R.id.currencyNameTextView)) + .setText(currency.getName()); + ((TextView) card.findViewById(R.id.currencySymbolTextView)) + .setText(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); + ((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); + + Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable(); + arrowDrawable.mutate(); + arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + arrowDrawable.invalidateSelf(); + + updateColor(card, currency); + + 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) + { + collapseView(view); + } + else + { + if (currency.getHistoryMinutes() == null) { + currency.updateHistoryMinutes(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + extendView(view); + setupLineChart(view, currency); + } + }); + } + else + { + extendView(view); + } + } + } + }); + + 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); + } + }); + + if(currency.getHistoryMinutes() != null) + { + setupLineChart(card, currency); + } + + return card; + } + private LineData generateData(Currency currency) { LineDataSet dataSet; @@ -456,7 +479,7 @@ public class Watchlist extends Fragment { protected Void doInBackground(Void... voids) { for(final Currency currency : watchlistManager.getWatchlist()) { - currency.updatePrice(getActivity(), new Currency.CurrencyCallBack() { + currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(final Currency sucessCurrency) { if(getIconUrl(sucessCurrency.getSymbol()) != null) 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 28374d9..6cef03b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -80,7 +80,7 @@ public class RecordTransactionActivity extends AppCompatActivity { } }); - currency.getTimestampPrice(this, new Currency.PriceCallBack() { + currency.getTimestampPrice(this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { @Override public void onSuccess(String price) { purchasedPrice.setText(price); @@ -119,7 +119,7 @@ public class RecordTransactionActivity extends AppCompatActivity { calendar.set(Calendar.MINUTE, minute); purchasedDate.setText(sdf.format(calendar.getTime())); - currency.getTimestampPrice(RecordTransactionActivity.this, new Currency.PriceCallBack() { + currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { @Override public void onSuccess(String price) { purchasedPrice.setText(price); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java index 9f032d5..9bdc14d 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -31,6 +31,7 @@ import android.util.Log; import android.view.MenuItem; import android.view.View; +import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.FingerprintToolkit.FingerprintDialogFragment; import com.nauk.coinfolio.FingerprintToolkit.FingerprintHandler; import com.nauk.coinfolio.R; @@ -230,6 +231,20 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return isChecked; } }); + + 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 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 5dc3515..6a351a5 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -96,7 +96,7 @@ public class BalanceManager { hitBtcManagers.clear(); - if(publicKey != null && privateKey != null && preferenceManager.isHitBTCActivated()) + if(preferenceManager.isHitBTCActivated() && publicKey != null && privateKey != null) { hitBtcManagers.add(new HitBtcManager(context, publicKey, privateKey)); } @@ -106,7 +106,7 @@ public class BalanceManager { binanceManagers.clear(); - if(publicKey != null && privateKey != null && preferenceManager.isBinanceActivated()) + if(preferenceManager.isBinanceActivated() && publicKey != null && privateKey != null) { binanceManagers.add(new BinanceManager(publicKey, privateKey)); } @@ -120,6 +120,8 @@ public class BalanceManager { public void updateTotalBalance(final VolleyCallBack callBack) { boolean isUpdated = false; + + balanceCounter = 0; manualBalances = databaseManager.getAllCurrenciesFromManualCurrency(); 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 1fcf88c..a4b616c 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 @@ -64,11 +64,11 @@ public class Currency implements Parcelable { //public Currency(int id, String symbol, String name, String algorithm, String proofType, ) - public void getTimestampPrice(android.content.Context context, final PriceCallBack callBack, long timestamp) + public void getTimestampPrice(android.content.Context context, String toSymbol, final PriceCallBack callBack, long timestamp) { dataRetriver = new CurrencyDataRetriever(context); - dataRetriver.getPriceTimestamp(symbol, new CurrencyDataRetriever.DataChartCallBack() { + dataRetriver.getPriceTimestamp(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() { @Override public void onSuccess(List dataChart) {} @@ -97,11 +97,11 @@ public class Currency implements Parcelable { return url; } - public void updatePrice(android.content.Context context, final CurrencyCallBack callBack) + public void updatePrice(android.content.Context context, String toSymbol, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); - dataRetriver.updatePrice(symbol, new CurrencyDataRetriever.PriceCallBack() { + dataRetriver.updatePrice(symbol, toSymbol, new CurrencyDataRetriever.PriceCallBack() { @Override public void onSuccess(Currency currencyInfo) { if(currencyInfo != null) @@ -117,11 +117,11 @@ public class Currency implements Parcelable { }); } - public void updateHistoryMinutes(android.content.Context context, final CurrencyCallBack callBack) + public void updateHistoryMinutes(android.content.Context context, String toSymbol, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); - dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() { + dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() { @Override public void onSuccess(List dataChart) { setHistoryMinutes(dataChart); @@ -134,10 +134,10 @@ public class Currency implements Parcelable { }, CurrencyDataRetriever.MINUTES); } - public void updateHistoryHours(android.content.Context context, final CurrencyCallBack callBack) + public void updateHistoryHours(android.content.Context context, String toSymbol, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); - dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() { + dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() { @Override public void onSuccess(List dataChart) { setHistoryHours(dataChart); @@ -150,10 +150,10 @@ public class Currency implements Parcelable { }, CurrencyDataRetriever.HOURS); } - public void updateHistoryDays(android.content.Context context, final CurrencyCallBack callBack) + public void updateHistoryDays(android.content.Context context, String toSymbol, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); - dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() { + dataRetriver.updateHistory(symbol, toSymbol, new CurrencyDataRetriever.DataChartCallBack() { @Override public void onSuccess(List dataChart) { setHistoryDays(dataChart); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java index 85f2860..2441881 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -44,7 +44,7 @@ public class CurrencyDataRetriever { requestQueue = Volley.newRequestQueue(context); } - private void getPriceTimestamp(final String symbolCurrencyFrom, String symbolCurrencyTo, final DataChartCallBack callBack, long timestamp) + public void getPriceTimestamp(final String symbolCurrencyFrom, String symbolCurrencyTo, final DataChartCallBack callBack, long timestamp) { final String requestUrl = "https://min-api.cryptocompare.com/data/pricehistorical?fsym=" + symbolCurrencyFrom + "&tsyms=" + symbolCurrencyTo + "&ts=" + timestamp; @@ -74,7 +74,7 @@ public class CurrencyDataRetriever { return result; } - private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) + public void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); @@ -95,7 +95,7 @@ public class CurrencyDataRetriever { requestQueue.add(stringRequest); } - private void updatePrice(final String symbolCurrencyFrom, String symbolCurrencyTo, final PriceCallBack callBack) + public void updatePrice(final String symbolCurrencyFrom, String symbolCurrencyTo, final PriceCallBack callBack) { String requestUrl = priceUrl + symbolCurrencyFrom + "&tsyms=" + symbolCurrencyTo; 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 7219f2d..32cb349 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -145,7 +145,6 @@ 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(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java index 1045f5d..f7cf4e9 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java @@ -23,7 +23,7 @@ import java.util.regex.Pattern; public class MarketCapManager { private static final String topCurrenciesUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=9"; - private static final String marketCapUrl = "https://api.coinmarketcap.com/v1/global/"; + private static final String marketCapUrl = "https://api.coinmarketcap.com/v1/global/?convert="; private RequestQueue requestQueue; private String topRequestResult[]; private long marketCap; @@ -57,9 +57,11 @@ public class MarketCapManager { requestQueue.add(strRequest); } - public void updateMarketCap(final VolleyCallBack callBack) + public void updateMarketCap(final VolleyCallBack callBack, String toSymbol) { - StringRequest strRequest = new StringRequest(Request.Method.GET, marketCapUrl, + String requestString = marketCapUrl + toSymbol; + + StringRequest strRequest = new StringRequest(Request.Method.GET, requestString, new Response.Listener() { @Override public void onResponse(String response) { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java index 706107f..74f4d60 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -34,6 +34,18 @@ public class PreferencesManager { return preferencesList.getBoolean("DetailOption", true); } + public void disableRefreshDefaultCurrency() + { + SharedPreferences.Editor editor = settingPreferences.edit(); + editor.putBoolean("refresh_default_currency", false); + editor.apply(); + } + + public String getDefaultCurrency() + { + return settingPreferences.getString("default_currency", "USD"); + } + public String getHitBTCPublicKey() { return settingPreferences.getString("hitbtc_publickey", null); 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 0f28802..a0dba8f 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -7,6 +7,7 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.preference.PreferenceScreen; import android.support.v7.widget.CardView; import android.util.Log; import android.view.LayoutInflater; @@ -24,6 +25,7 @@ import com.github.mikephil.charting.data.LineDataSet; 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.R; import java.text.DecimalFormat; @@ -53,11 +55,13 @@ public class HomeLayoutGenerator { 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) { collapseView(view); } else { if (currency.getHistoryMinutes() == null) { - currency.updateHistoryMinutes(context, new Currency.CurrencyCallBack() { + currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { //setupLineChart(view, currency); @@ -202,6 +206,28 @@ 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; + } ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); @@ -211,15 +237,8 @@ public class HomeLayoutGenerator { .setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); ((TextView) view.findViewById(R.id.currencyOwnedTextView)) .setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol())); - ((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.currencyFluctuationPercentageTextView)) .setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); Drawable arrowDrawable = ((ImageView) view.findViewById(R.id.detailsArrow)).getDrawable(); arrowDrawable.mutate(); diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index e4c5bc3..4a4ff92 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -13,8 +13,14 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_marginBottom="56dp" + android:orientation="vertical" android:background="@color/summary_background"> + + Data & sync - Sync frequency - - 15 minutes - 30 minutes - 1 hour - 3 hours - 6 hours - Never + Default currency + + USD + EUR + BTC + ETH - - 15 - 30 - 60 - 180 - 360 - -1 + + + USD + EUR + BTC + ETH @@ -142,12 +139,17 @@ %1$s%2$s (US$%1$s) US$%1$s + (%1$s€) + %1$s€ %1$s%% US$%1$s (%2$s%) + %1$s€ (%2$s%) - Volume\nUS$%1$s - Price\nUS$%1$s + Volume\nUS$%1$s + Price\nUS$%1$s + Volume\n%1$s€ + Price\n%1$s€ Date\n%1$s MainActivity @@ -156,8 +158,10 @@ Verify your fingerprint to continue - Total Market Capitalization :\nUS$%1$s - 24h volume :\nUS$%1$s + Total Market Capitalization :\nUS$%1$s + 24h volume :\nUS$%1$s + Total Market Capitalization :\n%1$s€ + 24h volume :\n%1$s€ ScrollingActivity diff --git a/app/src/main/res/xml/pref_data_sync.xml b/app/src/main/res/xml/pref_data_sync.xml index 6bd9192..1e29df1 100644 --- a/app/src/main/res/xml/pref_data_sync.xml +++ b/app/src/main/res/xml/pref_data_sync.xml @@ -3,14 +3,14 @@ - + android:entries="@array/pref_sync_frequency_titles" + android:entryValues="@array/pref_sync_frequency_values" + android:key="sync_frequency" + android:negativeButtonText="@null" + android:positiveButtonText="@null" + android:title="@string/pref_title_sync_frequency" />--> diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 264c219..f4f0328 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -5,6 +5,16 @@ android:key="hide_balance" android:title="@string/pref_title_hide_balance" /> + + +