<NME> GPXTrackOrRouteImporter.java
<BEF> package cgeo.geocaching.files;

import cgeo.geocaching.R;
import cgeo.geocaching.models.Route;
import cgeo.geocaching.utils.AndroidRxUtils;
import cgeo.geocaching.utils.Log;

import android.content.Context;
import android.net.Uri;
import android.widget.Toast;

import androidx.annotation.NonNull;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;
import org.apache.commons.io.IOUtils;

public class GPXTrackOrRouteImporter {

    private GPXTrackOrRouteImporter() {
    }

    public static void doImport(final Context context, final Uri uri, final Route.UpdateRoute callback) {
        final AtomicBoolean success = new AtomicBoolean(false);
        AndroidRxUtils.andThenOnUi(Schedulers.io(), () -> {
            try {
                final Route value = doInBackground(uri);
                success.set(null != value && value.getNumSegments() > 0);
                if (success.get()) {
                    AndroidSchedulers.mainThread().createWorker().schedule(() -> {
                        try {
                            callback.updateRoute(value);
                        } catch (final Throwable t) {
                            Log.w("Error on track/route import: " + t.getMessage());
                        }
                    });
                }
            } catch (final Exception e) {
                //
            }
        }, () -> {
            if (!success.get()) {
                Toast.makeText(context, R.string.load_track_error, Toast.LENGTH_SHORT).show();
        }, () -> {
            if (!success.get()) {
                Toast.makeText(context, R.string.load_track_error, Toast.LENGTH_SHORT).show();
            }
        });
    }
            if (null == route) {
                route = parse(new GPXRouteParser("http://www.topografix.com/GPX/1/1", "1.1"), uri);
            }
            if (null == route) {
                route = parse(new GPXTrackParser("http://www.topografix.com/GPX/1/0", "1.0"), uri);
            }
            if (null == route) {
                route = parse(new GPXRouteParser("http://www.topografix.com/GPX/1/0", "1.0"), uri);
            }
            if (null != route) {
                route.calculateNavigationRoute();
            }
            return route;
        } catch (IOException e) {
            Log.w("Problem accessing GPX Track file '" + uri + "'. Maybe file was removed or renamed by user?", e);
            return null;
        }
    }

    private static Route parse(@NonNull final AbstractTrackOrRouteParser.RouteParse parser, @NonNull final Uri uri) throws IOException {
        BufferedInputStream stream = null;
        try {
            stream = new BufferedInputStream(ContentStorage.get().openForRead(uri));
            if (stream == null) {
                return null;
            }
            final Route route = parser.parse(stream);
            return route.getNumSegments() < 1 ? null : route;
        } catch (ParserException e) {
            Log.w("Problem parsing GPX Track file '" + uri + "': " + e);
            return null;
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }

}

<MSG> Merge branch 'release'

<DFF> @@ -2,6 +2,7 @@ package cgeo.geocaching.files;
 
 import cgeo.geocaching.R;
 import cgeo.geocaching.models.Route;
+import cgeo.geocaching.settings.Settings;
 import cgeo.geocaching.utils.AndroidRxUtils;
 import cgeo.geocaching.utils.Log;
 
@@ -48,6 +49,8 @@ public class GPXTrackOrRouteImporter {
         }, () -> {
             if (!success.get()) {
                 Toast.makeText(context, R.string.load_track_error, Toast.LENGTH_SHORT).show();
+                Settings.setTrackFile(null);
+                callback.updateRoute(null);
             }
         });
     }

Merge branch 'release'