Save fragment instance

This commit is contained in:
PavelRatushny 2017-08-15 17:37:58 +03:00
parent dd5017a42e
commit 26a07b83a5
3 changed files with 18 additions and 18 deletions

View file

@ -944,7 +944,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
NewGpxLine newGpxLine = (NewGpxLine) toShow; NewGpxLine newGpxLine = (NewGpxLine) toShow;
QuadRect qr = newGpxLine.getRect(); QuadRect qr = newGpxLine.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0); mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
openAddingNewGpxLine(newGpxLine); MeasurementToolFragment.showInstance(getSupportFragmentManager(), newGpxLine);
} else { } else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
} }
@ -958,16 +958,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
} }
private void openAddingNewGpxLine(NewGpxLine newGpxLine) {
MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setNewGpxLine(newGpxLine);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
.addToBackStack(MeasurementToolFragment.TAG)
.commitAllowingStateLoss();
}
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {
return ((OsmandApplication) getApplication()); return ((OsmandApplication) getApplication());
} }

View file

@ -764,12 +764,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ContextMenuAdapter.ItemClickListener() { .setListener(new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
MeasurementToolFragment fragment = new MeasurementToolFragment(); MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), null);
mapActivity.getSupportFragmentManager()
.beginTransaction()
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
.addToBackStack(MeasurementToolFragment.TAG)
.commitAllowingStateLoss();
return true; return true;
} }
}).createItem()); }).createItem());

View file

@ -1101,7 +1101,7 @@ public class MeasurementToolFragment extends Fragment {
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newIntent); startActivity(newIntent);
} }
mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
@ -1133,4 +1133,19 @@ public class MeasurementToolFragment extends Fragment {
} }
} }
} }
public static boolean showInstance(FragmentManager fragmentManager, NewGpxLine newGpxLine) {
try {
MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setNewGpxLine(newGpxLine);
fragment.setRetainInstance(true);
fragmentManager
.beginTransaction()
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
}
}
} }