Merge
This commit is contained in:
commit
9ea83ebccd
17 changed files with 328 additions and 80 deletions
|
@ -242,7 +242,8 @@ p {
|
|||
color: var(--main-text-color-night);
|
||||
}
|
||||
|
||||
ul, dl {
|
||||
/* Lists */
|
||||
ul, dl, ol {
|
||||
/* font-size: var(--main-text-font-size); */
|
||||
color: var(--main-text-color-day);
|
||||
font-size: inherit;
|
||||
|
@ -259,15 +260,10 @@ li {
|
|||
padding-bottom: 1%;
|
||||
}
|
||||
|
||||
.nightmode ul, .nightmode dl {
|
||||
.nightmode ul, .nightmode dl, .nightmode ol {
|
||||
color: #cccccc;
|
||||
}
|
||||
|
||||
.toc {
|
||||
font-size: var(--main-text-font-size);
|
||||
}
|
||||
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
}
|
||||
|
@ -327,10 +323,47 @@ a.geo {
|
|||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
td {
|
||||
display: inline-block;
|
||||
/* Tables */
|
||||
table {
|
||||
display: block;
|
||||
overflow-y: scroll;
|
||||
word-wrap: break-word;
|
||||
color: var(--main-text-color-day);
|
||||
border: 1px solid var(--divider-color-day);
|
||||
background: var(--divider-color-day);
|
||||
margin-left: 0% !important;
|
||||
margin-right: 0% !important;
|
||||
margin-bottom: 7% !important;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
.nightmode table {
|
||||
color: var(--main-text-color-night);
|
||||
border: 1px solid var(--background-color-night);
|
||||
background: var(--divider-color-night) !important;
|
||||
}
|
||||
|
||||
|
||||
td, tr, th {
|
||||
border: 1px solid var(--divider-color-day);
|
||||
color: var(--main-text-color-night);
|
||||
background: var(--divider-color-day);
|
||||
}
|
||||
|
||||
.nightmode td, .nightmode tr, .nightmode th {
|
||||
color: var(--main-text-color-night);
|
||||
border: 1px solid var(--background-color-night);
|
||||
background: var(--divider-color-night) !important;
|
||||
}
|
||||
|
||||
.toc, .toc td, .toc tr {
|
||||
border: 0px solid;
|
||||
background: var(--background-color-day);
|
||||
}
|
||||
|
||||
.nightmode .toc, .toc td, .toc tr {
|
||||
border: 0px solid;
|
||||
background: var(--background-color-night) !important;
|
||||
}
|
||||
|
||||
.thumb-tright, .thumbinner {
|
||||
|
|
BIN
OsmAnd/res/drawable-hdpi/ic_action_subscription_osmand_live.png
Normal file
BIN
OsmAnd/res/drawable-hdpi/ic_action_subscription_osmand_live.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
OsmAnd/res/drawable-xhdpi/ic_action_subscription_osmand_live.png
Normal file
BIN
OsmAnd/res/drawable-xhdpi/ic_action_subscription_osmand_live.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
|
@ -76,6 +76,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
|
|
|
@ -28,14 +28,13 @@
|
|||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
|
||||
android:text="@string/maps_you_need_descr"
|
||||
android:textColor="@color/wikivoyage_secondary_text"
|
||||
android:textSize="@dimen/travel_card_primary_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="@string/maps_you_need_descr"/>
|
||||
osmand:typeface="@string/font_roboto_regular"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -54,6 +54,15 @@
|
|||
tools:text="En"
|
||||
tools:textColor="?attr/wikivoyage_active_color" />
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/options_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/shared_string_options"
|
||||
tools:src="@drawable/ic_overflow_menu_white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
|
|
@ -438,4 +438,7 @@
|
|||
<color name="wikivoyage_start_editing_card_image_background">#339966</color>
|
||||
<color name="wikivoyage_open_beta_card_image_background">#008bf8</color>
|
||||
|
||||
<color name="wiki_webview_background_light">#ffffff</color>
|
||||
<color name="wiki_webview_background_dark">#17191a</color>
|
||||
|
||||
</resources>
|
|
@ -10,10 +10,11 @@
|
|||
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="shared_string_restart">Restart</string>
|
||||
<string name="show_images">Show images</string>
|
||||
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
|
||||
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
|
||||
|
||||
<string name="maps_you_need_descr">You read articles: %1$s. Based on this, we suggest you download these maps:</string>
|
||||
<string name="maps_you_need_descr">Based on the articles you saved, we recommend you to download following maps:</string>
|
||||
<string name="maps_you_need">Maps you need</string>
|
||||
<string name="osmand_team">OsmAnd team</string>
|
||||
<string name="popular_destinations">Popular destinations</string>
|
||||
|
@ -673,7 +674,7 @@
|
|||
<string name="osm_live_hide_user_name">Do not show my name in reports</string>
|
||||
<string name="osm_live_support_region">Support region</string>
|
||||
<string name="osm_live_month_cost">Month cost</string>
|
||||
<string name="osm_live_month_cost_desc">Monthly payment.</string>
|
||||
<string name="osm_live_month_cost_desc">Monthly payment</string>
|
||||
<string name="osm_live_active">Active</string>
|
||||
<string name="osm_live_not_active">Inactive</string>
|
||||
<string name="osm_live_enter_email">Please enter a valid e-mail address</string>
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikipedia;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
|
@ -10,6 +11,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
|
@ -17,12 +19,12 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -30,7 +32,6 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.data.Amenity;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
|
@ -47,10 +48,6 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
|
||||
public static final String TAG = "WikipediaDialogFragment";
|
||||
|
||||
private static final int MENU_ITEM_NO_ID = 0;
|
||||
private static final int MENU_ITEM_SHOW_ID = 1;
|
||||
private static final int MENU_ITEM_WIFI_ID = 2;
|
||||
|
||||
private TextView readFullArticleButton;
|
||||
|
||||
private Amenity amenity;
|
||||
|
@ -75,7 +72,25 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||
|
||||
articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view);
|
||||
|
||||
ImageView options = (ImageView) mainView.findViewById(R.id.options_button);
|
||||
options.setImageDrawable(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm == null) {
|
||||
return;
|
||||
}
|
||||
WikipediaOptionsBottomSheetDialogFragment fragment = new WikipediaOptionsBottomSheetDialogFragment();
|
||||
fragment.setUsedOnMap(false);
|
||||
fragment.setTargetFragment(WikipediaDialogFragment.this,
|
||||
WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE);
|
||||
fragment.show(fm, WikipediaOptionsBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
});
|
||||
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode,
|
||||
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||
|
@ -106,6 +121,8 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
webSettings.setJavaScriptEnabled(true);
|
||||
contentWebView.setWebViewClient(new WikipediaWebViewClient(getActivity(), nightMode));
|
||||
updateWebSettings();
|
||||
contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(),
|
||||
nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
@ -254,37 +271,13 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
return showInstance(activity, amenity, null);
|
||||
}
|
||||
|
||||
protected void setupToolbar(Toolbar toolbar) {
|
||||
super.setupToolbar(toolbar);
|
||||
toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
|
||||
|
||||
Menu menu = toolbar.getMenu();
|
||||
MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == MENU_ITEM_SHOW_ID) {
|
||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON);
|
||||
return true;
|
||||
} else if (itemId == MENU_ITEM_WIFI_ID) {
|
||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI);
|
||||
return true;
|
||||
} else if (itemId == MENU_ITEM_NO_ID) {
|
||||
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
MenuItem itemShow = menu.add(0, MENU_ITEM_SHOW_ID, 0, R.string.shared_string_show);
|
||||
itemShow.setOnMenuItemClickListener(itemClickListener);
|
||||
MenuItem itemWifi = menu.add(0, MENU_ITEM_WIFI_ID, 0, R.string.shared_string_only_with_wifi);
|
||||
itemWifi.setOnMenuItemClickListener(itemClickListener);
|
||||
MenuItem itemNo = menu.add(0, MENU_ITEM_NO_ID, 0, R.string.shared_string_dont);
|
||||
itemNo.setOnMenuItemClickListener(itemClickListener);
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE
|
||||
&& resultCode == WikipediaOptionsBottomSheetDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
|
||||
updateWebSettings();
|
||||
populateArticle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package net.osmand.plus.wikipedia;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.Gravity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.WikiArticleShowImages;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
|
||||
|
||||
public class WikipediaOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public final static String TAG = "WikipediaOptionsBottomSheetDialogFragment";
|
||||
|
||||
public static final int REQUEST_CODE = 0;
|
||||
public static final int SHOW_PICTURES_CHANGED_REQUEST_CODE = 1;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
|
||||
|
||||
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
||||
|
||||
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(showImagesPref.get().name))
|
||||
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
|
||||
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||
.setTitle(getString(R.string.download_images))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
|
||||
for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) {
|
||||
MenuItem item = popup.getMenu().add(getString(showImages.name));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
showImagesPref.set(showImages);
|
||||
sendResult();
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
popup.show();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(showImagesItem);
|
||||
}
|
||||
|
||||
private void sendResult() {
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (fragment != null) {
|
||||
fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED_REQUEST_CODE, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
private static final String PREFIX_GEO = "geo:";
|
||||
private static final String PAGE_PREFIX_HTTP = "http://";
|
||||
private static final String PAGE_PREFIX_HTTPS = "https://";
|
||||
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.com/wiki/";
|
||||
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.org/wiki/";
|
||||
private static final String WIKI_DOMAIN = ".wikipedia.org/wiki/";
|
||||
private FetchWikiRegion fetchRegionTask;
|
||||
private WikiArticleSearchTask articleSearchTask;
|
||||
|
@ -80,7 +80,8 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (url.contains(WIKIVOAYAGE_DOMAIN)) {
|
||||
boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
|
||||
if (url.contains(WIKIVOAYAGE_DOMAIN) && isWebPage) {
|
||||
String lang = getLang(url);
|
||||
String articleName = getArticleNameFromUrl(url, lang);
|
||||
long articleId = app.getTravelDbHelper().getArticleId(articleName, lang);
|
||||
|
@ -90,11 +91,11 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
warnAboutExternalLoad(url, context, nightMode);
|
||||
}
|
||||
return true;
|
||||
} else if (url.contains(WIKI_DOMAIN)) {
|
||||
} else if (url.contains(WIKI_DOMAIN) && isWebPage) {
|
||||
String lang = getLang(url);
|
||||
String articleName = getArticleNameFromUrl(url, lang);
|
||||
getWikiArticle(articleName, lang, url);
|
||||
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
|
||||
} else if (isWebPage) {
|
||||
warnAboutExternalLoad(url, context, nightMode);
|
||||
} else if (url.startsWith(PREFIX_GEO)) {
|
||||
if (article != null) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentManager.BackStackEntry;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
|
@ -159,6 +160,8 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
|
|||
contentWebView.addJavascriptInterface(new WikivoyageArticleWebAppInterface(), "Android");
|
||||
webViewClient = new WikivoyageWebViewClient(getActivity(), getFragmentManager(), nightMode);
|
||||
contentWebView.setWebViewClient(webViewClient);
|
||||
contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(),
|
||||
nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
@ -253,7 +256,8 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
|
|||
for (String n : langs) {
|
||||
names.put(n, FileNameTranslationHelper.getVoiceName(getContext(), n));
|
||||
}
|
||||
for (final Map.Entry<String, String> e : names.entrySet()) {
|
||||
Map<String, String> sortedNames = AndroidUtils.sortByValue(names);
|
||||
for (final Map.Entry<String, String> e : sortedNames.entrySet()) {
|
||||
final String lang = e.getValue();
|
||||
final String langKey = e.getKey();
|
||||
MenuItem item = popup.getMenu().add(lang);
|
||||
|
|
|
@ -19,13 +19,16 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
|||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.NeededMapsVH;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private static final int DOWNLOAD_UPDATE_CARD_POSITION = 0;
|
||||
private static final int FIRST_POSITION = 0;
|
||||
private static final int SECOND_POSITION = 1;
|
||||
|
||||
private final List<BaseTravelCard> items = new ArrayList<>();
|
||||
|
||||
|
@ -48,6 +51,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
case HeaderTravelCard.TYPE:
|
||||
return new HeaderTravelVH(inflate(parent, R.layout.wikivoyage_list_header));
|
||||
|
||||
case TravelNeededMapsCard.TYPE:
|
||||
return new NeededMapsVH(inflate(parent, R.layout.travel_needed_maps_card));
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Unsupported view type: " + viewType);
|
||||
}
|
||||
|
@ -131,23 +137,45 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setNeededMapsCard(TravelNeededMapsCard card) {
|
||||
if (addItem(getNeededMapsCardPosition(), card)) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int getNeededMapsCardPosition() {
|
||||
if (downloadUpdateCardExists(FIRST_POSITION)) {
|
||||
return SECOND_POSITION;
|
||||
}
|
||||
return FIRST_POSITION;
|
||||
}
|
||||
|
||||
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
||||
if (addItem(DOWNLOAD_UPDATE_CARD_POSITION, card)) {
|
||||
if (addItem(getDownloadUpdateCardPosition(), card)) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDownloadUpdateCard() {
|
||||
notifyItemChanged(DOWNLOAD_UPDATE_CARD_POSITION);
|
||||
int pos = getDownloadUpdateCardPosition();
|
||||
if (downloadUpdateCardExists(pos)) {
|
||||
notifyItemChanged(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDownloadUpdateCard() {
|
||||
if (items.size() > DOWNLOAD_UPDATE_CARD_POSITION) {
|
||||
BaseTravelCard card = getItem(DOWNLOAD_UPDATE_CARD_POSITION);
|
||||
if (card.getCardType() == TravelDownloadUpdateCard.TYPE) {
|
||||
removeItem(DOWNLOAD_UPDATE_CARD_POSITION);
|
||||
notifyItemRemoved(DOWNLOAD_UPDATE_CARD_POSITION);
|
||||
}
|
||||
int pos = getDownloadUpdateCardPosition();
|
||||
if (downloadUpdateCardExists(pos)) {
|
||||
removeItem(pos);
|
||||
notifyItemRemoved(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private int getDownloadUpdateCardPosition() {
|
||||
return FIRST_POSITION;
|
||||
}
|
||||
|
||||
private boolean downloadUpdateCardExists(int position) {
|
||||
return items.size() > position && items.get(position).getCardType() == TravelDownloadUpdateCard.TYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
|||
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -93,17 +94,19 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
File targetFile = mainIndexItem.getTargetFile(app);
|
||||
if (downloadUpdateCard != null && mainIndexItem != null && targetFile.exists()) {
|
||||
downloadUpdateCard.setLoadingInProgress(false);
|
||||
removeDownloadUpdateCard();
|
||||
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
|
||||
travelDbHelper.initTravelBooks();
|
||||
travelDbHelper.selectTravelBook(targetFile);
|
||||
Fragment parent = getParentFragment();
|
||||
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
|
||||
((WikivoyageExploreDialogFragment) parent).populateData();
|
||||
if (mainIndexItem != null) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
File targetFile = mainIndexItem.getTargetFile(app);
|
||||
if (downloadUpdateCard != null && targetFile.exists()) {
|
||||
downloadUpdateCard.setLoadingInProgress(false);
|
||||
removeDownloadUpdateCard();
|
||||
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
|
||||
travelDbHelper.initTravelBooks();
|
||||
travelDbHelper.selectTravelBook(targetFile);
|
||||
Fragment parent = getParentFragment();
|
||||
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
|
||||
((WikivoyageExploreDialogFragment) parent).populateData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +156,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
this.mainIndexItem = mainIndexItem;
|
||||
this.neededIndexItems = neededIndexItems;
|
||||
addDownloadUpdateCard();
|
||||
addNeededMapsCard();
|
||||
}
|
||||
|
||||
private void addDownloadUpdateCard() {
|
||||
|
@ -209,6 +213,12 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
}
|
||||
}
|
||||
|
||||
private void addNeededMapsCard() {
|
||||
if (!neededIndexItems.isEmpty()) {
|
||||
adapter.setNeededMapsCard(new TravelNeededMapsCard(getMyApplication(), nightMode, neededIndexItems));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getWikivoyageFileName() {
|
||||
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
|
||||
|
|
|
@ -128,7 +128,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
|||
|
||||
@NonNull
|
||||
private String getFileTitle() {
|
||||
return indexItem == null ? "" : indexItem.getBasename().replace("_", " ");
|
||||
return indexItem == null ? "" : indexItem.getVisibleName(app, app.getRegions(), false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TravelNeededMapsCard extends BaseTravelCard {
|
||||
|
||||
public static final int TYPE = 70;
|
||||
|
||||
private List<IndexItem> items;
|
||||
|
||||
private Drawable downloadIcon;
|
||||
|
||||
public TravelNeededMapsCard(OsmandApplication app, boolean nightMode, List<IndexItem> items) {
|
||||
super(app, nightMode);
|
||||
this.items = items;
|
||||
downloadIcon = getActiveIcon(R.drawable.ic_action_import);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
|
||||
if (viewHolder instanceof NeededMapsVH) {
|
||||
NeededMapsVH holder = (NeededMapsVH) viewHolder;
|
||||
adjustChildCount(holder.itemsContainer);
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
boolean lastItem = i == items.size() - 1;
|
||||
IndexItem item = items.get(i);
|
||||
View view = holder.itemsContainer.getChildAt(i);
|
||||
((ImageView) view.findViewById(R.id.icon))
|
||||
.setImageDrawable(getActiveIcon(item.getType().getIconResource()));
|
||||
((TextView) view.findViewById(R.id.title)).setText(item.getVisibleName(app, app.getRegions(), false));
|
||||
((TextView) view.findViewById(R.id.description)).setText(getItemDescription(item));
|
||||
((ImageView) view.findViewById(R.id.icon_action)).setImageDrawable(downloadIcon);
|
||||
view.findViewById(R.id.divider).setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
private void adjustChildCount(LinearLayout itemsContainer) {
|
||||
int itemsCount = items.size();
|
||||
int childCount = itemsContainer.getChildCount();
|
||||
if (itemsCount == childCount) {
|
||||
return;
|
||||
}
|
||||
if (itemsCount > childCount) {
|
||||
LayoutInflater inflater = LayoutInflater.from(itemsContainer.getContext());
|
||||
for (int i = childCount; i < itemsCount; i++) {
|
||||
inflater.inflate(R.layout.travel_needed_map_item, itemsContainer);
|
||||
}
|
||||
} else if (itemsCount < childCount) {
|
||||
itemsContainer.removeViews(0, childCount - itemsCount);
|
||||
}
|
||||
}
|
||||
|
||||
private String getItemDescription(IndexItem item) {
|
||||
return app.getString(R.string.file_size_in_mb, item.getArchiveSizeMB()) + " • " + item.getType().getString(app);
|
||||
}
|
||||
|
||||
public static class NeededMapsVH extends RecyclerView.ViewHolder {
|
||||
|
||||
final LinearLayout itemsContainer;
|
||||
final View secondaryBtnContainer;
|
||||
final TextView secondaryBtn;
|
||||
final View buttonsDivider;
|
||||
final View primaryBtnContainer;
|
||||
final TextView primaryButton;
|
||||
|
||||
@SuppressWarnings("RedundantCast")
|
||||
public NeededMapsVH(View itemView) {
|
||||
super(itemView);
|
||||
itemsContainer = (LinearLayout) itemView.findViewById(R.id.items_container);
|
||||
secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container);
|
||||
secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button);
|
||||
buttonsDivider = itemView.findViewById(R.id.buttons_divider);
|
||||
primaryBtnContainer = itemView.findViewById(R.id.primary_btn_container);
|
||||
primaryButton = (TextView) itemView.findViewById(R.id.primary_button);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue