From 28783d3c9d28388761afc3fce82feb4329189ba9 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 14 Aug 2014 13:23:21 +0300 Subject: [PATCH 1/3] Refactoret states --- .../plus/sherpafy/TourViewActivity.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 3f392a14f0..d314709240 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -47,14 +47,18 @@ import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener; */ public class TourViewActivity extends SherlockFragmentActivity { - private static final int STATE_LOADING = -1; - private static final int STATE_SELECT_TOUR = 1; - private static final int STATE_TOUR_VIEW = 2; - private static final int STATE_STAGE_OVERVIEW = 3; - private static final int STATE_DETAILED_OVERVIEW = 4; - private static final int STATE_DETAILED_INSTRUCTIONS = 5; - private static final int STAGE_GALLERY = 6; - private static int state = STATE_LOADING; + private enum viewState { + STATE_LOADING, + STATE_SELECT_TOUR, + STATE_TOUR_VIEW, + STATE_STAGE_OVERVIEW, + STATE_DETAILED_OVERVIEW, + STATE_DETAILED_INSTRUCTIONS, + STAGE_GALLERY + } + + + private static viewState state = viewState.STATE_LOADING; public static final int APP_EXIT_CODE = 4; public static final String APP_EXIT_KEY = "APP_EXIT_KEY"; @@ -117,10 +121,10 @@ public class TourViewActivity extends SherlockFragmentActivity { if (getMyApplication().isApplicationInitializing()) { FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment()).commit(); - } else if (state == STATE_DETAILED_INSTRUCTIONS) { + } else if (state == viewState.STATE_DETAILED_INSTRUCTIONS) { TourInformation tour = (TourInformation) selectedItem; showDetailedInstructions(getString(R.string.sherpafy_instructions), tour.getInstructions()); - } else if (state == STATE_DETAILED_OVERVIEW) { + } else if (state == viewState.STATE_DETAILED_OVERVIEW) { TourInformation tour = (TourInformation) selectedItem; showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription()); } else { @@ -130,16 +134,16 @@ public class TourViewActivity extends SherlockFragmentActivity { @Override public void onBackPressed() { - if (state == STATE_SELECT_TOUR) { + if (state == viewState.STATE_SELECT_TOUR) { super.onBackPressed(); - } else if (state == STATE_TOUR_VIEW) { + } else if (state == viewState.STATE_TOUR_VIEW) { selectMenu(R.string.sherpafy_tours); - } else if (state == STATE_STAGE_OVERVIEW) { + } else if (state == viewState.STATE_STAGE_OVERVIEW) { SherpafyStageFragment fragment = (SherpafyStageFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(state)); if (fragment != null) { fragment.onBackPressed(); } - } else if (state == STATE_DETAILED_OVERVIEW || state == STATE_DETAILED_INSTRUCTIONS) { + } else if (state == viewState.STATE_DETAILED_OVERVIEW || state == viewState.STATE_DETAILED_INSTRUCTIONS) { showSelectedItem(); } } @@ -173,7 +177,7 @@ public class TourViewActivity extends SherlockFragmentActivity { } else { boolean visited = customization.isStageVisited(((StageInformation) it).getOrder()); imView.setImageDrawable( - new StageImageDrawable(TourViewActivity.this, + new StageImageDrawable(TourViewActivity.this, visited ? StageImageDrawable.INFO_COLOR : StageImageDrawable.MENU_COLOR, (((StageInformation) it).getOrder() + 1) + "", 0)); } @@ -189,11 +193,11 @@ public class TourViewActivity extends SherlockFragmentActivity { public void updateActionBarTitle() { - if (state == STATE_LOADING) { + if (state == viewState.STATE_LOADING) { getSupportActionBar().setTitle(R.string.app_name); - } else if (state == STATE_SELECT_TOUR) { + } else if (state == viewState.STATE_SELECT_TOUR) { getSupportActionBar().setTitle(R.string.sherpafy_tours); - } else if (state == STATE_TOUR_VIEW) { + } else if (state == viewState.STATE_TOUR_VIEW) { } invalidateOptionsMenu(); } @@ -223,7 +227,7 @@ public class TourViewActivity extends SherlockFragmentActivity { @Override protected void onResume() { super.onResume(); - if(refreshListAfterDownload){ + if (refreshListAfterDownload) { refreshListAfterDownload = false; selectMenu(selectedItem == null ? R.string.sherpafy_tours : selectedItem); } @@ -268,10 +272,10 @@ public class TourViewActivity extends SherlockFragmentActivity { } else { ((SherpafySelectToursFragment) fragment).refreshAdapter(); } - state = STATE_SELECT_TOUR; + state = viewState.STATE_SELECT_TOUR; setDrawerIndicatorVisible(true); } else if (item instanceof TourInformation) { - state = STATE_TOUR_VIEW; + state = viewState.STATE_TOUR_VIEW; if (fragment == null) { fragment = new SherpafyTourFragment(); Bundle bl = new Bundle(); @@ -281,7 +285,7 @@ public class TourViewActivity extends SherlockFragmentActivity { } setDrawerIndicatorVisible(true); } else if (item instanceof StageInformation) { - state = STATE_STAGE_OVERVIEW; + state = viewState.STATE_STAGE_OVERVIEW; if (fragment == null) { fragment = new SherpafyStageFragment(); Bundle bl = new Bundle(); @@ -358,12 +362,12 @@ public class TourViewActivity extends SherlockFragmentActivity { } public void showDetailedInstructions(String title, String cont) { - state = STATE_DETAILED_INSTRUCTIONS; + state = viewState.STATE_DETAILED_INSTRUCTIONS; showHtmlFragment(title, cont); } public void showDetailedOverview(String title, String cont) { - state = STATE_DETAILED_OVERVIEW; + state = viewState.STATE_DETAILED_OVERVIEW; showHtmlFragment(title, cont); } @@ -375,7 +379,7 @@ public class TourViewActivity extends SherlockFragmentActivity { bl.putString(SherpafyHtmlFragment.HTML, cont); bl.putString(SherpafyHtmlFragment.TITLE, title); fragment.setArguments(bl); - fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(STATE_DETAILED_OVERVIEW)).commit(); + fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(viewState.STATE_DETAILED_OVERVIEW)).commit(); } From e435a9eee47c46174cddda9c188b55a58edf53ab Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 14 Aug 2014 14:25:23 +0300 Subject: [PATCH 2/3] Fixed null reference on backPressed in Sherpafy --- OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index d314709240..970455ed36 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -266,7 +266,7 @@ public class TourViewActivity extends SherlockFragmentActivity { FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = fragments.get(item); if (new Integer(R.string.sherpafy_tours).equals(item)) { - if (fragment == null) { + if (fragment == null || fragment.getActivity() == null) { fragment = new SherpafySelectToursFragment(); fragments.put(item, fragment); } else { From 499ff8d868a8764817f60b8ff7dece18db97b938 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 14 Aug 2014 17:15:18 +0300 Subject: [PATCH 3/3] Added back button on stage favorite --- OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 970455ed36..2627ff8491 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -54,7 +54,8 @@ public class TourViewActivity extends SherlockFragmentActivity { STATE_STAGE_OVERVIEW, STATE_DETAILED_OVERVIEW, STATE_DETAILED_INSTRUCTIONS, - STAGE_GALLERY + STAGE_GALLERY, + STAGE_FAVORITES } @@ -143,7 +144,7 @@ public class TourViewActivity extends SherlockFragmentActivity { if (fragment != null) { fragment.onBackPressed(); } - } else if (state == viewState.STATE_DETAILED_OVERVIEW || state == viewState.STATE_DETAILED_INSTRUCTIONS) { + } else if (state == viewState.STATE_DETAILED_OVERVIEW || state == viewState.STATE_DETAILED_INSTRUCTIONS || state == viewState.STAGE_FAVORITES) { showSelectedItem(); } } @@ -350,6 +351,7 @@ public class TourViewActivity extends SherlockFragmentActivity { public void showFavoriteFragment(StageInformation stage, StageFavorite sf) { + state = viewState.STAGE_FAVORITES; FragmentManager fragmentManager = getSupportFragmentManager(); setDrawerIndicatorVisible(false); SherpafyFavoriteFragment fragment = new SherpafyFavoriteFragment();