[android] Improve wikipedia description in the place page

Shortened wiki description to show only first paragraph or only first 500 symbols of paragraph.

Closes: #3113

Signed-off-by: Andrew Shkrob <andrew.shkrob.social@yandex.by>
This commit is contained in:
Andrew Shkrob 2022-09-04 19:42:42 +02:00 committed by Alexander Borsuk
parent 591fd539eb
commit a58b3c41e4
3 changed files with 19 additions and 2 deletions

View file

@ -16,7 +16,7 @@
android:layout_marginEnd="@dimen/margin_base"
android:layout_marginStart="@dimen/margin_base"
android:layout_marginTop="@dimen/margin_base"
android:maxLength="500"
android:maxLength="@integer/place_page_description_max_length"
android:fontFamily="@string/robotoRegular"
android:textStyle="normal"
android:lineSpacingExtra="@dimen/line_spacing_extra_2"

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="guides_gallery_enable_snapping">true</bool>
<integer name="place_page_description_max_length">500</integer>
</resources>

View file

@ -93,6 +93,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
private boolean mIsDocked;
private boolean mIsFloating;
private int mDescriptionMaxLength;
// Preview.
private ViewGroup mPreview;
@ -694,6 +695,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
mIsDocked = attrArray.getBoolean(R.styleable.PlacePageView_docked, false);
mIsFloating = attrArray.getBoolean(R.styleable.PlacePageView_floating, false);
attrArray.recycle();
mDescriptionMaxLength = getResources().getInteger(R.integer.place_page_description_max_length);
}
public boolean isDocked()
@ -802,6 +804,20 @@ public class PlacePageView extends NestedScrollViewClickFixed
}
}
private Spanned getShortDescription(@NonNull MapObject mapObject)
{
String htmlDescription = mapObject.getDescription();
final int paragraphStart = htmlDescription.indexOf("<p>");
final int paragraphEnd = htmlDescription.indexOf("</p>");
if (paragraphStart == 0)
htmlDescription = htmlDescription.substring(3, paragraphEnd);
Spanned description = Html.fromHtml(htmlDescription);
if (description.length() > mDescriptionMaxLength)
description = (Spanned) description.subSequence(0, mDescriptionMaxLength);
return description;
}
private void setPlaceDescription(@NonNull MapObject mapObject)
{
boolean isBookmark = MapObject.isOfType(MapObject.BOOKMARK, mapObject);
@ -819,7 +835,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
return;
}
UiUtils.show(mPlaceDescriptionContainer, mPlaceDescriptionHeaderContainer);
mPlaceDescriptionView.setText(Html.fromHtml(mapObject.getDescription()));
mPlaceDescriptionView.setText(getShortDescription(mapObject));
}
private void setTextAndColorizeSubtitle(@NonNull MapObject mapObject)