change sizes and padding of explistview items

This commit is contained in:
Chumva 2018-04-11 18:10:24 +03:00
parent 23614d3ab1
commit ad64470d14
4 changed files with 108 additions and 32 deletions

View file

@ -94,11 +94,12 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/bottom_sheet_content_padding_small" android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
android:ellipsize="end" android:ellipsize="end"
android:textAllCaps="true"
android:gravity="center_vertical" android:gravity="center_vertical"
android:letterSpacing="@dimen/text_button_letter_spacing" android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1" android:maxLines="1"
android:paddingBottom="@dimen/context_menu_padding_margin_tiny" android:paddingBottom="@dimen/context_menu_padding_margin_tiny"
android:paddingLeft="@dimen/bottom_sheet_content_padding_small" android:paddingLeft="@dimen/bottom_sheet_content_margin"
android:paddingRight="@dimen/bottom_sheet_content_padding_small" android:paddingRight="@dimen/bottom_sheet_content_padding_small"
android:paddingTop="@dimen/context_menu_padding_margin_tiny" android:paddingTop="@dimen/context_menu_padding_margin_tiny"
android:text="@string/shared_string_contents" android:text="@string/shared_string_contents"
@ -118,12 +119,13 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/bottom_sheet_content_padding_small" android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
android:ellipsize="end" android:ellipsize="end"
android:textAllCaps="true"
android:gravity="center_vertical|end" android:gravity="center_vertical|end"
android:letterSpacing="@dimen/text_button_letter_spacing" android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1" android:maxLines="1"
android:paddingBottom="@dimen/context_menu_padding_margin_tiny" android:paddingBottom="@dimen/context_menu_padding_margin_tiny"
android:paddingLeft="@dimen/bottom_sheet_content_padding_small" android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
android:paddingRight="@dimen/bottom_sheet_content_padding_small" android:paddingRight="@dimen/bottom_sheet_content_margin"
android:paddingTop="@dimen/context_menu_padding_margin_tiny" android:paddingTop="@dimen/context_menu_padding_margin_tiny"
android:textColor="?attr/wikivoyage_active_color" android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"

View file

@ -0,0 +1,22 @@
<?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/expandable_list_item_background"
android:orientation="vertical">
<TextView
android:id="@+id/item_label"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:drawablePadding="@dimen/bottom_sheet_content_margin"
android:gravity="center"
android:textSize="@dimen/default_list_text_size"
tools:drawableStart="@drawable/ic_action_list_sort"
tools:text="@string/shared_string_contents" />
</LinearLayout>

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:orientation="vertical">
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
android:background="?attr/wikivoyage_card_divider_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/item_label"
android:layout_width="0dp"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:layout_weight="1"
android:drawablePadding="@dimen/bottom_sheet_content_margin"
android:gravity="start|center_vertical"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:drawableStart="@drawable/ic_action_list_header"
tools:text="@string/shared_string_contents" />
<ImageView
android:id="@+id/explist_indicator"
android:layout_width="24dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginRight="@dimen/list_content_padding"
android:scaleType="center" />
</LinearLayout>
<View
android:id="@+id/bottom_row_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
android:background="?attr/wikivoyage_card_divider_color" />
</LinearLayout>

View file

@ -10,7 +10,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -67,7 +66,9 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
ExpandableListAdapter listAdapter = new ExpandableListAdapter(getContext(), listDataHeader, listDataChild); ExpandableListAdapter listAdapter = new ExpandableListAdapter(getContext(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter); expListView.setAdapter(listAdapter);
expListView.setChildDivider(ContextCompat.getDrawable(getContext(), R.color.color_transparent)); Drawable transparent = ContextCompat.getDrawable(getContext(), R.color.color_transparent);
expListView.setDivider(transparent);
expListView.setGroupIndicator(transparent);
expListView.setLayoutParams(new LinearLayout.LayoutParams( expListView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT) LinearLayout.LayoutParams.MATCH_PARENT)
@ -76,33 +77,13 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) { int groupPosition, int childPosition, long id) {
link = map.get(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition)); link = map.get(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition));
sendResult(); sendResult();
dismiss(); dismiss();
return false; return false;
} }
}); });
int width = AndroidUtils.getScreenWidth(getActivity());
if (android.os.Build.VERSION.SDK_INT < 18) {
expListView.setIndicatorBounds(width - (AndroidUtils.dpToPx(getContext(), 50)),
width - (AndroidUtils.dpToPx(getContext(), 10)));
} else {
expListView.setIndicatorBoundsRelative(width - (AndroidUtils.dpToPx(getContext(), 50)),
width - (AndroidUtils.dpToPx(getContext(), 10)));
}
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
link = map.get(listDataHeader.get(groupPosition));
sendResult();
if (listDataChild.get(listDataHeader.get(groupPosition)) == null) {
dismiss();
}
return false;
}
});
LinearLayout container = new LinearLayout(getContext()); LinearLayout container = new LinearLayout(getContext());
container.addView(expListView); container.addView(expListView);
@ -144,7 +125,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
private Drawable itemChildIcon; private Drawable itemChildIcon;
ExpandableListAdapter(Context context, List<String> listDataHeader, ExpandableListAdapter(Context context, List<String> listDataHeader,
LinkedHashMap<String, List<String>> listChildData) { LinkedHashMap<String, List<String>> listChildData) {
this.context = context; this.context = context;
this.listDataHeader = listDataHeader; this.listDataHeader = listDataHeader;
this.listDataChild = listChildData; this.listDataChild = listChildData;
@ -158,7 +139,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
@Override @Override
public Object getChild(int groupPosition, int childPosititon) { public Object getChild(int groupPosition, int childPosititon) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosititon); return listDataChild.get(listDataHeader.get(groupPosition)).get(childPosititon);
} }
@Override @Override
@ -172,7 +153,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
String childText = (String) getChild(groupPosition, childPosition); String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(context) convertView = LayoutInflater.from(context)
.inflate(R.layout.wikivoyage_contents_list_item, parent, false); .inflate(R.layout.wikivoyage_contents_child_list_item, parent, false);
} }
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label); TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
txtListChild.setText(childText); txtListChild.setText(childText);
@ -181,6 +162,12 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
: R.color.wikivoyage_contents_parent_icon_light)); : R.color.wikivoyage_contents_parent_icon_light));
txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null); txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null);
if (childPosition == listDataChild.get(listDataHeader.get(groupPosition)).size() - 1) {
convertView.setPadding(0, 0, 0, AndroidUtils.dpToPx(getContext(),7));
} else {
convertView.setPadding(0, 0, 0, 0);
}
return convertView; return convertView;
} }
@ -206,18 +193,30 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
} }
@Override @Override
public View getGroupView(int groupPosition, boolean isExpanded, public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) { View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition); String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(context) convertView = LayoutInflater.from(context)
.inflate(R.layout.wikivoyage_contents_list_item, parent, false); .inflate(R.layout.wikivoyage_contents_group_list_item, parent, false);
} }
boolean light = getMyApplication().getSettings().isLightContent();
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label); TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
lblListHeader.setText(headerTitle); lblListHeader.setText(headerTitle);
lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null); lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null);
lblListHeader.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
link = map.get(listDataHeader.get(groupPosition));
sendResult();
dismiss();
}
});
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, light);
if (isExpanded) {
convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.GONE);
}
return convertView; return convertView;
} }