Merge pull request #5229 from osmandapp/WikivoyageImprovements

add options for downloading icons and clear history
This commit is contained in:
Alexander Sytnyk 2018-04-13 18:18:54 +03:00 committed by GitHub
commit 65ba05cc11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 113 additions and 19 deletions

View file

@ -9,6 +9,9 @@
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="images_cache">Images cache</string>
<string name="delete_search_history">Delete search history</string>
<string name="show_images">Show images</string>
<string name="download_maps_travel">Travel maps</string>
<string name="shared_string_wikivoyage">Wikivoyage</string>
<string name="article_removed">Article removed</string>

View file

@ -717,6 +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 = new BooleanPreference("wikivoyage_show_images", false);
public final CommonPreference<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();
public final CommonPreference<Boolean> COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal();

View file

@ -119,6 +119,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
contentWebView.getSettings().setJavaScriptEnabled(true);
contentWebView.getSettings().setLoadsImagesAutomatically(getSettings().WIKIVOYAGE_SHOW_IMAGES.get());
return mainView;
}
@ -229,9 +230,9 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private String createHtmlContent(@NonNull WikivoyageArticle article) {
StringBuilder sb = new StringBuilder(HEADER_INNER);
String articleTitle = article.getImageTitle();
if (!TextUtils.isEmpty(articleTitle)) {
String url = WikivoyageArticle.getImageUrl(articleTitle, false);
String imageTitle = article.getImageTitle();
if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
String url = WikivoyageArticle.getImageUrl(imageTitle, false);
sb.append("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
}
sb.append("<div class=\"main\">\n");

View file

@ -76,7 +76,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
final ItemVH holder = (ItemVH) viewHolder;
WikivoyageArticle article = (WikivoyageArticle) getItem(position);
boolean lastItem = position == getItemCount() - 1;
if (app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
Picasso.get()
.load(WikivoyageArticle.getImageUrl(article.getImageTitle(), false))
.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
@ -91,6 +91,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
holder.icon.setVisibility(View.GONE);
}
});
} else {
holder.icon.setVisibility(View.GONE);
}
holder.title.setText(article.getTitle());
holder.content.setText(article.getContent());
holder.partOf.setText(article.getGeoDescription());

View file

@ -41,6 +41,15 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikivoyageOptionsBottomSheetDialogFragment fragment = new WikivoyageOptionsBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), WikivoyageOptionsBottomSheetDialogFragment.TAG);
}
});
int searchColorId = nightMode ? R.color.icon_color : R.color.ctx_menu_title_color_dark;
((TextView) mainView.findViewById(R.id.search_hint)).setTextColor(getResolvedColor(searchColorId));
((ImageView) mainView.findViewById(R.id.search_icon))

View file

@ -0,0 +1,75 @@
package net.osmand.plus.wikivoyage.explore;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
items.add(new TitleItem(getString(R.string.shared_string_options)));
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(showImagesPref.get())
.setIcon(getContentIcon(R.drawable.ic_type_img))
.setTitle(getString(R.string.show_images))
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showImagesPref.set(!showImagesPref.get());
dismiss();
}
})
.create();
items.add(showImagesItem);
BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.shared_string_clear))
.setTitle(getString(R.string.images_cache) + ": ???") // TODO : show images cache size
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO : implement clearing of cache
Toast.makeText(getContext(), "Currently in development", Toast.LENGTH_SHORT).show();
}
})
.create();
items.add(clearCacheItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem clearHistoryItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_history))
.setTitle(getString(R.string.delete_search_history))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikivoyageLocalDataHelper.getInstance(app).clearHistory();
dismiss();
}
})
.create();
items.add(clearHistoryItem);
}
}

View file

@ -74,7 +74,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
if (item instanceof WikivoyageSearchResult) {
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
Picasso.get()
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true))
.load(app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()
? WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true) : null)
.transform(new CropCircleTransformation())
.placeholder(placeholder)
.into(holder.icon);