added asyncTask
This commit is contained in:
parent
9c09cb9c8b
commit
f76c511e6b
2 changed files with 30 additions and 13 deletions
|
@ -988,12 +988,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgressBar() {
|
void showProgressBar() {
|
||||||
updateClearButtonVisibility(false);
|
updateClearButtonVisibility(false);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideProgressBar() {
|
void hideProgressBar() {
|
||||||
updateClearButtonVisibility(true);
|
updateClearButtonVisibility(true);
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.search;
|
package net.osmand.plus.search;
|
||||||
|
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -86,7 +87,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
if (item.getType() == QuickSearchListItemType.BUTTON) {
|
if (item.getType() == QuickSearchListItemType.BUTTON) {
|
||||||
((QuickSearchButtonListItem) item).getOnClickListener().onClick(view);
|
((QuickSearchButtonListItem) item).getOnClickListener().onClick(view);
|
||||||
} else if (item.getType() == QuickSearchListItemType.SEARCH_RESULT) {
|
} else if (item.getType() == QuickSearchListItemType.SEARCH_RESULT) {
|
||||||
SearchResult sr = item.getSearchResult();
|
final SearchResult sr = item.getSearchResult();
|
||||||
|
|
||||||
if (sr.objectType == ObjectType.POI
|
if (sr.objectType == ObjectType.POI
|
||||||
|| sr.objectType == ObjectType.LOCATION
|
|| sr.objectType == ObjectType.LOCATION
|
||||||
|
@ -97,22 +98,37 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
|| sr.objectType == ObjectType.STREET_INTERSECTION) {
|
|| sr.objectType == ObjectType.STREET_INTERSECTION) {
|
||||||
|
|
||||||
showResult(sr);
|
showResult(sr);
|
||||||
} else {
|
} else if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE)
|
||||||
if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE)
|
|
||||||
&& sr.file != null && sr.object instanceof City) {
|
&& sr.file != null && sr.object instanceof City) {
|
||||||
City c = (City) sr.object;
|
final City c = (City) sr.object;
|
||||||
if (c.getStreets().isEmpty()) {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
dialogFragment.showProgressBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
sr.file.preloadStreets(c, null);
|
sr.file.preloadStreets(c, null);
|
||||||
if (c.getStreets().isEmpty()) {
|
|
||||||
showResult(sr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
dialogFragment.hideProgressBar();
|
||||||
|
if (c.getStreets().isEmpty()) {
|
||||||
|
showResult(sr);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
dialogFragment.completeQueryWithObject(sr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
} else {
|
||||||
dialogFragment.completeQueryWithObject(sr);
|
dialogFragment.completeQueryWithObject(sr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +136,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
Loading…
Reference in a new issue