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());
|
||||
}
|
||||
|
||||
private void showProgressBar() {
|
||||
void showProgressBar() {
|
||||
updateClearButtonVisibility(false);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void hideProgressBar() {
|
||||
void hideProgressBar() {
|
||||
updateClearButtonVisibility(true);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.search;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -86,7 +87,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
if (item.getType() == QuickSearchListItemType.BUTTON) {
|
||||
((QuickSearchButtonListItem) item).getOnClickListener().onClick(view);
|
||||
} else if (item.getType() == QuickSearchListItemType.SEARCH_RESULT) {
|
||||
SearchResult sr = item.getSearchResult();
|
||||
final SearchResult sr = item.getSearchResult();
|
||||
|
||||
if (sr.objectType == ObjectType.POI
|
||||
|| sr.objectType == ObjectType.LOCATION
|
||||
|
@ -97,22 +98,37 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
|| sr.objectType == ObjectType.STREET_INTERSECTION) {
|
||||
|
||||
showResult(sr);
|
||||
} else {
|
||||
if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE)
|
||||
&& sr.file != null && sr.object instanceof City) {
|
||||
City c = (City) sr.object;
|
||||
if (c.getStreets().isEmpty()) {
|
||||
} else if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE)
|
||||
&& sr.file != null && sr.object instanceof City) {
|
||||
final City c = (City) sr.object;
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
dialogFragment.showProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
try {
|
||||
sr.file.preloadStreets(c, null);
|
||||
if (c.getStreets().isEmpty()) {
|
||||
showResult(sr);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +136,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
|
Loading…
Reference in a new issue