Add field "isPartOf" to WikivoyageSearchResult

This commit is contained in:
Alex Sytnyk 2018-04-02 17:48:06 +03:00
parent d445faff60
commit 038f9d5615
3 changed files with 33 additions and 9 deletions

View file

@ -60,12 +60,20 @@ public class WikivoyageDbHelper {
private static final String SEARCH_COL_ARTICLE_TITLE = "article_title"; private static final String SEARCH_COL_ARTICLE_TITLE = "article_title";
private static final String SEARCH_COL_LANG = "lang"; private static final String SEARCH_COL_LANG = "lang";
private static final String SEARCH_TABLE_SELECT = "SELECT " + private static final String SEARCH_QUERY = "SELECT " +
SEARCH_COL_SEARCH_TERM + ", " + SEARCH_COL_SEARCH_TERM + ", " +
SEARCH_COL_CITY_ID + ", " + SEARCH_TABLE_NAME + "." + SEARCH_COL_CITY_ID + ", " +
SEARCH_COL_ARTICLE_TITLE + ", " + SEARCH_COL_ARTICLE_TITLE + ", " +
SEARCH_COL_LANG + SEARCH_TABLE_NAME + "." + SEARCH_COL_LANG + ", " +
" FROM " + SEARCH_TABLE_NAME; ARTICLES_COL_IS_PART_OF +
" FROM " + SEARCH_TABLE_NAME +
" JOIN " + ARTICLES_TABLE_NAME +
" ON " + SEARCH_TABLE_NAME + "." + SEARCH_COL_ARTICLE_TITLE + " = " + ARTICLES_TABLE_NAME + "." + ARTICLES_COL_TITLE +
" AND " + SEARCH_TABLE_NAME + "." + SEARCH_COL_LANG + " = " + ARTICLES_TABLE_NAME + "." + ARTICLES_COL_LANG +
" WHERE " + SEARCH_TABLE_NAME + "." + SEARCH_COL_CITY_ID +
" IN (SELECT " + SEARCH_TABLE_NAME + "." + SEARCH_COL_CITY_ID +
" FROM " + SEARCH_TABLE_NAME +
" WHERE " + SEARCH_COL_SEARCH_TERM + " LIKE ?)";
private final OsmandApplication application; private final OsmandApplication application;
@ -82,10 +90,7 @@ public class WikivoyageDbHelper {
SQLiteConnection conn = openConnection(); SQLiteConnection conn = openConnection();
if (conn != null) { if (conn != null) {
try { try {
String dbQuery = SEARCH_TABLE_SELECT + " WHERE " + SEARCH_COL_CITY_ID + SQLiteCursor cursor = conn.rawQuery(SEARCH_QUERY, new String[]{searchQuery + "%"});
" IN (SELECT " + SEARCH_COL_CITY_ID + " FROM " + SEARCH_TABLE_NAME +
" WHERE " + SEARCH_COL_SEARCH_TERM + " LIKE ?)";
SQLiteCursor cursor = conn.rawQuery(dbQuery, new String[]{searchQuery + "%"});
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
res.add(readSearchResult(cursor)); res.add(readSearchResult(cursor));
@ -179,6 +184,7 @@ public class WikivoyageDbHelper {
res.cityId = cursor.getLong(1); res.cityId = cursor.getLong(1);
res.articleTitles.add(cursor.getString(2)); res.articleTitles.add(cursor.getString(2));
res.langs.add(cursor.getString(3)); res.langs.add(cursor.getString(3));
res.isPartOf = cursor.getString(4);
return res; return res;
} }

View file

@ -12,6 +12,7 @@ public class WikivoyageSearchResult implements Parcelable {
long cityId; long cityId;
List<String> articleTitles = new ArrayList<>(); List<String> articleTitles = new ArrayList<>();
List<String> langs = new ArrayList<>(); List<String> langs = new ArrayList<>();
String isPartOf;
WikivoyageSearchResult() { WikivoyageSearchResult() {
@ -22,6 +23,7 @@ public class WikivoyageSearchResult implements Parcelable {
cityId = in.readLong(); cityId = in.readLong();
articleTitles = in.createStringArrayList(); articleTitles = in.createStringArrayList();
langs = in.createStringArrayList(); langs = in.createStringArrayList();
isPartOf = in.readString();
} }
public List<String> getSearchTerms() { public List<String> getSearchTerms() {
@ -40,6 +42,10 @@ public class WikivoyageSearchResult implements Parcelable {
return langs; return langs;
} }
public String getIsPartOf() {
return isPartOf;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -51,6 +57,7 @@ public class WikivoyageSearchResult implements Parcelable {
dest.writeLong(cityId); dest.writeLong(cityId);
dest.writeStringList(articleTitles); dest.writeStringList(articleTitles);
dest.writeStringList(langs); dest.writeStringList(langs);
dest.writeString(isPartOf);
} }
public static final Creator<WikivoyageSearchResult> CREATOR = new Creator<WikivoyageSearchResult>() { public static final Creator<WikivoyageSearchResult> CREATOR = new Creator<WikivoyageSearchResult>() {

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.search;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,6 +14,7 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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 net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -64,7 +66,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color) iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color)
); );
holder.title.setText(item.getArticleTitles().get(0)); holder.title.setText(item.getArticleTitles().get(0));
holder.description.setText(item.getLangs().get(0)); holder.description.setText(createItemDescription(item));
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE); holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE); holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
} }
@ -97,6 +99,15 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
notifyDataSetChanged(); notifyDataSetChanged();
} }
private String createItemDescription(WikivoyageSearchResult item) {
String isPartOf = item.getIsPartOf();
StringBuilder res = new StringBuilder(Algorithms.capitalizeFirstLetter(item.getLangs().get(0)));
if (!TextUtils.isEmpty(isPartOf)) {
res.append(" \u2014 ").append(isPartOf);
}
return res.toString();
}
static class HeaderVH extends RecyclerView.ViewHolder { static class HeaderVH extends RecyclerView.ViewHolder {
final TextView title; final TextView title;