Add small fixes to wikivoyage search logic

This commit is contained in:
alex 2018-03-29 13:46:52 +03:00
parent f19e0fdd28
commit 642f0aeafa
2 changed files with 23 additions and 27 deletions

View file

@ -131,18 +131,26 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
public void onPause() {
super.onPause();
paused = true;
searchHelper.unregisterListener(this);
searchHelper.unregisterListener();
}
@Override
public void onSearchStarted() {
switchProgressBarVisibility(true);
getMyApplication().runInUIThread(new Runnable() {
public void run() {
switchProgressBarVisibility(true);
}
});
}
@Override
public void onSearchFinished(@Nullable List<WikivoyageSearchResult> results) {
adapter.setItems(results);
switchProgressBarVisibility(false);
public void onSearchFinished(@Nullable final List<WikivoyageSearchResult> results) {
getMyApplication().runInUIThread(new Runnable() {
public void run() {
adapter.setItems(results);
switchProgressBarVisibility(false);
}
});
}
private void cancelSearch() {

View file

@ -6,9 +6,7 @@ import net.osmand.ResultMatcher;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -20,18 +18,18 @@ public class WikivoyageSearchHelper {
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
private OsmandApplication application;
private Set<SearchListener> listeners = new HashSet<>();
private SearchListener listener;
WikivoyageSearchHelper(OsmandApplication application) {
this.application = application;
}
public void registerListener(SearchListener listener) {
listeners.add(listener);
this.listener = listener;
}
public void unregisterListener(SearchListener listener) {
listeners.remove(listener);
public void unregisterListener() {
this.listener = null;
}
public void search(final String query, final ResultMatcher<WikivoyageSearchResult> rm) {
@ -39,14 +37,9 @@ public class WikivoyageSearchHelper {
@Override
public void run() {
try {
application.runInUIThread(new Runnable() {
@Override
public void run() {
for (SearchListener listener : listeners) {
listener.onSearchStarted();
}
}
});
if (listener != null) {
listener.onSearchStarted();
}
rm.publish(null);
@ -60,14 +53,9 @@ public class WikivoyageSearchHelper {
final List<WikivoyageSearchResult> results = application.getWikivoyageDbHelper().search(query);
application.runInUIThread(new Runnable() {
@Override
public void run() {
for (SearchListener listener : listeners) {
listener.onSearchFinished(results);
}
}
});
if (listener != null) {
listener.onSearchFinished(results);
}
} catch (InterruptedException e) {
e.printStackTrace();
}