Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
#44[30m]. Remove toolbar from fragments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Kanivets committed Mar 12, 2016
1 parent 8587a86 commit 723e3b8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.blogspot.e_kanivets.moneytracker.R;
Expand All @@ -29,7 +28,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig

@Override
protected int getContentViewId() {
return R.layout.activity_nav_drawer;
return R.layout.activity_main;
}

@Override
Expand All @@ -44,6 +43,11 @@ protected void initViews() {

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, RecordsFragment.newInstance())
.commit();
}

@Override
Expand All @@ -66,16 +70,6 @@ protected void initToolbar() {
toggle.syncState();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!drawer.isDrawerOpen(GravityCompat.START)) {
initToolbar();
return true;
}

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onNavigationItemSelected(MenuItem item) {
Fragment fragment = new Fragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_accounts, container, false);
initToolbar(rootView);
initViews(rootView);
return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.blogspot.e_kanivets.moneytracker.fragment;

import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.blogspot.e_kanivets.moneytracker.R;

/**
* Base (abstract) class to encapsulate some common fragment operations.
Expand All @@ -17,9 +14,7 @@ public abstract class BaseFragment extends Fragment {
@SuppressWarnings("unused")
private static final String TAG = "BaseFragment";

protected void initToolbar(View rootView) {
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
protected ActionBar getToolbar() {
return ((AppCompatActivity) getActivity()).getSupportActionBar();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_exchange_rates, container, false);
initToolbar(rootView);
initViews(rootView);
return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* Use the {@link RecordsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class RecordsFragment extends Fragment {
public class RecordsFragment extends BaseFragment {
public static final String TAG = "RecordsFragment";

private static final int REQUEST_ACTION_RECORD = 1;
Expand Down Expand Up @@ -102,8 +102,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_records, container, false);
initToolbar(rootView);
initViews(rootView);
initActionBar();
return rootView;
}

Expand Down Expand Up @@ -198,33 +198,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void update() {
recordList = recordController.getRecordsForPeriod(periodController.getPeriod());
Collections.reverse(recordList);

listView.setAdapter(new RecordAdapter(getActivity(), recordList));
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}

private void initViews(View rootView) {
if (rootView == null) return;

ButterKnife.bind(this, rootView);

//Set dates of current week
tvFromDate.setText(periodController.getFirstDay());
tvToDate.setText(periodController.getLastDay());

update();

if (PrefUtils.checkRateDialog()) showAppRateDialog();

registerForContextMenu(listView);
}

private void initActionBar() {
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();

protected void initToolbar(View rootView) {
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.RIGHT | Gravity.CENTER_VERTICAL);
Expand Down Expand Up @@ -277,7 +251,31 @@ public void onNothingSelected(AdapterView<?> parent) {
}
});

if (actionBar != null) actionBar.setCustomView(customNav, lp);
getToolbar().setCustomView(customNav, lp);
}

private void update() {
recordList = recordController.getRecordsForPeriod(periodController.getPeriod());
Collections.reverse(recordList);

listView.setAdapter(new RecordAdapter(getActivity(), recordList));
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}

private void initViews(View rootView) {
if (rootView == null) return;

ButterKnife.bind(this, rootView);

//Set dates of current week
tvFromDate.setText(periodController.getFirstDay());
tvToDate.setText(periodController.getLastDay());

update();

if (PrefUtils.checkRateDialog()) showAppRateDialog();

registerForContextMenu(listView);
}

private void showAppRateDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/fragment_accounts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
android:orientation="vertical"
tools:context="com.blogspot.e_kanivets.moneytracker.fragment.AccountsFragment">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/fragment_exchange_rates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
android:orientation="vertical"
tools:context="com.blogspot.e_kanivets.moneytracker.fragment.AccountsFragment">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/fragment_navigation_drawer.xml

This file was deleted.

11 changes: 1 addition & 10 deletions app/src/main/res/layout/fragment_records.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_grey"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 723e3b8

Please sign in to comment.