Fixed bug when application shows wrong layout after rotation

This commit is contained in:
Denis 2014-08-08 16:29:02 +03:00
parent 3fcfa5f2aa
commit bde478e39a
2 changed files with 71 additions and 56 deletions

View file

@ -92,9 +92,9 @@ public class SherpafyTourFragment extends SherlockListFragment {
if (si.type == StageItemType.GALLERY) {
// ((TourViewActivity) getSherlockActivity()).showGallery(tour);
} else if (si.type == StageItemType.OVERVIEW) {
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getFulldescription());
((TourViewActivity) getSherlockActivity()).showDetailedOverview(si.header, tour.getFulldescription());
} else if (si.type == StageItemType.INSTRUCTIONS) {
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getInstructions());
((TourViewActivity) getSherlockActivity()).showDetailedInstructions(si.header, tour.getInstructions());
}
}
}

View file

@ -48,6 +48,8 @@ public class TourViewActivity extends SherlockFragmentActivity {
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;
public static final int APP_EXIT_CODE = 4;
@ -112,6 +114,12 @@ 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) {
TourInformation tour = (TourInformation) selectedItem;
showDetailedInstructions(getString(R.string.sherpafy_instructions), tour.getInstructions());
} else if (state == STATE_DETAILED_OVERVIEW) {
TourInformation tour = (TourInformation) selectedItem;
showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription());
} else {
showSelectedItem();
}
@ -122,50 +130,47 @@ public class TourViewActivity extends SherlockFragmentActivity {
if (state == STATE_SELECT_TOUR) {
super.onBackPressed();
} else if (state == STATE_TOUR_VIEW) {
SherpafyHtmlFragment fragment = (SherpafyHtmlFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(STATE_DETAILED_OVERVIEW));
if (fragment != null && fragment.isVisible()) {
showSelectedItem();
} else {
selectMenu(R.string.sherpafy_tours);
}
selectMenu(R.string.sherpafy_tours);
} else if (state == 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) {
showSelectedItem();
}
}
private ArrayAdapter<Object> setupAdapter() {
return new ArrayAdapter<Object>(this, R.layout.sherpafy_drawer_list_item){
return new ArrayAdapter<Object>(this, R.layout.sherpafy_drawer_list_item) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Object it = getItem(position);
if(convertView == null){
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.sherpafy_drawer_list_item, null);
}
final ImageView imView = (ImageView) convertView.findViewById(R.id.Icon);
TextView tv = (TextView) convertView.findViewById(R.id.Text);
if(it.equals(R.string.sherpafy_tours)) {
if (it.equals(R.string.sherpafy_tours)) {
imView.
setImageResource(R.drawable.icon_sherpafy);
setImageResource(R.drawable.icon_sherpafy);
tv.setText(getString(R.string.sherpafy_tours));
} else if(it instanceof TourInformation){
if(selectedItem == it) {
} else if (it instanceof TourInformation) {
if (selectedItem == it) {
imView.setImageResource(R.drawable.ic_action_ok_light);
} else {
imView.setImageResource(R.drawable.ic_action_globus_light);
}
tv.setText(((TourInformation) it).getName());
} else if(it instanceof StageInformation){
if(customization.getSelectedStage() == it) {
} else if (it instanceof StageInformation) {
if (customization.getSelectedStage() == it) {
imView.setImageResource(R.drawable.ic_action_gplay_over_light);
} else if(selectedItem == it) {
} else if (selectedItem == it) {
imView.setImageResource(R.drawable.ic_action_ok_light);
} else {
imView.setImageDrawable(
new StageImageDrawable(TourViewActivity.this, StageImageDrawable.MENU_COLOR,
(((StageInformation) it).getOrder() + 1)+"", 0));
(((StageInformation) it).getOrder() + 1) + "", 0));
}
tv.setText(((StageInformation) it).getName());
} else {
@ -179,11 +184,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void updateActionBarTitle() {
if(state == STATE_LOADING) {
if (state == STATE_LOADING) {
getSupportActionBar().setTitle(R.string.app_name);
} else if(state == STATE_SELECT_TOUR) {
} else if (state == STATE_SELECT_TOUR) {
getSupportActionBar().setTitle(R.string.sherpafy_tours);
} else if(state == STATE_TOUR_VIEW) {
} else if (state == STATE_TOUR_VIEW) {
}
invalidateOptionsMenu();
}
@ -216,7 +221,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType,
final OnMenuItemClickListener listener) {
final OnMenuItemClickListener listener) {
// int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark;
int r = iconLight;
MenuItem menuItem = m.add(0, id, 0, titleRes);
@ -254,7 +259,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
state = STATE_SELECT_TOUR;
setDrawerIndicatorVisible(true);
} else if(item instanceof TourInformation) {
} else if (item instanceof TourInformation) {
state = STATE_TOUR_VIEW;
if (fragment == null) {
fragment = new SherpafyTourFragment();
@ -264,7 +269,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
fragments.put(item, fragment);
}
setDrawerIndicatorVisible(true);
} else if(item instanceof StageInformation) {
} else if (item instanceof StageInformation) {
state = STATE_STAGE_OVERVIEW;
if (fragment == null) {
fragment = new SherpafyStageFragment();
@ -276,7 +281,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
setDrawerIndicatorVisible(false);
}
if(fragment != null) {
if (fragment != null) {
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(state)).commit();
}
selectedItem = item;
@ -286,20 +291,20 @@ public class TourViewActivity extends SherlockFragmentActivity {
drawerAdapter.clear();
drawerAdapter.add(R.string.sherpafy_tours);
TourInformation selectedTour = customization.getSelectedTour();
for(TourInformation it : customization.getTourInformations()) {
for (TourInformation it : customization.getTourInformations()) {
int insert = drawerAdapter.getCount();
if(it == selectedTour) {
if (it == selectedTour) {
insert = 1;
}
drawerAdapter.insert(it, insert++);
if(it == selectedItem || (selectedItem instanceof StageInformation &&
if (it == selectedItem || (selectedItem instanceof StageInformation &&
((StageInformation) selectedItem).getTour() == it)) {
for(StageInformation st : it.getStageInformation()) {
for (StageInformation st : it.getStageInformation()) {
drawerAdapter.insert(st, insert++);
}
} else if(it == selectedTour) {
} else if (it == selectedTour) {
StageInformation st = customization.getSelectedStage();
if(st != null) {
if (st != null) {
drawerAdapter.insert(st, insert++);
}
}
@ -308,19 +313,19 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
private void setDrawerIndicatorVisible(boolean b) {
if(mDrawerToggle.isDrawerIndicatorEnabled() != b) {
if (mDrawerToggle.isDrawerIndicatorEnabled() != b) {
mDrawerToggle.setDrawerIndicatorEnabled(b);
}
}
public void showSelectedItem() {
if(selectedItem != null) {
if (selectedItem != null) {
selectMenu(selectedItem);
} else {
if(customization.getSelectedStage() != null) {
if (customization.getSelectedStage() != null) {
selectMenu(customization.getSelectedStage());
} else if(customization.getSelectedTour() != null) {
} else if (customization.getSelectedTour() != null) {
selectMenu(customization.getSelectedTour());
} else {
selectMenu(R.string.sherpafy_tours);
@ -341,7 +346,17 @@ public class TourViewActivity extends SherlockFragmentActivity {
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
}
public void showHtmlFragment(String title, String cont) {
public void showDetailedInstructions(String title, String cont) {
state = STATE_DETAILED_INSTRUCTIONS;
showHtmlFragment(title, cont);
}
public void showDetailedOverview(String title, String cont) {
state = STATE_DETAILED_OVERVIEW;
showHtmlFragment(title, cont);
}
private void showHtmlFragment(String title, String cont) {
FragmentManager fragmentManager = getSupportFragmentManager();
setDrawerIndicatorVisible(false);
SherpafyHtmlFragment fragment = new SherpafyHtmlFragment();
@ -360,7 +375,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
public void goToMap(LatLon location) {
if(location != null) {
if (location != null) {
getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), 16, null);
}
Intent newIntent = new Intent(this, customization.getMapActivity());
@ -369,7 +384,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
public void startStage(final StageInformation stage) {
if(stage != customization.getSelectedStage() && customization.getSelectedStage() != null) {
if (stage != customization.getSelectedStage() && customization.getSelectedStage() != null) {
Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.start_new_stage);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@ -387,7 +402,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void startTour(final TourInformation tour) {
if(tour != customization.getSelectedTour() && customization.getSelectedTour() != null) {
if (tour != customization.getSelectedTour() && customization.getSelectedTour() != null) {
Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.start_new_stage);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@ -435,12 +450,12 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
}
WptPt lp = gpx.getLastPoint();
if(lp != null) {
if (lp != null) {
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
targetPointsHelper.navigateToPoint(new LatLon(lp.lat, lp.lon), true, -1, lp.name);
getMyApplication().getSettings().navigateDialog();
}
if(startOver && point != null){
if (startOver && point != null) {
goToMap(new LatLon(point.lat, point.lon));
} else {
goToMap(null);