Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-03 15:26:41 +02:00
commit a9c7d4f5ba
9 changed files with 153 additions and 30 deletions

View file

@ -1,12 +1,22 @@
body {
max-width: 100% !important;
/* overflow-x: hidden; hide scroll bar */
display: block;
margin-top: 7%;
margin-bottom: 0;
margin-left: 7%;
margin-right: 7%;
background-color: white;
margin-top: 0%;
margin-bottom: 0%;
margin-left: 0%;
margin-right: 0%;
}
.main {
max-width: 100% !important;
/* overflow-x: hidden; hide scroll bar */
display: block;
margin-top: 7%;
margin-bottom: 0;
margin-left: 7%;
margin-right: 7%;
background-color: white;
font-family: sans-serif;
}
h2 {
@ -15,14 +25,15 @@ h2 {
font-family: serif;
font-weight: bold;
word-wrap: break-word;
padding-top: 5%;
}
h3 {
color: #212121;
font-size: 1.5em;
font-family: sans-serif;
padding-top: 5%;
word-wrap: break-word;
padding-top: 5%;
}
p {
@ -31,17 +42,18 @@ p {
line-height: 1.6em;
}
li {
font-family: sans-serif;
line-height: 1.6em;
}
ul {
font-size: 1.1em;
line-height: 1.6em;
padding-top: 3%;
padding-bottom: 3%;
}
li {
font-family: sans-serif;
padding-top: 1%;
padding-bottom: 1%;
}
img {
width: 100%;
@ -79,4 +91,4 @@ pre {
color: #727272;
font-style: italic;
text-align: center;
}
}

View file

@ -414,6 +414,8 @@ dependencies {
compile 'com.moparisthebest:junidecode:0.1.1'
compile 'org.immutables:gson:2.5.0'
compile 'com.vividsolutions:jts-core:1.14.0'
compile 'com.squareup.picasso:picasso:2.71828'
// size restrictions
// compile 'com.ibm.icu:icu4j:50.1'
// compile 'net.sf.trove4j:trove4j:3.0.3'

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item>
<shape android:shape="oval">
<solid android:color="@color/color_transparent"/>
<size
android:width="28dp"
android:height="28dp"/>
</shape>
</item>
<item
android:id="@+id/placeholder_icon"
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<bitmap
android:gravity="center"
android:src="@drawable/ic_action_placeholder_city"
android:tint="@color/icon_color"/>
</item>
</layer-list>

View file

@ -22,8 +22,8 @@
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"

View file

@ -0,0 +1,49 @@
package net.osmand.plus.widgets.tools;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import com.squareup.picasso.Transformation;
public class CropCircleTransformation implements Transformation {
private static final String KEY = "CropCircleTransformation";
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int width = (source.getWidth() - size) / 2;
int height = (source.getHeight() - size) / 2;
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader =
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
if (width != 0 || height != 0) {
// source isn't square, move viewport to center
Matrix matrix = new Matrix();
matrix.setTranslate(-width, -height);
shader.setLocalMatrix(matrix);
}
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
source.recycle();
return bitmap;
}
@Override
public String key() {
return KEY;
}
}

View file

@ -9,6 +9,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -36,8 +37,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" +
"<meta http-equiv=\"cleartype\" content=\"on\" />\n" +
"<link href=\"article_style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n" +
"</head><body>\n" +
"<div class=\"main\">\n";
"</head><body>";
private static final String FOOTER_INNER = "</div></body></html>";
private WikivoyageSearchResult searchResult;
@ -140,9 +140,25 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
if (article == null) {
return;
}
String articleTitle = "<h1>" + article.getTitle() + "</h1>";
String content = HEADER_INNER + articleTitle + article.getContent() + FOOTER_INNER;
contentWebView.loadDataWithBaseURL(getBaseUrl(), content, "text/html", "UTF-8", null);
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
}
@NonNull
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);
sb.append("<img class=\"title-image\" src=\"").append(url).append("\"/>");
}
sb.append("<div class=\"main\">\n");
sb.append("<h1>").append(article.getTitle()).append("</h1>");
sb.append(article.getContent());
sb.append(FOOTER_INNER);
return sb.toString();
}
@NonNull

View file

@ -24,6 +24,7 @@ public class WikivoyageArticle {
long cityId;
long originalId;
String lang;
String aggregatedPartOf;
public String getId() {
return id;
@ -69,6 +70,10 @@ public class WikivoyageArticle {
return lang;
}
public String getAggregatedPartOf() {
return aggregatedPartOf;
}
@NonNull
public static String getThumbImageUrl(@NonNull String imageTitle) {
String[] hash = getHash(imageTitle);

View file

@ -39,6 +39,7 @@ public class WikivoyageDbHelper {
private static final String ARTICLES_COL_CITY_ID = "city_id";
private static final String ARTICLES_COL_ORIGINAL_ID = "original_id";
private static final String ARTICLES_COL_LANG = "lang";
private static final String ARTICLES_COL_AGGREGATED_PART_OF = "aggregated_part_of";
private static final String ARTICLES_TABLE_SELECT = "SELECT " +
ARTICLES_COL_ID + ", " +
@ -51,7 +52,8 @@ public class WikivoyageDbHelper {
ARTICLES_COL_GPX_GZ + ", " +
ARTICLES_COL_CITY_ID + ", " +
ARTICLES_COL_ORIGINAL_ID + ", " +
ARTICLES_COL_LANG +
ARTICLES_COL_LANG + ", " +
ARTICLES_COL_AGGREGATED_PART_OF +
" FROM " + ARTICLES_TABLE_NAME;
private static final String SEARCH_TABLE_NAME = "wikivoyage_search";
@ -210,6 +212,7 @@ public class WikivoyageDbHelper {
res.cityId = cursor.getLong(8);
res.originalId = cursor.getLong(9);
res.lang = cursor.getString(10);
res.aggregatedPartOf = cursor.getString(11);
return res;
}

View file

@ -1,7 +1,10 @@
package net.osmand.plus.wikivoyage.search;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@ -9,9 +12,12 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.IconsCache;
import com.squareup.picasso.Picasso;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import java.util.ArrayList;
@ -23,7 +29,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
private static final int ITEM_TYPE = 1;
private OsmandApplication app;
private IconsCache iconsCache;
private LayerDrawable placeholder;
private List<Object> items = new ArrayList<>();
@ -35,7 +41,11 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
SearchRecyclerViewAdapter(OsmandApplication app) {
this.app = app;
this.iconsCache = app.getIconsCache();
placeholder = (LayerDrawable) ContextCompat.getDrawable(app, R.drawable.wikivoyage_search_placeholder);
if (Build.VERSION.SDK_INT < 21 && placeholder != null) {
placeholder.setDrawableByLayerId(R.id.placeholder_icon,
app.getIconsCache().getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color));
}
}
@NonNull
@ -60,9 +70,11 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
boolean lastItem = pos == getItemCount() - 1;
WikivoyageSearchResult item = (WikivoyageSearchResult) getItem(pos);
holder.icon.setImageDrawable(
iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color)
);
Picasso.get()
.load(WikivoyageArticle.getThumbImageUrl(item.getImageTitle()))
.transform(new CropCircleTransformation())
.placeholder(placeholder)
.into(holder.icon);
holder.title.setText(item.getArticleTitles().get(0));
holder.leftDescr.setText(item.getIsPartOf());
holder.rightDescr.setText(item.getFirstLangsString());
@ -102,7 +114,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
final TextView title;
public HeaderVH(View itemView) {
HeaderVH(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
}
@ -117,7 +129,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
final View divider;
final View shadow;
public ItemVH(View itemView) {
ItemVH(View itemView) {
super(itemView);
icon = (ImageView) itemView.findViewById(R.id.icon);
title = (TextView) itemView.findViewById(R.id.title);