Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
93ed67630a
1 changed files with 40 additions and 35 deletions
|
@ -294,44 +294,47 @@ public class FirstUsageWizardFragment extends Fragment implements OsmAndLocation
|
||||||
|
|
||||||
switch (wizardType) {
|
switch (wizardType) {
|
||||||
case SEARCH_LOCATION:
|
case SEARCH_LOCATION:
|
||||||
if (searchLocationByIp) {
|
if (searchLocationByIp) {
|
||||||
new AsyncTask<Void, Void, String>() {
|
new AsyncTask<Void, Void, String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... params) {
|
protected String doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
return AndroidNetworkUtils.sendRequest(app,
|
return AndroidNetworkUtils.sendRequest(app, "http://osmand.net/api/geo-ip", null,
|
||||||
"http://osmand.net/api/geo-ip", null, "Requesting location by IP...", false);
|
"Requesting location by IP...", false);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logError("Requesting location by IP error: ", e);
|
logError("Requesting location by IP error: ", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String response) {
|
protected void onPostExecute(String response) {
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
try {
|
try {
|
||||||
JSONObject obj = new JSONObject(response);
|
JSONObject obj = new JSONObject(response);
|
||||||
double latitude = obj.getDouble("latitude");
|
double latitude = obj.getDouble("latitude");
|
||||||
double longitude = obj.getDouble("longitude");
|
double longitude = obj.getDouble("longitude");
|
||||||
|
if (latitude == 0 && longitude == 0) {
|
||||||
|
showNoLocationFragment(getActivity());
|
||||||
|
} else {
|
||||||
location = new Location("geo-ip");
|
location = new Location("geo-ip");
|
||||||
location.setLatitude(latitude);
|
location.setLatitude(latitude);
|
||||||
location.setLongitude(longitude);
|
location.setLongitude(longitude);
|
||||||
|
|
||||||
showSearchMapFragment(getActivity());
|
showSearchMapFragment(getActivity());
|
||||||
} catch (Exception e) {
|
|
||||||
logError("JSON parsing error: ", e);
|
|
||||||
showNoLocationFragment(getActivity());
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
|
logError("JSON parsing error: ", e);
|
||||||
showNoLocationFragment(getActivity());
|
showNoLocationFragment(getActivity());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
showNoLocationFragment(getActivity());
|
||||||
}
|
}
|
||||||
}.execute();
|
}
|
||||||
|
}.execute();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) {
|
if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) {
|
||||||
ActivityCompat.requestPermissions(activity,
|
ActivityCompat.requestPermissions(activity,
|
||||||
|
@ -398,17 +401,19 @@ public class FirstUsageWizardFragment extends Fragment implements OsmAndLocation
|
||||||
@Override
|
@Override
|
||||||
public void updateLocation(final Location loc) {
|
public void updateLocation(final Location loc) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
app.runInUIThread(new Runnable() {
|
if (loc != null) {
|
||||||
@Override
|
app.runInUIThread(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
cancelLocationSearchTimer();
|
public void run() {
|
||||||
app.getLocationProvider().removeLocationListener(FirstUsageWizardFragment.this);
|
cancelLocationSearchTimer();
|
||||||
if (location == null) {
|
app.getLocationProvider().removeLocationListener(FirstUsageWizardFragment.this);
|
||||||
location = new Location(loc);
|
if (location == null) {
|
||||||
showSearchMapFragment(getActivity());
|
location = new Location(loc);
|
||||||
|
showSearchMapFragment(getActivity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue