Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-29 12:51:02 +02:00
commit 7807b54504
2 changed files with 23 additions and 27 deletions

View file

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

View file

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