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

This commit is contained in:
Victor Shcherb 2018-05-01 10:30:15 +03:00
commit e279b2fed1
28 changed files with 130 additions and 38 deletions

View file

@ -5,8 +5,8 @@
</item> </item>
<item> <item>
<shape> <shape>
<stroke android:color="?attr/wikivoyage_active_color" android:width="1dp"/> <stroke android:color="@color/wikivoyage_active_dark" android:width="1dp"/>
<solid android:color="?attr/wikivoyage_card_bg_color"/> <solid android:color="@color/wikivoyage_card_bg_dark"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>
</shape> </shape>
</item> </item>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch android:src="@drawable/bg_card_shadow_cr3dp"/>
</item>
<item>
<shape>
<stroke android:color="@color/wikivoyage_active_light" android:width="1dp"/>
<solid android:color="@color/wikivoyage_card_bg_light"/>
<corners android:radius="3dp"/>
</shape>
</item>
</layer-list>

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch android:src="@drawable/bg_card_shadow_cr3dp"/>
</item>
<item>
<shape>
<solid android:color="?attr/wikivoyage_card_bg_color"/>
<corners android:radius="3dp"/>
</shape>
</item>
</layer-list>

View file

@ -5,7 +5,7 @@
</item> </item>
<item> <item>
<shape> <shape>
<solid android:color="?attr/wikivoyage_card_bg_color"/> <solid android:color="@color/wikivoyage_card_bg_dark"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>
</shape> </shape>
</item> </item>

View file

@ -5,7 +5,7 @@
</item> </item>
<item> <item>
<shape> <shape>
<solid android:color="?attr/wikivoyage_card_bg_color"/> <solid android:color="@color/wikivoyage_card_bg_light"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>
</shape> </shape>
</item> </item>

View file

@ -5,7 +5,7 @@
<stroke <stroke
android:width="1dp" android:width="1dp"
android:color="?attr/wikivoyage_card_divider_color"/> android:color="@color/wikivoyage_card_divider_dark"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/wikivoyage_card_divider_light"/>
<corners android:radius="3dp"/>
</shape>

View file

@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<solid android:color="?attr/wikivoyage_active_color"/> <solid android:color="@color/wikivoyage_active_dark"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wikivoyage_active_light"/>
<corners android:radius="3dp"/>
</shape>

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<solid android:color="?attr/wikivoyage_secondary_btn_bg_color"/> <solid android:color="@color/wikivoyage_secondary_btn_bg_dark"/>
<corners android:radius="3dp"/> <corners android:radius="3dp"/>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wikivoyage_secondary_btn_bg_light"/>
<corners android:radius="3dp"/>
</shape>

View file

@ -75,7 +75,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/text_margin_small" android:layout_marginLeft="@dimen/text_margin_small"
android:layout_marginRight="@dimen/text_margin_small" android:layout_marginRight="@dimen/text_margin_small"
android:background="@drawable/wikivoyage_search_card_bg"> android:background="?attr/wikivoyage_travel_card_bg">
<LinearLayout <LinearLayout
android:id="@+id/search_button" android:id="@+id/search_button"

View file

@ -62,7 +62,7 @@
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small" android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small"
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small" android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/wikivoyage_secondary_btn_bg"> android:background="?attr/wikivoyage_secondary_btn_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_no" android:id="@+id/button_no"
@ -88,7 +88,7 @@
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small" android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small"
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small" android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/wikivoyage_secondary_btn_bg"> android:background="?attr/wikivoyage_secondary_btn_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_wifi" android:id="@+id/button_wifi"
@ -112,7 +112,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/wikivoyage_primary_btn_bg"> android:background="?attr/wikivoyage_primary_btn_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_yes" android:id="@+id/button_yes"

View file

@ -8,7 +8,7 @@
android:layout_marginBottom="@dimen/list_header_padding" android:layout_marginBottom="@dimen/list_header_padding"
android:layout_marginLeft="@dimen/card_padding" android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:background="@drawable/dialog_active_card_bg" android:background="?attr/purchase_dialog_active_card_bg"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/purchase_dialog_card_header"/> <include layout="@layout/purchase_dialog_card_header"/>

View file

@ -7,7 +7,7 @@
android:layout_marginBottom="@dimen/list_header_padding" android:layout_marginBottom="@dimen/list_header_padding"
android:layout_marginLeft="@dimen/card_padding" android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:background="@drawable/dialog_card_bg" android:background="?attr/wikivoyage_travel_card_bg"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/purchase_dialog_card_header"/> <include layout="@layout/purchase_dialog_card_header"/>

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/wikivoyage_active_card_bg"> android:background="?attr/wikivoyage_primary_btn_bg">
<LinearLayout <LinearLayout
android:id="@+id/card_button" android:id="@+id/card_button"

View file

@ -87,7 +87,7 @@
android:layout_marginLeft="@dimen/card_padding" android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:background="@drawable/wikivoyage_search_card_bg"> android:background="?attr/wikivoyage_travel_card_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_later" android:id="@+id/button_later"

View file

@ -7,7 +7,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/text_margin_small" android:layout_marginLeft="@dimen/text_margin_small"
android:layout_marginRight="@dimen/text_margin_small" android:layout_marginRight="@dimen/text_margin_small"
android:background="@drawable/travel_card_bg" android:background="?attr/wikivoyage_travel_card_bg"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
@ -64,7 +64,7 @@
android:layout_marginBottom="@dimen/content_padding" android:layout_marginBottom="@dimen/content_padding"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin_small" android:layout_marginLeft="@dimen/bottom_sheet_content_margin_small"
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small" android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
android:background="@drawable/travel_card_stroke_bg" android:background="?attr/wikivoyage_travel_card_stroke_bg"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height" android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"> android:paddingRight="@dimen/content_padding">
@ -135,7 +135,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/wikivoyage_secondary_btn_bg"> android:background="?attr/wikivoyage_secondary_btn_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/secondary_button" android:id="@+id/secondary_button"
@ -165,7 +165,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/wikivoyage_primary_btn_bg"> android:background="?attr/wikivoyage_primary_btn_bg">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/primary_button" android:id="@+id/primary_button"

View file

@ -8,7 +8,7 @@
android:layout_marginTop="@dimen/content_padding_small" android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/text_margin_small" android:layout_marginLeft="@dimen/text_margin_small"
android:layout_marginRight="@dimen/text_margin_small" android:layout_marginRight="@dimen/text_margin_small"
android:background="@drawable/travel_card_bg" android:background="?attr/wikivoyage_travel_card_bg"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout

View file

@ -8,7 +8,7 @@
android:layout_marginTop="@dimen/content_padding_small" android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/text_margin_small" android:layout_marginLeft="@dimen/text_margin_small"
android:layout_marginRight="@dimen/text_margin_small" android:layout_marginRight="@dimen/text_margin_small"
android:background="@drawable/travel_card_bg"> android:background="?attr/wikivoyage_travel_card_bg">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -81,6 +81,13 @@
<attr name="wikivoyage_primary_btn_text_color" format="reference"/> <attr name="wikivoyage_primary_btn_text_color" format="reference"/>
<attr name="wikivoyage_welcome_bg_color" format="reference"/> <attr name="wikivoyage_welcome_bg_color" format="reference"/>
<attr name="wikivoyage_primary_text_color" format="reference"/> <attr name="wikivoyage_primary_text_color" format="reference"/>
<attr name="wikivoyage_travel_card_bg" format="reference"/>
<attr name="wikivoyage_travel_card_stroke_bg" format="reference"/>
<attr name="wikivoyage_secondary_btn_bg" format="reference"/>
<attr name="wikivoyage_primary_btn_bg" format="reference"/>
<attr name="purchase_dialog_active_card_bg" format="reference"/>
</declare-styleable> </declare-styleable>
<declare-styleable name="PagerSlidingTabStrip"> <declare-styleable name="PagerSlidingTabStrip">

View file

@ -213,6 +213,13 @@
<item name="wikivoyage_primary_btn_text_color">@color/wikivoyage_primary_btn_text_light</item> <item name="wikivoyage_primary_btn_text_color">@color/wikivoyage_primary_btn_text_light</item>
<item name="wikivoyage_welcome_bg_color">@color/wikivoyage_welcome_bg_light</item> <item name="wikivoyage_welcome_bg_color">@color/wikivoyage_welcome_bg_light</item>
<item name="wikivoyage_primary_text_color">@color/wikivoyage_primary_text_light</item> <item name="wikivoyage_primary_text_color">@color/wikivoyage_primary_text_light</item>
<item name="wikivoyage_travel_card_bg">@drawable/travel_card_bg_light</item>
<item name="wikivoyage_travel_card_stroke_bg">@drawable/travel_card_stroke_bg_light</item>
<item name="wikivoyage_secondary_btn_bg">@drawable/wikivoyage_secondary_btn_bg_light</item>
<item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_light</item>
<item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_light</item>
</style> </style>
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow"> <style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
@ -414,6 +421,13 @@
<item name="wikivoyage_primary_btn_text_color">@color/wikivoyage_primary_btn_text_dark</item> <item name="wikivoyage_primary_btn_text_color">@color/wikivoyage_primary_btn_text_dark</item>
<item name="wikivoyage_welcome_bg_color">@color/wikivoyage_welcome_bg_dark</item> <item name="wikivoyage_welcome_bg_color">@color/wikivoyage_welcome_bg_dark</item>
<item name="wikivoyage_primary_text_color">@color/wikivoyage_primary_text_dark</item> <item name="wikivoyage_primary_text_color">@color/wikivoyage_primary_text_dark</item>
<item name="wikivoyage_travel_card_bg">@drawable/travel_card_bg_dark</item>
<item name="wikivoyage_travel_card_stroke_bg">@drawable/travel_card_stroke_bg_dark</item>
<item name="wikivoyage_secondary_btn_bg">@drawable/wikivoyage_secondary_btn_bg_dark</item>
<item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_dark</item>
<item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_dark</item>
</style> </style>
<style name="FreeVersionBanner" parent="OsmandDarkTheme"> <style name="FreeVersionBanner" parent="OsmandDarkTheme">

View file

@ -10,6 +10,8 @@ import com.squareup.picasso.Picasso;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Cache; import okhttp3.Cache;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -28,6 +30,8 @@ public class PicassoUtils {
private static boolean initialized; private static boolean initialized;
private static Map<String, Boolean> cached = new HashMap<>();
public static void setupPicasso(@NonNull Context context) { public static void setupPicasso(@NonNull Context context) {
if (!initialized) { if (!initialized) {
File cacheDir = createDefaultCacheDir(context); File cacheDir = createDefaultCacheDir(context);
@ -57,6 +61,19 @@ public class PicassoUtils {
e.printStackTrace(); e.printStackTrace();
} }
} }
cached.clear();
}
public static Boolean isCached(@NonNull String key) {
return cached.get(key);
}
public static void setCached(@NonNull String key, boolean val) {
cached.put(key, val);
}
public static void clearCachedMap() {
cached.clear();
} }
public static long getDiskCacheSizeBytes() throws IOException { public static long getDiskCacheSizeBytes() throws IOException {

View file

@ -116,6 +116,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
public void setItems(List<BaseTravelCard> items) { public void setItems(List<BaseTravelCard> items) {
this.items.clear(); this.items.clear();
this.items.addAll(items); this.items.addAll(items);
notifyDataSetChanged();
} }
private void removeItem(int position) { private void removeItem(int position) {

View file

@ -16,6 +16,7 @@ import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator; import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -76,22 +77,29 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
} else { } else {
final ItemVH holder = (ItemVH) viewHolder; final ItemVH holder = (ItemVH) viewHolder;
TravelArticle article = (TravelArticle) getItem(position); TravelArticle article = (TravelArticle) getItem(position);
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
Boolean cached = PicassoUtils.isCached(url);
boolean lastItem = position == getItemCount() - 1; boolean lastItem = position == getItemCount() - 1;
RequestCreator rc = Picasso.get() RequestCreator rc = Picasso.get()
.load(TravelArticle.getImageUrl(article.getImageTitle(), false)); .load(url);
WikivoyageUtils.setupNetworkPolicy(settings, rc); WikivoyageUtils.setupNetworkPolicy(settings, rc);
rc.transform(new CropCircleTransformation()) rc.transform(new CropCircleTransformation())
.into(holder.icon, new Callback() { .into(holder.icon, new Callback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
holder.icon.setVisibility(View.VISIBLE); holder.icon.setVisibility(View.VISIBLE);
PicassoUtils.setCached(url, true);
} }
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
holder.icon.setVisibility(View.GONE); holder.icon.setVisibility(View.GONE);
PicassoUtils.setCached(url, false);
} }
}); });
holder.icon.setVisibility(cached != null && cached ? View.VISIBLE : View.GONE);
holder.title.setText(article.getTitle()); holder.title.setText(article.getTitle());
holder.content.setText(article.getContent()); holder.content.setText(article.getContent());
holder.partOf.setText(article.getGeoDescription()); holder.partOf.setText(article.getGeoDescription());

View file

@ -143,6 +143,12 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
return mainView; return mainView;
} }
@Override
public void onDestroy() {
super.onDestroy();
PicassoUtils.clearCachedMap();
}
protected void onDataLoaded() { protected void onDataLoaded() {
mainView.findViewById(R.id.progress_bar).setVisibility(View.GONE); mainView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
updateSearchVisibility(); updateSearchVisibility();

View file

@ -12,6 +12,7 @@ import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator; import com.squareup.picasso.RequestCreator;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.widgets.tools.CropCircleTransformation;
@ -40,21 +41,28 @@ public class ArticleTravelCard extends BaseTravelCard {
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof ArticleTravelVH) { if (viewHolder instanceof ArticleTravelVH) {
final ArticleTravelVH holder = (ArticleTravelVH) viewHolder; final ArticleTravelVH holder = (ArticleTravelVH) viewHolder;
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
Boolean cached = PicassoUtils.isCached(url);
RequestCreator rc = Picasso.get() RequestCreator rc = Picasso.get()
.load(TravelArticle.getImageUrl(article.getImageTitle(), false)); .load(url);
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc); WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation()) rc.transform(new CropCircleTransformation())
.into(holder.icon, new Callback() { .into(holder.icon, new Callback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
holder.icon.setVisibility(View.VISIBLE); holder.icon.setVisibility(View.VISIBLE);
PicassoUtils.setCached(url, true);
} }
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
holder.icon.setVisibility(View.GONE); holder.icon.setVisibility(View.GONE);
PicassoUtils.setCached(url, false);
} }
}); });
holder.icon.setVisibility(cached != null && cached ? View.VISIBLE : View.GONE);
holder.title.setText(article.getTitle()); holder.title.setText(article.getTitle());
holder.content.setText(article.getPartialContent()); holder.content.setText(article.getPartialContent());
holder.partOf.setText(article.getGeoDescription()); holder.partOf.setText(article.getGeoDescription());

View file

@ -206,9 +206,9 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
@DrawableRes @DrawableRes
private int getPrimaryBtnBgRes(boolean enabled) { private int getPrimaryBtnBgRes(boolean enabled) {
if (enabled) { if (enabled) {
return R.drawable.wikivoyage_primary_btn_bg; return nightMode ? R.drawable.wikivoyage_primary_btn_bg_dark : R.drawable.wikivoyage_primary_btn_bg_light;
} }
return R.drawable.wikivoyage_secondary_btn_bg; return nightMode ? R.drawable.wikivoyage_secondary_btn_bg_dark : R.drawable.wikivoyage_secondary_btn_bg_light;
} }
@ColorRes @ColorRes