added show images dialog options for wikipedia
This commit is contained in:
parent
d6986043a5
commit
6dd1712cc8
4 changed files with 110 additions and 39 deletions
|
@ -54,6 +54,15 @@
|
||||||
tools:text="En"
|
tools:text="En"
|
||||||
tools:textColor="?attr/wikivoyage_active_color" />
|
tools:textColor="?attr/wikivoyage_active_color" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatImageView
|
||||||
|
android:id="@+id/options_button"
|
||||||
|
style="@style/Widget.AppCompat.ActionButton"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:contentDescription="@string/shared_string_options"
|
||||||
|
tools:src="@drawable/ic_overflow_menu_white"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
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
|
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="show_images">Show images</string>
|
||||||
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
|
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
|
||||||
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
|
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikipedia;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -10,6 +11,7 @@ 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.customtabs.CustomTabsIntent;
|
import android.support.customtabs.CustomTabsIntent;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.PopupMenu;
|
import android.support.v7.widget.PopupMenu;
|
||||||
|
@ -17,12 +19,12 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -30,10 +32,10 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
|
import net.osmand.plus.wikivoyage.WikipediaOptionsBottomSheetDialogFragment;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -47,10 +49,6 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
||||||
|
|
||||||
public static final String TAG = "WikipediaDialogFragment";
|
public static final String TAG = "WikipediaDialogFragment";
|
||||||
|
|
||||||
private static final int MENU_ITEM_NO_ID = 0;
|
|
||||||
private static final int MENU_ITEM_SHOW_ID = 1;
|
|
||||||
private static final int MENU_ITEM_WIFI_ID = 2;
|
|
||||||
|
|
||||||
private TextView readFullArticleButton;
|
private TextView readFullArticleButton;
|
||||||
|
|
||||||
private Amenity amenity;
|
private Amenity amenity;
|
||||||
|
@ -75,7 +73,25 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
||||||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||||
|
|
||||||
articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view);
|
articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view);
|
||||||
|
ImageView options = (ImageView) mainView.findViewById(R.id.options_button);
|
||||||
|
options.setImageDrawable(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
|
||||||
|
options.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null) {
|
||||||
|
FragmentManager fm = getFragmentManager();
|
||||||
|
if (fm == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WikipediaOptionsBottomSheetDialogFragment fragment = new WikipediaOptionsBottomSheetDialogFragment();
|
||||||
|
fragment.setUsedOnMap(false);
|
||||||
|
fragment.setTargetFragment(WikipediaDialogFragment.this,
|
||||||
|
WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE);
|
||||||
|
fragment.show(fm, WikipediaOptionsBottomSheetDialogFragment.TAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode,
|
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode,
|
||||||
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||||
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||||
|
@ -256,37 +272,12 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
||||||
return showInstance(activity, amenity, null);
|
return showInstance(activity, amenity, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupToolbar(Toolbar toolbar) {
|
@Override
|
||||||
super.setupToolbar(toolbar);
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (resultCode == WikipediaOptionsBottomSheetDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
|
||||||
Menu menu = toolbar.getMenu();
|
updateWebSettings();
|
||||||
MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() {
|
populateArticle();
|
||||||
@Override
|
}
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
OsmandApplication app = getMyApplication();
|
|
||||||
if (app != null) {
|
|
||||||
int itemId = item.getItemId();
|
|
||||||
if (itemId == MENU_ITEM_SHOW_ID) {
|
|
||||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON);
|
|
||||||
return true;
|
|
||||||
} else if (itemId == MENU_ITEM_WIFI_ID) {
|
|
||||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI);
|
|
||||||
return true;
|
|
||||||
} else if (itemId == MENU_ITEM_NO_ID) {
|
|
||||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MenuItem itemShow = menu.add(0, MENU_ITEM_SHOW_ID, 0, R.string.shared_string_show);
|
|
||||||
itemShow.setOnMenuItemClickListener(itemClickListener);
|
|
||||||
MenuItem itemWifi = menu.add(0, MENU_ITEM_WIFI_ID, 0, R.string.shared_string_only_with_wifi);
|
|
||||||
itemWifi.setOnMenuItemClickListener(itemClickListener);
|
|
||||||
MenuItem itemNo = menu.add(0, MENU_ITEM_NO_ID, 0, R.string.shared_string_dont);
|
|
||||||
itemNo.setOnMenuItemClickListener(itemClickListener);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package net.osmand.plus.wikivoyage;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.OsmandSettings.WikiArticleShowImages;
|
||||||
|
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.TitleItem;
|
||||||
|
|
||||||
|
|
||||||
|
public class WikipediaOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public final static String TAG = "WikipediaOptionsBottomSheetDialogFragment";
|
||||||
|
|
||||||
|
public static final int REQUEST_CODE = 0;
|
||||||
|
public static final int SHOW_PICTURES_CHANGED_REQUEST_CODE = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
final OsmandApplication app = getMyApplication();
|
||||||
|
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
|
||||||
|
|
||||||
|
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
||||||
|
|
||||||
|
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder()
|
||||||
|
.setDescription(getString(showImagesPref.get().name))
|
||||||
|
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||||
|
.setTitle(getString(R.string.download_images))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
|
||||||
|
for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) {
|
||||||
|
MenuItem item = popup.getMenu().add(getString(showImages.name));
|
||||||
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
showImagesPref.set(showImages);
|
||||||
|
sendResult();
|
||||||
|
dismiss();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(showImagesItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendResult() {
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment != null) {
|
||||||
|
fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED_REQUEST_CODE, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue