Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
866d80f340
8 changed files with 217 additions and 11 deletions
|
@ -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>
|
||||
|
@ -311,7 +314,7 @@
|
|||
<string name="depth_contour_descr">Sea depth contour lines and nautical point maps.</string>
|
||||
<string name="sea_depth_thanks">Thank you for purchasing nautical depth contours</string>
|
||||
<string name="index_item_depth_contours_osmand_ext">Nautical depth contours</string>
|
||||
|
||||
|
||||
<string name="index_item_world_wikivoyage">Worldwide Wikivoyage articles</string>
|
||||
<string name="index_item_depth_points_southern_hemisphere">Southern hemisphere nautical depth points </string>
|
||||
<string name="index_item_depth_points_northern_hemisphere">Northern hemisphere nautical depth points</string>
|
||||
|
|
91
OsmAnd/src/net/osmand/PicassoUtils.java
Normal file
91
OsmAnd/src/net/osmand/PicassoUtils.java
Normal file
|
@ -0,0 +1,91 @@
|
|||
package net.osmand;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.StatFs;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.squareup.picasso.LruCache;
|
||||
import com.squareup.picasso.OkHttp3Downloader;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||
|
||||
public class PicassoUtils {
|
||||
|
||||
private static final String PICASSO_CACHE = "picasso-cache";
|
||||
private static final int MIN_DISK_CACHE_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
private static final int MAX_DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
|
||||
|
||||
private static Cache diskCache;
|
||||
private static LruCache memoryCache;
|
||||
|
||||
private static boolean initialized;
|
||||
|
||||
public static void setupPicasso(@NonNull Context context) {
|
||||
if (!initialized) {
|
||||
File cacheDir = createDefaultCacheDir(context);
|
||||
|
||||
diskCache = new Cache(cacheDir, calculateDiskCacheSize(cacheDir));
|
||||
memoryCache = new LruCache(context);
|
||||
|
||||
Picasso picasso = new Picasso.Builder(context)
|
||||
.downloader(new OkHttp3Downloader(new OkHttpClient.Builder().cache(diskCache).build()))
|
||||
.memoryCache(memoryCache)
|
||||
.build();
|
||||
|
||||
Picasso.setSingletonInstance(picasso);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearAllPicassoCache() {
|
||||
if (memoryCache != null) {
|
||||
memoryCache.clear();
|
||||
}
|
||||
if (diskCache != null) {
|
||||
try {
|
||||
diskCache.evictAll();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static File createDefaultCacheDir(Context context) {
|
||||
File cache = new File(context.getApplicationContext().getCacheDir(), PICASSO_CACHE);
|
||||
if (!cache.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
cache.mkdirs();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
private static long calculateDiskCacheSize(File dir) {
|
||||
long size = MIN_DISK_CACHE_SIZE;
|
||||
|
||||
try {
|
||||
StatFs statFs = new StatFs(dir.getAbsolutePath());
|
||||
//noinspection deprecation
|
||||
long blockCount =
|
||||
SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockCount() : statFs.getBlockCountLong();
|
||||
//noinspection deprecation
|
||||
long blockSize =
|
||||
SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockSize() : statFs.getBlockSizeLong();
|
||||
long available = blockCount * blockSize;
|
||||
// Target 2% of the total space.
|
||||
size = available / 50;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
// Bound inside min/max size for disk cache.
|
||||
return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -117,8 +118,10 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
|
||||
saveBtn = (TextView) mainView.findViewById(R.id.save_button);
|
||||
|
||||
boolean 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);
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
@ -229,9 +232,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)) {
|
||||
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");
|
||||
|
|
|
@ -12,7 +12,9 @@ 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;
|
||||
|
@ -76,10 +78,12 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
|||
final ItemVH holder = (ItemVH) viewHolder;
|
||||
WikivoyageArticle article = (WikivoyageArticle) getItem(position);
|
||||
boolean lastItem = position == getItemCount() - 1;
|
||||
|
||||
Picasso.get()
|
||||
.load(WikivoyageArticle.getImageUrl(article.getImageTitle(), false))
|
||||
.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
|
||||
RequestCreator rc = Picasso.get()
|
||||
.load(WikivoyageArticle.getImageUrl(article.getImageTitle(), false));
|
||||
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
|
||||
rc.networkPolicy(NetworkPolicy.OFFLINE);
|
||||
}
|
||||
rc.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
|
||||
.into(holder.icon, new Callback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.wikivoyage.explore;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -18,6 +19,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PicassoUtils;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||
|
@ -34,6 +36,15 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
private static final int EXPLORE_POSITION = 0;
|
||||
private static final int SAVED_ARTICLES_POSITION = 1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
PicassoUtils.setupPicasso(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -41,6 +52,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))
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package net.osmand.plus.wikivoyage.explore;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import net.osmand.PicassoUtils;
|
||||
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))
|
||||
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
|
||||
.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) {
|
||||
new WebView(getContext()).clearCache(true);
|
||||
PicassoUtils.clearAllPicassoCache();
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.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);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,9 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.picasso.NetworkPolicy;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.squareup.picasso.RequestCreator;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -73,9 +75,12 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
Object item = getItem(pos);
|
||||
if (item instanceof WikivoyageSearchResult) {
|
||||
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
|
||||
Picasso.get()
|
||||
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true))
|
||||
.transform(new CropCircleTransformation())
|
||||
RequestCreator rc = Picasso.get()
|
||||
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true));
|
||||
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
|
||||
rc.networkPolicy(NetworkPolicy.OFFLINE);
|
||||
}
|
||||
rc.transform(new CropCircleTransformation())
|
||||
.placeholder(placeholder)
|
||||
.into(holder.icon);
|
||||
holder.title.setText(searchRes.getArticleTitles().get(0));
|
||||
|
|
Loading…
Reference in a new issue