Add header to wikivoyage search list
This commit is contained in:
parent
8df9966f42
commit
f0374526a0
6 changed files with 94 additions and 20 deletions
29
OsmAnd/res/layout/wikivoyage_search_list_header.xml
Normal file
29
OsmAnd/res/layout/wikivoyage_search_list_header.xml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include layout="@layout/list_item_divider"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/wikivoyage_search_list_header_height"
|
||||||
|
android:background="?attr/wikivoyage_card_bg_color"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/content_padding"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
tools:text="Search results"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -193,4 +193,6 @@
|
||||||
<dimen name="coords_input_show_hide_keyboard_btn_padding">19dp</dimen>
|
<dimen name="coords_input_show_hide_keyboard_btn_padding">19dp</dimen>
|
||||||
|
|
||||||
<dimen name="toolbar_height">84dp</dimen>
|
<dimen name="toolbar_height">84dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="wikivoyage_search_list_header_height">54dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -267,4 +267,6 @@
|
||||||
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
||||||
|
|
||||||
<dimen name="toolbar_height">56dp</dimen>
|
<dimen name="toolbar_height">56dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="wikivoyage_search_list_header_height">36dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -9,6 +9,7 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="shared_string_result">Result</string>
|
||||||
<string name="use_two_digits_longitude">Use two digits longitude</string>
|
<string name="use_two_digits_longitude">Use two digits longitude</string>
|
||||||
<string name="shared_string_travel">Travel</string>
|
<string name="shared_string_travel">Travel</string>
|
||||||
<string name="waypoints_removed_from_map_markers">Waypoints removed from map markers</string>
|
<string name="waypoints_removed_from_map_markers">Waypoints removed from map markers</string>
|
||||||
|
|
|
@ -17,11 +17,15 @@ import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecyclerViewAdapter.ViewHolder> {
|
public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private static final int HEADER_TYPE = 0;
|
||||||
|
private static final int ITEM_TYPE = 1;
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
private IconsCache iconsCache;
|
private IconsCache iconsCache;
|
||||||
|
|
||||||
private List<WikivoyageSearchResult> items = new ArrayList<>();
|
private List<Object> items = new ArrayList<>();
|
||||||
|
|
||||||
private View.OnClickListener onItemClickListener;
|
private View.OnClickListener onItemClickListener;
|
||||||
|
|
||||||
|
@ -30,28 +34,49 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchRecyclerViewAdapter(OsmandApplication app) {
|
SearchRecyclerViewAdapter(OsmandApplication app) {
|
||||||
|
this.app = app;
|
||||||
this.iconsCache = app.getIconsCache();
|
this.iconsCache = app.getIconsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||||
View itemView = LayoutInflater.from(viewGroup.getContext())
|
boolean header = viewType == HEADER_TYPE;
|
||||||
.inflate(R.layout.wikivoyage_search_list_item, viewGroup, false);
|
int layoutId = header ? R.layout.wikivoyage_search_list_header : R.layout.wikivoyage_search_list_item;
|
||||||
|
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
|
||||||
|
if (header) {
|
||||||
|
return new HeaderVH(itemView);
|
||||||
|
}
|
||||||
itemView.setOnClickListener(onItemClickListener);
|
itemView.setOnClickListener(onItemClickListener);
|
||||||
return new ViewHolder(itemView);
|
return new ItemVH(itemView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int pos) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int pos) {
|
||||||
boolean lastItem = pos == getItemCount() - 1;
|
if (viewHolder instanceof HeaderVH) {
|
||||||
|
((HeaderVH) viewHolder).title.setText((String) getItem(pos));
|
||||||
|
} else {
|
||||||
|
ItemVH holder = (ItemVH) viewHolder;
|
||||||
|
boolean lastItem = pos == getItemCount() - 1;
|
||||||
|
|
||||||
WikivoyageSearchResult item = items.get(pos);
|
WikivoyageSearchResult item = (WikivoyageSearchResult) getItem(pos);
|
||||||
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color));
|
holder.icon.setImageDrawable(
|
||||||
holder.title.setText(item.getArticleTitle().toString());
|
iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color)
|
||||||
holder.description.setText(item.getLang().toString());
|
);
|
||||||
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
holder.title.setText(item.getArticleTitle().toString());
|
||||||
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
holder.description.setText(item.getLang().toString());
|
||||||
|
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||||
|
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
Object item = getItem(position);
|
||||||
|
if (item instanceof String) {
|
||||||
|
return HEADER_TYPE;
|
||||||
|
}
|
||||||
|
return ITEM_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,20 +84,31 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WikivoyageSearchResult getItem(int pos) {
|
public Object getItem(int pos) {
|
||||||
return items.get(pos);
|
return items.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(@Nullable List<WikivoyageSearchResult> items) {
|
public void setItems(@Nullable List<WikivoyageSearchResult> items) {
|
||||||
if (items == null) {
|
if (items == null || items.isEmpty()) {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
} else {
|
} else {
|
||||||
this.items = items;
|
this.items.add(app.getString(R.string.shared_string_result));
|
||||||
|
this.items.addAll(items);
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class HeaderVH extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
final TextView title;
|
||||||
|
|
||||||
|
public HeaderVH(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
title = (TextView) itemView.findViewById(R.id.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ItemVH extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
final ImageView icon;
|
final ImageView icon;
|
||||||
final TextView title;
|
final TextView title;
|
||||||
|
@ -80,7 +116,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
||||||
final View divider;
|
final View divider;
|
||||||
final View shadow;
|
final View shadow;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ItemVH(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||||
title = (TextView) itemView.findViewById(R.id.title);
|
title = (TextView) itemView.findViewById(R.id.title);
|
||||||
|
|
|
@ -98,7 +98,11 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int pos = rv.getChildAdapterPosition(v);
|
int pos = rv.getChildAdapterPosition(v);
|
||||||
if (pos != RecyclerView.NO_POSITION) {
|
if (pos != RecyclerView.NO_POSITION) {
|
||||||
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), adapter.getItem(pos));
|
Object item = adapter.getItem(pos);
|
||||||
|
if (item instanceof WikivoyageSearchResult) {
|
||||||
|
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(),
|
||||||
|
(WikivoyageSearchResult) item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue