Several fixes/improvements

- Add Watchlist charts
- Add Detail Activity for Watchlist coins
- Add padding for Watchlist
- Remove superfluous 0s when displaying balance/price
- Fix Summary Detail Button not changing form
- Fix app crash when Marketcap fragment is not fully loaded
- Fix separate Fragment update obligations
- Fix 0 coin in Detail activity when coming from Watchlist
This commit is contained in:
Tanguy Herbron 2018-04-15 20:08:17 +02:00
parent 9973c4bf37
commit f0c4062871
15 changed files with 356 additions and 149 deletions

View File

@ -202,8 +202,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
TradeUpdater updater = new TradeUpdater();
updater.execute();
Log.d("coinfolio", "Details loaded for " + currency.getId());
}
private void updateInfoTab()
@ -213,7 +211,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private void setupActionBar()
{
setTitle(" " + currency.getName() + " | " + currency.getBalance());
if(currency.getBalance() == 0)
{
setTitle(" " + currency.getName());
}
else
{
setTitle(" " + currency.getName() + " | " + currency.getBalance());
}
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
@ -584,7 +589,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private String getDate(long timeStamp){
try{
//SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy");
SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault());
Date netDate = (new Date(timeStamp));
return sdf.format(netDate);
@ -833,7 +837,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
deleteLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
preferencesManager.setMustUpdate(true);
preferencesManager.setMustUpdateSummary(true);
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
drawTransactionList();
hasBeenModified = true;

View File

@ -7,8 +7,6 @@ import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@ -100,7 +98,7 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
DatabaseManager databaseManager = new DatabaseManager(getApplicationContext());
databaseManager.addCurrencyToWatchlist(selectedCurrency);
preferencesManager.setMustUpdate(true);
preferencesManager.setMustUpdateWatchlist(true);
}
else
{

View File

@ -93,12 +93,14 @@ public class HomeActivity extends AppCompatActivity {
switch (item.getItemId())
{
case R.id.navigation_watchlist:
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
viewPager.setCurrentItem(0);
break;
case R.id.navigation_currencies_list:
viewPager.setCurrentItem(1);
break;
case R.id.navigation_market_cap:
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
viewPager.setCurrentItem(2);
break;
}
@ -125,10 +127,16 @@ public class HomeActivity extends AppCompatActivity {
final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), 3);
viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(2);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
bottomNavigationView.getMenu().getItem(position).setChecked(true);
if(position % 2 == 0)
{
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
}
}
@Override
@ -165,11 +173,8 @@ public class HomeActivity extends AppCompatActivity {
//overridePendingTransition(R.anim.activity_enter, R.anim.activity_exit);
}
});
}
private void switchMainView()
{
Log.d("coinfolio", "Should");

View File

@ -2,8 +2,10 @@ package com.nauk.coinfolio.Activities.HomeActivityFragments;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.SpannableString;
import android.util.Log;
@ -11,6 +13,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TextView;
import com.github.mikephil.charting.charts.PieChart;
@ -53,7 +56,7 @@ public class MarketCapitalization extends Fragment {
setupDominantCurrenciesColors();
marketCapManager = new MarketCapManager(getContext());
refreshLayout = view.findViewById(R.id.swiperefresh);
refreshLayout = view.findViewById(R.id.swiperefreshmarketcap);
refreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@ -72,6 +75,12 @@ public class MarketCapitalization extends Fragment {
return view;
}
@Override
public void onResume()
{
super.onResume();
}
private void setupDominantCurrenciesColors()
{
dominantCurrenciesColors = new HashMap<>();
@ -196,11 +205,13 @@ public class MarketCapitalization extends Fragment {
{
case MotionEvent.ACTION_DOWN:
refreshLayout.setEnabled(false);
getActivity().findViewById(R.id.viewPager).setEnabled(false);
break;
case MotionEvent.ACTION_MOVE:
break;
default:
refreshLayout.setEnabled(true);
getActivity().findViewById(R.id.viewPager).setEnabled(true);
break;
}
return false;
@ -210,8 +221,7 @@ public class MarketCapitalization extends Fragment {
pieChart.getDescription().setEnabled(false);
pieChart.getLegend().setEnabled(false);
pieChart.setCenterText(generateCenterSpannableText());
pieChart.invalidate(); // refresh
pieChart.invalidate();
}
private SpannableString generateCenterSpannableText() {
@ -228,8 +238,8 @@ public class MarketCapitalization extends Fragment {
symbols.setGroupingSeparator(' ');
formatter.setDecimalFormatSymbols(symbols);
((TextView) view.findViewById(R.id.marketCapTextView)).setText(getResources().getString(R.string.market_cap_textview, formatter.format(marketCapManager.getMarketCap())));
((TextView) view.findViewById(R.id.marketCapTextView)).setText(getActivity().getResources().getString(R.string.market_cap_textview, formatter.format(marketCapManager.getMarketCap())));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap)).setText(getResources().getString(R.string.volume_market_cap_textview, formatter.format(marketCapManager.getDayVolume())));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap)).setText(getActivity().getResources().getString(R.string.volume_market_cap_textview, formatter.format(marketCapManager.getDayVolume())));
}
}

View File

@ -9,7 +9,6 @@ import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
@ -19,6 +18,7 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
@ -27,7 +27,6 @@ import android.widget.TextView;
import com.nauk.coinfolio.Activities.CurrencySelectionActivity;
import com.nauk.coinfolio.Activities.HomeActivity;
import com.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
@ -45,7 +44,6 @@ import java.util.List;
public class Summary extends Fragment {
private boolean isDetailed;
private LinearLayout currencyLayout;
private PreferencesManager preferencesManager;
private BalanceManager balanceManager;
@ -76,12 +74,10 @@ public class Summary extends Fragment {
preferencesManager = new PreferencesManager(getActivity());
balanceManager = new BalanceManager(getActivity());
layoutGenerator = new HomeLayoutGenerator(getActivity());
refreshLayout = view.findViewById(R.id.swiperefresh);
refreshLayout = view.findViewById(R.id.swiperefreshsummary);
toolbarSubtitle = getActivity().findViewById(R.id.toolbarSubtitle);
toolbarLayout = getActivity().findViewById(R.id.toolbar_layout);
isDetailed = preferencesManager.getDetailOption();
totalValue = 0;
totalFluctuation = 0;
lastTimestamp = 0;
@ -133,6 +129,7 @@ public class Summary extends Fragment {
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
preferencesManager.setDetailOption(!preferencesManager.getDetailOption());
updateViewButtonIcon();
switchView();
}
@ -140,18 +137,45 @@ public class Summary extends Fragment {
updateTitle();
generateSplashScreen();
updateAll(true);
generateSplashScreen();
return view;
}
private void generateSplashScreen()
{
LinearLayout loadingLayout = new LinearLayout(getActivity());
loadingLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
loadingLayout.setGravity(Gravity.CENTER);
loadingLayout.setOrientation(LinearLayout.VERTICAL);
loadingDialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
TextView txtView = new TextView(getActivity());
txtView.setText("Loading data...");
txtView.setTextSize(20);
txtView.setGravity(Gravity.CENTER);
txtView.setTextColor(this.getResources().getColor(R.color.cardview_light_background));
ProgressBar progressBar = new ProgressBar(getActivity());
progressBar.setIndeterminate(true);
loadingLayout.setBackgroundColor(getActivity().getResources().getColor(R.color.colorPrimaryDark));
loadingLayout.addView(txtView);
loadingLayout.addView(progressBar);
loadingDialog.setContentView(loadingLayout);
loadingDialog.show();
}
@Override
public void onResume() {
super.onResume();
updateAll(preferencesManager.mustUpdate());
updateAll(preferencesManager.mustUpdateSummary());
updateViewButtonIcon();
@ -207,45 +231,14 @@ public class Summary extends Fragment {
totalFluctuation = 0;
}
private void generateSplashScreen()
{
LinearLayout loadingLayout = new LinearLayout(getActivity());
loadingLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
loadingLayout.setGravity(Gravity.CENTER);
loadingLayout.setOrientation(LinearLayout.VERTICAL);
loadingDialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
TextView txtView = new TextView(getActivity());
txtView.setText("Loading data...");
txtView.setTextSize(20);
txtView.setGravity(Gravity.CENTER);
txtView.setTextColor(this.getResources().getColor(R.color.cardview_light_background));
ProgressBar progressBar = new ProgressBar(getActivity());
progressBar.setIndeterminate(true);
loadingLayout.setBackgroundColor(this.getResources().getColor(R.color.colorPrimaryDark));
loadingLayout.addView(txtView);
loadingLayout.addView(progressBar);
loadingDialog.setContentView(loadingLayout);
loadingDialog.show();
}
private void switchView()
{
if(isDetailed)
if(preferencesManager.getDetailOption())
{
isDetailed = false;
adaptView();
}
else
{
isDetailed = true;
adaptView();
}
}
@ -260,7 +253,7 @@ public class Summary extends Fragment {
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null))
{
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, preferencesManager.getDetailOption(), totalValue, preferencesManager.isBalanceHidden()));
}
}
}
@ -453,9 +446,11 @@ public class Summary extends Fragment {
Currency currency = balanceManager.getTotalBalance().get(i);
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) {
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, preferencesManager.getDetailOption(), totalValue, preferencesManager.isBalanceHidden()));
}
}
adaptView();
}
});
}
@ -502,7 +497,6 @@ public class Summary extends Fragment {
refreshLayout.setRefreshing(false);
refreshCurrencyList();
handler.removeCallbacks(updateRunnable);
adaptView();
}
}
@ -536,12 +530,10 @@ public class Summary extends Fragment {
if(preferencesManager.getDetailOption())
{
imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_unfold_less_black_24dp));
preferencesManager.setDetailOption(false);
}
else
{
imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_details_black_24dp));
preferencesManager.setDetailOption(true);
}
}

View File

@ -3,24 +3,40 @@ package com.nauk.coinfolio.Activities.HomeActivityFragments;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
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.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.nauk.coinfolio.Activities.CurrencyDetailsActivity;
import com.nauk.coinfolio.Activities.CurrencySelectionActivity;
import com.nauk.coinfolio.Activities.HomeActivity;
import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.DataManagers.WatchlistManager;
@ -32,6 +48,8 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static java.lang.Math.abs;
@ -55,7 +73,7 @@ public class Watchlist extends Fragment {
{
view = inflater.inflate(R.layout.fragment_watchlist_homeactivity, container, false);
refreshLayout = view.findViewById(R.id.swiperefresh);
refreshLayout = view.findViewById(R.id.swiperefreshwatchlist);
currencyDetailsList = new CurrencyDetailsList(getContext());
preferencesManager = new PreferencesManager(getContext());
@ -85,12 +103,78 @@ public class Watchlist extends Fragment {
return view;
}
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 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 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);
}
@Override
public void onResume()
{
super.onResume();
updateWatchlist(preferencesManager.mustUpdate());
updateWatchlist(preferencesManager.mustUpdateWatchlist());
}
private void updateWatchlist(boolean mustUpdate)
@ -131,7 +215,7 @@ public class Watchlist extends Fragment {
{
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
for(Currency currency : watchlistManager.getWatchlist())
for(final Currency currency : watchlistManager.getWatchlist())
{
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
@ -142,16 +226,42 @@ public class Watchlist extends Fragment {
((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon());
((TextView) card.findViewById(R.id.currencyValueTextView)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue())));
Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable();
arrowDrawable.mutate();
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
arrowDrawable.invalidateSelf();
updateColor(card, currency);
card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("coinfolio", "Clicked !");
if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE)
{
collapseView(view);
}
else
{
extendView(view);
}
}
});
card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
getActivity().getApplicationContext().startActivity(intent);
}
});
if(currency.getHistoryMinutes() != null)
{
setupLineChart(card, currency);
}
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(card, 0);
}
@ -161,6 +271,65 @@ public class Watchlist extends Fragment {
}
}
}
private LineData generateData(Currency currency)
{
LineDataSet dataSet;
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
ArrayList<Entry> values = new ArrayList<>();
Log.d("coinfolio", "Generating data for " + currency.getSymbol());
for(int i = 0; i < dataChartList.size(); i+=10)
{
values.add(new Entry(i, (float) dataChartList.get(i).getOpen()));
}
dataSet = new LineDataSet(values, "History");
dataSet.setDrawIcons(false);
dataSet.setColor(currency.getChartColor());
dataSet.setLineWidth(1);
dataSet.setDrawFilled(true);
dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f));
dataSet.setFormLineWidth(1);
dataSet.setFormSize(15);
dataSet.setDrawCircles(false);
dataSet.setDrawValues(false);
dataSet.setHighlightEnabled(false);
return new LineData(dataSet);
}
private int getColorWithAplha(int color, float ratio)
{
int transColor;
int alpha = Math.round(Color.alpha(color) * ratio);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
transColor = Color.argb(alpha, r, g, b);
return transColor ;
}
private void setupLineChart(View view, final Currency currency)
{
LineChart lineChart = view.findViewById(R.id.LineChartView);
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setScaleEnabled(false);
lineChart.setDragEnabled(false);
lineChart.getDescription().setEnabled(false);
lineChart.getAxisLeft().setEnabled(false);
lineChart.getAxisRight().setEnabled(false);
lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generateData(currency));
}
private void updateColor(View card, Currency currency)
{
@ -215,6 +384,20 @@ public class Watchlist extends Fragment {
callBack.onSuccess(result);
}
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 class WatchlistUpdater extends AsyncTask<Void, Integer, Void>
{
@Override
@ -225,7 +408,7 @@ public class Watchlist extends Fragment {
@Override
protected Void doInBackground(Void... voids) {
for(Currency currency : watchlistManager.getWatchlist())
for(final Currency currency : watchlistManager.getWatchlist())
{
currency.updateHistoryMinutes(getActivity(), new Currency.CurrencyCallBack() {
@Override
@ -236,6 +419,7 @@ public class Watchlist extends Fragment {
@Override
public void onSuccess(Bitmap bitmapIcon) {
sucessCurrency.setIcon(bitmapIcon);
updateChartColor(currency);
countWatchlist();
}
});

View File

@ -1,10 +1,7 @@
package com.nauk.coinfolio.Activities;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
@ -21,7 +18,6 @@ import com.nauk.coinfolio.R;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class RecordTransactionActivity extends AppCompatActivity {
@ -76,7 +72,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
@Override
public void onClick(View view) {
databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime(), purchasedPrice.getText().toString());
preferenceManager.setMustUpdate(true);
preferenceManager.setMustUpdateSummary(true);
Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

View File

@ -276,7 +276,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("mustUpdate", true);
editor.putBoolean("mustUpdateSummary", true);
editor.apply();
return isChecked;
@ -292,7 +292,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("mustUpdate", true);
editor.putBoolean("mustUpdateSummary", true);
editor.apply();
return isChecked;

View File

@ -83,20 +83,39 @@ public class PreferencesManager {
editor.apply();
}
public void setMustUpdate(boolean mustUpdate)
public void setMustUpdateWatchlist(boolean mustUpdate)
{
SharedPreferences.Editor editor = settingPreferences.edit();
editor.putBoolean("mustUpdate", mustUpdate);
editor.putBoolean("mustUpdateWatchlist", mustUpdate);
editor.apply();
}
public boolean mustUpdate()
public boolean mustUpdateWatchlist()
{
boolean mustUpdate = settingPreferences.getBoolean("mustUpdate", false);
boolean mustUpdate = settingPreferences.getBoolean("mustUpdateWatchlist", false);
if(mustUpdate)
{
setMustUpdate(false);
setMustUpdateWatchlist(false);
}
return mustUpdate;
}
public void setMustUpdateSummary(boolean mustUpdate)
{
SharedPreferences.Editor editor = settingPreferences.edit();
editor.putBoolean("mustUpdateSummary", mustUpdate);
editor.apply();
}
public boolean mustUpdateSummary()
{
boolean mustUpdate = settingPreferences.getBoolean("mustUpdateSummary", false);
if(mustUpdate)
{
setMustUpdateSummary(false);
}
return mustUpdate;

View File

@ -7,6 +7,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
@ -64,7 +65,19 @@ public class HomeLayoutGenerator {
updateCardViewInfos(view, currency, totalValue, isBalanceHidden);
setupLineChart(view, currency);
view.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
if(currency.getHistoryMinutes() != null)
{
setupLineChart(view, currency);
}
if(isExtended)
{
@ -152,15 +165,6 @@ public class HomeLayoutGenerator {
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generateData(currency));
lineChart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
}
private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden)
@ -249,6 +253,7 @@ public class HomeLayoutGenerator {
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
ArrayList<Entry> values = new ArrayList<>();
Log.d("coinfolio", "Generating data for " + currency.getSymbol());
for(int i = 0; i < dataChartList.size(); i+=10)
{
values.add(new Entry(i, (float) dataChartList.get(i).getOpen()));
@ -288,11 +293,11 @@ public class HomeLayoutGenerator {
if(abs(number) > 1)
{
str = String.format( Locale.UK, "%.2f", number);
str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", "");
}
else
{
str = String.format( Locale.UK, "%.4f", number);
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
return str;

View File

@ -1,5 +1,7 @@
package com.nauk.coinfolio;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

View File

@ -106,66 +106,57 @@
</LinearLayout>
<LinearLayout
android:id="@+id/separationLayout"
android:id="@+id/collapsableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:visibility="gone">
android:visibility="gone"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day history"
android:textSize="@dimen/cardViewSecondaryText" />
<View
<LinearLayout
android:id="@+id/separationLayout"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationColor" />
android:layout_height="wrap_content"
android:layout_margin="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day history"
android:textSize="@dimen/cardViewSecondaryText" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationColor" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayoutChart"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:clickable="true"
android:focusable="true">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/LineChartView"
android:layout_width="match_parent"
android:layout_height="150dp"/>
<ImageView
android:id="@+id/detailsArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_grey_48dp"
android:layout_gravity="center_vertical|end"/>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayoutChart"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:clickable="true"
android:focusable="true"
android:visibility="gone">
<!--<com.db.chart.view.LineChartView
android:id="@+id/LineChartView"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:visibility="gone" />-->
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/LineChartView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:visibility="gone"/>
<TextView
android:id="@+id/errorTextView"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:gravity="center"
android:text="Error"
android:visibility="gone" />
<ImageView
android:id="@+id/detailsArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_grey_48dp"
android:visibility="gone"
android:layout_gravity="center_vertical|end"/>
</FrameLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swiperefresh"
android:id="@+id/swiperefreshmarketcap"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

View File

@ -2,7 +2,7 @@
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swiperefresh"
android:id="@+id/swiperefreshsummary"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swiperefresh"
android:id="@+id/swiperefreshwatchlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
@ -11,7 +11,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:paddingTop="10dp">
<ScrollView
android:layout_width="match_parent"