Merge branch 'master' of https://github.com/osmandapp/Osmand into JsonContentsParser

This commit is contained in:
PaulStets 2018-04-15 13:27:54 +03:00
commit 8ab0e515e9
7 changed files with 92 additions and 25 deletions

View file

@ -9,6 +9,7 @@
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="shared_string_wifi_only">Only WiFi</string>
<string name="select_travel_book">Select travel book</string>
<string name="shared_string_travel_book">Travel book</string>
<string name="online_webpage_warning">This page is only available online. Do you wish to open it in a web browser?</string>

View file

@ -717,7 +717,7 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> WIKIVOYAGE_SHOW_IMAGES = new BooleanPreference("wikivoyage_show_images", false);
public final CommonPreference<WikivoyageShowImages> WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();
@ -3310,4 +3310,17 @@ public class OsmandSettings {
SECOND,
EMPTY
}
public enum WikivoyageShowImages {
ON(R.string.shared_string_on),
OFF(R.string.shared_string_off),
WIFI(R.string.shared_string_wifi_only);
public final int name;
WikivoyageShowImages(int name) {
this.name = name;
}
}
}

View file

@ -0,0 +1,24 @@
package net.osmand.plus.wikivoyage;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.RequestCreator;
import net.osmand.plus.OsmandSettings;
public class WikivoyageUtils {
public static void setupNetworkPolicy(OsmandSettings settings, RequestCreator rc) {
switch (settings.WIKIVOYAGE_SHOW_IMAGES.get()) {
case ON:
break;
case OFF:
rc.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.OFFLINE);
break;
case WIFI:
if (!settings.isWifiConnected()) {
rc.networkPolicy(NetworkPolicy.OFFLINE);
}
break;
}
}
}

View file

@ -24,6 +24,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.data.CustomWebViewClient;
@ -139,10 +140,22 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
saveBtn = (TextView) mainView.findViewById(R.id.save_button);
boolean showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
contentWebView.getSettings().setJavaScriptEnabled(true);
contentWebView.getSettings().setCacheMode(showImages ? WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY);
WebSettings webSettings = contentWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
switch (showImages) {
case ON:
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
break;
case OFF:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
break;
case WIFI:
webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ?
WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY);
break;
}
contentWebView.setWebViewClient(new CustomWebViewClient(getActivity(), getFragmentManager()));
return mainView;

View file

@ -12,16 +12,17 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Callback;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.widgets.tools.CropRectTransformation;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
@ -36,6 +37,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private static final boolean USE_ALTERNATIVE_CARD = false;
private final OsmandApplication app;
private final OsmandSettings settings;
private final List<Object> items = new ArrayList<>();
@ -50,7 +52,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
SavedArticlesRvAdapter(OsmandApplication app) {
this.app = app;
int colorId = app.getSettings().isLightContent()
this.settings = app.getSettings();
int colorId = settings.isLightContent()
? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
IconsCache ic = app.getIconsCache();
readIcon = ic.getIcon(R.drawable.ic_action_read_article, colorId);
@ -80,9 +84,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
boolean lastItem = position == getItemCount() - 1;
RequestCreator rc = Picasso.get()
.load(WikivoyageArticle.getImageUrl(article.getImageTitle(), false));
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
rc.networkPolicy(NetworkPolicy.OFFLINE);
}
WikivoyageUtils.setupNetworkPolicy(settings, rc);
rc.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
.into(holder.icon, new Callback() {
@Override

View file

@ -1,21 +1,19 @@
package net.osmand.plus.wikivoyage.explore;
import java.io.File;
import java.util.List;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AlertDialogLayout;
import android.support.v7.widget.PopupMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Toast;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -27,6 +25,9 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import java.io.File;
import java.util.List;
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
@ -55,7 +56,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options)));
@ -77,16 +78,30 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
}
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(showImagesPref.get())
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_switch)
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showImagesPref.set(!showImagesPref.get());
dismiss();
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
for (final WikivoyageShowImages showImages : WikivoyageShowImages.values()) {
MenuItem item = popup.getMenu().add(getString(showImages.name));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
showImagesPref.set(showImages);
dismiss();
return true;
}
});
}
popup.show();
}
})
.create();

View file

@ -19,6 +19,7 @@ import com.squareup.picasso.RequestCreator;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
@ -77,9 +78,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
RequestCreator rc = Picasso.get()
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true));
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
rc.networkPolicy(NetworkPolicy.OFFLINE);
}
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.placeholder(placeholder)
.into(holder.icon);