Compare commits

...

7 Commits

Author SHA1 Message Date
aa8717946a Several fixes
- CurrencySelectionActivity renamed to CurrencyListActivity
- Allow refresh from the Update snackbar button in Summary after an error
- Code cleaning
- Typo
2018-11-19 16:43:42 +01:00
cb428937d4
Fix decode feature in the app (MUST BE CHECKED) 2018-10-02 15:36:56 +02:00
1cb7c03d63 Remove useless code 2018-09-02 02:08:59 +02:00
3e56c6f90e Prepare suffix code for some inputs 2018-09-02 01:54:48 +02:00
f837372551 Add icon displaying animation 2018-09-02 01:03:29 +02:00
8ca63b5e85 Rework icon loading
- Icons are now downloaded after displaying the whole list
2018-09-01 23:31:17 +02:00
e6d69a01ce Update chart color definition algorithm
Everything comes now from the MoodlUtilBox
2018-09-01 23:30:19 +02:00
23 changed files with 519 additions and 450 deletions

75
.gitignore vendored
View File

@ -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

Binary file not shown.

View File

@ -34,7 +34,7 @@
android:label="@string/title_activity_settings"
android:screenOrientation="portrait" />
<activity
android:name=".Activities.CurrencySelectionActivity"
android:name=".Activities.CurrencyListActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"

View File

@ -1,11 +1,11 @@
package com.herbron.moodl.Activities;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@ -16,6 +16,8 @@ import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Toast;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
import com.herbron.moodl.DataNotifiers.CoinmarketcapNotifierInterface;
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
@ -25,15 +27,22 @@ import com.herbron.moodl.CustomAdapters.CoinWatchlistAdapter;
import com.herbron.moodl.R;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
public class CurrencySelectionActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, CryptocompareNotifierInterface {
public class CurrencyListActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, CryptocompareNotifierInterface, CoinmarketcapNotifierInterface {
private CoinWatchlistAdapter adapter;
private ListView listView;
private android.widget.Filter filter;
private CryptocompareApiManager cryptocompareApiManager;
private boolean isWatchList;
private CoinmarketCapAPIManager coinmarketCapAPIManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -42,15 +51,15 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_add_currency);
setContentView(R.layout.activity_currency_list);
cryptocompareApiManager = CryptocompareApiManager.getInstance(this);
cryptocompareApiManager.addListener(this);
setTitle(getString(R.string.select_coin));
coinmarketCapAPIManager = CoinmarketCapAPIManager.getInstance(this);
coinmarketCapAPIManager.addListener(this);
Intent intent = getIntent();
isWatchList = intent.getBooleanExtra("isWatchList", false);
setTitle(getString(R.string.select_coin));
ListLoader listLoader = new ListLoader();
listLoader.execute();
@ -68,17 +77,7 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
private void setupAdapter()
{
List<String> currencyNames = cryptocompareApiManager.getCurrenciesName();
List<String> currencySymbols = cryptocompareApiManager.getCurrenciesSymbol();
ArrayList<Currency> 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<Currency> currencyList) {
}
@Override
public void onTopCurrenciesUpdated() {
}
@Override
public void onMarketCapUpdated() {
}
@Override
public void onListingUpdated() {
detailsEvent();
}
private class ListLoader extends AsyncTask<Void, Integer, Void>
{
@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
{

View File

@ -44,6 +44,7 @@ import java.util.ArrayList;
import java.util.List;
import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
import static java.lang.Math.abs;
/**
@ -265,10 +266,8 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() {
@Override
public void onBitmapDownloaded(Bitmap bitmapIcon) {
Palette.Builder builder = Palette.from(bitmapIcon);
coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext())));
coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(getIconDominantColor(getContext(), bitmapIcon));
countIcons();

View File

@ -30,6 +30,7 @@ import com.herbron.moodl.R;
import java.util.List;
import static com.herbron.moodl.MoodlBox.getDrawable;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
/**
* Created by Administrator on 27/05/2018.
@ -121,20 +122,6 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
currencyLoader.execute();
}
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(0));
}
else
{
currency.setChartColor(12369084);
}
}
private void loadingIndicatorGenerator()
{
loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false);
@ -198,7 +185,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
@Override
public void onBitmapDownloaded(Bitmap bitmap) {
currency.setIcon(bitmap);
updateChartColor(currency);
currency.setChartColor(getIconDominantColor(getContext(), bitmap));
countIcons(currencies[0]);
}
});
@ -216,7 +203,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
currency.setIcon(icon);
updateChartColor(currency);
currency.setChartColor(getIconDominantColor(getContext(), icon));
countIcons(currencies[0]);
}
}

View File

@ -3,6 +3,7 @@ package com.herbron.moodl.Activities.HomeActivityFragments;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -61,6 +62,7 @@ import java.util.Random;
import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.getDrawable;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
import static com.herbron.moodl.MoodlBox.numberConformer;
import static java.lang.Math.abs;
@ -70,23 +72,22 @@ 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;
private Handler handler;
private Runnable updateRunnable;
private Runnable layoutRefresherRunnable;
private int coinCounter;
private int iconCounter;
private float totalValue;
private boolean detailsChecker;
private boolean tickersChecker;
@ -94,6 +95,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
private long lastTimestamp;
private BalanceUpdateInterface balanceUpdateInterface;
private CoinmarketCapAPIManager coinmarketCapAPIManager;
private CryptocompareApiManager cryptocompareApiManager;
@NonNull
@ -124,8 +126,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
initiateUpdateRunnable();
initiateLayoutRefresherRunnable();
refreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
@ -201,50 +201,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
};
}
private void initiateLayoutRefresherRunnable()
{
layoutRefresherRunnable = new Runnable() {
@Override
public void run() {
final List<Currency> renderedCurrencies = new ArrayList<>();
if (balanceManager.getTotalBalance() != null)
{
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) {
final Currency currency = balanceManager.getTotalBalance().get(i);
if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) {
//currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
renderedCurrencies.add(currency);
}
}
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
currencyLayout.removeAllViews();
for(int i = 0; i < renderedCurrencies.size(); i++)
{
//currencyLayout.addView(currencyView.get(i));
currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden()));
}
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
updateTitle();
handler.removeCallbacks(updateRunnable);
}
});
}
};
}
private void setupAddCurrencyButton(View fragmentView)
{
Button addCurrencyButton = fragmentView.findViewById(R.id.buttonAddTransaction);
@ -363,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();
@ -372,12 +328,46 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
private void resetCounters()
{
coinCounter = 0;
iconCounter = 0;
}
private void adaptView()
private void adaptView(float totalValue, float totalFluctuation)
{
layoutRefresherRunnable.run();
this.totalValue = totalValue;
this.totalFluctuation = totalFluctuation;
final List<Currency> renderedCurrencies = new ArrayList<>();
if (balanceManager.getTotalBalance() != null)
{
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) {
final Currency currency = balanceManager.getTotalBalance().get(i);
if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) {
//currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
renderedCurrencies.add(currency);
}
}
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
currencyLayout.removeAllViews();
for(int i = 0; i < renderedCurrencies.size(); i++)
{
currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden()));
}
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
updateTitle();
handler.removeCallbacks(updateRunnable);
}
});
}
private void countCoins(boolean isCoin, boolean isDetails, boolean isTickers)
@ -401,46 +391,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
{
if(balanceManager.getTotalBalance().size() == 0)
{
countIcons();
updateNoBalance();
}
else
{
if(coinCounter >= balanceManager.getTotalBalance().size() && detailsChecker && tickersChecker)
{
IconDownloader iconDownloader = new IconDownloader();
iconDownloader.execute();
}
}
}
}
private void countIcons()
{
int offset = 0;
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
if(balanceManager.getTotalBalance().get(i).getSymbol().equals("USD"))
{
offset++;
}
}
iconCounter++;
if(balanceManager.getTotalBalance() != null)
{
if(balanceManager.getTotalBalance().size() == 0)
{
updateNoBalance();
}
else
{
if(iconCounter == balanceManager.getTotalBalance().size() - offset)
{
UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
uiHeavyLoadCalculator.execute();
uiHeavyLoadCalculator.setOnUiEndListener(new UiHeavyLoadCalculator.OnUiEndListener() {
@Override
public void onEnd(float totalValue, float totalFluctuation) {
refreshLayout.setRefreshing(false);
adaptView(totalValue, totalFluctuation);
}
});
uiHeavyLoadCalculator.execute(getActivity().getBaseContext(), balanceManager, coinmarketCapAPIManager);
}
}
}
@ -467,23 +433,11 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
private void computeTotalValue()
{
totalValue = 0;
totalFluctuation = 0;
for(int i = 0; i < currencyLayout.getChildCount(); i++)
{
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
{
totalValue += ((CurrencyCardview) currencyLayout.getChildAt(i)).getOwnedValue();
totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation();
}
}
for(int i = 0; i < currencyLayout.getChildCount(); i++)
{
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
{
((CurrencyCardview) currencyLayout.getChildAt(i)).updateCardViewInfos(totalValue, preferencesManager.isBalanceHidden());
((CurrencyCardview) currencyLayout.getChildAt(i)).updateOwnedValues(totalValue, preferencesManager.isBalanceHidden());
}
}
}
@ -690,9 +644,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
countCoins(false, false, true);
}
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
private static class UiHeavyLoadCalculator extends AsyncTask<Object, Integer, Void>
{
private float totalValue = 0;
private float totalFluctuation = 0;
private BalanceManager balanceManager;
private CoinmarketCapAPIManager coinmarketCapAPIManager;
private OnUiEndListener onUiEndListener;
public void setOnUiEndListener(OnUiEndListener onUiEndListener)
{
this.onUiEndListener = onUiEndListener;
}
@Override
protected void onPreExecute()
{
@ -708,34 +675,19 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
super.onProgressUpdate(values);
}
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext())));
}
else
{
currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext()));
}
}
private void loadCurrency(Currency currency)
{
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
}
@Override
protected Void doInBackground(Void... params)
protected Void doInBackground(Object... params)
{
if(Looper.myLooper() == null)
{
Looper.prepare();
}
Context baseContext = (Context) params[0];
balanceManager = (BalanceManager) params[1];
coinmarketCapAPIManager = (CoinmarketCapAPIManager) params[2];
balanceManager.sortCoins();
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
@ -744,33 +696,34 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol()));
updateChartColor(localCurrency);
localCurrency.setChartColor(getIconDominantColor(baseContext, localCurrency.getIcon()));
loadCurrency(localCurrency);
totalValue += localCurrency.getValue() * localCurrency.getBalance();
totalFluctuation += localCurrency.getValue() * localCurrency.getBalance() * (localCurrency.getDayFluctuationPercentage() / 100);
balanceManager.getTotalBalance().set(i, localCurrency);
}
return null;
}
private void loadCurrency(Currency currency)
{
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
}
@Override
protected void onPostExecute(Void result)
{
refreshLayout.setRefreshing(false);
new AsyncTask<Void, Integer, Void>() {
onUiEndListener.onEnd(totalValue, totalFluctuation);
}
@Override
protected Void doInBackground(Void... voids) {
if(Looper.myLooper() == null)
{
Looper.prepare();
}
adaptView();
return null;
}
}.execute();
public interface OnUiEndListener
{
void onEnd(float totalValue, float totalFluctuation);
}
}
@ -798,63 +751,9 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
}
}
private class IconDownloader extends AsyncTask<Void, Integer, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... params)
{
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
String iconUrl = MoodlBox.getIconUrl(localCurrency.getSymbol(), balanceManager.getCryptocompareApiManager());
if(iconUrl != null)
{
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() {
@Override
public void onBitmapDownloaded(Bitmap bitmapIcon) {
localCurrency.setIcon(bitmapIcon);
countIcons();
}
});
}
else
{
Drawable drawable = getDrawable(R.drawable.ic_panorama_fish_eye_24dp, getActivity().getBaseContext());
Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
localCurrency.setIcon(icon);
countIcons();
}
}
return null;
}
}
private class DataUpdater extends AsyncTask<Void, Integer, Void>
{
@Override
protected Void doInBackground(Void... params)
{

View File

@ -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,7 @@ 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;
/**
* Created by Tiji on 13/04/2018.
@ -249,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);
}
@ -354,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())
{
@ -380,20 +381,6 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
}
}
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext())));
}
else
{
currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext()));
}
}
public int getCurrencyId(String symbol)
{
int id = 0;
@ -403,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;
@ -448,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);
updateChartColor(currency);
countWatchlist();
}
});
}
else
{
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl);
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
currency.setIcon(icon);
updateChartColor(currency);
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();
}
});
}
});
}

View File

@ -0,0 +1,51 @@
package com.herbron.moodl.CustomLayouts;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.design.widget.TextInputEditText;
import android.text.TextPaint;
import android.util.AttributeSet;
public class TextInputEditTextSuffix extends TextInputEditText {
private TextPaint textPaint = new TextPaint();
private String suffix = "";
public TextInputEditTextSuffix(Context context) {
super(context);
}
public TextInputEditTextSuffix(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TextInputEditTextSuffix(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(!getText().toString().equals(""))
{
int suffixXPosition = (int) textPaint.measureText(getText().toString() + getPaddingLeft());
canvas.drawText(suffix, Math.max(suffixXPosition, 0), getBaseline(), textPaint);
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
textPaint.setColor(getCurrentTextColor());
textPaint.setTextSize(getTextSize());
textPaint.setTextAlign(Paint.Align.LEFT);
}
public void setSuffix(String suffix)
{
this.suffix = suffix;
}
}

View File

@ -4,16 +4,27 @@ import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
@ -26,7 +37,9 @@ import com.github.mikephil.charting.data.LineDataSet;
import com.herbron.moodl.Activities.CurrencyDetailsActivity;
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.Utils.PlaceholderUtils;
import com.herbron.moodl.R;
@ -36,6 +49,7 @@ import java.util.List;
import static com.herbron.moodl.MoodlBox.collapseH;
import static com.herbron.moodl.MoodlBox.expandH;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
import static com.herbron.moodl.MoodlBox.numberConformer;
/**
@ -44,8 +58,11 @@ import static com.herbron.moodl.MoodlBox.numberConformer;
public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNotifierInterface {
private static final int FADE_IN_DURATION = 300;
private Currency currency;
private Activity parentActivity;
private Context context;
private OnClickListener detailsClickListener = new OnClickListener() {
@Override
@ -67,6 +84,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
public CurrencyCardview(@NonNull Context context) {
super(context);
this.context = context;
}
public CurrencyCardview(@NonNull final Context context, final Currency currency, final Activity activity)
@ -77,6 +95,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
this.currency = currency;
this.parentActivity = activity;
this.context = context;
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
@ -84,32 +103,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
setupCardView();
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
PreferencesManager preferencesManager = new PreferencesManager(context);
setOnClickListeners();
if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) {
collapseH(view.findViewById(R.id.collapsableLayout));
} else {
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE);
expandH(view.findViewById(R.id.collapsableLayout));
if (currency.getHistoryMinutes() == null) {
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency());
}
else
{
expandH(view.findViewById(R.id.collapsableLayout));
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
}
}
}
});
updateCardViewInfos(currency);
updateCardviewInfos();
findViewById(R.id.deleteCardWatchlist).setOnClickListener(new OnClickListener() {
@Override
@ -120,10 +116,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
}
});
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
updateColor();
updateColor(currency);
startIconUpdater();
}
public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, boolean isBalanceHidden)
@ -134,6 +129,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
this.currency = currency;
this.parentActivity = activity;
this.context = context;
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
@ -141,6 +137,74 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
setupCardView();
setOnClickListeners();
updateCardviewInfos();
updateColor();
startIconUpdater();
}
private void startIconUpdater()
{
IconDownloader iconDownloader = new IconDownloader();
iconDownloader.execute(context, currency);
iconDownloader.setOnBitmapDownloadedListener(new IconDownloader.OnBitmapDownloadedListener() {
@Override
public void onDownloaded(Bitmap icon) {
currency.setIcon(icon);
currency.setChartColor(getIconDominantColor(context, icon));
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
updateCurrencyColorRelatedLayouts();
}
});
}
});
}
private void updateCurrencyColorRelatedLayouts()
{
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new AccelerateInterpolator());
fadeIn.setDuration(FADE_IN_DURATION);
ImageView currencyIconImageView = findViewById(R.id.currencyIcon);
currencyIconImageView.setImageBitmap(currency.getIcon());
currencyIconImageView.startAnimation(fadeIn);
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
arrowDrawable.mutate();
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
arrowDrawable.invalidateSelf();
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechart)).getIndeterminateDrawable();
progressDrawable.mutate();
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressDrawable.invalidateSelf();
if(findViewById(R.id.currencyPortfolioDominance) != null)
{
Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable();
progressBarDrawable.mutate();
progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressBarDrawable.invalidateSelf();
}
LineChart lineChart = findViewById(R.id.LineChartView);
if(currency.getHistoryMinutes() != null)
{
lineChart.setData(generateData());
lineChart.invalidate();
}
}
private void setOnClickListeners()
{
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
@ -150,7 +214,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
collapseH(view.findViewById(R.id.collapsableLayout));
} else {
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE);
view.findViewById(R.id.progressBarLinechart).setVisibility(View.VISIBLE);
expandH(view.findViewById(R.id.collapsableLayout));
if (currency.getHistoryMinutes() == null) {
@ -159,7 +223,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
else
{
expandH(view.findViewById(R.id.collapsableLayout));
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
view.findViewById(R.id.progressBarLinechart).setVisibility(View.GONE);
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
}
}
@ -169,7 +233,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
updateColor(currency);
}
public Currency getCurrency()
@ -210,81 +273,33 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generateData(currency));
lineChart.setData(generateData());
}
private void updateCardViewInfos(Currency currency)
private void updateCardviewInfos()
{
((TextView) findViewById(R.id.currencyFluctuationTextView))
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext()));
((TextView) findViewById(R.id.currencyValueTextView))
.setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext()));
((ImageView) findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon());
((TextView) findViewById(R.id.currencyNameTextView))
.setText(currency.getName());
((TextView) findViewById(R.id.currencySymbolTextView))
.setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext()));
((TextView) findViewById(R.id.currencyFluctuationPercentageTextView))
.setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext()));
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
if(arrowDrawable != null)
{
arrowDrawable.mutate();
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
arrowDrawable.invalidateSelf();
}
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable();
if(progressDrawable != null)
{
progressDrawable.mutate();
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressDrawable.invalidateSelf();
}
}
public void updateCardViewInfos(float totalValue, boolean isBalanceHidden)
public void updateOwnedValues(float totalValue, boolean isBalanceHidden)
{
double value = currency.getValue() * currency.getBalance();
double percentage = value / totalValue * 100;
((TextView) findViewById(R.id.currencyValueOwnedTextView))
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext()));
((TextView) findViewById(R.id.currencyFluctuationTextView))
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext()));
((TextView) findViewById(R.id.currencyValueTextView))
.setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext()));
((ImageView) findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon());
((TextView) findViewById(R.id.currencyNameTextView))
.setText(currency.getName());
((TextView) findViewById(R.id.currencySymbolTextView))
.setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext()));
((TextView) findViewById(R.id.currencyOwnedTextView))
.setText(PlaceholderUtils.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext()));
((TextView) findViewById(R.id.currencyFluctuationPercentageTextView))
.setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext()));
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
arrowDrawable.mutate();
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
arrowDrawable.invalidateSelf();
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable();
progressDrawable.mutate();
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressDrawable.invalidateSelf();
Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable();
progressBarDrawable.mutate();
progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressBarDrawable.invalidateSelf();
((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage));
((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderUtils.getPercentageString(numberConformer(percentage), getContext()));
@ -303,17 +318,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
}
}
public double getOwnedValue()
{
return currency.getValue() * currency.getBalance();
}
public double getFluctuation()
{
return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100);
}
private LineData generateData(Currency currency)
private LineData generateData()
{
LineDataSet dataSet;
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
@ -340,7 +345,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
return new LineData(dataSet);
}
private void updateColor(Currency currency)
private void updateColor()
{
if(currency.getDayFluctuationPercentage() >= 0)
{
@ -379,18 +384,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
@Override
public void onHistoryDataUpdated() {
View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist);
View progressSummaryView = findViewById(R.id.progressBarLinechartSummary);
View progressView = findViewById(R.id.progressBarLinechart);
if(progressWatchlistView != null)
{
progressWatchlistView.setVisibility(View.GONE);
}
if(progressSummaryView != null)
{
progressSummaryView.setVisibility(View.GONE);
}
progressView.setVisibility(View.GONE);
findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
@ -404,4 +400,46 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
public void onPriceUpdated(Currency currency) {
}
private static class IconDownloader extends AsyncTask<Object, Integer, Void> implements MoodlboxNotifierInterface
{
private Bitmap icon = null;
private OnBitmapDownloadedListener onBitmapDownloadedListener;
public Bitmap getIcon()
{
return icon;
}
public void setOnBitmapDownloadedListener(OnBitmapDownloadedListener onBitmapDownloadedListener) {
this.onBitmapDownloadedListener = onBitmapDownloadedListener;
}
@Override
protected Void doInBackground(Object... objects) {
Context context = (Context) objects[0];
Currency currency = (Currency) objects[1];
CryptocompareApiManager cryptocompareApiManager = CryptocompareApiManager.getInstance(context);
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager);
if(iconUrl != null)
{
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), context.getResources(), context, this);
}
return null;
}
@Override
public void onBitmapDownloaded(Bitmap bitmap) {
icon = bitmap;
onBitmapDownloadedListener.onDownloaded(bitmap);
}
public interface OnBitmapDownloadedListener {
void onDownloaded(Bitmap icon);
}
}
}

View File

@ -73,10 +73,12 @@ public class DataCrypter {
IvParameterSpec ivParameterSpec = new IvParameterSpec(context.getString(R.string.ivKey).getBytes("UTF-8"));
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, aesKey, ivParameterSpec);
cipher.init(Cipher.DECRYPT_MODE, aesKey, ivParameterSpec);
byte[] decryptedBytes = cipher.doFinal(data.getBytes("UTF-8"));
byte[] dataBytes = Base64.decode(data, Base64.DEFAULT);
decryptedData = new String(dataBytes, StandardCharsets.UTF_8);
//byte[] dataBytes = Base64.decode(data, Base64.DEFAULT);
decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
} catch(NoSuchPaddingException | NoSuchAlgorithmException
| InvalidKeyException | UnsupportedEncodingException

View File

@ -203,6 +203,11 @@ public class CoinmarketCapAPIManager {
}
}
public List<Currency> getTotalListing()
{
return currencyTickerList;
}
public void updateTopCurrencies(final String toSymbol)
{
String requestString = topCurrenciesUrl + toSymbol;

View File

@ -4,8 +4,10 @@ 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;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.View;
@ -208,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);
}
@ -297,4 +314,18 @@ public class MoodlBox {
return url;
}
public static int getIconDominantColor(Context context, Bitmap icon)
{
if(icon != null)
{
Palette.Builder builder = Palette.from(icon);
return builder.generate().getDominantColor(getColor(R.color.default_color, context));
}
else
{
return getColor(R.color.default_color, context);
}
}
}

View File

@ -31,7 +31,7 @@
android:id="@+id/currencyIcon"
android:layout_width="@dimen/currency_icon_cardview_size"
android:layout_height="@dimen/currency_icon_cardview_size"
android:layout_margin="1dp" />
android:layout_margin="1dp"/>
<TextView
android:id="@+id/currencyNameTextView"
@ -165,7 +165,7 @@
android:focusable="true">
<ProgressBar
android:id="@+id/progressBarLinechartSummary"
android:id="@+id/progressBarLinechart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -51,7 +51,7 @@
android:id="@+id/currencyIcon"
android:layout_width="@dimen/currency_icon_cardview_size"
android:layout_height="@dimen/currency_icon_cardview_size"
android:layout_margin="1dp" />
android:layout_margin="1dp"/>
<TextView
android:id="@+id/currencyNameTextView"
@ -177,7 +177,7 @@
android:visibility="visible">
<ProgressBar
android:id="@+id/progressBarLinechartWatchlist"
android:id="@+id/progressBarLinechart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -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" />
</LinearLayout>

View File

@ -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">
<LinearLayout
android:layout_width="match_parent"

View File

@ -32,7 +32,7 @@
android:id="@+id/currencyIcon"
android:layout_width="@dimen/currency_icon_cardview_size"
android:layout_height="@dimen/currency_icon_cardview_size"
android:layout_margin="1dp" />
android:layout_margin="1dp"/>
<TextView
android:id="@+id/currencyNameTextView"
@ -166,7 +166,7 @@
android:focusable="true">
<ProgressBar
android:id="@+id/progressBarLinechartSummary"
android:id="@+id/progressBarLinechart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -53,7 +53,7 @@
android:id="@+id/currencyIcon"
android:layout_width="@dimen/currency_icon_cardview_size"
android:layout_height="@dimen/currency_icon_cardview_size"
android:layout_margin="1dp" />
android:layout_margin="1dp"/>
<TextView
android:id="@+id/currencyNameTextView"
@ -180,7 +180,7 @@
android:visibility="visible">
<ProgressBar
android:id="@+id/progressBarLinechartWatchlist"
android:id="@+id/progressBarLinechart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -149,7 +149,7 @@
<string name="cannot_resole_host">Impossible de résoudre l\'hôte</string>
<string name="unexpected">Erreur inconnue</string>
<string name="select_coin">Selectionner une monnaie</string>
<string name="already_watchlisr">Monnaie déjà présente dans la liste suivie</string>
<string name="already_watchlist">Monnaie déjà présente dans la liste suivie</string>
<string name="create_backup">Créer une sauvegarde</string>
<string name="wrong_password">Mauvais mot de passe</string>
<string name="error">Erreur</string>

View File

@ -261,7 +261,7 @@
<string name="cannot_resole_host">Can\'t resolve host</string>
<string name="unexpected">Unexpected error</string>
<string name="select_coin">Select a coin</string>
<string name="already_watchlisr">Currency already in watchlist</string>
<string name="already_watchlist">Currency already in watchlist</string>
<string name="create_backup">Create backup</string>
<string name="wrong_password">Wrong password</string>
<string name="error">Error</string>

View File

@ -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

View File

@ -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