Split out the Nav Drawers between activities

This commit is contained in:
DjBushido 2014-04-16 13:57:33 -04:00
parent 77d808ca1b
commit 0feee0b940
8 changed files with 94 additions and 47 deletions

View File

@ -32,7 +32,7 @@
<fragment <fragment
android:id="@+id/navigation_drawer" android:id="@+id/navigation_drawer"
android:name="org.bspeice.minimalbible.activities.NavigationDrawerFragment" android:name="org.bspeice.minimalbible.activities.viewer.ViewerNavDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width" android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"

View File

@ -32,7 +32,7 @@
<fragment <fragment
android:id="@+id/navigation_drawer" android:id="@+id/navigation_drawer"
android:name="org.bspeice.minimalbible.activities.NavigationDrawerFragment" android:name="org.bspeice.minimalbible.activities.downloader.DownloadNavDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width" android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" /> android:layout_gravity="start" />

View File

@ -7,5 +7,5 @@
android:choiceMode="singleChoice" android:choiceMode="singleChoice"
android:divider="@android:color/transparent" android:divider="@android:color/transparent"
android:dividerHeight="0dp" android:dividerHeight="0dp"
tools:context="org.bspeice.minimalbible.activities.NavigationDrawerFragment" /> tools:context="org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment" />

View File

@ -34,7 +34,7 @@ import com.readystatesoftware.systembartint.SystemBarTintManager;
* > design guidelines</a> for a complete explanation of the behaviors * > design guidelines</a> for a complete explanation of the behaviors
* implemented here. * implemented here.
*/ */
public class NavigationDrawerFragment extends Fragment { public class BaseNavigationDrawerFragment extends Fragment {
/** /**
* Remember the position of the selected item. * Remember the position of the selected item.
@ -58,14 +58,14 @@ public class NavigationDrawerFragment extends Fragment {
private ActionBarDrawerToggle mDrawerToggle; private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout; private DrawerLayout mDrawerLayout;
private ListView mDrawerListView; protected ListView mDrawerListView;
private View mFragmentContainerView; private View mFragmentContainerView;
private int mCurrentSelectedPosition = 0; protected int mCurrentSelectedPosition = 0;
private boolean mFromSavedInstanceState; private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer; private boolean mUserLearnedDrawer;
public NavigationDrawerFragment() { public BaseNavigationDrawerFragment() {
} }
@Override @Override
@ -97,29 +97,6 @@ public class NavigationDrawerFragment extends Fragment {
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
.getThemedContext(), android.R.layout.simple_list_item_1,
android.R.id.text1, new String[] {
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3), }));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
public boolean isDrawerOpen() { public boolean isDrawerOpen() {
return mDrawerLayout != null return mDrawerLayout != null
&& mDrawerLayout.isDrawerOpen(mFragmentContainerView); && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
@ -214,7 +191,7 @@ public class NavigationDrawerFragment extends Fragment {
mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerListener(mDrawerToggle);
} }
private void selectItem(int position) { public void selectItem(int position) {
mCurrentSelectedPosition = position; mCurrentSelectedPosition = position;
if (mDrawerListView != null) { if (mDrawerListView != null) {
mDrawerListView.setItemChecked(position, true); mDrawerListView.setItemChecked(position, true);
@ -275,13 +252,6 @@ public class NavigationDrawerFragment extends Fragment {
if (mDrawerToggle.onOptionsItemSelected(item)) { if (mDrawerToggle.onOptionsItemSelected(item)) {
return true; return true;
} }
if (item.getItemId() == R.id.action_example) {
Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT)
.show();
return true;
}
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -297,7 +267,7 @@ public class NavigationDrawerFragment extends Fragment {
// actionBar.setTitle(R.string.app_name); // actionBar.setTitle(R.string.app_name);
} }
private ActionBar getActionBar() { protected ActionBar getActionBar() {
return ((ActionBarActivity) getActivity()).getSupportActionBar(); return ((ActionBarActivity) getActivity()).getSupportActionBar();
} }

View File

@ -3,7 +3,7 @@ package org.bspeice.minimalbible.activities.downloader;
import org.bspeice.minimalbible.MinimalBibleConstants; import org.bspeice.minimalbible.MinimalBibleConstants;
import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activities.BaseActivity; import org.bspeice.minimalbible.activities.BaseActivity;
import org.bspeice.minimalbible.activities.NavigationDrawerFragment; import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -23,13 +23,13 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class DownloadActivity extends BaseActivity implements public class DownloadActivity extends BaseActivity implements
NavigationDrawerFragment.NavigationDrawerCallbacks { BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
/** /**
* Fragment managing the behaviors, interactions and presentation of the * Fragment managing the behaviors, interactions and presentation of the
* navigation drawer. * navigation drawer.
*/ */
private NavigationDrawerFragment mNavigationDrawerFragment; private DownloadNavDrawerFragment mNavigationDrawerFragment;
/** /**
* Used to store the last screen title. For use in * Used to store the last screen title. For use in
@ -42,7 +42,7 @@ public class DownloadActivity extends BaseActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download); setContentView(R.layout.activity_download);
mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer); .findFragmentById(R.id.navigation_drawer);
mTitle = getTitle(); mTitle = getTitle();

View File

@ -0,0 +1,39 @@
package org.bspeice.minimalbible.activities.downloader;
import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
.getThemedContext(), android.R.layout.simple_list_item_1,
android.R.id.text1, new String[] {
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3), }));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
}

View File

@ -6,7 +6,7 @@ import org.bspeice.minimalbible.R.layout;
import org.bspeice.minimalbible.R.menu; import org.bspeice.minimalbible.R.menu;
import org.bspeice.minimalbible.R.string; import org.bspeice.minimalbible.R.string;
import org.bspeice.minimalbible.activities.BaseActivity; import org.bspeice.minimalbible.activities.BaseActivity;
import org.bspeice.minimalbible.activities.NavigationDrawerFragment; import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
import org.bspeice.minimalbible.activities.downloader.DownloadActivity; import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
import android.app.Activity; import android.app.Activity;
@ -28,13 +28,13 @@ import android.widget.TextView;
import com.readystatesoftware.systembartint.SystemBarTintManager; import com.readystatesoftware.systembartint.SystemBarTintManager;
public class BibleViewer extends BaseActivity implements public class BibleViewer extends BaseActivity implements
NavigationDrawerFragment.NavigationDrawerCallbacks { BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
/** /**
* Fragment managing the behaviors, interactions and presentation of the * Fragment managing the behaviors, interactions and presentation of the
* navigation drawer. * navigation drawer.
*/ */
private NavigationDrawerFragment mNavigationDrawerFragment; private ViewerNavDrawerFragment mNavigationDrawerFragment;
/** /**
* Used to store the last screen title. For use in * Used to store the last screen title. For use in
@ -47,7 +47,7 @@ public class BibleViewer extends BaseActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bible_viewer); setContentView(R.layout.activity_bible_viewer);
mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer); .findFragmentById(R.id.navigation_drawer);
mTitle = getTitle(); mTitle = getTitle();

View File

@ -0,0 +1,38 @@
package org.bspeice.minimalbible.activities.viewer;
import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ViewerNavDrawerFragment extends BaseNavigationDrawerFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
.getThemedContext(), android.R.layout.simple_list_item_1,
android.R.id.text1, new String[] {
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3)}));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
}