Reword Actionbar depending on fragment

This commit is contained in:
Tanguy Herbron 2018-04-17 23:20:49 +02:00
parent b3f566bf31
commit eab8ff14bf
9 changed files with 332 additions and 213 deletions

View File

@ -72,7 +72,6 @@ import java.util.Locale;
public class HomeActivity extends AppCompatActivity {
private CollapsingToolbarLayout toolbarLayout;
private BottomNavigationView bottomNavigationView;
private ViewPager viewPager;
@ -115,7 +114,6 @@ public class HomeActivity extends AppCompatActivity {
//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));
viewPager = findViewById(R.id.viewPager);
final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), 3);
@ -125,7 +123,7 @@ public class HomeActivity extends AppCompatActivity {
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
bottomNavigationView.getMenu().getItem(position).setChecked(true);
//bottomNavigationView.getMenu().getItem(position).setChecked(true);
if(position % 2 == 0)
{
@ -147,24 +145,10 @@ public class HomeActivity extends AppCompatActivity {
//Objects initialization
//Layouts setup
toolbarLayout = findViewById(R.id.toolbar_layout);
bottomNavigationView = findViewById(R.id.navigationSummary);
bottomNavigationView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener);
bottomNavigationView.setSelectedItemId(R.id.navigation_currencies_list);
toolbarLayout.setForegroundGravity(Gravity.CENTER);
ImageButton settingsButton = findViewById(R.id.settings_button);
settingsButton.setBackground(this.getResources().getDrawable(R.drawable.ic_settings_black_24dp));
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent settingIntent = new Intent(HomeActivity.this, SettingsActivity.class);
startActivity(settingIntent);
//overridePendingTransition(R.anim.activity_enter, R.anim.activity_exit);
}
});
}
@Override

View File

@ -1,6 +1,7 @@
package com.nauk.coinfolio.Activities.HomeActivityFragments;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
@ -14,6 +15,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageButton;
import android.widget.TextView;
import com.github.mikephil.charting.charts.PieChart;
@ -21,6 +23,7 @@ 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.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.DataManagers.MarketCapManager;
import com.nauk.coinfolio.R;
@ -70,6 +73,16 @@ public class MarketCapitalization extends Fragment {
lastTimestamp = 0;
ImageButton settingsButton = view.findViewById(R.id.settings_button);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent settingIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingIntent);
}
});
updateMarketCap();
return view;
@ -205,13 +218,11 @@ public class MarketCapitalization extends Fragment {
{
case MotionEvent.ACTION_DOWN:
refreshLayout.setEnabled(false);
getActivity().findViewById(R.id.viewPager).setEnabled(false);
break;
case MotionEvent.ACTION_MOVE:
break;
default:
refreshLayout.setEnabled(true);
getActivity().findViewById(R.id.viewPager).setEnabled(true);
break;
}
return false;

View File

@ -27,6 +27,7 @@ import android.widget.TextView;
import com.nauk.coinfolio.Activities.CurrencySelectionActivity;
import com.nauk.coinfolio.Activities.HomeActivity;
import com.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
@ -75,8 +76,7 @@ public class Summary extends Fragment {
balanceManager = new BalanceManager(getActivity());
layoutGenerator = new HomeLayoutGenerator(getActivity());
refreshLayout = view.findViewById(R.id.swiperefreshsummary);
toolbarSubtitle = getActivity().findViewById(R.id.toolbarSubtitle);
toolbarLayout = getActivity().findViewById(R.id.toolbar_layout);
toolbarSubtitle = view.findViewById(R.id.toolbarSubtitle);
totalValue = 0;
totalFluctuation = 0;
@ -113,9 +113,21 @@ public class Summary extends Fragment {
);
handler.postDelayed(updateRunnable, 10000);
toolbarLayout = view.findViewById(R.id.toolbar_layout);
toolbarLayout.setForegroundGravity(Gravity.CENTER);
Button addCurrencyButton = view.findViewById(R.id.buttonAddTransaction);
ImageButton settingsButton = view.findViewById(R.id.settings_button);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent settingIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingIntent);
}
});
addCurrencyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -125,7 +137,7 @@ public class Summary extends Fragment {
}
});
ImageButton detailsButton = getActivity().findViewById(R.id.switch_button);
ImageButton detailsButton = view.findViewById(R.id.switch_button);
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@ -23,6 +23,7 @@ import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -34,6 +35,7 @@ import com.github.mikephil.charting.data.LineDataSet;
import com.nauk.coinfolio.Activities.CurrencyDetailsActivity;
import com.nauk.coinfolio.Activities.CurrencySelectionActivity;
import com.nauk.coinfolio.Activities.HomeActivity;
import com.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
@ -100,6 +102,16 @@ public class Watchlist extends Fragment {
}
});
ImageButton settingsButton = view.findViewById(R.id.settings_button);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent settingIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingIntent);
}
});
return view;
}

View File

@ -0,0 +1,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:startColor="@color/colorPrimary"
android:endColor="@color/colorPrimaryDark"
android:angle="180"/>
</shape>

View File

@ -1,82 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout 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.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@drawable/gradient_background">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@drawable/gradient_background"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar"
app:collapsedTitleGravity="center"
app:expandedTitleGravity="center"
app:titleEnabled="true">
<TextView
android:id="@+id/toolbarSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="35dp"
android:gravity="center"
android:textSize="20sp"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_marginStart="-30dp">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quick_button"
android:visibility="visible"
android:layout_gravity="start"
android:contentDescription="Switch view"/>
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_settings"
android:visibility="visible"
android:layout_gravity="end"
android:contentDescription="Settings"/>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
tools:context="com.nauk.coinfolio.Activities.HomeActivity"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/masterLayout"
@ -107,4 +36,4 @@
app:menu="@menu/navigation_home"
android:layout_gravity="bottom" />
</android.support.design.widget.CoordinatorLayout>
</android.support.constraint.ConstraintLayout>

View File

@ -1,12 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/gradient_background_reverse">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_settings"
android:background="@drawable/ic_settings_black_24dp"
android:visibility="visible"
android:layout_gravity="end"
android:contentDescription="Settings"/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshmarketcap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="56dp"
android:background="@color/summary_background">
<LinearLayout android:id="@+id/layoutMarketCap"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -59,3 +98,4 @@
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>

View File

@ -1,12 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<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.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@drawable/gradient_background">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@drawable/gradient_background"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar"
app:collapsedTitleGravity="center"
app:expandedTitleGravity="center"
app:titleEnabled="true">
<TextView
android:id="@+id/toolbarSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="35dp"
android:gravity="center"
android:textSize="20sp"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_marginStart="-30dp">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quick_button"
android:visibility="visible"
android:layout_gravity="start"
android:contentDescription="Switch view"/>
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_settings"
android:visibility="visible"
android:layout_gravity="end"
android:background="@drawable/ic_settings_black_24dp"
android:contentDescription="Settings"/>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshsummary"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="56dp"
android:background="@color/summary_background">
<android.support.v4.widget.NestedScrollView
@ -47,3 +123,5 @@
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -1,13 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/gradient_background_reverse">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_settings"
android:background="@drawable/ic_settings_black_24dp"
android:visibility="visible"
android:layout_gravity="end"
android:contentDescription="Settings"/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshwatchlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="56dp"
android:background="@color/summary_background">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -54,4 +96,8 @@
android:layout_height="10dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>