Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-29 10:45:32 +02:00
commit e7f96a208f
7 changed files with 39 additions and 40 deletions

View file

@ -13,8 +13,8 @@ import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle; import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment { public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {

View file

@ -2,17 +2,16 @@ package net.osmand.plus.wikivoyage.data;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import net.osmand.Collator; import net.osmand.Collator;
import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.OsmAndCollator; import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import gnu.trove.map.hash.TLongObjectHashMap;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -21,7 +20,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import gnu.trove.map.hash.TLongObjectHashMap;
public class WikivoyageDbHelper { public class WikivoyageDbHelper {
@ -77,13 +77,13 @@ public class WikivoyageDbHelper {
} }
@NonNull @NonNull
public Collection<WikivoyageSearchResult> search(final String searchQuery) { public List<WikivoyageSearchResult> search(final String searchQuery) {
List<WikivoyageSearchResult> res = new ArrayList<>(); List<WikivoyageSearchResult> res = new ArrayList<>();
SQLiteConnection conn = openConnection(); SQLiteConnection conn = openConnection();
if (conn != null) { if (conn != null) {
try { try {
String dbQuery = SEARCH_TABLE_SELECT + " WHERE " + SEARCH_COL_SEARCH_TERM + " LIKE ?"; String dbQuery = SEARCH_TABLE_SELECT + " WHERE " + SEARCH_COL_SEARCH_TERM + " LIKE ?";
SQLiteCursor cursor = conn.rawQuery(dbQuery, new String[] { searchQuery + "%" }); SQLiteCursor cursor = conn.rawQuery(dbQuery, new String[]{searchQuery + "%"});
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
res.add(readSearchResult(cursor)); res.add(readSearchResult(cursor));
@ -94,22 +94,21 @@ public class WikivoyageDbHelper {
conn.close(); conn.close();
} }
} }
List<WikivoyageSearchResult> list = new ArrayList(groupSearchResultsByCityId(res));
List<WikivoyageSearchResult> list = new ArrayList<>(groupSearchResultsByCityId(res));
Collections.sort(list, new Comparator<WikivoyageSearchResult>() { Collections.sort(list, new Comparator<WikivoyageSearchResult>() {
@Override @Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) { public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
boolean c1 = CollatorStringMatcher.cmatches(collator, searchQuery, o1.articleTitle.get(0), boolean c1 = CollatorStringMatcher.cmatches(collator, searchQuery, o1.articleTitle.get(0),
StringMatcherMode.CHECK_ONLY_STARTS_WITH); StringMatcherMode.CHECK_ONLY_STARTS_WITH);
boolean c2 = CollatorStringMatcher.cmatches(collator, searchQuery, o2.articleTitle.get(0), boolean c2 = CollatorStringMatcher.cmatches(collator, searchQuery, o2.articleTitle.get(0),
StringMatcherMode.CHECK_ONLY_STARTS_WITH); StringMatcherMode.CHECK_ONLY_STARTS_WITH);
if(c1 == c2) { if (c1 == c2) {
return collator.compare(o1.articleTitle.get(0), o2.articleTitle.get(0)); return collator.compare(o1.articleTitle.get(0), o2.articleTitle.get(0));
} } else if (c1) {
if(c1) {
return -1; return -1;
} else if(c2) { } else if (c2) {
return 1; return 1;
} }
return 0; return 0;
@ -121,15 +120,15 @@ public class WikivoyageDbHelper {
private Collection<WikivoyageSearchResult> groupSearchResultsByCityId(List<WikivoyageSearchResult> res) { private Collection<WikivoyageSearchResult> groupSearchResultsByCityId(List<WikivoyageSearchResult> res) {
String baseLng = application.getLanguage(); String baseLng = application.getLanguage();
TLongObjectHashMap<WikivoyageSearchResult> wikivoyage = new TLongObjectHashMap<WikivoyageSearchResult>(); TLongObjectHashMap<WikivoyageSearchResult> wikivoyage = new TLongObjectHashMap<>();
for(WikivoyageSearchResult rs: res) { for (WikivoyageSearchResult rs : res) {
WikivoyageSearchResult prev = wikivoyage.get(rs.cityId); WikivoyageSearchResult prev = wikivoyage.get(rs.cityId);
if(prev != null) { if (prev != null) {
int insInd = prev.langs.size(); int insInd = prev.langs.size();
if(rs.getLang().get(0).equals(baseLng)) { if (rs.getLang().get(0).equals(baseLng)) {
insInd = 0; insInd = 0;
} else if(rs.getLang().get(0).equals("en")) { } else if (rs.getLang().get(0).equals("en")) {
if(!prev.getLang().get(0).equals(baseLng)) { if (!prev.getLang().get(0).equals(baseLng)) {
insInd = 0; insInd = 0;
} else { } else {
insInd = 1; insInd = 1;
@ -143,7 +142,6 @@ public class WikivoyageDbHelper {
} }
} }
return wikivoyage.valueCollection(); return wikivoyage.valueCollection();
} }
@Nullable @Nullable
@ -181,6 +179,7 @@ public class WikivoyageDbHelper {
res.cityId = cursor.getLong(1); res.cityId = cursor.getLong(1);
res.articleTitle.add(cursor.getString(2)); res.articleTitle.add(cursor.getString(2));
res.langs.add(cursor.getString(3)); res.langs.add(cursor.getString(3));
return res; return res;
} }

View file

@ -10,7 +10,6 @@ public class WikivoyageSearchResult {
List<String> articleTitle = new ArrayList<>(); List<String> articleTitle = new ArrayList<>();
List<String> langs = new ArrayList<>(); List<String> langs = new ArrayList<>();
public List<String> getSearchTerm() { public List<String> getSearchTerm() {
return searchTerm; return searchTerm;
} }

View file

@ -6,11 +6,11 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult; import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecyclerViewAdapter.ViewHolder> { public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecyclerViewAdapter.ViewHolder> {
@ -50,11 +50,11 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
return items.get(pos); return items.get(pos);
} }
public void setItems(@Nullable Collection<WikivoyageSearchResult> items) { public void setItems(@Nullable List<WikivoyageSearchResult> items) {
if (items == null) { if (items == null) {
this.items.clear(); this.items.clear();
} else { } else {
this.items = new ArrayList<>(items); this.items = items;
} }
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -15,6 +15,7 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.base.BaseOsmAndDialogFragment;
@ -22,7 +23,6 @@ import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult; import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import net.osmand.plus.wikivoyage.search.WikivoyageSearchHelper.SearchListener; import net.osmand.plus.wikivoyage.search.WikivoyageSearchHelper.SearchListener;
import java.util.Collection;
import java.util.List; import java.util.List;
public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment implements SearchListener { public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment implements SearchListener {
@ -140,7 +140,7 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
} }
@Override @Override
public void onSearchFinished(@Nullable Collection<WikivoyageSearchResult> results) { public void onSearchFinished(@Nullable List<WikivoyageSearchResult> results) {
adapter.setItems(results); adapter.setItems(results);
switchProgressBarVisibility(false); switchProgressBarVisibility(false);
} }

View file

@ -2,11 +2,12 @@ package net.osmand.plus.wikivoyage.search;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
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.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -20,7 +21,7 @@ public class WikivoyageSearchHelper {
private LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(); private LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
private ThreadPoolExecutor singleThreadExecutor = private ThreadPoolExecutor singleThreadExecutor =
new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, workQueue); new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, workQueue);
private AsyncTask<Void, Void, Collection<WikivoyageSearchResult>> currentTask; private AsyncTask<Void, Void, List<WikivoyageSearchResult>> currentTask;
private OsmandApplication application; private OsmandApplication application;
private Set<SearchListener> listeners = new HashSet<>(); private Set<SearchListener> listeners = new HashSet<>();
@ -54,10 +55,10 @@ public class WikivoyageSearchHelper {
void onSearchStarted(); void onSearchStarted();
void onSearchFinished(@Nullable Collection<WikivoyageSearchResult> results); void onSearchFinished(@Nullable List<WikivoyageSearchResult> results);
} }
private class SearchAsyncTask extends AsyncTask<Void, Void, Collection<WikivoyageSearchResult>> { private class SearchAsyncTask extends AsyncTask<Void, Void, List<WikivoyageSearchResult>> {
private String query; private String query;
@ -74,7 +75,7 @@ public class WikivoyageSearchHelper {
} }
@Override @Override
protected Collection<WikivoyageSearchResult> doInBackground(Void... voids) { protected List<WikivoyageSearchResult> doInBackground(Void... voids) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime <= TIMEOUT_BETWEEN_CHARS) { while (System.currentTimeMillis() - startTime <= TIMEOUT_BETWEEN_CHARS) {
if (isCancelled()) { if (isCancelled()) {
@ -91,7 +92,7 @@ public class WikivoyageSearchHelper {
} }
@Override @Override
protected void onPostExecute(Collection<WikivoyageSearchResult> results) { protected void onPostExecute(List<WikivoyageSearchResult> results) {
super.onPostExecute(results); super.onPostExecute(results);
for (SearchListener listener : listeners) { for (SearchListener listener : listeners) {
listener.onSearchFinished(results); listener.onSearchFinished(results);

View file

@ -1,8 +1,8 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 26 compileSdkVersion 27
buildToolsVersion "26.0.2" buildToolsVersion "27.0.3"
dexOptions { dexOptions {
jumboMode true jumboMode true