Change wikivoyage search list item layout

This commit is contained in:
Alex Sytnyk 2018-04-02 13:11:02 +03:00
parent cfe53d4d7f
commit 56cf31eb0e
6 changed files with 78 additions and 70 deletions

View file

@ -29,6 +29,7 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</LinearLayout>

View file

@ -1,70 +1,64 @@
<?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:background="?attr/selectableItemBackground"
android:orientation="vertical"
android:padding="8dp">
android:background="?attr/wikivoyage_card_bg_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<TextView
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="search_term: "/>
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
tools:src="@drawable/ic_action_placeholder_city"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
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>
<TextView
android:id="@+id/search_term"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="city_id: "/>
<TextView
android:id="@+id/city_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="article_title: "/>
<TextView
android:id="@+id/article_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lang: "/>
<TextView
android:id="@+id/lang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
android:layout_height="1dp"
android:layout_marginLeft="@dimen/bottom_sheet_selected_item_title_height"
android:layout_marginStart="@dimen/bottom_sheet_selected_item_title_height"
android:background="?attr/wikivoyage_card_divider_color"
android:focusable="false"/>
</LinearLayout>

View file

@ -67,6 +67,7 @@
<attr name="wikivoyage_bg_color" format="reference"/>
<attr name="wikivoyage_card_bg_color" format="reference"/>
<attr name="wikivoyage_card_divider_color" format="reference"/>
<attr name="wikivoyage_app_bar_color" format="reference"/>
<attr name="wikivoyage_app_bar_text_color" format="reference"/>
<attr name="wikivoyage_active_color" format="reference"/>

View file

@ -199,6 +199,7 @@
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_light</item>
<item name="wikivoyage_card_bg_color">@color/wikivoyage_card_bg_light</item>
<item name="wikivoyage_card_divider_color">@color/wikivoyage_card_divider_light</item>
<item name="wikivoyage_app_bar_color">@color/wikivoyage_app_bar_light</item>
<item name="wikivoyage_app_bar_text_color">@color/wikivoyage_app_bar_text_light</item>
<item name="wikivoyage_active_color">@color/wikivoyage_active_light</item>
@ -389,6 +390,7 @@
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_dark</item>
<item name="wikivoyage_card_bg_color">@color/wikivoyage_card_bg_dark</item>
<item name="wikivoyage_card_divider_color">@color/wikivoyage_card_divider_dark</item>
<item name="wikivoyage_app_bar_color">@color/wikivoyage_app_bar_dark</item>
<item name="wikivoyage_app_bar_text_color">@color/wikivoyage_app_bar_text_dark</item>
<item name="wikivoyage_active_color">@color/wikivoyage_active_dark</item>

View file

@ -6,8 +6,11 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
@ -16,6 +19,8 @@ import java.util.List;
public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecyclerViewAdapter.ViewHolder> {
private IconsCache iconsCache;
private List<WikivoyageSearchResult> items = new ArrayList<>();
private View.OnClickListener onItemClickListener;
@ -24,6 +29,10 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
this.onItemClickListener = onItemClickListener;
}
SearchRecyclerViewAdapter(OsmandApplication app) {
this.iconsCache = app.getIconsCache();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
@ -34,13 +43,14 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
WikivoyageSearchResult item = items.get(i);
// FIXME
viewHolder.searchTerm.setText(item.getSearchTerm().toString());
viewHolder.cityId.setText(String.valueOf(item.getCityId()));
viewHolder.articleTitle.setText(item.getArticleTitle().toString());
viewHolder.lang.setText(item.getLang().toString());
public void onBindViewHolder(@NonNull ViewHolder holder, int pos) {
boolean lastItem = pos == getItemCount() - 1;
WikivoyageSearchResult item = items.get(pos);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color));
holder.title.setText(item.getArticleTitle().toString());
holder.description.setText(item.getLang().toString());
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
}
@Override
@ -63,17 +73,17 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
static class ViewHolder extends RecyclerView.ViewHolder {
final TextView searchTerm;
final TextView cityId;
final TextView articleTitle;
final TextView lang;
final ImageView icon;
final TextView title;
final TextView description;
final View divider;
public ViewHolder(View itemView) {
super(itemView);
searchTerm = (TextView) itemView.findViewById(R.id.search_term);
cityId = (TextView) itemView.findViewById(R.id.city_id);
articleTitle = (TextView) itemView.findViewById(R.id.article_title);
lang = (TextView) itemView.findViewById(R.id.lang);
icon = (ImageView) itemView.findViewById(R.id.icon);
title = (TextView) itemView.findViewById(R.id.title);
description = (TextView) itemView.findViewById(R.id.description);
divider = itemView.findViewById(R.id.divider);
}
}
}

View file

@ -89,7 +89,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
}
});
adapter = new SearchRecyclerViewAdapter();
adapter = new SearchRecyclerViewAdapter(getMyApplication());
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setAdapter(adapter);