From 6e0657e5db19e46e6f2eb379e677335d15dfa479 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 14:12:23 +0200 Subject: [PATCH] Code cleanup --- .idea/statistic.xml | 21 ++ .../Activities/CurrencyDetailsActivity.java | 244 +++++++------ .../Activities/CurrencySelectionActivity.java | 5 + .../coinfolio/Activities/HomeActivity.java | 322 +++++++++--------- .../Activities/RecordTransactionActivity.java | 2 - .../Activities/SettingsActivity.java | 1 - .../DataManagers/BalanceManager.java | 1 - .../CurrencyData/CurrencyDataChart.java | 14 +- .../CurrencyData/CurrencyDataRetriever.java | 58 ++-- .../DataManagers/DatabaseManager.java | 3 - .../ExchangeManager/BinanceManager.java | 3 - .../ExchangeManager/HitBtcManager.java | 55 +-- .../FingerprintDialogFragment.java | 2 - .../FingerprintHandler.java | 7 - .../LayoutManagers/CurrencyAdapter.java | 19 +- .../LayoutManagers/HomeLayoutGenerator.java | 111 +++--- 16 files changed, 468 insertions(+), 400 deletions(-) create mode 100644 .idea/statistic.xml diff --git a/.idea/statistic.xml b/.idea/statistic.xml new file mode 100644 index 0000000..66820b8 --- /dev/null +++ b/.idea/statistic.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java index f8bfc50..60f924d 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -26,7 +26,6 @@ import android.widget.TextView; import android.widget.ViewFlipper; import com.daimajia.swipe.SwipeLayout; -import com.db.chart.tooltip.Tooltip; import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.BarData; @@ -45,10 +44,8 @@ import com.nauk.coinfolio.R; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.List; -import java.util.Locale; /**Create a Parcelable**/ @@ -67,6 +64,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private final static int MONTH = 3; private final static int YEAR = 4; private List dataChartList; + private LineChart lineChart; + private BarChart barChart; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -122,6 +121,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); chartLayout = findViewById(R.id.chartsLayout); + lineChart = findViewById(R.id.chartPriceView); + barChart = findViewById(R.id.chartVolumeView); drawTransactionList(); @@ -129,6 +130,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { createCharts(DAY, 1); + setupActionBar(); + + BottomNavigationView navigation = findViewById(R.id.navigation_details); + navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + + hasBeenModified = false; + } + + private void setupActionBar() + { setTitle(" " + currency.getName() + " | " + currency.getBalance()); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); @@ -145,10 +156,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { getSupportActionBar().setIcon(new BitmapDrawable(Bitmap.createScaledBitmap(result, 120, 120, false))); - BottomNavigationView navigation = findViewById(R.id.navigation_details); - navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - - hasBeenModified = false; } private void initializeButtons() @@ -185,7 +192,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - chartEvent((Button) v); + updateCharts((Button) v); } private float convertDpToPx(float dp) @@ -193,7 +200,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return dp * this.getResources().getDisplayMetrics().density; } - private void chartEvent(Button button) + private void updateCharts(Button button) { findViewById(R.id.chartPriceView).setVisibility(View.GONE); findViewById(R.id.chartVolumeView).setVisibility(View.GONE); @@ -344,8 +351,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void drawVolumeChart() { - final BarChart barChart = findViewById(R.id.chartVolumeView); + initializeBarChart(barChart); + barChart.setData(generateVolumeChartSet()); + barChart.invalidate(); + + findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); + } + + private void initializeBarChart(BarChart barChart) + { barChart.setDrawGridBackground(false); barChart.setDrawBorders(false); barChart.setDrawMarkers(true); @@ -360,18 +375,42 @@ public class CurrencyDetailsActivity extends AppCompatActivity { barChart.getXAxis().setEnabled(false); barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setFitBars(true); - - barChart.setData(generateVolumeChartSet()); - barChart.invalidate(); - - findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); } private void drawPriceChart() { - final LineChart lineChart = findViewById(R.id.chartPriceView); - final BarChart barChart = findViewById(R.id.chartVolumeView); + initializeLineChart(lineChart); + lineChart.setData(generatePriceChartSet()); + lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); + + lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { + @Override + public void onValueSelected(Entry e, Highlight h) { + valueSelectedEvent(e); + } + + @Override + public void onNothingSelected() { + + } + }); + + lineChart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return toucheEvent(motionEvent); + } + }); + + updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + + findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); + findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + } + + private void initializeLineChart(LineChart lineChart) + { lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); lineChart.setDrawMarkers(true); @@ -385,61 +424,57 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.getLegend().setEnabled(false); lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); + } - lineChart.setData(generatePriceChartSet()); - lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); + private void valueSelectedEvent(Entry e) + { + //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); + int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); + String date = null; + barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { - @Override - public void onValueSelected(Entry e, Highlight h) { - //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); - int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); - String date = null; - barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); + if(dataChartList.size() > 200) + { + date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); + } + else + { + date = getDate(dataChartList.get(index).getTimestamp() * 1000); + } - if(dataChartList.size() > 200) - { - date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); - } - else - { - date = getDate(dataChartList.get(index).getTimestamp() * 1000); - } + displayDataIndicators(); - ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); - ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); - ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); - } + ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); + ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); + ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); - @Override - public void onNothingSelected() { + } - } - }); + private boolean toucheEvent(MotionEvent motionEvent) + { + if(motionEvent.getAction() == MotionEvent.ACTION_UP) + { + lineChart.highlightValue(null); + updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + barChart.highlightValues(null); + hideDataIndicators(); + } - lineChart.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if(motionEvent.getAction() == MotionEvent.ACTION_UP) - { - lineChart.highlightValue(null); - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); - barChart.highlightValues(null); - findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); - } - return false; - } - }); + return false; + } - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + private void displayDataIndicators() + { + findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); + } - findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); - findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + private void hideDataIndicators() + { + findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); } private String getDate(long timeStamp){ @@ -514,7 +549,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); - //dataSet.setFillDrawable(fillDrawable); return new LineData(dataSet); } @@ -582,49 +616,53 @@ public class CurrencyDetailsActivity extends AppCompatActivity { amountTxtView.setText(transactionList.get(i).getAmount() + ""); - SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); - - //set show mode. - swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); - - //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) - swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); - - swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { - @Override - public void onClose(SwipeLayout layout) { - //when the SurfaceView totally cover the BottomView. - } - - @Override - public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { - //you are swiping. - } - - @Override - public void onStartOpen(SwipeLayout layout) { - - } - - @Override - public void onOpen(SwipeLayout layout) { - //when the BottomView totally show. - } - - @Override - public void onStartClose(SwipeLayout layout) { - - } - - @Override - public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { - //when user's hand released. - } - }); + setupSwipeView(view); transactionLayout.addView(view); } + } + private void setupSwipeView(View view) + { + SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); + + //set show mode. + swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); + + //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) + swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); + + swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onClose(SwipeLayout layout) { + //when the SurfaceView totally cover the BottomView. + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + //you are swiping. + } + + @Override + public void onStartOpen(SwipeLayout layout) { + + } + + @Override + public void onOpen(SwipeLayout layout) { + //when the BottomView totally show. + } + + @Override + public void onStartClose(SwipeLayout layout) { + + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + //when user's hand released. + } + }); } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java index 364de08..17d2753 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java @@ -46,6 +46,11 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear setupList(); + setupSearchView(); + } + + private void setupSearchView() + { SearchView searchView = findViewById(R.id.search_bar); searchView.setIconifiedByDefault(false); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index fa11d1b..3274f46 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -6,8 +6,6 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; -import android.graphics.Outline; -import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -23,11 +21,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; import android.support.v7.widget.Toolbar; import android.text.SpannableString; -import android.text.style.ForegroundColorSpan; -import android.text.style.RelativeSizeSpan; -import android.text.style.StyleSpan; import android.util.Log; -import android.view.DragEvent; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -35,22 +29,17 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewOutlineProvider; -import android.view.Window; -import android.view.WindowManager; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ViewFlipper; -import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.PercentFormatter; -import com.github.mikephil.charting.utils.ColorTemplate; import com.luseen.spacenavigation.SpaceItem; import com.luseen.spacenavigation.SpaceNavigationView; import com.luseen.spacenavigation.SpaceOnClickListener; @@ -61,8 +50,6 @@ import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; import com.nauk.coinfolio.R; -import org.w3c.dom.Text; - import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -74,7 +61,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Random; //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart @@ -149,7 +135,7 @@ public class HomeActivity extends AppCompatActivity { setContentView(R.layout.activity_currency_summary); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); - generateSplash(); + generateSplashScreen(); //Objects initialization preferencesManager = new PreferencesManager(this); @@ -195,12 +181,6 @@ public class HomeActivity extends AppCompatActivity { toolbarSubtitle.setText("US$0.00"); - /*BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation_home); - navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - navigation.setSelectedItemId(R.id.navigation_view_list); - navigation.setFitsSystemWindows(true); - navigation.setItemBackgroundResource(R.color.colorAccent);*/ - //Events setup detailsButton.setOnClickListener(new View.OnClickListener() { @Override @@ -304,59 +284,66 @@ public class HomeActivity extends AppCompatActivity { spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() { @Override public void onCentreButtonClick() { - //Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show(); - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); - SpaceNavigationView nav = findViewById(R.id.space); - - nav.changeCurrentItem(-1); - - findViewById(R.id.toolbar_layout).setFocusable(true); - ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); - findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true); - - findViewById(R.id.app_bar).setEnabled(true); - findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(true); - findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(true); - - findViewById(R.id.switch_button).setVisibility(View.VISIBLE); - - viewFlipper.setDisplayedChild(1); + spaceNavigationCentreButtonEvent(); } @Override public void onItemClick(int itemIndex, String itemName) { - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - ((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); - - //0 : Watchlist - //1 : Market cap - findViewById(R.id.toolbar_layout).setFocusable(false); - ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); - findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); - - findViewById(R.id.app_bar).setEnabled(false); - findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(false); - findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(false); - - findViewById(R.id.switch_button).setVisibility(View.GONE); - - - - viewFlipper.setDisplayedChild(itemIndex * 2); - - if(itemIndex == 1) - { - ((PieChart) findViewById(R.id.marketCapPieChart)).animateX(1000); - } } @Override public void onItemReselected(int itemIndex, String itemName) { - //Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show(); + spaceNavigationItemEvent(itemIndex); } }); } + private void spaceNavigationCentreButtonEvent() + { + //Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show(); + ((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); + SpaceNavigationView nav = findViewById(R.id.space); + + nav.changeCurrentItem(-1); + + findViewById(R.id.toolbar_layout).setFocusable(true); + ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); + findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true); + + findViewById(R.id.app_bar).setEnabled(true); + findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(true); + findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(true); + + findViewById(R.id.switch_button).setVisibility(View.VISIBLE); + + viewFlipper.setDisplayedChild(1); + } + + private void spaceNavigationItemEvent(int itemIndex) + { + ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); + ((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); + + //0 : Watchlist + //1 : Market cap + findViewById(R.id.toolbar_layout).setFocusable(false); + ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); + findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); + + findViewById(R.id.app_bar).setEnabled(false); + findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(false); + findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(false); + + findViewById(R.id.switch_button).setVisibility(View.GONE); + + viewFlipper.setDisplayedChild(itemIndex * 2); + + if(itemIndex == 1) + { + ((PieChart) findViewById(R.id.marketCapPieChart)).animateX(1000); + } + } + @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -379,13 +366,24 @@ public class HomeActivity extends AppCompatActivity { protected void onResume() { super.onResume(); + //addTestWatchlistCardview(); + Intent intent = getIntent(); + updateAll(intent.getBooleanExtra("update", false)); + + ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + } + + private void addTestWatchlistCardview() + { View view = LayoutInflater.from(this).inflate(R.layout.cardview_watchlist, null); + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%"); ((TextView) view.findViewById(R.id.currencyFluctuationTextView)).setText("$3"); ((TextView) view.findViewById(R.id.currencyNameTextView)).setText("TanguyCoin"); ((TextView) view.findViewById(R.id.currencySymbolTextView)).setText("TGC"); ((TextView) view.findViewById(R.id.currencyValueTextView)).setText("$100"); + view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); view.setOnClickListener(new View.OnClickListener() { @Override @@ -394,14 +392,7 @@ public class HomeActivity extends AppCompatActivity { } }); - //((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); - - Intent intent = getIntent(); - - Log.d("coinfolio", "Updated ? " + intent.getBooleanExtra("update", false)); - - updateAll(intent.getBooleanExtra("update", false)); - ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + ((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); } @Override @@ -455,7 +446,6 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - //currencyLayout.addView(layoutGenerator.getInfoLayout(currency)); currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed)); } } @@ -574,13 +564,10 @@ public class HomeActivity extends AppCompatActivity { { marketCapCounter = 0; - Log.d("coinfolio", "Start update market cap"); - marketCapManager.updateTopCurrencies(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { - Log.d("coinfolio", "Top updated"); countCompletedMarketCapRequest(); } }); @@ -588,7 +575,6 @@ public class HomeActivity extends AppCompatActivity { marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { - Log.d("coinfolio", "Marketcap updated"); countCompletedMarketCapRequest(); } }); @@ -610,8 +596,6 @@ public class HomeActivity extends AppCompatActivity { ArrayList colors = new ArrayList<>(); - PieChart pieChart = findViewById(R.id.marketCapPieChart); - float otherCurrenciesDominance = 0; for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); ) @@ -632,38 +616,47 @@ public class HomeActivity extends AppCompatActivity { PieData data = new PieData(set); data.setValueTextSize(10); data.setValueFormatter(new PercentFormatter()); - pieChart.setData(data); - pieChart.setDrawSlicesUnderHole(false); - pieChart.setUsePercentValues(true); - pieChart.setTouchEnabled(true); - pieChart.setEntryLabelColor(Color.parseColor("#FF000000")); - - pieChart.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getAction()) - { - case MotionEvent.ACTION_DOWN: - refreshLayout.setEnabled(false); - break; - case MotionEvent.ACTION_MOVE: - break; - default: - refreshLayout.setEnabled(true); - break; - } - return false; - } - }); - - pieChart.getDescription().setEnabled(false); - pieChart.getLegend().setEnabled(false); - pieChart.setCenterText(generateCenterSpannableText()); - pieChart.invalidate(); // refresh + setupPieChart(data); } } + private void setupPieChart(PieData data) + { + PieChart pieChart = findViewById(R.id.marketCapPieChart); + + pieChart.setData(data); + pieChart.setDrawSlicesUnderHole(false); + pieChart.setUsePercentValues(true); + pieChart.setTouchEnabled(true); + + pieChart.setEntryLabelColor(Color.parseColor("#FF000000")); + + pieChart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) + { + case MotionEvent.ACTION_DOWN: + refreshLayout.setEnabled(false); + break; + case MotionEvent.ACTION_MOVE: + break; + default: + refreshLayout.setEnabled(true); + break; + } + return false; + } + }); + + pieChart.getDescription().setEnabled(false); + pieChart.getLegend().setEnabled(false); + pieChart.setCenterText(generateCenterSpannableText()); + pieChart.invalidate(); // refresh + + } + private void setupTextViewMarketCap() { DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK); @@ -679,8 +672,8 @@ public class HomeActivity extends AppCompatActivity { private SpannableString generateCenterSpannableText() { - SpannableString s = new SpannableString("Market Capitalization Dominance"); - return s; + SpannableString spannableString = new SpannableString("Market Capitalization Dominance"); + return spannableString; } private void countCoins(boolean isCoin, boolean isDetails) @@ -706,8 +699,6 @@ public class HomeActivity extends AppCompatActivity { { if(balanceManager.getTotalBalance().size() == 0) { - Log.d("coinfolio", "Empty"); - countIcons(); } } @@ -732,7 +723,7 @@ public class HomeActivity extends AppCompatActivity { } } - private void generateSplash() + private void generateSplashScreen() { LinearLayout loadingLayout = new LinearLayout(this); @@ -825,49 +816,40 @@ public class HomeActivity extends AppCompatActivity { super.onProgressUpdate(values); } - @Override - protected Void doInBackground(Void... params) + private void updateChartColor(Currency currency) { - final List cardList = new ArrayList<>(); - - Looper.prepare(); - - balanceManager.sortCoins(); - - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + if(currency.getIcon() != null) { - final Currency localCurrency = balanceManager.getTotalBalance().get(i); + Palette.Builder builder = Palette.from(currency.getIcon()); - if(localCurrency.getIcon() != null) - { - Palette.Builder builder = Palette.from(localCurrency.getIcon()); + currency.setChartColor(builder.generate().getDominantColor(0)); + } + else + { + currency.setChartColor(12369084); + } + } - localCurrency.setChartColor(builder.generate().getDominantColor(0)); + private void loadCurrency(Currency currency, List cardList) + { + if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) + { + currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); + currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); + totalValue += currency.getValue() * currency.getBalance(); + totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100); - } - else - { - localCurrency.setChartColor(12369084); - } - - if(!localCurrency.getSymbol().equals("USD") && (localCurrency.getBalance() * localCurrency.getValue()) > 0.001) - { - localCurrency.setName(balanceManager.getCurrencyName(localCurrency.getSymbol())); - localCurrency.setId(balanceManager.getCurrencyId(localCurrency.getSymbol())); - totalValue += localCurrency.getValue() * localCurrency.getBalance(); - totalFluctuation += (localCurrency.getValue() * localCurrency.getBalance()) * (localCurrency.getDayFluctuationPercentage() / 100); - - cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); - } - - if(!localCurrency.getSymbol().equals("USD") && localCurrency.getHistoryMinutes() == null) - { - cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); - } - - balanceManager.getTotalBalance().set(i, localCurrency); + cardList.add(layoutGenerator.getInfoLayout(currency, true)); } + if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null) + { + cardList.add(layoutGenerator.getInfoLayout(currency, true)); + } + } + + private void refreshCurrencyList(final List cardList) + { runOnUiThread(new Runnable() { @Override public void run() { @@ -882,9 +864,10 @@ public class HomeActivity extends AppCompatActivity { adaptView(); } }); + } - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); - + private void updateFluctuation() + { if(totalFluctuation > 0) { runOnUiThread(new Runnable() { @@ -903,7 +886,10 @@ public class HomeActivity extends AppCompatActivity { } }); } + } + private void updateTitle() + { runOnUiThread(new Runnable() { @Override public void run() { @@ -918,6 +904,35 @@ public class HomeActivity extends AppCompatActivity { } } }); + } + + @Override + protected Void doInBackground(Void... params) + { + final List cardList = new ArrayList<>(); + + Looper.prepare(); + + balanceManager.sortCoins(); + + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + { + final Currency localCurrency = balanceManager.getTotalBalance().get(i); + + updateChartColor(localCurrency); + + loadCurrency(localCurrency, cardList); + + balanceManager.getTotalBalance().set(i, localCurrency); + } + + refreshCurrencyList(cardList); + + toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); + + updateFluctuation(); + + updateTitle(); return null; } @@ -1011,17 +1026,6 @@ public class HomeActivity extends AppCompatActivity { updateMarketCap(); - /*marketCapManager.updateTopCurrencies(new BalanceManager.VolleyCallBack() { - @Override - public void onSuccess() { - - } - - @Override - public void onError(String error) { - - }});*/ - return null; } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index f30af5f..a6ffcc1 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -49,9 +49,7 @@ public class RecordTransactionActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); validateButton = findViewById(R.id.validateButton); - amountTxtView = findViewById(R.id.currencyAmount); - purchasedDate = findViewById(R.id.purchaseDate); purchasedDate.setText(sdf.format(calendar.getTime())); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java index 40e91e8..8caff1b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -280,7 +280,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { if(preferences.getBoolean("enable_fingerprint", false)) { - newFragment.setCancelable(false); newFragment.show(getFragmentManager(), "dialog"); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java index be4cf06..43ecafb 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -95,7 +95,6 @@ public class BalanceManager { while(index < 11) { - //currenciesDetails.add(index, coinInfosHashmap.keySet().iterator().next()); index++; Log.d("coinfolio", "For " + index + " : " + coinIterator.next()); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java index 1f96930..2ca5f20 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java @@ -9,13 +9,13 @@ import android.os.Parcelable; public class CurrencyDataChart implements Parcelable { - long timestamp; - double close; - double high; - double low; - double open; - double volumeFrom; - double volumeTo; + private long timestamp; + private double close; + private double high; + private double low; + private double open; + private double volumeFrom; + private double volumeTo; public CurrencyDataChart(long timestamp, double close, double high, double low, double open, double volumeFrom, double volumeTo) { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java index 95a3aee..2ffb89d 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -44,20 +44,7 @@ public class CurrencyDataRetriever { private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { - String requestUrl = null; - - switch (timeUnit) - { - case MINUTES: - requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440"; - break; - case HOURS: - requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744"; - break; - case DAYS: - requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365"; - break; - } + String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, new Response.Listener() { @@ -76,6 +63,26 @@ public class CurrencyDataRetriever { requestQueue.add(stringRequest); } + private String getRequestUrl(int timeUnit, String symbolCurrencyFrom, String symbolCyrrencyTo) + { + String requestUrl = null; + + switch (timeUnit) + { + case MINUTES: + requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440"; + break; + case HOURS: + requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744"; + break; + case DAYS: + requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365"; + break; + } + + return requestUrl; + } + private List processHistoryResult(String response) { List dataChart = new ArrayList<>(); @@ -99,15 +106,7 @@ public class CurrencyDataRetriever { try { JSONObject jsonObject = new JSONObject(tab[i]); - long timestamp = Long.parseLong(jsonObject.getString("time")); - double close = Double.parseDouble(jsonObject.getString("close")); - double high = Double.parseDouble(jsonObject.getString("high")); - double low = Double.parseDouble(jsonObject.getString("low")); - double open = Double.parseDouble(jsonObject.getString("open")); - double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom")); - double volumeTo = Double.parseDouble(jsonObject.getString("volumeto")); - - dataChart.add(new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo)); + dataChart.add(parseJSON(jsonObject)); } catch (JSONException e) { Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i); @@ -122,6 +121,19 @@ public class CurrencyDataRetriever { return dataChart; } + private CurrencyDataChart parseJSON(JSONObject jsonObject) throws JSONException { + + long timestamp = Long.parseLong(jsonObject.getString("time")); + double close = Double.parseDouble(jsonObject.getString("close")); + double high = Double.parseDouble(jsonObject.getString("high")); + double low = Double.parseDouble(jsonObject.getString("low")); + double open = Double.parseDouble(jsonObject.getString("open")); + double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom")); + double volumeTo = Double.parseDouble(jsonObject.getString("volumeto")); + + return new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo); + } + void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) { if(symbolCurrencyFrom.equals("USD")) diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 82e566e..01a1b4f 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -110,19 +110,16 @@ public class DatabaseManager extends SQLiteOpenHelper{ return currencyList; } - //public HashMap getCurrencyTransactions(String symbol) public List getCurrencyTransactions(String symbol) { String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor resultatList = db.rawQuery(searchQuerry, null); - //HashMap transactionList = new HashMap<>(); List transactionList = new ArrayList<>(); while(resultatList.moveToNext()) { - //transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4))); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index 25544e5..07d9d15 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -22,8 +22,6 @@ public class BinanceManager { private List balance; - public BinanceManager(){} - public BinanceManager(String publicKey, String privateKey) { this.publicKey = publicKey; @@ -32,7 +30,6 @@ public class BinanceManager { public void updateBalance(BinanceCallBack callBack) { - Map accountBalanceCache; BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); BinanceApiRestClient client = factory.newRestClient(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java index 43c7a91..49afd1b 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java @@ -36,12 +36,6 @@ public class HitBtcManager { private List balance; private android.content.Context context; - public HitBtcManager(android.content.Context context) - { - this.context = context; - requestQueue = Volley.newRequestQueue(context); - } - public HitBtcManager(android.content.Context context, String publicKey, String privateKey) { this.context = context; @@ -53,27 +47,9 @@ public class HitBtcManager { public void updateBalance(final HitBtcCallBack callBack) { - JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl, - new Response.Listener() { - @Override - public void onResponse(JSONArray response) { - if (response.length() > 0) { - parseBalance(response); - } else { - //No balance - } - - callBack.onSuccess(); - } - }, - new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(context.getResources().getString(R.string.debug), "API Error : " + error); - callBack.onError(error.toString()); - } - } - ) { + JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl + , getResponseListener(callBack), getErrorResponseListener(callBack)) + { @Override public Map getHeaders() throws AuthFailureError { Map headers = new HashMap<>(); @@ -89,6 +65,31 @@ public class HitBtcManager { requestQueue.add(arrayRequest); } + private Response.Listener getResponseListener(final HitBtcCallBack callBack) + { + return new Response.Listener() { + @Override + public void onResponse(JSONArray response) { + if (response.length() > 0) { + parseBalance(response); + } + + callBack.onSuccess(); + } + }; + } + + private Response.ErrorListener getErrorResponseListener(final HitBtcCallBack callBack) + { + return new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.e(context.getResources().getString(R.string.debug), "API Error : " + error); + callBack.onError(error.toString()); + } + }; + } + private void parseBalance(JSONArray response) { balance = new ArrayList<>(); diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java index 86ab29e..71c82e9 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java @@ -32,8 +32,6 @@ public class FingerprintDialogFragment extends DialogFragment{ View view = inflater.inflate(R.layout.fragment_fingerprint_scanner, container); - //getDialog().getWindow().setLayout(getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_width), getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_height)); - view.findViewById(R.id.cancelButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java index bdbc661..0eae113 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java @@ -37,7 +37,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { - //Toast.makeText(context, "Authentification error\n" + errString, Toast.LENGTH_LONG).show(); if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint("Error"); @@ -56,7 +55,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationFailed() { - //Toast.makeText(context, "Authentification failed", Toast.LENGTH_LONG).show(); if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint("Wrong fingerprint"); @@ -75,8 +73,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationHelp(int helpMsgIf, CharSequence helpString) { - //Toast.makeText(context, "Authentification help\n" + helpString, Toast.LENGTH_LONG).show(); - if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint(helpString.toString()); @@ -95,9 +91,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { - //Toast.makeText(context, "Success !", Toast.LENGTH_LONG).show(); - //dialogFragment.dismiss(); - dialogFragment.correctFingerprint(); new Handler().postDelayed(new Runnable() { @Override diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java index 5691fd8..166ede8 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java @@ -31,20 +31,25 @@ public class CurrencyAdapter extends ArrayAdapter { } @Override - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, ViewGroup parent) + { Currency currency = getItem(position); + if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_currency_row, parent, false); } + TextView currencyName = convertView.findViewById(R.id.currencyName); TextView currencySymbol = convertView.findViewById(R.id.currencySymbol); + if (currencyName != null) currencyName.setText(currency.getName()); + if(currencySymbol != null) { currencySymbol.setText(currency.getSymbol()); } - // Now assign alternate color for rows + if (position % 2 == 0) convertView.setBackgroundColor(context.getResources().getColor(R.color.listBackground2)); else @@ -74,7 +79,7 @@ public class CurrencyAdapter extends ArrayAdapter { int found = 0; String temp = constraint.toString().toLowerCase(); - while(i < tempCurrency.size() && found < 25) + while(i < tempCurrency.size() && found < 50) { Currency currency = tempCurrency.get(i); if (currency.getName().toLowerCase().startsWith(temp) @@ -85,14 +90,6 @@ public class CurrencyAdapter extends ArrayAdapter { i++; } - - /*for (Currency currency : tempCurrency) { - if (currency.getName().toLowerCase().startsWith(temp) - || currency.getSymbol().toLowerCase().startsWith(temp)) { - suggestions.add(currency); - } - }*/ - FilterResults filterResults = new FilterResults(); filterResults.values = suggestions; filterResults.count = suggestions.size(); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index ac2cb2a..a1b468e 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -64,6 +64,64 @@ public class HomeLayoutGenerator { } }); + updateCardViewInfos(view, currency); + + view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + + setupLineChart(view, currency); + + if(isExtended) + { + extendView(currency, view); + } + else + { + collapseView(view); + } + + updateColor(view, currency); + + return view; + } + + 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)); + + 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) + { ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) view.findViewById(R.id.currencyNameTextView)) @@ -83,57 +141,6 @@ public class HomeLayoutGenerator { .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); ((ImageView) view.findViewById(R.id.detailsArrow)) .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - - view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - }); - - if(currency.getHistoryMinutes() != null) - { - 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)); - - 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); - } - }); - } - - if(isExtended) - { - extendView(currency, view); - } - else - { - collapseView(view); - } - - updateColor(view, currency); - - return view; } private void collapseView(View view) @@ -241,7 +248,9 @@ public class HomeLayoutGenerator { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); + transColor = Color.argb(alpha, r, g, b); + return transColor ; }