Merge pull request #5293 from osmandapp/WikivoyageExploreCards

Wikivoyage explore cards
This commit is contained in:
vshcherb 2018-04-27 15:32:12 +02:00 committed by GitHub
commit 492adbfbf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 64 deletions

View file

@ -1,6 +1,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
@ -16,21 +17,19 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:paddingTop="22dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:text="@string/wikivoyage_download_pics"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
android:textSize="@dimen/dialog_header_text_size"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_content_padding"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:textSize="@dimen/empty_state_text_size"
android:textColor="?attr/wikivoyage_primary_text_color"
android:text="@string/wikivoyage_download_pics" />
</LinearLayout>
@ -56,54 +55,87 @@
android:paddingRight="@dimen/list_header_padding"
android:paddingEnd="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:orientation="horizontal">
android:orientation="horizontal"
android:baselineAligned="false">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_no"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_dont"/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small"
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
android:layout_weight="1"
android:background="@drawable/wikivoyage_secondary_btn_bg">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_wifi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_only_with_wifi"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_no"
android:layout_width="match_parent"
android:layout_height="@dimen/wikivoyage_card_button_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/shared_string_dont"
android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_do"/>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small"
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
android:layout_weight="1"
android:background="@drawable/wikivoyage_secondary_btn_bg">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_wifi"
android:layout_width="match_parent"
android:layout_height="@dimen/wikivoyage_card_button_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/shared_string_only_with_wifi"
android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/wikivoyage_primary_btn_bg">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_yes"
android:layout_width="match_parent"
android:layout_height="@dimen/wikivoyage_card_button_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/shared_string_do"
android:textColor="?attr/wikivoyage_primary_btn_text_color"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -30,6 +30,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.R;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageWebViewClient;
@ -40,6 +41,8 @@ import net.osmand.util.Algorithms;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragment {
@ -321,22 +324,26 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
if (langs == null) {
return;
}
final PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.END);
for (final String lang : langs) {
Map<String, String> names = new HashMap<>();
for (String n : langs) {
names.put(n, FileNameTranslationHelper.getVoiceName(getContext(), n));
}
for (final Map.Entry<String, String> e : names.entrySet()) {
final String lang = e.getValue();
final String langKey = e.getKey();
MenuItem item = popup.getMenu().add(lang);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (!selectedLang.equals(lang)) {
selectedLang = lang;
if (!selectedLang.equals(langKey)) {
selectedLang = langKey;
populateArticle();
}
return true;
}
});
}
popup.show();
}
@ -408,7 +415,10 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
String url = TravelArticle.getImageUrl(imageTitle, false);
sb.append("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
}
sb.append("<div class=\"main\">\n");
String nightModeClass = nightMode?"nightmode":"";
sb.append("<div class=\"main "+nightModeClass+"\">\n");
sb.append("<h1>").append(article.getTitle()).append("</h1>");
sb.append(article.getContent());
sb.append(FOOTER_INNER);