Add some wikivoyage UI polishing; add the ability to change article language
This commit is contained in:
parent
8ad13b3d3e
commit
e773b08a87
8 changed files with 195 additions and 8 deletions
|
@ -2,19 +2,52 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/wikivoyage_bg"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
android:layout_height="@dimen/toolbar_height"
|
||||||
android:minHeight="@dimen/dashboard_map_toolbar"
|
android:background="?attr/wikivoyage_app_bar"
|
||||||
android:theme="?attr/toolbar_theme"
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="@dimen/toolbar_height"
|
||||||
osmand:contentInsetLeft="54dp"
|
osmand:contentInsetLeft="54dp"
|
||||||
osmand:contentInsetStart="54dp">
|
osmand:contentInsetStart="54dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/select_language_text_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginBottom="@dimen/content_padding_small"
|
||||||
|
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
|
||||||
|
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
|
||||||
|
android:layout_marginTop="@dimen/content_padding_small"
|
||||||
|
android:drawablePadding="@dimen/context_menu_padding_margin_small"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:padding="@dimen/context_menu_padding_margin_tiny"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:background="?attr/ctx_menu_controller_bg"
|
||||||
|
tools:drawableLeft="@drawable/ic_action_map_language"
|
||||||
|
tools:text="En"
|
||||||
|
tools:textColor="?attr/ctx_menu_controller_text_color"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
|
|
|
@ -191,4 +191,6 @@
|
||||||
<dimen name="side_of_the_world_button_size">54dp</dimen>
|
<dimen name="side_of_the_world_button_size">54dp</dimen>
|
||||||
|
|
||||||
<dimen name="coords_input_show_hide_keyboard_btn_padding">19dp</dimen>
|
<dimen name="coords_input_show_hide_keyboard_btn_padding">19dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="toolbar_height">84dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -64,6 +64,9 @@
|
||||||
<attr name="secondary_icon_color" format="color"/>
|
<attr name="secondary_icon_color" format="color"/>
|
||||||
<attr name="primary_icon_color" format="color"/>
|
<attr name="primary_icon_color" format="color"/>
|
||||||
<attr name="light_icon_color" format="color"/>
|
<attr name="light_icon_color" format="color"/>
|
||||||
|
|
||||||
|
<attr name="wikivoyage_bg" format="reference"/>
|
||||||
|
<attr name="wikivoyage_app_bar" format="reference"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="PagerSlidingTabStrip">
|
<declare-styleable name="PagerSlidingTabStrip">
|
||||||
|
|
|
@ -265,4 +265,6 @@
|
||||||
|
|
||||||
<dimen name="coords_input_show_hide_keyboard_btn_padding">13dp</dimen>
|
<dimen name="coords_input_show_hide_keyboard_btn_padding">13dp</dimen>
|
||||||
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="toolbar_height">56dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -192,6 +192,9 @@
|
||||||
<item name="keyboard_controls_divider">@color/keyboard_item_add_button_divider_light</item>
|
<item name="keyboard_controls_divider">@color/keyboard_item_add_button_divider_light</item>
|
||||||
|
|
||||||
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_light</item>
|
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_light</item>
|
||||||
|
|
||||||
|
<item name="wikivoyage_bg">@color/wikivoyage_bg_light</item>
|
||||||
|
<item name="wikivoyage_app_bar">@color/wikivoyage_app_bar_light</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
|
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
|
||||||
|
@ -376,6 +379,9 @@
|
||||||
<item name="keyboard_controls_divider">@color/keyboard_item_add_button_divider_dark</item>
|
<item name="keyboard_controls_divider">@color/keyboard_item_add_button_divider_dark</item>
|
||||||
|
|
||||||
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_dark</item>
|
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_dark</item>
|
||||||
|
|
||||||
|
<item name="wikivoyage_bg">@color/wikivoyage_bg_dark</item>
|
||||||
|
<item name="wikivoyage_app_bar">@color/wikivoyage_app_bar_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="FreeVersionBanner" parent="OsmandDarkTheme">
|
<style name="FreeVersionBanner" parent="OsmandDarkTheme">
|
||||||
|
|
|
@ -270,6 +270,14 @@ public class AndroidUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLightStatusBarFlag(View view) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
|
int flags = view.getSystemUiVisibility();
|
||||||
|
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
||||||
|
view.setSystemUiVisibility(flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int getNavBarHeight(Context ctx) {
|
public static int getNavBarHeight(Context ctx) {
|
||||||
if (!hasNavBar(ctx)) {
|
if (!hasNavBar(ctx)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
package net.osmand.plus.wikivoyage;
|
package net.osmand.plus.wikivoyage;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||||
|
@ -19,24 +29,134 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
public static final String TAG = "WikivoyageArticleDialogFragment";
|
public static final String TAG = "WikivoyageArticleDialogFragment";
|
||||||
|
|
||||||
private static final String SEARCH_RESULT_KEY = "search_result_key";
|
private static final String SEARCH_RESULT_KEY = "search_result_key";
|
||||||
|
private static final String SELECTED_LANG_KEY = "selected_lang_key";
|
||||||
|
|
||||||
|
private WikivoyageSearchResult searchResult;
|
||||||
|
private String selectedLang;
|
||||||
|
|
||||||
|
private TextView selectedLangTv;
|
||||||
|
private WebView contentWebView;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
Window window = dialog.getWindow();
|
||||||
|
if (window != null) {
|
||||||
|
window.setStatusBarColor(getResolvedColor(nightMode
|
||||||
|
? R.color.status_bar_wikivoyage_dark
|
||||||
|
: R.color.status_bar_wikivoyage_light));
|
||||||
|
if (!nightMode) {
|
||||||
|
AndroidUtils.setLightStatusBarFlag(window.getDecorView());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container);
|
final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container);
|
||||||
|
|
||||||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||||
|
|
||||||
WikivoyageSearchResult searchResult = (WikivoyageSearchResult) getArguments().getParcelable(SEARCH_RESULT_KEY);
|
ColorStateList selectedLangColorStateList = AndroidUtils.createColorStateList(
|
||||||
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
|
getContext(), nightMode,
|
||||||
.getArticle(searchResult.getCityId(), searchResult.getLang().get(0));
|
R.color.icon_color, R.color.wikivoyage_active_light,
|
||||||
|
R.color.icon_color, R.color.wikivoyage_active_dark
|
||||||
|
);
|
||||||
|
|
||||||
WebView contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
|
selectedLangTv = (TextView) mainView.findViewById(R.id.select_language_text_view);
|
||||||
contentWebView.loadData(article.getContent(), "text/html", "UTF-8");
|
selectedLangTv.setTextColor(selectedLangColorStateList);
|
||||||
|
selectedLangTv.setCompoundDrawablesWithIntrinsicBounds(getSelectedLangIcon(), null, null, null);
|
||||||
|
selectedLangTv.setBackgroundResource(nightMode
|
||||||
|
? R.drawable.wikipedia_select_lang_bg_dark_n : R.drawable.wikipedia_select_lang_bg_light_n);
|
||||||
|
selectedLangTv.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
showPopupLangMenu(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
|
||||||
|
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
populateArticle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(SELECTED_LANG_KEY, selectedLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPopupLangMenu(View view) {
|
||||||
|
if (searchResult == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.END);
|
||||||
|
for (final String lang : searchResult.getLang()) {
|
||||||
|
MenuItem item = popup.getMenu().add(lang);
|
||||||
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (!selectedLang.equals(lang)) {
|
||||||
|
selectedLang = lang;
|
||||||
|
populateArticle();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateArticle() {
|
||||||
|
if (searchResult == null) {
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args != null) {
|
||||||
|
searchResult = (WikivoyageSearchResult) args.getParcelable(SEARCH_RESULT_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (searchResult == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (selectedLang == null) {
|
||||||
|
selectedLang = searchResult.getLang().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedLangTv.setText(selectedLang);
|
||||||
|
|
||||||
|
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
|
||||||
|
.getArticle(searchResult.getCityId(), selectedLang);
|
||||||
|
if (article == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
contentWebView.loadData(article.getContent(), "text/html", "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getSelectedLangIcon() {
|
||||||
|
Drawable normal = getContentIcon(R.drawable.ic_action_map_language);
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
Drawable active = getActiveIcon(R.drawable.ic_action_map_language);
|
||||||
|
return AndroidUtils.createStateListDrawable(normal, active);
|
||||||
|
}
|
||||||
|
return normal;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean showInstance(FragmentManager fm, WikivoyageSearchResult searchResult) {
|
public static boolean showInstance(FragmentManager fm, WikivoyageSearchResult searchResult) {
|
||||||
try {
|
try {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
@ -2,8 +2,12 @@ package net.osmand.plus.wikivoyage;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
|
import android.support.annotation.ColorRes;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -28,6 +32,15 @@ public class WikivoyageBaseDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
return getIcon(id, R.color.icon_color);
|
return getIcon(id, R.color.icon_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Drawable getActiveIcon(@DrawableRes int iconId) {
|
||||||
|
return getIcon(iconId, nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ColorInt
|
||||||
|
protected int getResolvedColor(@ColorRes int colorId) {
|
||||||
|
return ContextCompat.getColor(getContext(), colorId);
|
||||||
|
}
|
||||||
|
|
||||||
protected View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) {
|
protected View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) {
|
||||||
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes))
|
return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes))
|
||||||
|
|
Loading…
Reference in a new issue