Merge pull request #5224 from osmandapp/WikivoyageImprovements

change sizes and padding of explistview items
This commit is contained in:
Alexander Sytnyk 2018-04-12 14:31:32 +03:00 committed by GitHub
commit ab6c0fc734
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 49 deletions

View file

@ -74,12 +74,6 @@
android:layout_height="10dp" android:layout_height="10dp"
android:background="@drawable/bg_contextmenu_shadow_top_light" /> android:background="@drawable/bg_contextmenu_shadow_top_light" />
<View
android:id="@+id/bottom_row_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/wikivoyage_bottom_bar_divider_color"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height" android:layout_height="@dimen/bottom_sheet_cancel_button_height"
@ -98,7 +92,7 @@
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"
@ -107,7 +101,7 @@
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:drawableLeft="@drawable/ic_action_list_header" tools:drawableLeft="@drawable/ic_action_list_header"
tools:drawableTint="?attr/wikivoyage_active_color" tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute"/> tools:ignore="UnusedAttribute" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/save_button" android:id="@+id/save_button"
@ -123,7 +117,7 @@
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"
@ -131,7 +125,7 @@
tools:drawableRight="@drawable/ic_action_read_later_fill" tools:drawableRight="@drawable/ic_action_read_later_fill"
tools:drawableTint="?attr/wikivoyage_active_color" tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute" tools:ignore="UnusedAttribute"
tools:text="Save"/> tools:text="Save" />
</LinearLayout> </LinearLayout>

View file

@ -1,23 +1,56 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="@dimen/bottom_sheet_list_item_height" android:layout_width="match_parent"
android:background="?attr/expandable_list_item_background" android:layout_height="wrap_content"
android:orientation="vertical"> android:background="?attr/selectableItemBackground"
android:orientation="vertical">
<TextView <View
android:id="@+id/item_label" android:id="@+id/upper_row_divider"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_list_item_height" android:layout_height="1dp"
android:layout_gravity="center_vertical" android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
android:drawablePadding="@dimen/showAllButtonMarginRight" android:background="?attr/wikivoyage_card_divider_color" />
android:gravity="center"
android:paddingLeft="@dimen/showAllButtonMarginRight" <LinearLayout
android:textColor="?android:textColorPrimary" android:layout_width="match_parent"
android:textSize="@dimen/default_list_text_size" android:layout_height="wrap_content"
tools:drawableStart="@drawable/ic_action_list_sort" android:orientation="horizontal">
tools:text="@string/shared_string_contents"
tools:textStyle="bold" /> <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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:scaleType="center"
tools:src="@drawable/ic_action_arrow_up" />
</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> </LinearLayout>

View file

@ -10,11 +10,10 @@ 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.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -36,6 +35,8 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
public static final int REQUEST_LINK_CODE = 0; public static final int REQUEST_LINK_CODE = 0;
private ExpandableListView expListView;
private LinkedHashMap<String, String> map; private LinkedHashMap<String, String> map;
private String link; private String link;
@ -63,11 +64,14 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
items.add(new TitleItem(getString(R.string.shared_string_contents))); items.add(new TitleItem(getString(R.string.shared_string_contents)));
ExpandableListView expListView = new ExpandableListView(getContext()); expListView = new ExpandableListView(getContext());
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.setSelector(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)
@ -83,23 +87,12 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
return false; return false;
} }
}); });
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
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 @Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
link = map.get(listDataHeader.get(groupPosition)); link = map.get(listDataHeader.get(groupPosition));
sendResult(); sendResult();
if (listDataChild.get(listDataHeader.get(groupPosition)) == null) { dismiss();
dismiss();
}
return false; return false;
} }
}); });
@ -158,7 +151,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
@ -181,6 +174,14 @@ 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);
convertView.findViewById(R.id.upper_row_divider).setVisibility(View.GONE);
txtListChild.setTypeface(null);
if (childPosition == listDataChild.get(listDataHeader.get(groupPosition)).size() - 1) {
convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.VISIBLE);
} else {
convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.GONE);
}
return convertView; return convertView;
} }
@ -206,18 +207,36 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
} }
@Override @Override
public View getGroupView(int groupPosition, boolean isExpanded, public View getGroupView(final int groupPosition, final 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_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);
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, light);
ImageView indicator = (ImageView) convertView.findViewById(R.id.explist_indicator);
indicator.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isExpanded){
expListView.collapseGroup(groupPosition);
} else {
expListView.expandGroup(groupPosition);
}
}
});
if (isExpanded) {
convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.GONE);
} else {
convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.VISIBLE);
}
return convertView; return convertView;
} }
@ -231,4 +250,4 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
return true; return true;
} }
} }
} }