Navbar for summary activity

This commit is contained in:
Tanguy Herbron 2018-02-12 19:43:17 +01:00
parent 7bd7d360d6
commit 3cb139390c
10 changed files with 100 additions and 70 deletions

View File

@ -33,6 +33,7 @@ dependencies {
implementation 'com.android.support:palette-v7:26.1.0' implementation 'com.android.support:palette-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar' implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.github.armcha:SpaceNavigationView:1.6.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

View File

@ -16,7 +16,6 @@ import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette; import android.support.v7.graphics.Palette;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@ -31,6 +30,9 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; 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.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator;
@ -81,14 +83,14 @@ public class HomeActivity extends AppCompatActivity {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.navigation_something: case R.id.navigation_something:
((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
return true; return true;
case R.id.navigation_view_list: case R.id.navigation_view_list:
((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); //((FloatingActionButton) findViewById(R.id.floatingAddButton)).show();
//viewFlipper.setDisplayedChild(1); //viewFlipper.setDisplayedChild(1);
return true; return true;
case R.id.navigation_market_cap: case R.id.navigation_market_cap:
((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
//viewFlipper.setDisplayedChild(2); //viewFlipper.setDisplayedChild(2);
return true; return true;
} }
@ -142,7 +144,7 @@ public class HomeActivity extends AppCompatActivity {
toolbarSubtitle = findViewById(R.id.toolbarSubtitle); toolbarSubtitle = findViewById(R.id.toolbarSubtitle);
currencyLayout = findViewById(R.id.currencyListLayout); 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 detailsButton = findViewById(R.id.switch_button);
ImageButton settingsButton = findViewById(R.id.settings_button); ImageButton settingsButton = findViewById(R.id.settings_button);
@ -205,6 +207,49 @@ public class HomeActivity extends AppCompatActivity {
updateViewButtonIcon(); updateViewButtonIcon();
lastTimestamp = 0; 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() private void showErrorSnackbar()
@ -226,6 +271,7 @@ public class HomeActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
updateAll(intent.getBooleanExtra("update", false)); updateAll(intent.getBooleanExtra("update", false));
((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp);
} }
@Override @Override
@ -342,54 +388,35 @@ public class HomeActivity extends AppCompatActivity {
private void countIcons() 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(balanceManager.getTotalBalance() != null)
{ {
if(iconCounter == balanceManager.getTotalBalance().size()) if(iconCounter == balanceManager.getTotalBalance().size() - offset)
{ {
Log.d("coinfolio", "1"); if(balanceManager.getTotalBalance().size() == 0)
if(coinCounter == balanceManager.getTotalBalance().size()) {
updateNoBalance();
}
else
{ {
Log.d("coinfolio", "Loading heavy"); Log.d("coinfolio", "Loading heavy");
UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator(); UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
uiHeavyLoadCalculator.execute(); 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);
}
});
}
}*/
}
} }
private void updateNoBalance() private void updateNoBalance()
@ -417,8 +444,6 @@ public class HomeActivity extends AppCompatActivity {
private void countCoins(boolean isCoin, boolean isDetails) private void countCoins(boolean isCoin, boolean isDetails)
{ {
Log.d("coinfolio", "Coin++ " + coinCounter + " " + balanceManager.getTotalBalance().size());
if(isCoin) if(isCoin)
{ {
coinCounter++; coinCounter++;
@ -433,16 +458,12 @@ public class HomeActivity extends AppCompatActivity {
{ {
if(coinCounter == balanceManager.getTotalBalance().size()) if(coinCounter == balanceManager.getTotalBalance().size())
{ {
Log.d("coinfolio", "Going through");
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) for (int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{ {
final Currency localCurrency = balanceManager.getTotalBalance().get(i); final Currency localCurrency = balanceManager.getTotalBalance().get(i);
if(balanceManager.getIconUrl(localCurrency.getSymbol()) != null) if(balanceManager.getIconUrl(localCurrency.getSymbol()) != null)
{ {
Log.d("coinfolio", "Downloading bitmap");
getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new IconCallBack() { getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new IconCallBack() {
@Override @Override
public void onSuccess(Bitmap bitmapIcon) { public void onSuccess(Bitmap bitmapIcon) {
@ -656,7 +677,6 @@ public class HomeActivity extends AppCompatActivity {
if(balanceManager.getTotalBalance().size() > 0) if(balanceManager.getTotalBalance().size() > 0)
{ {
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{ {
balance.get(i).updateHistoryMinutes(getApplicationContext(), new Currency.CurrencyCallBack() { balance.get(i).updateHistoryMinutes(getApplicationContext(), new Currency.CurrencyCallBack() {

View File

@ -67,15 +67,16 @@ public class Currency implements Parcelable {
public void updateHistoryMinutes(android.content.Context context, final CurrencyCallBack callBack) public void updateHistoryMinutes(android.content.Context context, final CurrencyCallBack callBack)
{ {
dataRetriver = new CurrencyDataRetriever(context); dataRetriver = new CurrencyDataRetriever(context);
dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() { dataRetriver.updateHistory(symbol, new CurrencyDataRetriever.DataChartCallBack() {
@Override @Override
public void onSuccess(List<CurrencyDataChart> dataChart) { public void onSuccess(List<CurrencyDataChart> dataChart) {
setHistoryMinutes(dataChart); setHistoryMinutes(dataChart);
updateDayFluctuation();
if(dataChart != null) if(dataChart != null)
{ {
setValue(dataChart.get(dataChart.size() - 1).getClose()); setValue(dataChart.get(dataChart.size() - 1).getClose());
updateDayFluctuation();
} }
else else
{ {

View File

@ -42,7 +42,7 @@ public class CurrencyDataRetriever {
requestQueue = Volley.newRequestQueue(context); 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; String requestUrl = null;
@ -122,7 +122,11 @@ public class CurrencyDataRetriever {
void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) 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); updateHistory(symbolCurrencyFrom, "USD", callBack, timeUnit);
} }

View File

@ -60,10 +60,6 @@ public class HomeLayoutGenerator {
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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) if(view.findViewById(R.id.LineChartView).getVisibility() == View.VISIBLE || view.findViewById(R.id.errorTextView).getVisibility() == View.VISIBLE)
{ {
collapseView(view); collapseView(view);
@ -95,6 +91,15 @@ public class HomeLayoutGenerator {
((ImageView) view.findViewById(R.id.detailsArrow)) ((ImageView) view.findViewById(R.id.detailsArrow))
.getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); .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) if(currency.getHistoryMinutes() != null)
{ {
List<Double> borders = getAxisBorders(currency); List<Double> borders = getAxisBorders(currency);

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#FF000000" android:fillColor="#FFFFFFFF"
android:pathData="M4,14h4v-4L4,10v4zM4,19h4v-4L4,15v4zM4,9h4L8,5L4,5v4zM9,14h12v-4L9,10v4zM9,19h12v-4L9,15v4zM9,5v4h12L21,5L9,5z"/> android:pathData="M4,14h4v-4L4,10v4zM4,19h4v-4L4,15v4zM4,9h4L8,5L4,5v4zM9,14h12v-4L9,10v4zM9,19h12v-4L9,15v4zM9,5v4h12L21,5L9,5z"/>
</vector> </vector>

View File

@ -98,20 +98,29 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation_home" app:menu="@menu/navigation_home"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_gravity="bottom" /> android:layout_gravity="bottom"
android:visibility="gone"/>
<com.luseen.spacenavigation.SpaceNavigationView
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/floatingAddButton" android:id="@+id/floatingAddButton"
android:layout_width="64dp" android:layout_width="wrap_content"
android:layout_height="64dp" android:layout_height="wrap_content"
android:elevation="0dp" android:elevation="0dp"
app:borderWidth="0dp" app:borderWidth="0dp"
android:background="@color/cardview_light_background" android:background="@color/cardview_light_background"
android:src="@drawable/ic_add_white_24dp" android:src="@drawable/ic_add_white_24dp"
android:layout_gravity="bottom|center_horizontal" android:layout_gravity="bottom|center_horizontal"
android:clickable="true" android:clickable="true"
android:focusable="true"/> android:focusable="true"
android:layout_margin="8dp"
android:visibility="visible"/>
</FrameLayout> </FrameLayout>

View File

@ -28,15 +28,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"/> android:orientation="vertical"/>
<ImageButton
android:id="@+id/addCurrencyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
style="@style/Widget.AppCompat.Button"
android:src="@drawable/ic_add_black_24dp"/>
<Space <Space
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="10dp" /> android:layout_height="10dp" />

View File

@ -8,7 +8,7 @@
<item <item
android:id="@+id/navigation_view_list" android:id="@+id/navigation_view_list"
android:icon="@drawable/ic_view_list_black_24dp" android:icon="@drawable/ic_view_list_white_24dp"
android:title="@string/title_home" /> android:title="@string/title_home" />
<item <item

View File

@ -140,6 +140,5 @@
<string name="currencyDollarParenthesisPlaceholder">(US$%1$s)</string> <string name="currencyDollarParenthesisPlaceholder">(US$%1$s)</string>
<string name="currencyDollarPlaceholder">US$%1$s</string> <string name="currencyDollarPlaceholder">US$%1$s</string>
<string name="currencyPercentagePlaceholder">%1$s%%</string> <string name="currencyPercentagePlaceholder">%1$s%%</string>
<string name="title_activity_main">MainActivity</string>
</resources> </resources>