Small refactoring
This commit is contained in:
parent
1410321173
commit
246c5c0a08
1 changed files with 56 additions and 48 deletions
|
@ -763,84 +763,39 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(SearchResult object) {
|
public boolean publish(SearchResult object) {
|
||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
if (results.size() > 0) {
|
if (results.size() > 0) {
|
||||||
getResultCollection().addSearchResults(results, true, true);
|
getResultCollection().addSearchResults(results, true, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (object.objectType) {
|
switch (object.objectType) {
|
||||||
case SEARCH_API_FINISHED:
|
case SEARCH_API_FINISHED:
|
||||||
final SearchCoreAPI searchApi = (SearchCoreAPI) object.object;
|
final SearchCoreAPI searchApi = (SearchCoreAPI) object.object;
|
||||||
|
|
||||||
final List<SearchResult> apiResults;
|
final List<SearchResult> apiResults;
|
||||||
final SearchPhrase phrase = object.requiredSearchPhrase;
|
final SearchPhrase phrase = object.requiredSearchPhrase;
|
||||||
final SearchCoreAPI regionApi = regionResultApi;
|
final SearchCoreAPI regionApi = regionResultApi;
|
||||||
final SearchResultCollection regionCollection = regionResultCollection;
|
final SearchResultCollection regionCollection = regionResultCollection;
|
||||||
|
|
||||||
final boolean hasRegionCollection = (searchApi == regionApi && regionCollection != null);
|
final boolean hasRegionCollection = (searchApi == regionApi && regionCollection != null);
|
||||||
if (hasRegionCollection) {
|
if (hasRegionCollection) {
|
||||||
apiResults = regionCollection.getCurrentSearchResults();
|
apiResults = regionCollection.getCurrentSearchResults();
|
||||||
} else {
|
} else {
|
||||||
apiResults = results;
|
apiResults = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
regionResultApi = null;
|
regionResultApi = null;
|
||||||
regionResultCollection = null;
|
regionResultCollection = null;
|
||||||
results = new ArrayList<>();
|
results = new ArrayList<>();
|
||||||
|
showApiResults(apiResults, phrase, hasRegionCollection);
|
||||||
app.runInUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!paused) {
|
|
||||||
boolean appended = false;
|
|
||||||
if (getResultCollection() == null || getResultCollection().getPhrase() != phrase) {
|
|
||||||
SearchResultCollection resCollection =
|
|
||||||
new SearchResultCollection(phrase);
|
|
||||||
resCollection.addSearchResults(results, true, true);
|
|
||||||
setResultCollection(resCollection);
|
|
||||||
} else {
|
|
||||||
getResultCollection().addSearchResults(apiResults, false, true );
|
|
||||||
appended = true;
|
|
||||||
}
|
|
||||||
if (!hasRegionCollection) {
|
|
||||||
updateSearchResult(getResultCollection(), appended);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case SEARCH_API_REGION_FINISHED:
|
case SEARCH_API_REGION_FINISHED:
|
||||||
regionResultApi = (SearchCoreAPI) object.object;
|
regionResultApi = (SearchCoreAPI) object.object;
|
||||||
final SearchPhrase regionPhrase = object.requiredSearchPhrase;
|
final SearchPhrase regionPhrase = object.requiredSearchPhrase;
|
||||||
regionResultCollection = new SearchResultCollection(regionPhrase);
|
regionResultCollection = new SearchResultCollection(regionPhrase);
|
||||||
regionResultCollection.addSearchResults(results, true, true);
|
regionResultCollection.addSearchResults(results, true, true);
|
||||||
app.runInUIThread(new Runnable() {
|
showRegionResults(regionPhrase, regionResultCollection);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!paused) {
|
|
||||||
boolean appended = getResultCollection() != null && getResultCollection().getPhrase() == regionPhrase;
|
|
||||||
if (appended) {
|
|
||||||
SearchResultCollection resCollection =
|
|
||||||
getResultCollection().combineWithCollection(regionResultCollection, false, true);
|
|
||||||
updateSearchResult(resCollection, true);
|
|
||||||
} else {
|
|
||||||
updateSearchResult(regionResultCollection, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case PARTIAL_LOCATION:
|
case PARTIAL_LOCATION:
|
||||||
app.runInUIThread(new Runnable() {
|
showLocationToolbar();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
foundPartialLocation = true;
|
|
||||||
updateToolbarButton();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
results.add(object);
|
results.add(object);
|
||||||
|
@ -849,12 +804,65 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return paused;
|
return paused;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showLocationToolbar() {
|
||||||
|
app.runInUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
foundPartialLocation = true;
|
||||||
|
updateToolbarButton();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showApiResults(final List<SearchResult> apiResults, final SearchPhrase phrase,
|
||||||
|
final boolean hasRegionCollection) {
|
||||||
|
app.runInUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!paused) {
|
||||||
|
boolean appended = false;
|
||||||
|
if (getResultCollection() == null || getResultCollection().getPhrase() != phrase) {
|
||||||
|
SearchResultCollection resCollection = new SearchResultCollection(phrase);
|
||||||
|
resCollection.addSearchResults(apiResults, true, true);
|
||||||
|
setResultCollection(resCollection);
|
||||||
|
} else {
|
||||||
|
getResultCollection().addSearchResults(apiResults, false, true );
|
||||||
|
appended = true;
|
||||||
|
}
|
||||||
|
if (!hasRegionCollection) {
|
||||||
|
updateSearchResult(getResultCollection(), appended);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showRegionResults(final SearchPhrase regionPhrase, final SearchResultCollection regionResultCollection) {
|
||||||
|
app.runInUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!paused) {
|
||||||
|
boolean appended = getResultCollection() != null && getResultCollection().getPhrase() == regionPhrase;
|
||||||
|
if (appended) {
|
||||||
|
SearchResultCollection resCollection =
|
||||||
|
getResultCollection().combineWithCollection(regionResultCollection, false, true);
|
||||||
|
updateSearchResult(resCollection, true);
|
||||||
|
} else {
|
||||||
|
updateSearchResult(regionResultCollection, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void completeQueryWithObject(SearchResult sr) {
|
public void completeQueryWithObject(SearchResult sr) {
|
||||||
searchUICore.selectSearchResult(sr);
|
searchUICore.selectSearchResult(sr);
|
||||||
|
|
Loading…
Reference in a new issue