Refactoret states
This commit is contained in:
parent
d295c9361d
commit
28783d3c9d
1 changed files with 29 additions and 25 deletions
|
@ -47,14 +47,18 @@ import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
|
||||||
*/
|
*/
|
||||||
public class TourViewActivity extends SherlockFragmentActivity {
|
public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
private static final int STATE_LOADING = -1;
|
private enum viewState {
|
||||||
private static final int STATE_SELECT_TOUR = 1;
|
STATE_LOADING,
|
||||||
private static final int STATE_TOUR_VIEW = 2;
|
STATE_SELECT_TOUR,
|
||||||
private static final int STATE_STAGE_OVERVIEW = 3;
|
STATE_TOUR_VIEW,
|
||||||
private static final int STATE_DETAILED_OVERVIEW = 4;
|
STATE_STAGE_OVERVIEW,
|
||||||
private static final int STATE_DETAILED_INSTRUCTIONS = 5;
|
STATE_DETAILED_OVERVIEW,
|
||||||
private static final int STAGE_GALLERY = 6;
|
STATE_DETAILED_INSTRUCTIONS,
|
||||||
private static int state = STATE_LOADING;
|
STAGE_GALLERY
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static viewState state = viewState.STATE_LOADING;
|
||||||
|
|
||||||
public static final int APP_EXIT_CODE = 4;
|
public static final int APP_EXIT_CODE = 4;
|
||||||
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
||||||
|
@ -117,10 +121,10 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
if (getMyApplication().isApplicationInitializing()) {
|
if (getMyApplication().isApplicationInitializing()) {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment()).commit();
|
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;
|
TourInformation tour = (TourInformation) selectedItem;
|
||||||
showDetailedInstructions(getString(R.string.sherpafy_instructions), tour.getInstructions());
|
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;
|
TourInformation tour = (TourInformation) selectedItem;
|
||||||
showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription());
|
showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription());
|
||||||
} else {
|
} else {
|
||||||
|
@ -130,16 +134,16 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (state == STATE_SELECT_TOUR) {
|
if (state == viewState.STATE_SELECT_TOUR) {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
} else if (state == STATE_TOUR_VIEW) {
|
} else if (state == viewState.STATE_TOUR_VIEW) {
|
||||||
selectMenu(R.string.sherpafy_tours);
|
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));
|
SherpafyStageFragment fragment = (SherpafyStageFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(state));
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.onBackPressed();
|
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();
|
showSelectedItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +177,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
} else {
|
} else {
|
||||||
boolean visited = customization.isStageVisited(((StageInformation) it).getOrder());
|
boolean visited = customization.isStageVisited(((StageInformation) it).getOrder());
|
||||||
imView.setImageDrawable(
|
imView.setImageDrawable(
|
||||||
new StageImageDrawable(TourViewActivity.this,
|
new StageImageDrawable(TourViewActivity.this,
|
||||||
visited ? StageImageDrawable.INFO_COLOR : StageImageDrawable.MENU_COLOR,
|
visited ? StageImageDrawable.INFO_COLOR : StageImageDrawable.MENU_COLOR,
|
||||||
(((StageInformation) it).getOrder() + 1) + "", 0));
|
(((StageInformation) it).getOrder() + 1) + "", 0));
|
||||||
}
|
}
|
||||||
|
@ -189,11 +193,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
|
|
||||||
public void updateActionBarTitle() {
|
public void updateActionBarTitle() {
|
||||||
if (state == STATE_LOADING) {
|
if (state == viewState.STATE_LOADING) {
|
||||||
getSupportActionBar().setTitle(R.string.app_name);
|
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);
|
getSupportActionBar().setTitle(R.string.sherpafy_tours);
|
||||||
} else if (state == STATE_TOUR_VIEW) {
|
} else if (state == viewState.STATE_TOUR_VIEW) {
|
||||||
}
|
}
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
@ -223,7 +227,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if(refreshListAfterDownload){
|
if (refreshListAfterDownload) {
|
||||||
refreshListAfterDownload = false;
|
refreshListAfterDownload = false;
|
||||||
selectMenu(selectedItem == null ? R.string.sherpafy_tours : selectedItem);
|
selectMenu(selectedItem == null ? R.string.sherpafy_tours : selectedItem);
|
||||||
}
|
}
|
||||||
|
@ -268,10 +272,10 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
} else {
|
} else {
|
||||||
((SherpafySelectToursFragment) fragment).refreshAdapter();
|
((SherpafySelectToursFragment) fragment).refreshAdapter();
|
||||||
}
|
}
|
||||||
state = STATE_SELECT_TOUR;
|
state = viewState.STATE_SELECT_TOUR;
|
||||||
setDrawerIndicatorVisible(true);
|
setDrawerIndicatorVisible(true);
|
||||||
} else if (item instanceof TourInformation) {
|
} else if (item instanceof TourInformation) {
|
||||||
state = STATE_TOUR_VIEW;
|
state = viewState.STATE_TOUR_VIEW;
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
fragment = new SherpafyTourFragment();
|
fragment = new SherpafyTourFragment();
|
||||||
Bundle bl = new Bundle();
|
Bundle bl = new Bundle();
|
||||||
|
@ -281,7 +285,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
}
|
}
|
||||||
setDrawerIndicatorVisible(true);
|
setDrawerIndicatorVisible(true);
|
||||||
} else if (item instanceof StageInformation) {
|
} else if (item instanceof StageInformation) {
|
||||||
state = STATE_STAGE_OVERVIEW;
|
state = viewState.STATE_STAGE_OVERVIEW;
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
fragment = new SherpafyStageFragment();
|
fragment = new SherpafyStageFragment();
|
||||||
Bundle bl = new Bundle();
|
Bundle bl = new Bundle();
|
||||||
|
@ -358,12 +362,12 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDetailedInstructions(String title, String cont) {
|
public void showDetailedInstructions(String title, String cont) {
|
||||||
state = STATE_DETAILED_INSTRUCTIONS;
|
state = viewState.STATE_DETAILED_INSTRUCTIONS;
|
||||||
showHtmlFragment(title, cont);
|
showHtmlFragment(title, cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDetailedOverview(String title, String cont) {
|
public void showDetailedOverview(String title, String cont) {
|
||||||
state = STATE_DETAILED_OVERVIEW;
|
state = viewState.STATE_DETAILED_OVERVIEW;
|
||||||
showHtmlFragment(title, cont);
|
showHtmlFragment(title, cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +379,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
||||||
bl.putString(SherpafyHtmlFragment.HTML, cont);
|
bl.putString(SherpafyHtmlFragment.HTML, cont);
|
||||||
bl.putString(SherpafyHtmlFragment.TITLE, title);
|
bl.putString(SherpafyHtmlFragment.TITLE, title);
|
||||||
fragment.setArguments(bl);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue