|
@@ -51,6 +51,7 @@ public class MainActivity extends Activity {
|
|
|
private CharSequence mTitle;
|
|
|
|
|
|
public Fragment displayedFragment;
|
|
|
+ private int selectedMenuItemPosition;
|
|
|
|
|
|
private ArrayList<DrawerListItem> drawerItems;
|
|
|
private HoneyService mHoneyService;
|
|
@@ -66,7 +67,7 @@ public class MainActivity extends Activity {
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
MainActivity.context = getApplicationContext();
|
|
|
-
|
|
|
+ this.selectedMenuItemPosition = 0;
|
|
|
|
|
|
setContentView(R.layout.activity_drawer_main);
|
|
|
|
|
@@ -176,9 +177,18 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
|
|
|
private void displayView(int position) {
|
|
|
- // update the main content by replacing fragments
|
|
|
- Fragment fragment = null;
|
|
|
- switch (position) {
|
|
|
+ // DONT OPEN SAME VIEW AGAIN
|
|
|
+ int menuItemPosition = position;
|
|
|
+
|
|
|
+ Fragment fragment = null;
|
|
|
+
|
|
|
+ if (this.selectedMenuItemPosition == position && this.displayedFragment != null) {
|
|
|
+ menuItemPosition = -1;
|
|
|
+ fragment = this.displayedFragment;
|
|
|
+ }
|
|
|
+
|
|
|
+ // update the main content by replacing fragments
|
|
|
+ switch (menuItemPosition) {
|
|
|
case 0:
|
|
|
fragment = new HomeFragment();
|
|
|
break;
|
|
@@ -201,20 +211,22 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
|
|
|
if (fragment != null) {
|
|
|
- this.displayedFragment = fragment;
|
|
|
- FragmentManager fragmentManager = getFragmentManager();
|
|
|
-
|
|
|
- FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
|
- fragmentTransaction.replace(R.id.content_frame, fragment, fragment.getTag());
|
|
|
- fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
|
|
|
- fragmentTransaction.commit();
|
|
|
-
|
|
|
- // update selected item and title, then close the drawer
|
|
|
- mDrawerList.setItemChecked(position, true);
|
|
|
- mDrawerList.setSelection(position);
|
|
|
- setTitle(drawerItems.get(position).text);
|
|
|
- mDrawerLayout.closeDrawer(mDrawerList);
|
|
|
- }
|
|
|
+ // update selected item and title, then close the drawer if needed
|
|
|
+ if (!fragment.equals(this.displayedFragment)){
|
|
|
+ FragmentManager fragmentManager = getFragmentManager();
|
|
|
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
|
+ fragmentTransaction.replace(R.id.content_frame, fragment, fragment.getTag());
|
|
|
+ fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
|
|
|
+ fragmentTransaction.commit();
|
|
|
+ mDrawerList.setItemChecked(position, true);
|
|
|
+ mDrawerList.setSelection(position);
|
|
|
+ setTitle(drawerItems.get(position).text);
|
|
|
+ this.selectedMenuItemPosition = position;
|
|
|
+ }
|
|
|
+
|
|
|
+ mDrawerLayout.closeDrawer(mDrawerList);
|
|
|
+ this.displayedFragment = fragment;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Intent getServiceIntent() {
|