Show first three langs in wikivoyage search list items
This commit is contained in:
parent
b4ed49e4a7
commit
8147966949
3 changed files with 49 additions and 22 deletions
|
@ -45,14 +45,33 @@
|
|||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Amsterdam"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="Amstellend North Holland"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/left_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="Amstellend North Holland"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/right_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="En, Ru, De, ..."/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -3,11 +3,15 @@ package net.osmand.plus.wikivoyage.data;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WikivoyageSearchResult implements Parcelable {
|
||||
|
||||
private static final int SHOW_LANGS = 3;
|
||||
|
||||
List<String> searchTerms = new ArrayList<>();
|
||||
long cityId;
|
||||
List<String> articleTitles = new ArrayList<>();
|
||||
|
@ -46,6 +50,18 @@ public class WikivoyageSearchResult implements Parcelable {
|
|||
return isPartOf;
|
||||
}
|
||||
|
||||
public String getFirstLangsString() {
|
||||
StringBuilder res = new StringBuilder();
|
||||
int limit = Math.min(SHOW_LANGS, langs.size());
|
||||
for (int i = 0; i < limit; i++) {
|
||||
res.append(Algorithms.capitalizeFirstLetter(langs.get(i)));
|
||||
if (i != limit - 1) {
|
||||
res.append(", ");
|
||||
}
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.search;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -14,7 +13,6 @@ import net.osmand.plus.IconsCache;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -66,7 +64,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color)
|
||||
);
|
||||
holder.title.setText(item.getArticleTitles().get(0));
|
||||
holder.description.setText(createItemDescription(item));
|
||||
holder.leftDescr.setText(item.getIsPartOf());
|
||||
holder.rightDescr.setText(item.getFirstLangsString());
|
||||
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
@ -99,15 +98,6 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
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 {
|
||||
|
||||
final TextView title;
|
||||
|
@ -122,7 +112,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
|
||||
final ImageView icon;
|
||||
final TextView title;
|
||||
final TextView description;
|
||||
final TextView leftDescr;
|
||||
final TextView rightDescr;
|
||||
final View divider;
|
||||
final View shadow;
|
||||
|
||||
|
@ -130,7 +121,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
super(itemView);
|
||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
description = (TextView) itemView.findViewById(R.id.description);
|
||||
leftDescr = (TextView) itemView.findViewById(R.id.left_description);
|
||||
rightDescr = (TextView) itemView.findViewById(R.id.right_description);
|
||||
divider = itemView.findViewById(R.id.divider);
|
||||
shadow = itemView.findViewById(R.id.shadow);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue