Merge pull request #8833 from osmandapp/custom_download_fixes

Description download actions
This commit is contained in:
max-klaus 2020-04-24 11:30:57 +03:00 committed by GitHub
commit 72089a6ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 300 additions and 250 deletions

View file

@ -16,7 +16,8 @@
<net.osmand.plus.LockableViewPager <net.osmand.plus.LockableViewPager
android:id="@+id/images_pager" android:id="@+id/images_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="132dp" /> android:layout_height="@dimen/download_description_images_height"
tools:visibility="gone" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/description" android:id="@+id/description"

View file

@ -22,47 +22,47 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<FrameLayout <include
android:layout_width="match_parent" layout="@layout/free_version_banner"
android:layout_height="match_parent"> android:background="#F00" />
<ScrollView <include layout="@layout/progress_with_two_texts" />
<FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activity_background_basic"> android:background="?attr/activity_background_basic">
<LinearLayout <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" android:scrollbars="none">
android:paddingBottom="@dimen/dialog_button_ex_height">
<ImageView <LinearLayout
android:id="@+id/item_image" android:id="@+id/description_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:orientation="vertical">
android:adjustViewBounds="true"
android:background="?attr/bg_color" <net.osmand.plus.LockableViewPager
android:maxHeight="132dp" android:id="@+id/images_pager"
android:scaleType="fitCenter" android:layout_width="match_parent"
tools:src="@drawable/extension_stub" /> android:layout_height="@dimen/download_description_images_height"
tools:visibility="gone" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/item_description" android:id="@+id/description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/bg_color" android:background="?attr/list_background_color"
android:letterSpacing="@dimen/text_button_letter_spacing" android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small" android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_regular" app:typeface="@string/font_roboto_regular"
tools:text="@string/lorem_ipsum" /> tools:text="@string/plugin_disabled_descr" />
<include layout="@layout/card_bottom_divider" /> <include layout="@layout/card_bottom_divider" />
@ -71,14 +71,12 @@
</ScrollView> </ScrollView>
<LinearLayout <LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:background="?attr/list_background_color"> android:background="?attr/list_background_color"
android:orientation="vertical" />
<include layout="@layout/bottom_buttons" />
</LinearLayout>
</FrameLayout> </FrameLayout>

View file

@ -241,4 +241,5 @@
<dimen name="settings_divider_margin_start">108dp</dimen> <dimen name="settings_divider_margin_start">108dp</dimen>
<dimen name="setting_list_item_large_height">108dp</dimen> <dimen name="setting_list_item_large_height">108dp</dimen>
<dimen name="download_description_images_height">198dp</dimen>
</resources> </resources>

View file

@ -367,4 +367,6 @@
<dimen name="mtrl_slider_track_side_padding">@dimen/slider_thumb_size</dimen> <dimen name="mtrl_slider_track_side_padding">@dimen/slider_thumb_size</dimen>
<dimen name="list_item_move_header_min_height">65dp</dimen> <dimen name="list_item_move_header_min_height">65dp</dimen>
<dimen name="download_description_images_height">132dp</dimen>
</resources> </resources>

View file

@ -143,15 +143,15 @@ public class CustomRegion extends WorldRegion {
long containerSize = itemJson.optLong("containerSize"); long containerSize = itemJson.optLong("containerSize");
String indexType = itemJson.optString("type", type); String indexType = itemJson.optString("type", type);
String webUrl = itemJson.optString("weburl");
String fileName = itemJson.optString("filename"); String fileName = itemJson.optString("filename");
String downloadUrl = itemJson.optString("downloadurl"); String downloadUrl = itemJson.optString("downloadurl");
String size = new DecimalFormat("#.#").format(containerSize / (1024f * 1024f)); String size = new DecimalFormat("#.#").format(containerSize / (1024f * 1024f));
List<String> descrImageUrl = JsonUtils.jsonArrayToList("image-description-url", itemJson);
Map<String, String> indexNames = JsonUtils.getLocalizedMapFromJson("name", itemJson); Map<String, String> indexNames = JsonUtils.getLocalizedMapFromJson("name", itemJson);
Map<String, String> descriptions = JsonUtils.getLocalizedMapFromJson("description", itemJson); Map<String, String> firstSubNames = JsonUtils.getLocalizedMapFromJson("firstsubname", itemJson);
Map<String, String> webButtonText = JsonUtils.getLocalizedMapFromJson("web-button-text", itemJson); Map<String, String> secondSubNames = JsonUtils.getLocalizedMapFromJson("secondsubname", itemJson);
DownloadDescriptionInfo descriptionInfo = DownloadDescriptionInfo.fromJson(itemJson.optJSONObject("description"));
DownloadActivityType type = DownloadActivityType.getIndexType(indexType); DownloadActivityType type = DownloadActivityType.getIndexType(indexType);
if (type != null) { if (type != null) {
@ -160,10 +160,9 @@ public class CustomRegion extends WorldRegion {
.setSubfolder(subfolder) .setSubfolder(subfolder)
.setDownloadUrl(downloadUrl) .setDownloadUrl(downloadUrl)
.setNames(indexNames) .setNames(indexNames)
.setDescriptions(descriptions) .setFirstSubNames(firstSubNames)
.setImageDescrUrl(descrImageUrl) .setSecondSubNames(secondSubNames)
.setWebUrl(webUrl) .setDescriptionInfo(descriptionInfo)
.setWebButtonText(webButtonText)
.setTimestamp(timestamp) .setTimestamp(timestamp)
.setSize(size) .setSize(size)
.setContentSize(contentSize) .setContentSize(contentSize)

View file

@ -7,44 +7,42 @@ import androidx.annotation.NonNull;
import net.osmand.JsonUtils; import net.osmand.JsonUtils;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.download.ui.DownloadDescriptionInfo;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Map; import java.util.Map;
public class CustomIndexItem extends IndexItem { public class CustomIndexItem extends IndexItem {
private String subfolder; private String subfolder;
private String downloadUrl; private String downloadUrl;
private String webUrl;
private List<String> imageDescrUrl;
private Map<String, String> names; private Map<String, String> names;
private Map<String, String> descriptions; private Map<String, String> firstSubNames;
private Map<String, String> webButtonTexts; private Map<String, String> secondSubNames;
private DownloadDescriptionInfo descriptionInfo;
public CustomIndexItem(String fileName, public CustomIndexItem(String fileName,
String subfolder, String subfolder,
String downloadUrl, String downloadUrl,
String webUrl,
String size, String size,
long timestamp, long timestamp,
long contentSize, long contentSize,
long containerSize, long containerSize,
List<String> imageDescrUrl,
Map<String, String> names, Map<String, String> names,
Map<String, String> descriptions, Map<String, String> firstSubNames,
Map<String, String> webButtonTexts, Map<String, String> secondSubNames,
@NonNull DownloadActivityType type) { @NonNull DownloadActivityType type,
DownloadDescriptionInfo descriptionInfo) {
super(fileName, null, timestamp, size, contentSize, containerSize, type); super(fileName, null, timestamp, size, contentSize, containerSize, type);
this.names = names;
this.firstSubNames = firstSubNames;
this.secondSubNames = secondSubNames;
this.subfolder = subfolder; this.subfolder = subfolder;
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
this.webUrl = webUrl; this.descriptionInfo = descriptionInfo;
this.imageDescrUrl = imageDescrUrl;
this.names = names;
this.descriptions = descriptions;
this.webButtonTexts = webButtonTexts;
} }
@Override @Override
@ -76,21 +74,26 @@ public class CustomIndexItem extends IndexItem {
return JsonUtils.getLocalizedResFromMap(ctx, names, name); return JsonUtils.getLocalizedResFromMap(ctx, names, name);
} }
public List<String> getDescriptionImageUrl() { public String getSubName(Context ctx) {
return imageDescrUrl; String subName = getFirstSubName(ctx);
String secondSubName = getSecondSubName(ctx);
if (secondSubName != null) {
subName = subName == null ? secondSubName : subName + "" + secondSubName;
}
return subName;
} }
public String getLocalizedDescription(Context ctx) { public String getFirstSubName(Context ctx) {
String description = super.getDescription(); return JsonUtils.getLocalizedResFromMap(ctx, firstSubNames, null);
return JsonUtils.getLocalizedResFromMap(ctx, descriptions, description);
} }
public String getWebUrl() { public String getSecondSubName(Context ctx) {
return webUrl; return JsonUtils.getLocalizedResFromMap(ctx, secondSubNames, null);
} }
public String getWebButtonText(Context ctx) { public DownloadDescriptionInfo getDescriptionInfo() {
return JsonUtils.getLocalizedResFromMap(ctx, webButtonTexts, null); return descriptionInfo;
} }
public static class CustomIndexItemBuilder { public static class CustomIndexItemBuilder {
@ -98,19 +101,18 @@ public class CustomIndexItem extends IndexItem {
private String fileName; private String fileName;
private String subfolder; private String subfolder;
private String downloadUrl; private String downloadUrl;
private String webUrl;
private String size; private String size;
private long timestamp; private long timestamp;
private long contentSize; private long contentSize;
private long containerSize; private long containerSize;
private List<String> imageDescrUrl;
private Map<String, String> names; private Map<String, String> names;
private Map<String, String> descriptions; private Map<String, String> firstSubNames;
private Map<String, String> webButtonText; private Map<String, String> secondSubNames;
private DownloadActivityType type; private DownloadActivityType type;
private DownloadDescriptionInfo descriptionInfo;
public CustomIndexItemBuilder setFileName(String fileName) { public CustomIndexItemBuilder setFileName(String fileName) {
this.fileName = fileName; this.fileName = fileName;
@ -127,11 +129,6 @@ public class CustomIndexItem extends IndexItem {
return this; return this;
} }
public CustomIndexItemBuilder setWebUrl(String webUrl) {
this.webUrl = webUrl;
return this;
}
public CustomIndexItemBuilder setSize(String size) { public CustomIndexItemBuilder setSize(String size) {
this.size = size; this.size = size;
return this; return this;
@ -152,23 +149,23 @@ public class CustomIndexItem extends IndexItem {
return this; return this;
} }
public CustomIndexItemBuilder setImageDescrUrl(List<String> imageDescrUrl) {
this.imageDescrUrl = imageDescrUrl;
return this;
}
public CustomIndexItemBuilder setNames(Map<String, String> names) { public CustomIndexItemBuilder setNames(Map<String, String> names) {
this.names = names; this.names = names;
return this; return this;
} }
public CustomIndexItemBuilder setDescriptions(Map<String, String> descriptions) { public CustomIndexItemBuilder setFirstSubNames(Map<String, String> firstSubNames) {
this.descriptions = descriptions; this.firstSubNames = firstSubNames;
return this; return this;
} }
public CustomIndexItemBuilder setWebButtonText(Map<String, String> webButtonText) { public CustomIndexItemBuilder setSecondSubNames(Map<String, String> secondSubNames) {
this.webButtonText = webButtonText; this.secondSubNames = secondSubNames;
return this;
}
public CustomIndexItemBuilder setDescriptionInfo(DownloadDescriptionInfo descriptionInfo) {
this.descriptionInfo = descriptionInfo;
return this; return this;
} }
@ -181,16 +178,15 @@ public class CustomIndexItem extends IndexItem {
return new CustomIndexItem(fileName, return new CustomIndexItem(fileName,
subfolder, subfolder,
downloadUrl, downloadUrl,
webUrl,
size, size,
timestamp, timestamp,
contentSize, contentSize,
containerSize, containerSize,
imageDescrUrl,
names, names,
descriptions, firstSubNames,
webButtonText, secondSubNames,
type); type,
descriptionInfo);
} }
} }
} }

View file

@ -21,14 +21,14 @@ public class DownloadDescriptionInfo {
private JSONArray buttonsJson; private JSONArray buttonsJson;
private List<String> imageUrls; private List<String> imageUrls;
private Map<String, String> texts; private Map<String, String> localizedDescription;
public List<String> getImageUrls() { public List<String> getImageUrls() {
return imageUrls; return imageUrls;
} }
public CharSequence getLocalizedDescription(Context ctx) { public CharSequence getLocalizedDescription(Context ctx) {
String description = JsonUtils.getLocalizedResFromMap(ctx, texts, null); String description = JsonUtils.getLocalizedResFromMap(ctx, localizedDescription, null);
return description != null ? Html.fromHtml(description) : null; return description != null ? Html.fromHtml(description) : null;
} }
@ -63,7 +63,7 @@ public class DownloadDescriptionInfo {
if (json != null) { if (json != null) {
DownloadDescriptionInfo downloadDescriptionInfo = new DownloadDescriptionInfo(); DownloadDescriptionInfo downloadDescriptionInfo = new DownloadDescriptionInfo();
try { try {
downloadDescriptionInfo.texts = JsonUtils.getLocalizedMapFromJson("text", json); downloadDescriptionInfo.localizedDescription = JsonUtils.getLocalizedMapFromJson("text", json);
downloadDescriptionInfo.imageUrls = JsonUtils.jsonArrayToList("image", json); downloadDescriptionInfo.imageUrls = JsonUtils.jsonArrayToList("image", json);
downloadDescriptionInfo.buttonsJson = json.optJSONArray("button"); downloadDescriptionInfo.buttonsJson = json.optJSONArray("button");
} catch (JSONException e) { } catch (JSONException e) {
@ -77,7 +77,7 @@ public class DownloadDescriptionInfo {
public JSONObject toJson() throws JSONException { public JSONObject toJson() throws JSONException {
JSONObject descrJson = new JSONObject(); JSONObject descrJson = new JSONObject();
JsonUtils.writeLocalizedMapToJson("text", descrJson, texts); JsonUtils.writeLocalizedMapToJson("text", descrJson, localizedDescription);
JsonUtils.writeStringListToJson("image", descrJson, imageUrls); JsonUtils.writeStringListToJson("image", descrJson, imageUrls);
descrJson.putOpt("button", buttonsJson); descrJson.putOpt("button", buttonsJson);
@ -87,6 +87,8 @@ public class DownloadDescriptionInfo {
public static class ActionButton { public static class ActionButton {
public static final String DOWNLOAD_ACTION = "download";
private String actionType; private String actionType;
private String name; private String name;
private String url; private String url;

View file

@ -2,37 +2,43 @@ package net.osmand.plus.download.ui;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.view.ViewTreeObserver;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.viewpager.widget.ViewPager;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.map.WorldRegion;
import net.osmand.plus.CustomRegion;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.download.CustomIndexItem; import net.osmand.plus.download.CustomIndexItem;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.DownloadDescriptionInfo.ActionButton;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.List;
import static net.osmand.plus.download.ui.DownloadResourceGroupFragment.REGION_ID_DLG_KEY; import static net.osmand.plus.download.ui.DownloadResourceGroupFragment.REGION_ID_DLG_KEY;
public class DownloadItemFragment extends DialogFragment { public class DownloadItemFragment extends DialogFragment implements DownloadEvents {
public static final String ITEM_ID_DLG_KEY = "index_item_dialog_key"; public static final String ITEM_ID_DLG_KEY = "index_item_dialog_key";
@ -41,14 +47,14 @@ public class DownloadItemFragment extends DialogFragment {
private String regionId = ""; private String regionId = "";
private int itemIndex = -1; private int itemIndex = -1;
private BannerAndDownloadFreeVersion banner;
private DownloadResourceGroup group; private DownloadResourceGroup group;
private CustomIndexItem indexItem;
private View view;
private Toolbar toolbar; private Toolbar toolbar;
private ImageView image;
private TextView description; private TextView description;
private TextView buttonTextView; private ViewPager imagesPager;
private View descriptionContainer;
private ViewGroup buttonsContainer;
private boolean nightMode; private boolean nightMode;
@ -58,12 +64,11 @@ public class DownloadItemFragment extends DialogFragment {
nightMode = !getMyApplication().getSettings().isLightContent(); nightMode = !getMyApplication().getSettings().isLightContent();
int themeId = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; int themeId = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
setStyle(STYLE_NO_FRAME, themeId); setStyle(STYLE_NO_FRAME, themeId);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.item_info_fragment, container, false); final View view = inflater.inflate(R.layout.item_info_fragment, container, false);
if (savedInstanceState != null) { if (savedInstanceState != null) {
regionId = savedInstanceState.getString(REGION_ID_DLG_KEY); regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
@ -85,77 +90,131 @@ public class DownloadItemFragment extends DialogFragment {
} }
}); });
description = view.findViewById(R.id.item_description); banner = new BannerAndDownloadFreeVersion(view, (DownloadActivity) getActivity(), false);
image = view.findViewById(R.id.item_image);
View dismissButton = view.findViewById(R.id.dismiss_button); description = view.findViewById(R.id.description);
dismissButton.setOnClickListener(new View.OnClickListener() { imagesPager = view.findViewById(R.id.images_pager);
buttonsContainer = view.findViewById(R.id.buttons_container);
descriptionContainer = view.findViewById(R.id.description_container);
reloadData();
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onClick(View v) { public void onGlobalLayout() {
if (indexItem != null && !Algorithms.isEmpty(indexItem.getWebUrl())) { ViewTreeObserver obs = view.getViewTreeObserver();
WikipediaDialogFragment.showFullArticle(v.getContext(), Uri.parse(indexItem.getWebUrl()), nightMode); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
} }
descriptionContainer.setPadding(0, 0, 0, buttonsContainer.getHeight());
} }
}); });
UiUtilities.setupDialogButton(nightMode, dismissButton, UiUtilities.DialogButtonType.PRIMARY, "");
buttonTextView = (TextView) dismissButton.findViewById(R.id.button_text);
return view; return view;
} }
@Override @Override
public void onResume() { public void onSaveInstanceState(@NonNull Bundle outState) {
super.onResume();
reloadData();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putString(REGION_ID_DLG_KEY, regionId); outState.putString(REGION_ID_DLG_KEY, regionId);
outState.putInt(ITEM_ID_DLG_KEY, itemIndex); outState.putInt(ITEM_ID_DLG_KEY, itemIndex);
} }
@Override
public void newDownloadIndexes() {
if (banner != null) {
banner.updateBannerInProgress();
}
reloadData();
}
@Override
public void downloadHasFinished() {
if (banner != null) {
banner.updateBannerInProgress();
}
reloadData();
}
@Override
public void downloadInProgress() {
if (banner != null) {
banner.updateBannerInProgress();
}
}
private void reloadData() { private void reloadData() {
DownloadActivity downloadActivity = getDownloadActivity(); DownloadActivity activity = getDownloadActivity();
if (downloadActivity != null) { OsmandApplication app = activity.getMyApplication();
OsmandApplication app = downloadActivity.getMyApplication(); DownloadResources indexes = activity.getDownloadThread().getIndexes();
DownloadResources indexes = getDownloadActivity().getDownloadThread().getIndexes();
group = indexes.getGroupById(regionId); group = indexes.getGroupById(regionId);
indexItem = (CustomIndexItem) group.getItemByIndex(itemIndex); CustomIndexItem indexItem = (CustomIndexItem) group.getItemByIndex(itemIndex);
if (indexItem != null) { if (indexItem != null) {
toolbar.setTitle(indexItem.getVisibleName(app, app.getRegions())); toolbar.setTitle(indexItem.getVisibleName(app, app.getRegions()));
WorldRegion region = group.getRegion();
if (region instanceof CustomRegion) { DownloadDescriptionInfo descriptionInfo = indexItem.getDescriptionInfo();
CustomRegion customRegion = (CustomRegion) region; if (descriptionInfo != null) {
int color = customRegion.getHeaderColor(); updateDescription(app, descriptionInfo, description);
if (color != -1) { updateImagesPager(app, descriptionInfo, imagesPager);
toolbar.setBackgroundColor(color); updateActionButtons(activity, descriptionInfo, indexItem, buttonsContainer, R.layout.bottom_buttons, nightMode);
}
} }
} }
description.setText(indexItem.getLocalizedDescription(app)); static void updateActionButtons(final DownloadActivity ctx, DownloadDescriptionInfo descriptionInfo,
buttonTextView.setText(indexItem.getWebButtonText(app)); @Nullable final IndexItem indexItem, ViewGroup buttonsContainer,
@LayoutRes int layoutId, final boolean nightMode) {
buttonsContainer.removeAllViews();
final PicassoUtils picassoUtils = PicassoUtils.getPicasso(app); List<ActionButton> actionButtons = descriptionInfo.getActionButtons(ctx);
Picasso picasso = Picasso.get(); if (Algorithms.isEmpty(actionButtons) && indexItem != null && !indexItem.isDownloaded()) {
for (final String imageUrl : indexItem.getDescriptionImageUrl()) { actionButtons.add(new ActionButton(ActionButton.DOWNLOAD_ACTION, ctx.getString(R.string.shared_string_download), null));
RequestCreator rc = picasso.load(imageUrl); }
rc.into(image, new Callback() {
for (final ActionButton actionButton : actionButtons) {
View buttonView = UiUtilities.getInflater(ctx, nightMode).inflate(layoutId, buttonsContainer, false);
View button = buttonView.findViewById(R.id.dismiss_button);
if (button != null) {
UiUtilities.setupDialogButton(nightMode, button, UiUtilities.DialogButtonType.PRIMARY, actionButton.getName());
} else {
TextView buttonText = buttonView.findViewById(R.id.button_text);
buttonText.setText(actionButton.getName());
}
buttonView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onSuccess() { public void onClick(View v) {
image.setVisibility(View.VISIBLE); if (actionButton.getUrl() != null) {
picassoUtils.setResultLoaded(imageUrl, true); WikipediaDialogFragment.showFullArticle(ctx, Uri.parse(actionButton.getUrl()), nightMode);
} else if (ActionButton.DOWNLOAD_ACTION.equalsIgnoreCase(actionButton.getActionType()) && indexItem != null) {
boolean isDownloading = ctx.getDownloadThread().isDownloading(indexItem);
if (!isDownloading) {
ctx.startDownload(indexItem);
}
} else {
String text = ctx.getString(R.string.download_unsupported_action, actionButton.getActionType());
Toast.makeText(ctx, text, Toast.LENGTH_SHORT).show();
} }
@Override
public void onError(Exception e) {
image.setVisibility(View.GONE);
picassoUtils.setResultLoaded(imageUrl, false);
} }
}); });
buttonsContainer.addView(buttonView);
} }
} }
static void updateDescription(OsmandApplication app, DownloadDescriptionInfo descriptionInfo, TextView descriptionView) {
CharSequence descr = descriptionInfo.getLocalizedDescription(app);
descriptionView.setText(descr);
AndroidUiHelper.updateVisibility(descriptionView, !Algorithms.isEmpty(descr));
}
static void updateImagesPager(OsmandApplication app, DownloadDescriptionInfo descriptionInfo, ViewPager viewPager) {
if (!Algorithms.isEmpty(descriptionInfo.getImageUrls())) {
ImagesPagerAdapter adapter = new ImagesPagerAdapter(app, descriptionInfo.getImageUrls());
viewPager.setAdapter(adapter);
viewPager.setVisibility(View.VISIBLE);
} else {
viewPager.setVisibility(View.GONE);
} }
} }

View file

@ -5,7 +5,6 @@ import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.TypedValue; import android.util.TypedValue;
@ -22,19 +21,13 @@ import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.view.MenuItemCompat; import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.viewpager.widget.PagerAdapter;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.plus.CustomRegion; import net.osmand.plus.CustomRegion;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -51,12 +44,9 @@ import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.DownloadDescriptionInfo.ActionButton;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.json.JSONException; import org.json.JSONException;
@ -68,6 +58,10 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static net.osmand.plus.download.ui.DownloadItemFragment.updateActionButtons;
import static net.osmand.plus.download.ui.DownloadItemFragment.updateDescription;
import static net.osmand.plus.download.ui.DownloadItemFragment.updateImagesPager;
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents, public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents,
InAppPurchaseListener, OnChildClickListener { InAppPurchaseListener, OnChildClickListener {
public static final int RELOAD_ID = 0; public static final int RELOAD_ID = 0;
@ -254,40 +248,17 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
if (descriptionView != null) { if (descriptionView != null) {
if (group != null && group.getRegion() instanceof CustomRegion) { if (group != null && group.getRegion() instanceof CustomRegion) {
CustomRegion customRegion = (CustomRegion) group.getRegion(); CustomRegion customRegion = (CustomRegion) group.getRegion();
DownloadDescriptionInfo downloadDescriptionInfo = customRegion.getDescriptionInfo(); DownloadDescriptionInfo descriptionInfo = customRegion.getDescriptionInfo();
if (downloadDescriptionInfo != null) { if (descriptionInfo != null) {
OsmandApplication app = activity.getMyApplication();
TextView description = descriptionView.findViewById(R.id.description); TextView description = descriptionView.findViewById(R.id.description);
CharSequence descr = downloadDescriptionInfo.getLocalizedDescription(activity); updateDescription(app, descriptionInfo, description);
description.setText(descr);
AndroidUiHelper.updateVisibility(description, !Algorithms.isEmpty(descr));
ViewGroup buttonsContainer = descriptionView.findViewById(R.id.buttons_container); ViewGroup buttonsContainer = descriptionView.findViewById(R.id.buttons_container);
buttonsContainer.removeAllViews(); updateActionButtons(activity, descriptionInfo, null, buttonsContainer, R.layout.download_description_button, nightMode);
for (final ActionButton actionButton : downloadDescriptionInfo.getActionButtons(activity)) {
String name = actionButton.getName();
if (!Algorithms.isEmpty(name)) {
TextView buttonText = (TextView) activity.getLayoutInflater().inflate(R.layout.download_description_button, buttonsContainer, false);
buttonText.setText(name);
buttonText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (actionButton.getUrl() != null) {
WikipediaDialogFragment.showFullArticle(activity, Uri.parse(actionButton.getUrl()), nightMode);
} else {
activity.getMyApplication().showShortToastMessage(R.string.download_unsupported_action, actionButton.getActionType());
}
}
});
buttonsContainer.addView(buttonText);
}
}
LockableViewPager viewPager = descriptionView.findViewById(R.id.images_pager); LockableViewPager viewPager = descriptionView.findViewById(R.id.images_pager);
if (!Algorithms.isEmpty(downloadDescriptionInfo.getImageUrls())) { updateImagesPager(app, descriptionInfo, viewPager);
ImagesPagerAdapter adapter = new ImagesPagerAdapter(downloadDescriptionInfo.getImageUrls());
viewPager.setAdapter(adapter);
} else {
viewPager.setVisibility(View.GONE);
}
descriptionView.findViewById(R.id.container).setVisibility(View.VISIBLE); descriptionView.findViewById(R.id.container).setVisibility(View.VISIBLE);
return; return;
@ -798,60 +769,4 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
return true; return true;
} }
} }
private class ImagesPagerAdapter extends PagerAdapter {
private PicassoUtils picassoUtils;
private List<String> imageUrls;
public ImagesPagerAdapter(List<String> imageUrls) {
this.imageUrls = imageUrls;
picassoUtils = PicassoUtils.getPicasso(getMyApplication());
}
@Override
public int getCount() {
return imageUrls.size();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = createImageView(position);
container.addView(view, 0);
return view;
}
@Override
public void destroyItem(ViewGroup collection, int position, @NonNull Object view) {
collection.removeView((View) view);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
private View createImageView(int position) {
final ImageView imageView = new ImageView(getContext());
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final String imageUrl = imageUrls.get(position);
Picasso.get().load(imageUrl).into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(imageUrl, true);
}
@Override
public void onError(Exception e) {
imageView.setVisibility(View.INVISIBLE);
picassoUtils.setResultLoaded(imageUrl, false);
}
});
return imageView;
}
}
} }

View file

@ -0,0 +1,74 @@
package net.osmand.plus.download.ui;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import java.util.List;
public class ImagesPagerAdapter extends PagerAdapter {
private OsmandApplication app;
private PicassoUtils picassoUtils;
private List<String> imageUrls;
public ImagesPagerAdapter(@NonNull OsmandApplication app, List<String> imageUrls) {
this.app = app;
this.imageUrls = imageUrls;
picassoUtils = PicassoUtils.getPicasso(app);
}
@Override
public int getCount() {
return imageUrls.size();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = createImageView(position);
container.addView(view, 0);
return view;
}
@Override
public void destroyItem(ViewGroup collection, int position, @NonNull Object view) {
collection.removeView((View) view);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
private View createImageView(int position) {
final ImageView imageView = new ImageView(app);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final String imageUrl = imageUrls.get(position);
Picasso.get().load(imageUrl).into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(imageUrl, true);
}
@Override
public void onError(Exception e) {
imageView.setVisibility(View.INVISIBLE);
picassoUtils.setResultLoaded(imageUrl, false);
}
});
return imageView;
}
}

View file

@ -27,6 +27,7 @@ import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.download.CityItem; import net.osmand.plus.download.CityItem;
import net.osmand.plus.download.CustomIndexItem;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResourceGroup;
@ -179,7 +180,9 @@ public class ItemViewHolder {
if (!isDownloading) { if (!isDownloading) {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
descrTextView.setVisibility(View.VISIBLE); descrTextView.setVisibility(View.VISIBLE);
if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) { if (indexItem instanceof CustomIndexItem && (((CustomIndexItem) indexItem).getSubName(context) != null)) {
descrTextView.setText(((CustomIndexItem) indexItem).getSubName(context));
} else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
descrTextView.setText(context.getString(R.string.depth_contour_descr)); descrTextView.setText(context.getString(R.string.depth_contour_descr));
} else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE } else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE