SpaceNavigationView to BottomNavigationView

Switeched from SpaceNavigationView back to BottomNavigationView for the upcoming UI rework
Added transaction adding button at the bottom of the currency list
Reworked a bit of the loading sequence of the currency selection activity, more to come
This commit is contained in:
Tanguy Herbron 2018-04-11 00:55:45 +02:00
parent f1a4a03a5a
commit e9c2baab4c
18 changed files with 247 additions and 191 deletions

View File

@ -32,7 +32,6 @@ dependencies {
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:palette-v7:27.1.0'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.github.armcha:SpaceNavigationView:1.6.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-core:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.8.5'

View File

@ -10,7 +10,6 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.SwitchPreference;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.NavUtils;
@ -180,8 +179,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
}
});
((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false);
setupActionBar();
drawTransactionList();

View File

@ -1,7 +1,9 @@
package com.nauk.coinfolio.Activities;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.Menu;
@ -25,6 +27,7 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
private CurrencyListAdapter adapter;
private ListView listView;
private android.widget.Filter filter;
private Intent comingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -35,18 +38,12 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
setContentView(R.layout.activity_add_currency);
Intent intent = getIntent();
currencySymbols = intent.getStringArrayExtra("currencyListSymbols");
currencyNames = intent.getStringArrayExtra("currencyListNames");
comingIntent = getIntent();
setTitle("Select a coin");
setupAdapter();
setupList();
setupSearchView();
ListLoader listLoader = new ListLoader();
listLoader.execute();
}
private void setupSearchView()
@ -141,4 +138,51 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
{
return false;
}
private class ListLoader extends AsyncTask<Void, Integer, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... params)
{
if(Looper.myLooper() == null)
{
Looper.prepare();
}
currencySymbols = comingIntent.getStringArrayExtra("currencyListSymbols");
currencyNames = comingIntent.getStringArrayExtra("currencyListNames");
setupAdapter();
setupList();
runOnUiThread(new Runnable() {
@Override
public void run() {
setupSearchView();
}
});
return null;
}
@Override
protected void onPostExecute(Void result)
{
findViewById(R.id.coinsPreview).setVisibility(View.VISIBLE);
findViewById(R.id.currencyListProgressBar).setVisibility(View.GONE);
}
}
}

View File

@ -10,9 +10,10 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
@ -27,6 +28,7 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
@ -38,9 +40,6 @@ 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.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.DataManagers.MarketCapManager;
@ -94,9 +93,32 @@ public class HomeActivity extends AppCompatActivity {
private Runnable updateRunnable;
private ViewFlipper viewFlipper;
private HomeLayoutGenerator layoutGenerator;
private BottomNavigationView bottomNavigationView;
private HashMap<String, Integer> dominantCurrenciesColors;
private BottomNavigationView.OnNavigationItemSelectedListener onNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
item.setChecked(true);
switch (item.getItemId())
{
case R.id.navigation_watchlist:
switchSecondaryViews(0);
break;
case R.id.navigation_currencies_list:
switchMainView();
break;
case R.id.navigation_market_cap:
switchSecondaryViews(2);
break;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -107,7 +129,7 @@ public class HomeActivity extends AppCompatActivity {
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
//getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
setContentView(R.layout.activity_currency_summary);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
@ -146,11 +168,14 @@ public class HomeActivity extends AppCompatActivity {
toolbarSubtitle = findViewById(R.id.toolbarSubtitle);
currencyLayout = findViewById(R.id.currencyListLayout);
viewFlipper = findViewById(R.id.viewFlipperSummary);
viewFlipper.setDisplayedChild(1);
bottomNavigationView = findViewById(R.id.navigationSummary);
bottomNavigationView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener);
bottomNavigationView.setSelectedItemId(R.id.navigation_currencies_list);
layoutGenerator = new HomeLayoutGenerator(this);
ImageButton addCurrencyButton = findViewById(R.id.floatingAddButton);
Button addCurrencyButton = findViewById(R.id.buttonAddTransaction);
ImageButton detailsButton = findViewById(R.id.switch_button);
ImageButton settingsButton = findViewById(R.id.settings_button);
@ -223,8 +248,6 @@ public class HomeActivity extends AppCompatActivity {
lastTimestamp = 0;
setupNavBar(savedInstanceState);
setupDominantCurrenciesColors();
}
@ -299,43 +322,8 @@ public class HomeActivity extends AppCompatActivity {
dominantCurrenciesColors.put("ETC", -10448784);
}
private void setupNavBar(Bundle savedInstanceState)
private void switchMainView()
{
final SpaceNavigationView spaceNavigationView = findViewById(R.id.space);
spaceNavigationView.initWithSaveInstanceState(savedInstanceState);
spaceNavigationView.addSpaceItem(new SpaceItem("WatchList", R.drawable.ic_remove_red_eye_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_view_list_white_24dp);
spaceNavigationView.setCentreButtonColor(getResources().getColor(R.color.colorPrimary));
spaceNavigationView.setCentreButtonIconColorFilterEnabled(false);
spaceNavigationView.changeCurrentItem(-1);
spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() {
@Override
public void onCentreButtonClick() {
spaceNavigationCentreButtonEvent();
}
@Override
public void onItemClick(int itemIndex, String itemName) {
spaceNavigationItemEvent(itemIndex);
}
@Override
public void onItemReselected(int itemIndex, String itemName) {
}
});
}
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);
@ -349,13 +337,8 @@ public class HomeActivity extends AppCompatActivity {
viewFlipper.setDisplayedChild(1);
}
private void spaceNavigationItemEvent(int itemIndex)
private void switchSecondaryViews(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);
@ -366,23 +349,12 @@ public class HomeActivity extends AppCompatActivity {
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);
((SpaceNavigationView) findViewById(R.id.space)).onSaveInstanceState(outState);
viewFlipper.setDisplayedChild(itemIndex);
}
private void showErrorSnackbar()
{
Snackbar.make(findViewById(R.id.currencyListLayout), "Error while updating data", Snackbar.LENGTH_LONG)
Snackbar.make(findViewById(R.id.viewFlipperSummary), "Error while updating data", Snackbar.LENGTH_LONG)
.setAction("Update", new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@ -215,7 +215,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);
((SwitchPreference) findPreference("hide_balance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
findPreference("hide_balance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
boolean isChecked = ((SwitchPreference) findPreference("hide_balance")).isChecked();
@ -267,7 +267,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
bindPreferenceSummaryToValue(findPreference("hitbtc_privatekey"));
bindPreferenceSummaryToValue(findPreference("binance_privatekey"));
((SwitchPreference) findPreference("enable_hitbtc")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
findPreference("enable_hitbtc").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
boolean isChecked = ((SwitchPreference) findPreference("enable_hitbtc")).isChecked();
@ -283,7 +283,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
});
((SwitchPreference) findPreference("enable_binance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
findPreference("enable_binance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
boolean isChecked = ((SwitchPreference) findPreference("enable_binance")).isChecked();

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/transparent"/>
<corners android:radius="2dp"/>
<stroke
android:color="@color/separationColor"
android:width="2dp"
android:dashGap="4dp"
android:dashWidth="9dp"/>
</shape>
</item>
</selector>

View File

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

View File

@ -22,7 +22,20 @@
<ListView
android:id="@+id/coinsPreview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/currencyListProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

View File

@ -211,7 +211,7 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
android:background="@color/separationColor"/>
<LinearLayout
android:layout_width="match_parent"
@ -237,7 +237,7 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
android:background="@color/separationColor"/>
<LinearLayout
android:layout_width="match_parent"
@ -263,7 +263,7 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
android:background="@color/separationColor"/>
<LinearLayout
android:layout_width="match_parent"
@ -289,7 +289,7 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
android:background="@color/separationColor"/>
<LinearLayout
android:layout_width="match_parent"
@ -315,7 +315,7 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
android:background="@color/separationColor"/>
<LinearLayout
android:layout_width="match_parent"

View File

@ -1,17 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.nauk.coinfolio.Activities.HomeActivity">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
@ -19,8 +15,7 @@
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@drawable/gradient_background"
android:elevation="10dp">
android:background="@drawable/gradient_background">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
@ -81,29 +76,20 @@
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_currency_summary" />
<include layout="@layout/content_currency_summary"/>
<com.luseen.spacenavigation.SpaceNavigationView
android:id="@+id/space"
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigationSummary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingAddButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="0dp"
app:borderWidth="0dp"
android:backgroundTint="@color/colorPrimary"
android:background="@color/cardview_light_background"
android:src="@drawable/ic_add_white_24dp"
android:layout_gravity="bottom|center_horizontal"
android:clickable="true"
android:focusable="true"
android:layout_margin="8dp"
android:visibility="visible"/>
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation_home"
android:layout_gravity="bottom" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -3,6 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:clickable="true"
android:focusable="true"
android:paddingBottom="4dp">
@ -13,9 +14,9 @@
android:layout_margin="10dp"
android:clickable="false"
android:backgroundTint="@color/cardview_background"
android:elevation="@dimen/cardview_elevation"
app:cardCornerRadius="2dp"
app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintBottom_toBottomOf="parent"
card_view:cardElevation="@dimen/cardview_elevation">
<LinearLayout
android:id="@+id/mainLinear"
@ -169,7 +170,7 @@
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationLine" />
android:background="@color/separationColor" />
</LinearLayout>

View File

@ -124,7 +124,7 @@
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationLine" />
android:background="@color/separationColor" />
</LinearLayout>

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="50dp"
android:layout_marginBottom="56dp"
android:background="@color/summary_background">
<ViewFlipper
@ -16,7 +16,24 @@
<LinearLayout
android:id="@+id/linearLayoutWatchlist"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/buttonAddWatchlist"
android:text="Add to watchlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_dashed_background"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:textColor="@color/separationColor"
style="@style/Widget.AppCompat.Button.Borderless"/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<ProgressBar
android:id="@+id/progressBarWatchlist"
@ -48,6 +65,18 @@
android:layout_height="wrap_content"
android:orientation="vertical" />
<Button
android:id="@+id/buttonAddTransaction"
android:text="Add transaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_dashed_background"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:textColor="@color/separationColor"
style="@style/Widget.AppCompat.Button.Borderless"/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />

View File

@ -47,7 +47,7 @@
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/separationLine"
android:background="@color/separationColor"
/>
</LinearLayout>

View File

@ -9,6 +9,7 @@
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:enabled="false"
android:title="@string/title_infos" />
<item

View File

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

View File

@ -29,7 +29,7 @@
<color name="increase">#FF00E000</color>
<color name="listBackground">#FFEEEEEE</color>
<color name="listBackground2">#FFFFFFFF</color>
<color name="separationLine">#FF999999</color>
<color name="separationColor">#66999999</color>
<color name="buttonColor">#FFFFFFFF</color>
<color name="red">#FFF44336</color>
<color name="green">#FF4CAF50</color>

View File

@ -6,7 +6,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="swirl_ridgeColor">@color/separationLine</item>
<item name="swirl_ridgeColor">@color/separationColor</item>
<item name="swirl_errorColor">@color/decrease</item>
<!--<item name="android:windowTranslucentStatus">false</item>