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.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
@ -42,7 +42,7 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
});
TextView contentTv = (TextView) mainView.findViewById(R.id.content_text_view);
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper().getArticle(searchResult.getCityId(),
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper().getArticle(searchResult.getCityId(),
searchResult.getLang().get(0));
contentTv.setText(new SpannableString(Html.fromHtml(article.getContent())));

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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