renamed show image settings and refactored writeOutHTML

This commit is contained in:
Chumva 2018-05-03 15:27:47 +03:00
parent c14ba4f0fd
commit 81449c9c2d
8 changed files with 27 additions and 33 deletions

View file

@ -717,8 +717,8 @@ 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_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal();
public final CommonPreference<WikivoyageShowImages> WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> WIKI_ARTICLE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal();
public final CommonPreference<WikiArticleShowImages> WIKI_ARTICLE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikiArticleShowImages.OFF, WikiArticleShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();
@ -3315,14 +3315,14 @@ public class OsmandSettings {
EMPTY
}
public enum WikivoyageShowImages {
public enum WikiArticleShowImages {
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) {
WikiArticleShowImages(int name) {
this.name = name;
}
}

View file

@ -76,7 +76,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
settings.WEBGL_SUPPORTED.set(true);
settings.METRIC_SYSTEM_CHANGED_MANUALLY.set(false);
settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(false);
settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.set(false);
getMyApplication().showToastMessage(R.string.shared_string_ok);
return true;

View file

@ -20,7 +20,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFragment {
public abstract class WikiArticleBaseDialogFragment extends WikivoyageBaseDialogFragment {
protected static final String HEADER_INNER = "<html><head>\n" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" +
@ -88,7 +88,7 @@ public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFrag
protected void updateWebSettings() {
OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
OsmandSettings.WikiArticleShowImages showImages = getSettings().WIKI_ARTICLE_SHOW_IMAGES.get();
WebSettings webSettings = contentWebView.getSettings();
switch (showImages) {
case ON:
@ -113,8 +113,7 @@ public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFrag
return "file:///android_asset/";
}
protected void writeOutHTML(StringBuilder sb) {
File file = new File(getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), "page.html");
protected void writeOutHTML(StringBuilder sb, File file) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(file));

View file

@ -31,7 +31,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.wikipedia.ArticleBaseDialogFragment;
import net.osmand.util.Algorithms;
import java.util.HashMap;
@ -40,7 +39,7 @@ import java.util.Set;
import java.util.TreeSet;
public class WikipediaDialogFragment extends ArticleBaseDialogFragment {
public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
public static final String TAG = "WikipediaDialogFragment";
@ -267,13 +266,13 @@ public class WikipediaDialogFragment extends ArticleBaseDialogFragment {
if (app != null) {
int itemId = item.getItemId();
if (itemId == MENU_ITEM_SHOW_ID) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON);
return true;
} else if (itemId == MENU_ITEM_WIFI_ID) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI);
return true;
} else if (itemId == MENU_ITEM_NO_ID) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF);
return true;
}
}

View file

@ -16,7 +16,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.OsmandSettings.WikiArticleShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -38,7 +38,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.OFF);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.OFF);
}
sendResult();
dismiss();
@ -52,7 +52,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.WIFI);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.WIFI);
}
sendResult();
dismiss();
@ -65,7 +65,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.ON);
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.ON);
}
sendResult();
dismiss();

View file

@ -8,7 +8,7 @@ import net.osmand.plus.OsmandSettings;
public class WikivoyageUtils {
public static void setupNetworkPolicy(OsmandSettings settings, RequestCreator rc) {
switch (settings.WIKIVOYAGE_SHOW_IMAGES.get()) {
switch (settings.WIKI_ARTICLE_SHOW_IMAGES.get()) {
case ON:
break;
case OFF:

View file

@ -13,7 +13,6 @@ import android.support.v4.app.FragmentManager.BackStackEntry;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -32,7 +31,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.wikipedia.ArticleBaseDialogFragment;
import net.osmand.plus.wikipedia.WikiArticleBaseDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageWebViewClient;
import net.osmand.plus.wikivoyage.data.TravelArticle;
@ -40,10 +39,7 @@ import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.util.Algorithms;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -51,10 +47,10 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static net.osmand.plus.OsmandSettings.WikivoyageShowImages.OFF;
import static net.osmand.plus.OsmandSettings.WikiArticleShowImages.OFF;
public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment {
public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragment {
public static final String TAG = "WikivoyageArticleDialogFragment";
@ -211,14 +207,14 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment {
public void onResume() {
super.onResume();
OsmandSettings settings = getMyApplication().getSettings();
if (!settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.get()) {
if (!settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.get()) {
FragmentActivity activity = getActivity();
FragmentManager fm = getFragmentManager();
if (activity != null && fm != null) {
WikivoyageShowPicturesDialogFragment fragment = new WikivoyageShowPicturesDialogFragment();
fragment.setTargetFragment(this, WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE);
fragment.show(fm, WikivoyageShowPicturesDialogFragment.TAG);
settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(true);
settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.set(true);
}
}
}
@ -337,7 +333,7 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment {
}
}
String url = TravelArticle.getImageUrl(imageTitle, false);
if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKIVOYAGE_SHOW_IMAGES.get() != OFF &&
if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKI_ARTICLE_SHOW_IMAGES.get() != OFF &&
!url.startsWith(EMPTY_URL)) {
sb.append("<div class=\"title-image"+nightModeClass+"\" style=\"background-image: url(").append(url).append(")\"></div>");
}
@ -349,7 +345,7 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment {
sb.append(article.getContent());
sb.append(FOOTER_INNER);
if (OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null) {
writeOutHTML(sb);
writeOutHTML(sb, new File(getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), "page.html"));
}
return sb.toString();
}

View file

@ -15,7 +15,7 @@ import android.webkit.WebView;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.OsmandSettings.WikiArticleShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -40,7 +40,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
final TravelDbHelper dbHelper = app.getTravelDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options)));
@ -75,7 +75,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
@Override
public void onClick(View v) {
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
for (final WikivoyageShowImages showImages : WikivoyageShowImages.values()) {
for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) {
MenuItem item = popup.getMenu().add(getString(showImages.name));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override