diff --git a/.gitignore b/.gitignore index e8267b1..a02421c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,69 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries .DS_Store -/build -/captures -.externalNativeBuild + +# Built application files *.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 8067773..92dcb68 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4620055..24b4107 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ android:label="@string/title_activity_settings" android:screenOrientation="portrait" /> currencyNames = cryptocompareApiManager.getCurrenciesName(); - List currencySymbols = cryptocompareApiManager.getCurrenciesSymbol(); - - ArrayList currencyArrayList = new ArrayList<>(); - - for(int i = 0; i < currencyNames.size(); i++) - { - currencyArrayList.add(new Currency(currencyNames.get(i), currencySymbols.get(i))); - } - - adapter = new CoinWatchlistAdapter(this, currencyArrayList); + adapter = new CoinWatchlistAdapter(this, new ArrayList<>(coinmarketCapAPIManager.getTotalListing())); } private void setupList() @@ -93,26 +92,16 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear public void onItemClick(AdapterView adapterView, View view, int i, long l) { Currency selectedCurrency = (Currency) adapterView.getItemAtPosition(i); - if(isWatchList) - { - PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); - DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); + PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); + DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); - if(databaseManager.addCurrencyToWatchlist(selectedCurrency)) - { - preferencesManager.setMustUpdateWatchlist(true); - } - else - { - Toast.makeText(getApplicationContext(), getString(R.string.already_watchlisr), Toast.LENGTH_SHORT).show(); - } + if(databaseManager.addCurrencyToWatchlist(selectedCurrency)) + { + preferencesManager.setMustUpdateWatchlist(true); } else { - Intent intent = new Intent(CurrencySelectionActivity.this, RecordTransactionActivity.class); - intent.putExtra("coin", selectedCurrency.getName()); - intent.putExtra("symbol", selectedCurrency.getSymbol()); - startActivity(intent); + Toast.makeText(getApplicationContext(), getString(R.string.already_watchlist), Toast.LENGTH_SHORT).show(); } finish(); @@ -166,17 +155,20 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear private void detailsEvent() { - runOnUiThread(new Runnable() { - @Override - public void run() { - setupAdapter(); - setupList(); - setupSearchView(); + if(coinmarketCapAPIManager.isUpToDate() && cryptocompareApiManager.isDetailsUpToDate()) + { + runOnUiThread(new Runnable() { + @Override + public void run() { + setupAdapter(); + setupList(); + setupSearchView(); - expand(findViewById(R.id.listContainerLayout)); - findViewById(R.id.currencyListProgressBar).setVisibility(View.GONE); - } - }); + expand(findViewById(R.id.listContainerLayout)); + findViewById(R.id.currencyListProgressBar).setVisibility(View.GONE); + } + }); + } } @Override @@ -189,6 +181,26 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear } + @Override + public void onCurrenciesRetrieved(List currencyList) { + + } + + @Override + public void onTopCurrenciesUpdated() { + + } + + @Override + public void onMarketCapUpdated() { + + } + + @Override + public void onListingUpdated() { + detailsEvent(); + } + private class ListLoader extends AsyncTask { @Override @@ -211,9 +223,17 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear Looper.prepare(); } - if(!cryptocompareApiManager.isDetailsUpToDate()) + if(!cryptocompareApiManager.isDetailsUpToDate() || !coinmarketCapAPIManager.isUpToDate()) { - cryptocompareApiManager.updateDetails(); + if(!cryptocompareApiManager.isDetailsUpToDate()) + { + cryptocompareApiManager.updateDetails(); + } + + if(!coinmarketCapAPIManager.isUpToDate()) + { + coinmarketCapAPIManager.updateListing(); + } } else { diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 17541e2..57a00b8 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -72,13 +72,14 @@ import static java.lang.Math.abs; public class Summary extends Fragment implements BalanceSwitchManagerInterface, BalanceUpdateNotifierInterface, CryptocompareNotifierInterface, CoinmarketcapNotifierInterface { + + private LinearLayout currencyLayout; private PreferencesManager preferencesManager; private BalanceManager balanceManager; private SwipeRefreshLayout refreshLayout; private Dialog loadingDialog; private String defaultCurrency; - private CoinmarketCapAPIManager coinmarketCapAPIManager; private TextView toolbarSubtitle; private CollapsingToolbarLayout toolbarLayout; @@ -87,7 +88,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private Runnable updateRunnable; private int coinCounter; - private int iconCounter; private float totalValue; private boolean detailsChecker; private boolean tickersChecker; @@ -95,6 +95,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private long lastTimestamp; private BalanceUpdateInterface balanceUpdateInterface; + private CoinmarketCapAPIManager coinmarketCapAPIManager; private CryptocompareApiManager cryptocompareApiManager; @NonNull @@ -318,7 +319,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, .setAction(getString(R.string.update), new View.OnClickListener() { @Override public void onClick(View view) { - + updateAll(true); } }) .show(); @@ -327,7 +328,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private void resetCounters() { coinCounter = 0; - iconCounter = 0; } private void adaptView(float totalValue, float totalFluctuation) @@ -753,6 +753,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private class DataUpdater extends AsyncTask { + @Override protected Void doInBackground(Void... params) { diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java index 803043d..10ef21a 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -12,14 +12,14 @@ import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.graphics.Palette; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; -import com.herbron.moodl.Activities.CurrencySelectionActivity; +import com.herbron.moodl.Activities.CurrencyListActivity; import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface; import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; @@ -42,7 +42,6 @@ import java.util.List; import static com.herbron.moodl.MoodlBox.collapseW; import static com.herbron.moodl.MoodlBox.expandW; -import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** @@ -250,7 +249,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac disableEdition(); } - Intent selectionIntent = new Intent(getActivity(), CurrencySelectionActivity.class); + Intent selectionIntent = new Intent(getActivity(), CurrencyListActivity.class); selectionIntent.putExtra("isWatchList", true); startActivity(selectionIntent); } @@ -355,6 +354,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac public void run() { dragLinearLayout.removeAllViews(); view.findViewById(R.id.progressBarWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.buttonAddWatchlist).setVisibility(View.VISIBLE); for(Currency currency : watchlistManager.getWatchlist()) { @@ -390,6 +390,9 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac id = jsonObject.getInt("Id"); } catch (JSONException e) { e.printStackTrace(); + } catch (NullPointerException e) { + Log.d("moodl", "ID not found"); + e.printStackTrace(); } return id; @@ -435,27 +438,14 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac public void onPriceUpdated(Currency successCurrency) { String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager); - if(iconUrl != null) - { - MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { - @Override - public void onBitmapDownloaded(Bitmap bitmapIcon) { - currency.setIcon(bitmapIcon); - currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); - countWatchlist(); - - } - }); - } - else - { - Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); - icon = Bitmap.createScaledBitmap(icon, 50, 50, false); - - currency.setIcon(icon); - currency.setChartColor(getIconDominantColor(getContext(), icon)); - countWatchlist(); - } + MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { + @Override + public void onBitmapDownloaded(Bitmap bitmapIcon) { + currency.setIcon(bitmapIcon); + currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); + countWatchlist(); + } + }); } }); } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java index ea1bc67..0a12a9f 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/InfoAPIManagers/CoinmarketCapAPIManager.java @@ -203,6 +203,11 @@ public class CoinmarketCapAPIManager { } } + public List getTotalListing() + { + return currencyTickerList; + } + public void updateTopCurrencies(final String toSymbol) { String requestString = topCurrenciesUrl + toSymbol; diff --git a/app/src/main/java/com/herbron/moodl/MoodlBox.java b/app/src/main/java/com/herbron/moodl/MoodlBox.java index 87cbe61..08cb719 100644 --- a/app/src/main/java/com/herbron/moodl/MoodlBox.java +++ b/app/src/main/java/com/herbron/moodl/MoodlBox.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v7.graphics.Palette; @@ -209,36 +210,51 @@ public class MoodlBox { public static void getBitmapFromURL(String src, String symbol, Resources resources, Context context, MoodlboxNotifierInterface callBack) { - String size = src.substring(src.lastIndexOf("=") + 1, src.length()); - String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png"; Bitmap result; - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - - result = BitmapFactory.decodeFile(filepath, options); - - if(result == null) + if(src != null) { - try { - java.net.URL url = new java.net.URL(src); - HttpURLConnection connection = (HttpURLConnection) url - .openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - result = BitmapFactory.decodeStream(input); + String size = src.substring(src.lastIndexOf("=") + 1, src.length()); + String filepath = context.getCacheDir() + "/" + symbol + "x" + size + ".png"; - FileOutputStream out = new FileOutputStream(filepath); - result.compress(Bitmap.CompressFormat.PNG, 100, out); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inPreferredConfig = Bitmap.Config.ARGB_8888; - } catch (IOException e) { - Log.d("moodl", "Error while downloading " + symbol + " icon > " + e.getMessage()); - result = BitmapFactory.decodeResource(resources, - R.mipmap.ic_launcher_moodl); - result = Bitmap.createScaledBitmap(result, Integer.valueOf(size), Integer.valueOf(size), false); + result = BitmapFactory.decodeFile(filepath, options); + + if(result == null) + { + try { + java.net.URL url = new java.net.URL(src); + HttpURLConnection connection = (HttpURLConnection) url + .openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + result = BitmapFactory.decodeStream(input); + + FileOutputStream out = new FileOutputStream(filepath); + result.compress(Bitmap.CompressFormat.PNG, 100, out); + + } catch (IOException e) { + Log.d("moodl", "Error while downloading " + symbol + " icon > " + e.getMessage()); + Drawable defautlDrawable = resources.getDrawable(R.drawable.ic_panorama_fish_eye_24dp); + result = Bitmap.createBitmap(defautlDrawable.getIntrinsicWidth(), defautlDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + defautlDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + defautlDrawable.draw(canvas); + } } } + else + { + Log.d("moodl", "No URL for " + symbol); + Drawable defautlDrawable = resources.getDrawable(R.drawable.ic_panorama_fish_eye_24dp); + result = Bitmap.createBitmap(defautlDrawable.getIntrinsicWidth(), defautlDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(result); + defautlDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + defautlDrawable.draw(canvas); + } callBack.onBitmapDownloaded(result); } diff --git a/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml b/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml index 3396bfe..b3bcd36 100644 --- a/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml +++ b/app/src/main/res/layout-v21/homeactivity_fragment_watchlist.xml @@ -94,7 +94,8 @@ android:background="@drawable/button_dashed_background" android:layout_margin="10dp" android:textColor="@color/separationColor" - style="@style/Widget.AppCompat.Button.Borderless"/> + android:visibility="gone" + style="@style/Widget.AppCompat.Button.Borderless" /> diff --git a/app/src/main/res/layout/activity_add_currency.xml b/app/src/main/res/layout/activity_currency_list.xml similarity index 95% rename from app/src/main/res/layout/activity_add_currency.xml rename to app/src/main/res/layout/activity_currency_list.xml index f3fe515..a13e939 100644 --- a/app/src/main/res/layout/activity_add_currency.xml +++ b/app/src/main/res/layout/activity_currency_list.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.herbron.moodl.Activities.CurrencySelectionActivity"> + tools:context="com.herbron.moodl.Activities.CurrencyListActivity"> Impossible de résoudre l\'hôte Erreur inconnue Selectionner une monnaie - Monnaie déjà présente dans la liste suivie + Monnaie déjà présente dans la liste suivie Créer une sauvegarde Mauvais mot de passe Erreur diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 581f285..74b03f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -261,7 +261,7 @@ Can\'t resolve host Unexpected error Select a coin - Currency already in watchlist + Currency already in watchlist Create backup Wrong password Error diff --git a/build.gradle b/build.gradle index 04c6bc4..ce91d76 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cc87b0f..e1f6f58 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Jun 17 03:10:32 CEST 2018 +#Tue Oct 02 22:45:37 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip