Merge pull request #5363 from osmandapp/WikipediaInContextMenu
Wikipedia in context menu (ui)
This commit is contained in:
commit
d65529983f
10 changed files with 228 additions and 23 deletions
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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:minHeight="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/content_padding_small"
|
||||
tools:src="@drawable/list_destination" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/wikilink_bottom_sheet_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:paddingStart="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:paddingTop="@dimen/content_padding_small">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingBottom="@dimen/text_margin_small"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
tools:text="Some description" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
39
OsmAnd/res/layout/bottom_sheet_item_title_with_descr.xml
Normal file
39
OsmAnd/res/layout/bottom_sheet_item_title_with_descr.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?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/selectableItemBackground"
|
||||
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:paddingBottom="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/wikilink_bottom_sheet_padding"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Some title" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Some description" />
|
||||
|
||||
</LinearLayout>
|
|
@ -212,4 +212,6 @@
|
|||
<dimen name="wikivoyage_start_editing_card_text_image_padding">60dp</dimen>
|
||||
<dimen name="wikivoyage_show_images_dialog_buttons_height">66dp</dimen>
|
||||
|
||||
<dimen name="wikilink_bottom_sheet_padding">21dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -299,6 +299,8 @@
|
|||
|
||||
<dimen name="wikivoyage_explore_card_image_height">144dp</dimen>
|
||||
|
||||
<dimen name="wikilink_bottom_sheet_padding">14dp</dimen>
|
||||
|
||||
<dimen name="text_button_letter_spacing" format="float">0.01</dimen>
|
||||
<dimen name="text_button_line_spacing_multiplier" format="float">1.2</dimen>
|
||||
</resources>
|
|
@ -9,6 +9,11 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="open_wikipedia_link_online">Open wikipedia link online</string>
|
||||
<string name="open_wikipedia_link_online_description">OsmAnd will redirect you to the browser and open the link online.</string>
|
||||
<string name="read_wikipedia_offline_description">Get OsmAnd Live subscription to read Wikipedia and Wikivoyage articles offline.</string>
|
||||
<string name="how_to_open_link">How to open link?</string>
|
||||
<string name="read_wikipedia_offline">Read Wikipedia offline</string>
|
||||
<string name="download_all">Download all</string>
|
||||
<string name="shared_string_restart">Restart</string>
|
||||
<string name="show_images">Show images</string>
|
||||
|
|
|
@ -20,6 +20,9 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class WikiArticleBaseDialogFragment extends WikiBaseDialogFragment {
|
||||
|
||||
|
@ -82,6 +85,7 @@ public abstract class WikiArticleBaseDialogFragment extends WikiBaseDialogFragme
|
|||
" }" +
|
||||
"}</script>"
|
||||
+ "</body></html>";
|
||||
protected static final Set<String> rtlLanguages = new HashSet<>(Arrays.asList("ar","dv","he","iw","fa","nqo","ps","sd","ug","ur","yi"));
|
||||
|
||||
protected WebView contentWebView;
|
||||
protected TextView selectedLangTv;
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package net.osmand.plus.wikipedia;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleDividerItem;
|
||||
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
||||
|
||||
|
||||
public class WikipediaArticleWikiLinkFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = WikivoyageArticleWikiLinkFragment.class.getSimpleName();
|
||||
|
||||
public static final String ARTICLE_URL_KEY = "article_url";
|
||||
|
||||
private String articleUrl;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final Context ctx = getContext();
|
||||
if (ctx == null) {
|
||||
return;
|
||||
}
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
articleUrl = args.getString(ARTICLE_URL_KEY);
|
||||
}
|
||||
|
||||
BaseBottomSheetItem wikiLinkitem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(articleUrl)
|
||||
.setTitle(getString(R.string.how_to_open_link))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_title_with_descr)
|
||||
.create();
|
||||
items.add(wikiLinkitem);
|
||||
items.add(new TitleDividerItem(ctx));
|
||||
|
||||
Drawable osmandLiveIcon = getIcon(R.drawable.ic_action_subscription_osmand_live, 0);
|
||||
|
||||
Drawable viewOnlineIcon = getIcon(R.drawable.ic_world_globe_dark, nightMode
|
||||
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light);
|
||||
|
||||
BaseBottomSheetItem wikiArticleOnlineItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.open_wikipedia_link_online_description))
|
||||
.setIcon(viewOnlineIcon)
|
||||
.setTitle(getString(R.string.open_wikipedia_link_online))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_in_frame_with_descr_and_icon)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
WikipediaDialogFragment.showFullArticle(ctx, Uri.parse(articleUrl), nightMode);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(wikiArticleOnlineItem);
|
||||
|
||||
items.add(new DividerHalfItem(ctx));
|
||||
|
||||
BaseBottomSheetItem wikiArticleOfflineItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.read_wikipedia_offline_description))
|
||||
.setIcon(osmandLiveIcon)
|
||||
.setTitle(getString(R.string.read_wikipedia_offline))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_in_frame_with_descr_and_icon)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
ChoosePlanDialogFragment.showWikivoyageInstance(fm);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(wikiArticleOfflineItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_close;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBgColorId() {
|
||||
return nightMode ? R.color.wikivoyage_bottom_bar_bg_dark : R.color.bg_color_light;
|
||||
}
|
||||
|
||||
public static boolean showInstance(@NonNull FragmentManager fm,
|
||||
@NonNull String articleUrl) {
|
||||
try {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARTICLE_URL_KEY, articleUrl);
|
||||
WikipediaArticleWikiLinkFragment fragment = new WikipediaArticleWikiLinkFragment();
|
||||
|
||||
fragment.setArguments(args);
|
||||
fragment.show(fm, TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,9 +38,7 @@ import net.osmand.plus.helpers.FileNameTranslationHelper;
|
|||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
@ -134,9 +132,7 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
@NonNull
|
||||
protected String createHtmlContent() {
|
||||
StringBuilder sb = new StringBuilder(HEADER_INNER);
|
||||
String[] rtlLanguages = new String[]{"ar", "dv", "he", "iw", "fa", "nqo", "ps", "sd", "ug", "ur", "yi"};
|
||||
Set<String> rtls = new HashSet<>(Arrays.asList(rtlLanguages));
|
||||
String bodyTag = rtls.contains(langSelected) ? "<body dir=\"rtl\">\n" : "<body>\n";
|
||||
String bodyTag = rtlLanguages.contains(langSelected) ? "<body dir=\"rtl\">\n" : "<body>\n";
|
||||
sb.append(bodyTag);
|
||||
String nightModeClass = nightMode ? " nightmode" : "";
|
||||
sb.append("<div class=\"main");
|
||||
|
|
|
@ -42,11 +42,8 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.plus.OsmandSettings.WikiArticleShowImages.OFF;
|
||||
|
||||
|
@ -311,9 +308,7 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
|
|||
@NonNull
|
||||
protected String createHtmlContent() {
|
||||
StringBuilder sb = new StringBuilder(HEADER_INNER);
|
||||
String[] rtlLanguages = new String[]{"ar","dv","he","iw","fa","nqo","ps","sd","ug","ur","yi"};
|
||||
Set<String> rtls = new HashSet<>(Arrays.asList(rtlLanguages));
|
||||
String bodyTag = rtls.contains(article.getLang()) ? "<body dir=\"rtl\">\n" : "<body>\n";
|
||||
String bodyTag = rtlLanguages.contains(article.getLang()) ? "<body dir=\"rtl\">\n" : "<body>\n";
|
||||
sb.append(bodyTag);
|
||||
String nightModeClass = nightMode ? " nightmode" : "";
|
||||
String imageTitle = article.getImageTitle();
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleDividerItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||
|
||||
|
@ -48,12 +47,13 @@ public class WikivoyageArticleWikiLinkFragment extends MenuBottomSheetDialogFrag
|
|||
wikiRegion = args.getString(WIKI_REGION);
|
||||
}
|
||||
}
|
||||
items.add(new TitleItem(getString(R.string.how_to_open_wiki_title)));
|
||||
|
||||
BaseBottomSheetItem wikiLinkitem = new TitleItem.Builder().setTitle(articleUrl)
|
||||
.setTitleColorId(nightMode
|
||||
BaseBottomSheetItem wikiLinkitem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(articleUrl)
|
||||
.setDescriptionColorId(nightMode
|
||||
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_title)
|
||||
.setTitle(getString(R.string.how_to_open_wiki_title))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_title_with_descr)
|
||||
.create();
|
||||
items.add(wikiLinkitem);
|
||||
items.add(new TitleDividerItem(getContext()));
|
||||
|
@ -69,7 +69,7 @@ public class WikivoyageArticleWikiLinkFragment extends MenuBottomSheetDialogFrag
|
|||
getString(R.string.download_wiki_region_placeholder) : wikiRegion))
|
||||
.setIcon(downloadIcon)
|
||||
.setTitle(getString(R.string.download_wikipedia_label))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_in_frame_with_descr_and_icon)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -92,7 +92,7 @@ public class WikivoyageArticleWikiLinkFragment extends MenuBottomSheetDialogFrag
|
|||
.setDescription(getString(R.string.open_in_browser_wiki_description))
|
||||
.setIcon(viewOnlineIcon)
|
||||
.setTitle(getString(R.string.open_in_browser_wiki))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_in_frame_with_descr_and_icon)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -111,11 +111,6 @@ public class WikivoyageArticleWikiLinkFragment extends MenuBottomSheetDialogFrag
|
|||
outState.putString(WIKI_REGION, wikiRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBgColorId() {
|
||||
return nightMode ? R.color.wikivoyage_bottom_bar_bg_dark : R.color.bg_color_light;
|
||||
|
|
Loading…
Reference in a new issue