Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't force recreating the map object and associated layer state #2718

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewStub;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -492,13 +493,17 @@ protected void onCreate(final Bundle savedInstanceState) {
LinearLayout ml = (LinearLayout) getLayoutInflater().inflate(layout, null);
mapLayout = (RelativeLayout) ml.findViewById(R.id.mainMap);

if (map != null) {
Log.d(DEBUG_TAG, "map exists .. destroying");
map.onDestroy();
Logic logic = App.getLogic(); // logic instance might still be around
map = logic != null ? logic.getMap() : null;
if (map == null) {
map = new Map(this);
map.setId(R.id.map_view);
} else {
ViewGroup parent = (ViewGroup) map.getParent();
if (parent != null) {
parent.removeView(map);
}
}
map = new Map(this);
map.setId(R.id.map_view);

// Register some Listener
mapTouchListener = new MapTouchListener();
map.setOnTouchListener(mapTouchListener);
Expand Down Expand Up @@ -585,14 +590,14 @@ protected void onCreate(final Bundle savedInstanceState) {

loadOnResume = false;

if (App.getLogic() == null) {
if (logic == null) {
Log.i(DEBUG_TAG, "onCreate - creating new logic");
App.newLogic();
logic = App.newLogic();
}
Log.i(DEBUG_TAG, "onCreate - setting new map");

App.getLogic().setPrefs(prefs);
App.getLogic().setMap(map, true);
logic.setPrefs(prefs);
logic.setMap(map, true);

Log.d(DEBUG_TAG, "StorageDelegator dirty is " + App.getDelegator().isDirty());
if (StorageDelegator.isStateAvailable(this) && !App.getDelegator().isDirty()) {
Expand Down Expand Up @@ -806,7 +811,7 @@ public void onError(@Nullable AsyncResult result) {
// loadStateFromFile does this above
App.getLogic().loadEditingState(this, setViewBox);
}
logic.loadLayerState(this, postLoadTasks);
// layer state should still be available if logic is still around, no need to load
map.invalidate();
checkPermissions(() -> {
postLoadData.onSuccess();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public MapViewLayer getLayer(int index) {
if (index >= 0 && index < mLayers.size()) {
return mLayers.get(index);
}
Log.e(DEBUG_TAG, "Layer for index " + index + " is null");
Log.e(DEBUG_TAG, "Layer for index " + index + " is null " + mLayers.size() + " layers total");
return null;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/blau/android/dialogs/Layers.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ protected Void doInBackground(Void param) {
* @param map current Map
* @param type the layer type
*/
private void addStyleableLayerFromFile(final FragmentActivity activity, final Preferences prefs, final Map map, @NonNull final LayerType type) {
private void addStyleableLayerFromFile(@NonNull final FragmentActivity activity, @NonNull final Preferences prefs, @NonNull final Map map,
@NonNull final LayerType type) {
Log.d(DEBUG_TAG, "addStyleableLayerFromFile");
SelectFile.read(activity, R.string.config_osmPreferredDir_key, new ReadFile() {
private static final long serialVersionUID = 1L;
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/de/blau/android/osm/ApiErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void onSuccess() {

@Override
public void onError(AsyncResult result) {
System.out.println("FailOnErrorHandler onError");
System.out.println("FailOnSuccessHandler onError " + expectedError + " " + result.getCode());
assertEquals(expectedError, result.getCode());
signal.countDown();
}
Expand All @@ -106,14 +106,15 @@ public void onError(AsyncResult result) {
public void setup() {
mockServer = new MockWebServerPlus();
HttpUrl mockBaseUrl = mockServer.server().url("/api/0.6/");
App.getDelegator().reset(true);
main = Robolectric.buildActivity(Main.class).create().resume().get();
prefDB = new AdvancedPrefDatabase(main);
prefDB.deleteAPI("Test");
prefDB.addAPI("Test", "Test", mockBaseUrl.toString(), null, null, "user", "pass", API.Auth.BASIC);
prefDB.selectAPI("Test");
System.out.println("mock api url " + mockBaseUrl.toString()); // NOSONAR
Logic logic = App.getLogic();
System.out.println("mock api url " + mockBaseUrl.toString()); // NOSONAR
prefs = new Preferences(main);
Logic logic = App.getLogic();
logic.setPrefs(prefs);
logic.getMap().setPrefs(main, prefs);
}
Expand Down
Loading