From 373a944e4112ef9687397329650a800cd83ecfdb Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sat, 5 May 2018 16:53:22 +0200 Subject: [PATCH] Fix and improvements - Clear code - Add Mooblbox for toolbox methods - Add minimum value settings to display a currency (ex : everything above 0.01) - Fix Market capitalization padding - Reduce FPS drop while reloading data - Fix refresh for 1H, 3H and 1D charts in detail activity --- app/build.gradle | 7 +- .../Activities/CurrencyDetailsActivity.java | 106 +++--- .../nauk/moodl/Activities/HomeActivity.java | 6 - .../MarketCapitalization.java | 80 ++-- .../HomeActivityFragments/Summary.java | 343 +++++++++--------- .../HomeActivityFragments/Watchlist.java | 219 +++-------- .../Activities/RecordTransactionActivity.java | 45 ++- .../moodl/Activities/SettingsActivity.java | 72 +--- .../DataManagers/PreferencesManager.java | 18 + .../FingerprintDialogFragment.java | 12 +- .../LayoutManagers/HomeLayoutGenerator.java | 49 +-- .../LayoutManagers/TradeListAdapter.java | 16 +- .../TransactionListAdapter.java | 89 +---- .../main/java/com/nauk/moodl/MoodlBox.java | 191 ++++++++++ .../fragment_marketcap_homeactivity.xml | 2 +- app/src/main/res/values-fr/strings.xml | 30 ++ app/src/main/res/values/strings.xml | 37 +- app/src/main/res/xml/pref_general.xml | 9 + export/release/output.json | 2 +- 19 files changed, 631 insertions(+), 702 deletions(-) create mode 100644 app/src/main/java/com/nauk/moodl/MoodlBox.java create mode 100644 app/src/main/res/values-fr/strings.xml diff --git a/app/build.gradle b/app/build.gradle index 7e14a8b..3abb9cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,14 +6,17 @@ android { applicationId "com.nauk.moodl" minSdkVersion 23 targetSdkVersion 27 - versionCode 1 - versionName "0.0.1" + versionCode 2 + versionName "0.0.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + lintOptions { + disable 'MissingTranslation' + } } } sourceSets { diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java index 961ee89..079618b 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java @@ -1,12 +1,9 @@ package com.nauk.moodl.Activities; -import android.app.ProgressDialog; -import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; @@ -17,14 +14,12 @@ import android.os.Bundle; import android.os.Looper; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; -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.support.v7.widget.CardView; import android.text.Html; import android.text.method.LinkMovementMethod; -import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; @@ -65,13 +60,11 @@ import com.nauk.moodl.LayoutManagers.TransactionListAdapter; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; -import java.lang.reflect.Array; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Locale; +import static com.nauk.moodl.MoodlBox.numberConformer; +import static com.nauk.moodl.MoodlBox.getDateFromTimestamp; import static java.lang.Math.abs; /**Create a Parcelable**/ @@ -266,8 +259,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { .setText(currency.getStartDate()); } - ((TextView) findViewById(R.id.txtViewDescription)) - .setText(Html.fromHtml(currency.getDescription())); + if(currency.getDescription() != null) + { + ((TextView) findViewById(R.id.txtViewDescription)) + .setText(Html.fromHtml(currency.getDescription())); + } + ((TextView) findViewById(R.id.txtViewDescription)) .setMovementMethod(LinkMovementMethod.getInstance()); ((TextView) findViewById(R.id.txtViewPercentageCoinEmited)) @@ -412,13 +409,43 @@ public class CurrencyDetailsActivity extends AppCompatActivity { switch (interval) { case "1h": - updateChartTab(HOUR, 1); + currency.updateHistoryMinutes(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(CurrencyDetailsActivity.HOUR, 1); + } + }); + } + }); break; case "3h": - updateChartTab(HOUR, 3); + currency.updateHistoryMinutes(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(CurrencyDetailsActivity.HOUR, 3); + } + }); + } + }); break; case "1d": - updateChartTab(DAY, 1); + currency.updateHistoryMinutes(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(CurrencyDetailsActivity.DAY, 1); + } + }); + } + }); break; case "3d": currency.updateHistoryHours(this, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @@ -664,11 +691,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { if(dataChartList.size() > 200) { - date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); + date = getDateFromTimestamp(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); } else { - date = getDate(dataChartList.get(index).getTimestamp() * 1000); + date = getDateFromTimestamp(dataChartList.get(index).getTimestamp() * 1000); } volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), this); @@ -707,18 +734,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); } - private String getDate(long timeStamp){ - - try{ - SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault()); - Date netDate = (new Date(timeStamp)); - return sdf.format(netDate); - } - catch(Exception ex){ - return "xx"; - } - } - private BarData generateVolumeChartSet() { BarDataSet dataSet; @@ -746,41 +761,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return new BarData(dataSet); } - 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*$", ""); - } - - if(!str.equals("Infinity")) - { - int counter = 0; - int i = str.indexOf("."); - if(i <= 0) - { - i = str.length(); - } - for(i -= 1; i > 0; i--) - { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } - } - } - - return str; - } - private CandleData generatePriceCandleStickChartSet() { CandleDataSet dataSet; diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java index 283c3c2..26fe9ff 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java @@ -61,12 +61,6 @@ public class HomeActivity extends AppCompatActivity { w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - //Setup main interface - //requestWindowFeature(Window.FEATURE_NO_TITLE); - //getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); - //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); - //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - setContentView(R.layout.activity_currency_summary); viewPager = findViewById(R.id.viewPager); diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index 871230d..85118d8 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; +import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; /** @@ -52,12 +53,27 @@ 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(); + preferencesManager = new PreferencesManager(getContext()); marketCapManager = new MarketCapManager(getContext()); + + defaultCurrency = preferencesManager.getDefaultCurrency(); + lastTimestamp = 0; + + setupRefreshLayout(); + + setupSettingsButton(); + + updateMarketCap(true); + + return view; + } + + private void setupRefreshLayout() + { refreshLayout = view.findViewById(R.id.swiperefreshmarketcap); refreshLayout.setOnRefreshListener( @@ -69,10 +85,10 @@ public class MarketCapitalization extends Fragment { } ); + } - defaultCurrency = preferencesManager.getDefaultCurrency(); - lastTimestamp = 0; - + private void setupSettingsButton() + { ImageButton settingsButton = view.findViewById(R.id.settings_button); settingsButton.setOnClickListener(new View.OnClickListener() { @@ -82,10 +98,6 @@ public class MarketCapitalization extends Fragment { startActivity(settingIntent); } }); - - updateMarketCap(true); - - return view; } @Override @@ -170,6 +182,20 @@ public class MarketCapitalization extends Fragment { view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE); view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE); + PieData data = new PieData(getMarketDominanceDataSet()); + data.setValueTextSize(10); + data.setValueFormatter(new PercentFormatter()); + + setupPieChart(data); + + if(refreshLayout.isRefreshing()) + { + refreshLayout.setRefreshing(false); + } + } + + private PieDataSet getMarketDominanceDataSet() + { List entries = new ArrayList<>(); ArrayList colors = new ArrayList<>(); @@ -192,16 +218,7 @@ public class MarketCapitalization extends Fragment { 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); - } + return set; } @SuppressLint("ClickableViewAccessibility") @@ -250,33 +267,6 @@ public class MarketCapitalization extends Fragment { pieChart.invalidate(); } - 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*$", ""); - } - - int counter = 0; - for(int i = str.length() - 1; i > 0; i--) - { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } - } - - return str; - } - private SpannableString generateCenterSpannableText() { SpannableString spannableString = new SpannableString("Market Capitalization Dominance"); diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java index 2d8cf08..beb5085 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; /** @@ -66,6 +67,7 @@ public class Summary extends Fragment { private Handler handler; private Runnable updateRunnable; + private Runnable layoutRefresherRunnable; private int coinCounter; private int iconCounter; @@ -81,22 +83,51 @@ public class Summary extends Fragment { { View fragmentView = inflater.inflate(R.layout.fragment_summary_homeactivity, container, false); - currencyLayout = fragmentView.findViewById(R.id.currencyListLayout); preferencesManager = new PreferencesManager(getActivity()); balanceManager = new BalanceManager(getActivity()); layoutGenerator = new HomeLayoutGenerator(getActivity()); - refreshLayout = fragmentView.findViewById(R.id.swiperefreshsummary); - toolbarSubtitle = fragmentView.findViewById(R.id.toolbarSubtitle); currencyTickerList = new CurrencyTickerList(getActivity()); - totalValue = 0; - totalFluctuation = 0; - lastTimestamp = 0; - tickersChecker = false; + currencyLayout = fragmentView.findViewById(R.id.currencyListLayout); + refreshLayout = fragmentView.findViewById(R.id.swiperefreshsummary); + toolbarSubtitle = fragmentView.findViewById(R.id.toolbarSubtitle); + + resetCounters(); defaultCurrency = preferencesManager.getDefaultCurrency(); handler = new Handler(); + + initiateUpdateRunnable(); + + initiateLayoutRefresherRunnable(); + + refreshLayout.setOnRefreshListener( + new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + updateAll(false); + } + } + ); + + handler.postDelayed(updateRunnable, 10000); + toolbarLayout = fragmentView.findViewById(R.id.toolbar_layout); + toolbarLayout.setForegroundGravity(Gravity.CENTER); + + setupAddCurrencyButton(fragmentView); + + setupSettingsButton(fragmentView); + + updateAll(true); + + generateSplashScreen(); + + return fragmentView; + } + + private void initiateUpdateRunnable() + { updateRunnable = new Runnable() { @Override public void run() { @@ -115,23 +146,62 @@ public class Summary extends Fragment { } } }; + } - refreshLayout.setOnRefreshListener( - new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - updateAll(false); + private void initiateLayoutRefresherRunnable() + { + layoutRefresherRunnable = new Runnable() { + @Override + public void run() { + final List currencyView = new ArrayList<>(); + + if (balanceManager.getTotalBalance() != null) + { + 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()) > preferencesManager.getMinimumAmount())) { + currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + } } - } - ); - handler.postDelayed(updateRunnable, 10000); - toolbarLayout = fragmentView.findViewById(R.id.toolbar_layout); - toolbarLayout.setForegroundGravity(Gravity.CENTER); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + currencyLayout.removeAllViews(); + for(int i = 0; i < currencyView.size(); i++) + { + currencyLayout.addView(currencyView.get(i)); + } + + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } + } + }); + } + }; + } + + private void setupAddCurrencyButton(View fragmentView) + { Button addCurrencyButton = fragmentView.findViewById(R.id.buttonAddTransaction); + addCurrencyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent addIntent = new Intent(getActivity(), CurrencySelectionActivity.class); + + startActivity(addIntent); + } + }); + } + + private void setupSettingsButton(View fragmentView) + { ImageButton settingsButton = fragmentView.findViewById(R.id.settings_button); settingsButton.setOnClickListener(new View.OnClickListener() { @@ -142,20 +212,6 @@ public class Summary extends Fragment { } }); - addCurrencyButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent addIntent = new Intent(getActivity(), CurrencySelectionActivity.class); - - startActivity(addIntent); - } - }); - - updateAll(true); - - generateSplashScreen(); - - return fragmentView; } private void generateSplashScreen() @@ -231,14 +287,14 @@ public class Summary extends Fragment { private void showErrorSnackbar() { - /*Snackbar.make(getActivity().findViewById(R.id.viewFlipperSummary), "Error while updating data", Snackbar.LENGTH_LONG) + Snackbar.make(getActivity().findViewById(R.id.snackbar_placer), "Error while updating data", Snackbar.LENGTH_LONG) .setAction("Update", new View.OnClickListener() { @Override public void onClick(View view) { } }) - .show();*/ + .show(); } private void resetCounters() @@ -253,42 +309,8 @@ public class Summary extends Fragment { private void adaptView() { - currencyLayout.removeAllViews(); - final List currencyView = new ArrayList<>(); - - Runnable newRunnable = new Runnable() { - @Override - public void run() { - if (balanceManager.getTotalBalance() != null) - { - 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())); - } - } - } - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - for(int i = 0; i < currencyView.size(); i++) - { - currencyLayout.addView(currencyView.get(i)); - } - - if(loadingDialog.isShowing()) - { - loadingDialog.dismiss(); - } - } - }); - } - }; - - newRunnable.run(); + layoutRefresherRunnable.run(); } private void countCoins(boolean isCoin, boolean isDetails, boolean isTickers) @@ -349,8 +371,6 @@ public class Summary extends Fragment { { if(iconCounter == balanceManager.getTotalBalance().size() - offset) { - Log.d(getResources().getString(R.string.debug), "Loading heavy"); - UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator(); uiHeavyLoadCalculator.execute(); } @@ -372,7 +392,6 @@ public class Summary extends Fragment { getActivity().runOnUiThread(new Runnable() { @Override public void run() { - updateTitle(); } }); @@ -384,79 +403,57 @@ public class Summary extends Fragment { if(preferencesManager.isBalanceHidden()) { - toolbarLayout.setTitle(PlaceholderManager.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity())); - toolbarSubtitle.setVisibility(View.GONE); - - if(totalFluctuation > 0) - { - toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.increase)); - toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.increase)); - } - else - { - toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.decrease)); - toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.decrease)); - } + updateHideBalanceTitle(totalFluctuationPercentage); } else { - toolbarLayout.setTitle(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); - toolbarLayout.setCollapsedTitleTextColor(Color.WHITE); - toolbarLayout.setExpandedTitleColor(Color.WHITE); - - toolbarSubtitle.setVisibility(View.VISIBLE); - - if(totalFluctuation > 0) - { - toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase)); - } - else - { - toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease)); - } - - if(totalFluctuation == 0) - { - toolbarSubtitle.setText(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); - toolbarSubtitle.setTextColor(-1275068417); - } - else - { - toolbarSubtitle.setText(PlaceholderManager.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity())); - } + updateBalanceDisplayedTitle(totalFluctuationPercentage); } } - private String numberConformer(double number) + public void updateBalanceDisplayedTitle(float totalFluctuationPercentage) { - String str; + toolbarLayout.setTitle(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); + toolbarLayout.setCollapsedTitleTextColor(Color.WHITE); + toolbarLayout.setExpandedTitleColor(Color.WHITE); - if(abs(number) > 1) + toolbarSubtitle.setVisibility(View.VISIBLE); + + if(totalFluctuation > 0) { - str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", ""); + toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase)); } else { - str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", ""); + toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease)); } - int counter = 0; - int i = str.indexOf("."); - if(i <= 0) + if(totalFluctuation == 0) { - i = str.length(); + toolbarSubtitle.setText(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); + toolbarSubtitle.setTextColor(-1275068417); } - for(i -= 1; i > 0; i--) + else { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } + toolbarSubtitle.setText(PlaceholderManager.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity())); } + } - return str; + private void updateHideBalanceTitle(float totalFluctuationPercentage) + { + toolbarLayout.setTitle(PlaceholderManager.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity())); + toolbarSubtitle.setVisibility(View.GONE); + + if(totalFluctuation > 0) + { + toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.increase)); + toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.increase)); + } + else + { + toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.decrease)); + toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.decrease)); + } } private class UiHeavyLoadCalculator extends AsyncTask @@ -493,7 +490,8 @@ public class Summary extends Fragment { private void loadCurrency(Currency currency) { - if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) + Log.d("moodl", "For " + currency.getSymbol() + " " + (currency.getBalance() * currency.getValue()) + " " + preferencesManager.getMinimumAmount()); + if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > preferencesManager.getMinimumAmount()) { currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); @@ -539,8 +537,19 @@ public class Summary extends Fragment { protected void onPostExecute(Void result) { refreshLayout.setRefreshing(false); - //refreshCurrencyList(); - adaptView(); + new AsyncTask() { + + @Override + protected Void doInBackground(Void... voids) { + if(Looper.myLooper() == null) + { + Looper.prepare(); + } + + adaptView(); + return null; + } + }.execute(); handler.removeCallbacks(updateRunnable); } } @@ -625,17 +634,49 @@ public class Summary extends Fragment { return null; } - - @Override - protected void onPostExecute(Void result) - { - - } } private class DataUpdater extends AsyncTask { + private void generateSnackBarError(String error) + { + View view = getActivity().findViewById(R.id.snackbar_placer); + + switch (error) + { + case "com.android.volley.AuthFailureError": + preferencesManager.disableHitBTC(); + 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(view, "Binance synchronization error : Invalid keys", Snackbar.LENGTH_LONG) + .show(); + + updateAll(true); + break; + case "com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host \"api.hitbtc.com\": No address associated with hostname": + Snackbar.make(view, "Can't resolve host", Snackbar.LENGTH_LONG) + .show(); + break; + case "com.android.volley.TimeoutError": + break; + default: + Snackbar.make(view, "Unexpected error", Snackbar.LENGTH_LONG) + .show(); + + Log.d("moodl", error); + + updateAll(false); + } + } + @Override protected Void doInBackground(Void... params) { @@ -684,44 +725,12 @@ public class Summary extends Fragment { public void onError(String error) { - View view = getActivity().findViewById(R.id.snackbar_placer); - - switch (error) - { - case "com.android.volley.AuthFailureError": - preferencesManager.disableHitBTC(); - 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(view, "Binance synchronization error : Invalid keys", Snackbar.LENGTH_LONG) - .show(); - - updateAll(true); - break; - default: - Snackbar.make(view, "Unexpected error", Snackbar.LENGTH_LONG) - .show(); - - Log.d("moodl", error); - - updateAll(true); - } + generateSnackBarError(error); } }); return null; } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - } } } diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index 98d7ed2..cee11d7 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -12,13 +12,11 @@ import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.graphics.Palette; -import android.support.v7.widget.CardView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; -import android.view.animation.Transformation; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; @@ -55,6 +53,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import static com.nauk.moodl.MoodlBox.collapseH; +import static com.nauk.moodl.MoodlBox.collapseW; +import static com.nauk.moodl.MoodlBox.expandH; +import static com.nauk.moodl.MoodlBox.expandW; +import static com.nauk.moodl.MoodlBox.getVerticalExpandAnimation; +import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; /** @@ -110,25 +114,17 @@ public class Watchlist extends Fragment { } }); - Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist); - addWatchlistButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent selectionIntent = new Intent(getActivity(), CurrencySelectionActivity.class); - selectionIntent.putExtra("isWatchList", true); - startActivity(selectionIntent); - } - }); + setupAddWatchlistButton(); - ImageButton settingsButton = view.findViewById(R.id.settings_button); - settingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent settingIntent = new Intent(getActivity(), SettingsActivity.class); - startActivity(settingIntent); - } - }); + setupSettingsButton(); + setupEditButton(); + + return view; + } + + private void setupEditButton() + { ImageButton editButton = view.findViewById(R.id.edit_button); editButton.setOnClickListener(new View.OnClickListener() { @Override @@ -147,133 +143,53 @@ public class Watchlist extends Fragment { { editModeEnabled = true; + LinearLayout watchlistLayout = Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist); + + Animation anim = getVerticalExpandAnimation(watchlistLayout.getChildAt(0)); + for(int i = 0; i < ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildCount(); i++) { - ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).setClickable(false); - expandW(((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).findViewById(R.id.deleteCardWatchlist)); + View watchlistElement = watchlistLayout.getChildAt(i); + + watchlistElement.setClickable(false); + expandW(watchlistElement.findViewById(R.id.deleteCardWatchlist), anim); } } } }); - - return view; } - private void collapseView(View view) + private void setupAddWatchlistButton() { - collapse(view.findViewById(R.id.collapsableLayout)); + Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist); + addWatchlistButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent selectionIntent = new Intent(getActivity(), CurrencySelectionActivity.class); + selectionIntent.putExtra("isWatchList", true); + startActivity(selectionIntent); + } + }); } - private void extendView(View view) + private void setupSettingsButton() { - expand(view.findViewById(R.id.collapsableLayout)); + ImageButton settingsButton = view.findViewById(R.id.settings_button); + settingsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent settingIntent = new Intent(getActivity(), SettingsActivity.class); + startActivity(settingIntent); + } + }); + } + + private void displayChartView() + { + expandH(view.findViewById(R.id.collapsableLayout)); view.findViewById(R.id.LineChartView).invalidate(); } - private static void expand(final View v) { - v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); - final int targetHeight = v.getMeasuredHeight(); - - // Older versions of android (pre API 21) cancel animations for views with a height of 0. - v.getLayoutParams().height = 1; - v.setVisibility(View.VISIBLE); - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - v.getLayoutParams().height = interpolatedTime == 1 - ? CardView.LayoutParams.WRAP_CONTENT - : (int)(targetHeight * interpolatedTime); - v.requestLayout(); - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private static void expandW(final View v) { - v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); - final int targetWidth = v.getMeasuredWidth(); - - v.getLayoutParams().width = 1; - v.setVisibility(View.VISIBLE); - Animation a = new Animation() { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - v.getLayoutParams().width = interpolatedTime == 1 - ? CardView.LayoutParams.WRAP_CONTENT - : (int)(targetWidth * interpolatedTime); - v.requestLayout(); - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - a.setDuration((int)(targetWidth / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private static void collapse(final View v) { - final int initialHeight = v.getMeasuredHeight(); - - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if(interpolatedTime == 1){ - v.setVisibility(View.GONE); - }else{ - v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private static void collapseW(final View v) { - final int initialWidth = v.getMeasuredWidth(); - - Animation a = new Animation() { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if(interpolatedTime == 1) { - v.setVisibility(View.GONE); - } else { - v.getLayoutParams().width = initialWidth - (int)(initialWidth * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - a.setDuration((int)(initialWidth / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - @Override public void onResume() { @@ -408,7 +324,7 @@ public class Watchlist extends Fragment { card.findViewById(R.id.deleteCardWatchlist).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - collapse(card); + collapseH(card); DatabaseManager databaseManager = new DatabaseManager(getActivity()); databaseManager.deleteCurrencyFromWatchlist(currency.getSymbol()); } @@ -431,13 +347,14 @@ public class Watchlist extends Fragment { public void onClick(final View view) { if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { - collapseView(view); + collapseH(view.findViewById(R.id.collapsableLayout)); } else { view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); - extendView(view); + + displayChartView(); if (currency.getHistoryMinutes() == null) { currency.updateHistoryMinutes(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @@ -460,7 +377,7 @@ public class Watchlist extends Fragment { } else { - extendView(view); + displayChartView(); view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } @@ -647,36 +564,4 @@ 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).replaceAll("\\.?0*$", ""); - } - else - { - str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", ""); - } - - int counter = 0; - int i = str.indexOf("."); - if(i <= 0) - { - i = str.length(); - } - for(i -= 1; i > 0; i--) - { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } - } - - return str; - } } diff --git a/app/src/main/java/com/nauk/moodl/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/moodl/Activities/RecordTransactionActivity.java index a57deec..0fbbf43 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/RecordTransactionActivity.java @@ -24,6 +24,7 @@ import com.nauk.moodl.R; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Locale; public class RecordTransactionActivity extends AppCompatActivity { @@ -97,26 +98,18 @@ public class RecordTransactionActivity extends AppCompatActivity { Intent intent = getIntent(); - sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy"); + sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.UK); calendar = Calendar.getInstance(); databaseManager = new DatabaseManager(this); preferenceManager = new PreferencesManager(this); - symbolTxtView = findViewById(R.id.currencySymbol); - amountTxtView = findViewById(R.id.currencyAmount); - feesTxtView = findViewById(R.id.feesTextView); - purchasedDateLayout = findViewById(R.id.input_purchase_date); - purchaseDate = findViewById(R.id.purchaseDate); - purchasedPriceEditText = findViewById(R.id.purchasePrice); - buyButton = findViewById(R.id.buyButton); - sellButton = findViewById(R.id.sellButton); - transferButton = findViewById(R.id.transfertButton); + initializeViewElements(); coin = intent.getStringExtra("coin"); - Log.d("moodl", "1" + coin); symbol = intent.getStringExtra("symbol"); + transactionId = intent.getIntExtra("transactionId", -1); if(transactionId != -1) @@ -158,6 +151,18 @@ public class RecordTransactionActivity extends AppCompatActivity { } }); + initializeButtons(); + + currency.getTimestampPrice(this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { + @Override + public void onSuccess(String price) { + purchasedPriceEditText.setText(price); + } + }, calendar.getTimeInMillis() / 1000); + } + + private void initializeButtons() + { buyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -189,13 +194,19 @@ public class RecordTransactionActivity extends AppCompatActivity { // Prepare transfer interface } }); + } - currency.getTimestampPrice(this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { - @Override - public void onSuccess(String price) { - purchasedPriceEditText.setText(price); - } - }, calendar.getTimeInMillis() / 1000); + private void initializeViewElements() + { + symbolTxtView = findViewById(R.id.currencySymbol); + amountTxtView = findViewById(R.id.currencyAmount); + feesTxtView = findViewById(R.id.feesTextView); + purchasedDateLayout = findViewById(R.id.input_purchase_date); + purchaseDate = findViewById(R.id.purchaseDate); + purchasedPriceEditText = findViewById(R.id.purchasePrice); + buyButton = findViewById(R.id.buyButton); + sellButton = findViewById(R.id.sellButton); + transferButton = findViewById(R.id.transfertButton); } private void createDatePicker() diff --git a/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java index c9f730f..3f16f39 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java @@ -14,6 +14,7 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; @@ -28,10 +29,12 @@ import android.security.keystore.KeyProperties; import android.support.v4.app.ActivityCompat; import android.support.v7.app.ActionBar; import android.text.TextUtils; +import android.util.Log; import android.view.MenuItem; import android.view.View; import com.nauk.moodl.BuildConfig; +import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.FingerprintToolkit.FingerprintDialogFragment; import com.nauk.moodl.FingerprintToolkit.FingerprintHandler; import com.nauk.moodl.R; @@ -199,8 +202,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName) - || DataSyncPreferenceFragment.class.getName().equals(fragmentName) - || NotificationPreferenceFragment.class.getName().equals(fragmentName) || ExchangePreferenceFragment.class.getName().equals(fragmentName); } @@ -232,9 +233,14 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } }); - ((PreferenceScreen) findPreference("version")).setSummary(BuildConfig.VERSION_NAME); + findPreference("version").setSummary(BuildConfig.VERSION_NAME); bindPreferenceSummaryToValue(findPreference("default_currency")); + bindPreferenceSummaryToValue(findPreference("minimum_value_displayed")); + + EditTextPreference editTextPreference = (EditTextPreference) findPreference("minimum_value_displayed"); + editTextPreference.setPositiveButtonText("Save"); + editTextPreference.setNegativeButtonText("Cancel"); } @Override @@ -433,64 +439,4 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } } - - /** - * This fragment shows notification preferences only. It is used when the - * activity is showing a two-pane settings UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class NotificationPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_notification); - setHasOptionsMenu(true); - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone")); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } - } - - /** - * This fragment shows data and sync preferences only. It is used when the - * activity is showing a two-pane settings UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class DataSyncPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_data_sync); - setHasOptionsMenu(true); - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("sync_frequency")); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } - } } diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java index 846b5d9..47fd5f6 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java @@ -2,6 +2,7 @@ package com.nauk.moodl.DataManagers; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.util.Log; /** * Created by Guitoune on 09/01/2018. @@ -48,6 +49,23 @@ public class PreferencesManager { return settingPreferences.getBoolean("refresh_default_currency", false); } + public float getMinimumAmount() + { + String str = settingPreferences.getString("minimum_value_displayed", "0"); + float ret; + + if(str.equals("")) + { + ret = 0; + } + else + { + ret = Float.valueOf(str); + } + + return ret; + } + private void disableRefreshDefaultCurrency() { SharedPreferences.Editor editor = settingPreferences.edit(); diff --git a/app/src/main/java/com/nauk/moodl/FingerprintToolkit/FingerprintDialogFragment.java b/app/src/main/java/com/nauk/moodl/FingerprintToolkit/FingerprintDialogFragment.java index a6f15b5..63831cf 100644 --- a/app/src/main/java/com/nauk/moodl/FingerprintToolkit/FingerprintDialogFragment.java +++ b/app/src/main/java/com/nauk/moodl/FingerprintToolkit/FingerprintDialogFragment.java @@ -55,10 +55,14 @@ public class FingerprintDialogFragment extends DialogFragment{ public void wrongFingerprint(String errorString) { - ((SwirlView) this.getView().findViewById(R.id.swirl)).clearColorFilter(); - ((SwirlView) this.getView().findViewById(R.id.swirlBackground)).clearColorFilter(); - ((SwirlView) this.getView().findViewById(R.id.swirl)).setState(SwirlView.State.ERROR); - ((SwirlView) this.getView().findViewById(R.id.swirlBackground)).setState(SwirlView.State.ERROR); + SwirlView swirlView = this.getView().findViewById(R.id.swirl); + SwirlView swirlBackground = this.getView().findViewById(R.id.swirlBackground); + + swirlView.clearColorFilter(); + swirlView.setState(SwirlView.State.ERROR); + + swirlBackground.clearColorFilter(); + swirlBackground.setState(SwirlView.State.ERROR); ((TextView) this.getView().findViewById(R.id.fingerprint_error)).setText(errorString); } diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java index 6397f10..c184d10 100644 --- a/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/HomeLayoutGenerator.java @@ -29,9 +29,10 @@ import com.nauk.moodl.R; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; -import java.util.Locale; -import static java.lang.Math.abs; +import static com.nauk.moodl.MoodlBox.collapseH; +import static com.nauk.moodl.MoodlBox.expandH; +import static com.nauk.moodl.MoodlBox.numberConformer; /** * Created by Tiji on 05/01/2018. @@ -58,11 +59,11 @@ public class HomeLayoutGenerator { PreferencesManager preferencesManager = new PreferencesManager(context); if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { - collapseView(view); + collapseH(view.findViewById(R.id.collapsableLayout)); } else { view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); - extendView(view); + expandH(view.findViewById(R.id.collapsableLayout)); if (currency.getHistoryMinutes() == null) { currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @@ -85,7 +86,7 @@ public class HomeLayoutGenerator { } else { - extendView(view); + expandH(view.findViewById(R.id.collapsableLayout)); view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } @@ -272,17 +273,6 @@ public class HomeLayoutGenerator { } } - private void collapseView(View view) - { - collapse(view.findViewById(R.id.collapsableLayout)); - } - - private void extendView(View view) - { - expand(view.findViewById(R.id.collapsableLayout)); - //view.findViewById(R.id.LineChartView).invalidate(); - } - private void updateColor(View view, Currency currency) { if(currency.getDayFluctuationPercentage() >= 0) @@ -339,31 +329,4 @@ public class HomeLayoutGenerator { return transColor ; } - - 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*$", ""); - } - - int counter = 0; - for(int i = str.indexOf(".") - 1; i > 0; i--) - { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } - } - - return str; - } } diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/TradeListAdapter.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/TradeListAdapter.java index 8ac95c7..a216cd0 100644 --- a/app/src/main/java/com/nauk/moodl/LayoutManagers/TradeListAdapter.java +++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/TradeListAdapter.java @@ -17,6 +17,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.Locale; +import static com.nauk.moodl.MoodlBox.getDateFromTimestamp; + /** * Created by Guitoune on 24/04/2018. */ @@ -49,7 +51,7 @@ public class TradeListAdapter extends ArrayAdapter { amountTxtView.setText(String.valueOf(trade.getQty())); purchasedPrice.setText(trade.getPrice()); - dateTxtView.setText(getDate(trade.getTime())); + dateTxtView.setText(getDateFromTimestamp(trade.getTime())); tradePair.setText(trade.getSymbol() + "/" + trade.getPairSymbol()); if(trade.isBuyer()) @@ -63,16 +65,4 @@ public class TradeListAdapter extends ArrayAdapter { return convertView; } - - private String getDate(long timeStamp){ - - try{ - SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault()); - Date netDate = (new Date(timeStamp)); - return sdf.format(netDate); - } - catch(Exception ex){ - return "xx"; - } - } } diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/TransactionListAdapter.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/TransactionListAdapter.java index c89652e..2546242 100644 --- a/app/src/main/java/com/nauk/moodl/LayoutManagers/TransactionListAdapter.java +++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/TransactionListAdapter.java @@ -5,30 +5,25 @@ import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.Transformation; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.TextView; import com.daimajia.swipe.SwipeLayout; -import com.nauk.moodl.Activities.CurrencyDetailsActivity; -import com.nauk.moodl.Activities.CurrencySelectionActivity; import com.nauk.moodl.Activities.RecordTransactionActivity; import com.nauk.moodl.DataManagers.CurrencyData.Transaction; import com.nauk.moodl.DataManagers.DatabaseManager; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.R; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; -import java.util.Locale; +import static com.nauk.moodl.MoodlBox.collapseH; +import static com.nauk.moodl.MoodlBox.getDateFromTimestamp; +import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; /** @@ -61,7 +56,7 @@ public class TransactionListAdapter extends ArrayAdapter { amountTxtView.setText(String.valueOf(transaction.getAmount())); valueTxtView.setText(numberConformer(transaction.getPurchasedPrice() * transaction.getAmount())); - dateTxtView.setText(getDate(transaction.getTimestamp())); + dateTxtView.setText(getDateFromTimestamp(transaction.getTimestamp())); LinearLayout deleteLayout = convertView.findViewById(R.id.deleteTransactionLayout); deleteLayout.setTag(transaction.getTransactionId()); @@ -73,7 +68,7 @@ public class TransactionListAdapter extends ArrayAdapter { DatabaseManager databaseManager = new DatabaseManager(context); preferencesManager.setMustUpdateSummary(true); databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); - collapse((View) view.getParent().getParent().getParent()); + collapseH((View) view.getParent().getParent().getParent()); } }); @@ -98,32 +93,6 @@ public class TransactionListAdapter extends ArrayAdapter { return convertView; } - private static void collapse(final View v) { - final int initialHeight = v.getMeasuredHeight(); - - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if(interpolatedTime == 1){ - v.setVisibility(View.GONE); - }else{ - v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - private void setupSwipeView(View view) { SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); @@ -166,52 +135,4 @@ public class TransactionListAdapter extends ArrayAdapter { } }); } - - - private String getDate(long timeStamp){ - - try{ - SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault()); - Date netDate = (new Date(timeStamp)); - return sdf.format(netDate); - } - catch(Exception ex){ - return "xx"; - } - } - - 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*$", ""); - } - - if(!str.equals("Infinity")) - { - int counter = 0; - int i = str.indexOf("."); - if(i <= 0) - { - i = str.length(); - } - for(i -= 1; i > 0; i--) - { - counter++; - if(counter == 3) - { - str = str.substring(0, i) + " " + str.substring(i, str.length()); - counter = 0; - } - } - } - - return str; - } } diff --git a/app/src/main/java/com/nauk/moodl/MoodlBox.java b/app/src/main/java/com/nauk/moodl/MoodlBox.java new file mode 100644 index 0000000..2dca48c --- /dev/null +++ b/app/src/main/java/com/nauk/moodl/MoodlBox.java @@ -0,0 +1,191 @@ +package com.nauk.moodl; + +import android.support.v7.widget.CardView; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.Transformation; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import static java.lang.Math.abs; + +/** + * Created by Guitoune on 30/04/2018. + */ + +public class MoodlBox { + + public static void expandH(final View v) { + v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); + int targetHeight = v.getMeasuredHeight(); + + // Older versions of android (pre API 21) cancel animations for views with a height of 0. + v.getLayoutParams().height = 1; + v.setVisibility(View.VISIBLE); + + Animation a = getHorizontalExpandAnimation(v); + + // 1dp/ms + a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static Animation getHorizontalExpandAnimation(final View v) + { + final int targetHeight = v.getMeasuredHeight(); + + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + v.getLayoutParams().height = interpolatedTime == 1 + ? CardView.LayoutParams.WRAP_CONTENT + : (int)(targetHeight * interpolatedTime); + v.requestLayout(); + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + return a; + } + + public static void expandW(final View v, Animation a) + { + v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); + int targetWidth = v.getMeasuredWidth(); + + v.getLayoutParams().width = 1; + v.setVisibility(View.VISIBLE); + + a.setDuration((int)(targetWidth / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static void expandW(final View v) { + expandW(v, getVerticalExpandAnimation(v)); + } + + public static Animation getVerticalExpandAnimation(final View v) + { + final int targetWidth = v.getMeasuredWidth(); + + Animation a = new Animation() { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + v.getLayoutParams().width = interpolatedTime == 1 + ? CardView.LayoutParams.WRAP_CONTENT + : (int)(targetWidth * interpolatedTime); + v.requestLayout(); + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + return a; + } + + public static void collapseH(final View v) { + final int initialHeight = v.getMeasuredHeight(); + + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + if(interpolatedTime == 1){ + v.setVisibility(View.GONE); + }else{ + v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); + v.requestLayout(); + } + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + // 1dp/ms + a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static void collapseW(final View v) { + final int initialWidth = v.getMeasuredWidth(); + + Animation a = new Animation() { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + if(interpolatedTime == 1) { + v.setVisibility(View.GONE); + } else { + v.getLayoutParams().width = initialWidth - (int)(initialWidth * interpolatedTime); + v.requestLayout(); + } + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + a.setDuration((int)(initialWidth / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static 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*$", ""); + } + + if(!str.equals("Infinity")) + { + int counter = 0; + int i = str.indexOf("."); + if(i <= 0) + { + i = str.length(); + } + for(i -= 1; i > 0; i--) + { + counter++; + if(counter == 3) + { + str = str.substring(0, i) + " " + str.substring(i, str.length()); + counter = 0; + } + } + } + + return str; + } + + public static String getDateFromTimestamp(long timeStamp){ + try{ + SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault()); + Date netDate = (new Date(timeStamp)); + return sdf.format(netDate); + } + catch(Exception ex){ + return "xx"; + } + } +} diff --git a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml index c3ef65a..9519758 100644 --- a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml +++ b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml @@ -62,7 +62,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - xmlns:android="http://schemas.android.com/apk/res/android"> + android:paddingTop="20dp"> + + Donation + Changement de vue + Réglages + Général + Cacher le solde + Monnaie par défaut + Achat + Vente + Transfère + Enregistrer + Vérifiez votre emprunte + Réglages des échanges + Activer la synchronisation + Clé public + Clé privée + Activer la synchronisation + Clé public + Clé privée + Montant + Prix d\'achat + Date d\'achat + Frais + Historique + Informations + Transactions + Possessions + Capitalisation du marché + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4fd7ac..cd6606a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,10 +1,8 @@ - Moodl - Settings - Edit mode - Fais un don wallah - Moodl_debug - Moodl_debugVolley + Moodl + Donation + Moodl_debug + Moodl_debugVolley Switch view Settings @@ -15,23 +13,8 @@ Hide balance - Display name - John Smith - - Add friends to messages - - Always - When possible - Never - - - 1 - 0 - -1 - - - Data & sync + Minimum amount displayed Default currency @@ -90,19 +73,19 @@ Exchanges settings - Touch ID + Touch ID Enable synchronization Public key Private key - HitBTC + HitBTC Enable synchronization Public key Private key - GDAX + GDAX Enable synchronization @@ -129,7 +112,7 @@ Fees CurrencyDetailsActivity History charts - Watchlist + Watchlist Infos Transactions Holdings @@ -203,5 +186,7 @@ 24h volume :\n%1$s¥ ScrollingActivity + Settings + Edition diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 3423141..c248722 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -14,6 +14,15 @@ android:positiveButtonText="@null" android:title="@string/pref_title_default_currency" /> + + diff --git a/export/release/output.json b/export/release/output.json index 82b2719..9383b9b 100644 --- a/export/release/output.json +++ b/export/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.nauk.moodl","split":"","minSdkVersion":"23"}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2},"path":"app-release.apk","properties":{"packageId":"com.nauk.moodl","split":"","minSdkVersion":"23"}}] \ No newline at end of file