From 3cb139390cb4280e53a628025b24a8e3c1a1e7dd Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 12 Feb 2018 19:43:17 +0100 Subject: [PATCH] Navbar for summary activity --- app/build.gradle | 1 + .../coinfolio/Activities/HomeActivity.java | 114 ++++++++++-------- .../DataManagers/CurrencyData/Currency.java | 3 +- .../CurrencyData/CurrencyDataRetriever.java | 8 +- .../LayoutManagers/HomeLayoutGenerator.java | 13 +- ...k_24dp.xml => ic_view_list_white_24dp.xml} | 2 +- .../res/layout/activity_currency_summary.xml | 17 ++- .../res/layout/content_currency_summary.xml | 9 -- app/src/main/res/menu/navigation_home.xml | 2 +- app/src/main/res/values/strings.xml | 1 - 10 files changed, 100 insertions(+), 70 deletions(-) rename app/src/main/res/drawable/{ic_view_list_black_24dp.xml => ic_view_list_white_24dp.xml} (90%) diff --git a/app/build.gradle b/app/build.gradle index f4c6c4c..71f323c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation 'com.android.support:palette-v7:26.1.0' implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.daimajia.swipelayout:library:1.2.0@aar' + implementation 'com.github.armcha:SpaceNavigationView:1.6.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 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 2372e50..f656174 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -16,7 +16,6 @@ import android.support.design.widget.Snackbar; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; -import android.support.v7.widget.CardView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Gravity; @@ -31,6 +30,9 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import com.luseen.spacenavigation.SpaceItem; +import com.luseen.spacenavigation.SpaceNavigationView; +import com.luseen.spacenavigation.SpaceOnClickListener; import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; @@ -81,14 +83,14 @@ public class HomeActivity extends AppCompatActivity { switch (item.getItemId()) { case R.id.navigation_something: - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); + //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); return true; case R.id.navigation_view_list: - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); + //((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); //viewFlipper.setDisplayedChild(1); return true; case R.id.navigation_market_cap: - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); + //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); //viewFlipper.setDisplayedChild(2); return true; } @@ -142,7 +144,7 @@ public class HomeActivity extends AppCompatActivity { toolbarSubtitle = findViewById(R.id.toolbarSubtitle); currencyLayout = findViewById(R.id.currencyListLayout); - ImageButton addCurrencyButton = findViewById(R.id.addCurrencyButton); + ImageButton addCurrencyButton = findViewById(R.id.floatingAddButton); ImageButton detailsButton = findViewById(R.id.switch_button); ImageButton settingsButton = findViewById(R.id.settings_button); @@ -205,6 +207,49 @@ public class HomeActivity extends AppCompatActivity { updateViewButtonIcon(); lastTimestamp = 0; + + setupNavBar(savedInstanceState); + } + + private void setupNavBar(Bundle savedInstanceState) + { + final SpaceNavigationView spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space); + spaceNavigationView.initWithSaveInstanceState(savedInstanceState); + spaceNavigationView.addSpaceItem(new SpaceItem("Charts", R.drawable.ic_show_chart_black_24dp)); + spaceNavigationView.addSpaceItem(new SpaceItem("Market Cap.", R.drawable.ic_pie_chart_black_24dp)); + spaceNavigationView.setSpaceBackgroundColor(getResources().getColor(R.color.colorPrimary)); + //spaceNavigationView.setCentreButtonIcon(R.drawable.ic_add_white_24dp); + spaceNavigationView.setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); + spaceNavigationView.setCentreButtonColor(getResources().getColor(R.color.colorAccent)); + spaceNavigationView.setCentreButtonIconColorFilterEnabled(false); + + 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); + } + + @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); + } + + @Override + public void onItemReselected(int itemIndex, String itemName) { + //Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + ((SpaceNavigationView) findViewById(R.id.space)).onSaveInstanceState(outState); } private void showErrorSnackbar() @@ -226,6 +271,7 @@ public class HomeActivity extends AppCompatActivity { Intent intent = getIntent(); updateAll(intent.getBooleanExtra("update", false)); + ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); } @Override @@ -342,53 +388,34 @@ public class HomeActivity extends AppCompatActivity { private void countIcons() { - iconCounter++; + int offset = 0; - Log.d("coinfolio", "Icon ++ " + iconCounter); + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + { + if(balanceManager.getTotalBalance().get(i).getSymbol().equals("USD")) + { + offset++; + } + } + + iconCounter++; if(balanceManager.getTotalBalance() != null) { - if(iconCounter == balanceManager.getTotalBalance().size()) + if(iconCounter == balanceManager.getTotalBalance().size() - offset) { - Log.d("coinfolio", "1"); - if(coinCounter == balanceManager.getTotalBalance().size()) + if(balanceManager.getTotalBalance().size() == 0) + { + updateNoBalance(); + } + else { Log.d("coinfolio", "Loading heavy"); UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator(); uiHeavyLoadCalculator.execute(); } - - if(balanceManager.getTotalBalance().size() == 0) - { - updateNoBalance(); - } } - /*else - { - if(balanceManager.getTotalBalance().size() == 0) - { - currencyLayout.removeAllViews(); - - refreshLayout.setRefreshing(false); - - if(loadingDialog.isShowing()) - { - loadingDialog.dismiss(); - } - - runOnUiThread(new Runnable() { - @Override - public void run() { - toolbarLayout.setTitle("US$0.00"); - - toolbarSubtitle.setText("US$0.00"); - - toolbarSubtitle.setTextColor(-1275068417); - } - }); - } - }*/ } } @@ -417,8 +444,6 @@ public class HomeActivity extends AppCompatActivity { private void countCoins(boolean isCoin, boolean isDetails) { - Log.d("coinfolio", "Coin++ " + coinCounter + " " + balanceManager.getTotalBalance().size()); - if(isCoin) { coinCounter++; @@ -433,16 +458,12 @@ public class HomeActivity extends AppCompatActivity { { if(coinCounter == balanceManager.getTotalBalance().size()) { - Log.d("coinfolio", "Going through"); - for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { final Currency localCurrency = balanceManager.getTotalBalance().get(i); if(balanceManager.getIconUrl(localCurrency.getSymbol()) != null) { - Log.d("coinfolio", "Downloading bitmap"); - getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new IconCallBack() { @Override public void onSuccess(Bitmap bitmapIcon) { @@ -656,7 +677,6 @@ public class HomeActivity extends AppCompatActivity { if(balanceManager.getTotalBalance().size() > 0) { - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) { balance.get(i).updateHistoryMinutes(getApplicationContext(), new Currency.CurrencyCallBack() { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java index 209e55a..df450c1 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java @@ -67,15 +67,16 @@ public class Currency implements Parcelable { public void updateHistoryMinutes(android.content.Context context, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); + dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() { @Override public void onSuccess(List dataChart) { setHistoryMinutes(dataChart); - updateDayFluctuation(); if(dataChart != null) { setValue(dataChart.get(dataChart.size() - 1).getClose()); + updateDayFluctuation(); } else { 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 0a58524..feeab70 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 @@ -42,7 +42,7 @@ public class CurrencyDataRetriever { requestQueue = Volley.newRequestQueue(context); } - private void updateHistory(String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) + private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { String requestUrl = null; @@ -122,7 +122,11 @@ public class CurrencyDataRetriever { void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) { - if(!symbolCurrencyFrom.equals("USD")) + if(symbolCurrencyFrom.equals("USD")) + { + callBack.onSuccess(null); + } + else { updateHistory(symbolCurrencyFrom, "USD", callBack, timeUnit); } 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 d941804..614b6cc 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -60,10 +60,6 @@ public class HomeLayoutGenerator { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - /*view.animate(); - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent);*/ if(view.findViewById(R.id.LineChartView).getVisibility() == View.VISIBLE || view.findViewById(R.id.errorTextView).getVisibility() == View.VISIBLE) { collapseView(view); @@ -95,6 +91,15 @@ public class HomeLayoutGenerator { ((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) { List borders = getAxisBorders(currency); diff --git a/app/src/main/res/drawable/ic_view_list_black_24dp.xml b/app/src/main/res/drawable/ic_view_list_white_24dp.xml similarity index 90% rename from app/src/main/res/drawable/ic_view_list_black_24dp.xml rename to app/src/main/res/drawable/ic_view_list_white_24dp.xml index 78118c1..222dc3b 100644 --- a/app/src/main/res/drawable/ic_view_list_black_24dp.xml +++ b/app/src/main/res/drawable/ic_view_list_white_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index 27a8316..4afe4f3 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -98,20 +98,29 @@ app:layout_constraintRight_toRightOf="parent" app:menu="@menu/navigation_home" android:layout_alignParentBottom="true" - android:layout_gravity="bottom" /> + android:layout_gravity="bottom" + android:visibility="gone"/> + + + android:focusable="true" + android:layout_margin="8dp" + android:visibility="visible"/> \ No newline at end of file diff --git a/app/src/main/res/layout/content_currency_summary.xml b/app/src/main/res/layout/content_currency_summary.xml index 257608e..ce95d76 100644 --- a/app/src/main/res/layout/content_currency_summary.xml +++ b/app/src/main/res/layout/content_currency_summary.xml @@ -28,15 +28,6 @@ android:layout_height="wrap_content" android:orientation="vertical"/> - - diff --git a/app/src/main/res/menu/navigation_home.xml b/app/src/main/res/menu/navigation_home.xml index b67b8a4..22996d8 100644 --- a/app/src/main/res/menu/navigation_home.xml +++ b/app/src/main/res/menu/navigation_home.xml @@ -8,7 +8,7 @@ (US$%1$s) US$%1$s %1$s%% - MainActivity