Show all available obf travel files in the card to download
This commit is contained in:
parent
9483c80790
commit
f55c64159e
6 changed files with 166 additions and 522 deletions
|
@ -1,198 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/text_margin_small"
|
||||
android:layout_marginRight="@dimen/text_margin_small"
|
||||
android:background="?attr/wikivoyage_travel_card_bg"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginEnd="@dimen/text_margin_small"
|
||||
android:layout_marginStart="@dimen/text_margin_small">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/content_padding"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_content_padding_small">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?attr/wikivoyage_primary_text_color"
|
||||
android:textSize="@dimen/travel_card_primary_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Download file"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@drawable/travel_card_download_icon"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<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:textColor="@color/wikivoyage_secondary_text"
|
||||
android:textSize="@dimen/travel_card_primary_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="Download this Wikivoyage travel guides file to view articles about places around the world without an internet connection."/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/file_data_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/content_padding"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_content_margin_small"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_content_margin_small"
|
||||
android:background="?attr/wikivoyage_travel_card_stroke_bg"
|
||||
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_margin_small"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_content_margin_small">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/file_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@drawable/ic_action_read_article"
|
||||
tools:tint="?attr/wikivoyage_active_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/file_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?attr/wikivoyage_primary_text_color"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="Wikivoyage"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/file_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/wikivoyage_secondary_text"
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="255 Mb • Update 11 April"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:minHeight="0dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@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_marginEnd="@dimen/bottom_sheet_content_margin_small"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_margin_small">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/secondary_btn_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/wikivoyage_secondary_btn_bg">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/secondary_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/wikivoyage_card_button_height"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:textColor="?attr/wikivoyage_active_color"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:text="Later"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/buttons_divider"
|
||||
android:layout_width="@dimen/bottom_sheet_content_margin_small"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/primary_btn_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/wikivoyage_primary_btn_bg">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/primary_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/wikivoyage_card_button_height"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:textColor="?attr/wikivoyage_primary_btn_text_color"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:text="Update"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -18,16 +18,34 @@
|
|||
android:layout_margin="@dimen/content_padding"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/content_padding"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_content_padding_small">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/maps_you_need"
|
||||
android:textColor="?attr/wikivoyage_primary_text_color"
|
||||
android:textSize="@dimen/travel_card_primary_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Download file" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@drawable/travel_card_download_icon" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/description"
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard.OpenBet
|
|||
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.TravelGpxCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
|
||||
|
@ -53,12 +52,10 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
case TravelGpxCard.TYPE:
|
||||
return new TravelGpxVH(inflate(parent, R.layout.wikivoyage_travel_gpx_card));
|
||||
|
||||
case TravelDownloadUpdateCard.TYPE:
|
||||
return new DownloadUpdateVH(inflate(parent, R.layout.travel_download_update_card));
|
||||
|
||||
case HeaderTravelCard.TYPE:
|
||||
return new HeaderTravelVH(inflate(parent, R.layout.wikivoyage_list_header));
|
||||
|
||||
case TravelDownloadUpdateCard.TYPE:
|
||||
case TravelNeededMapsCard.TYPE:
|
||||
return new NeededMapsVH(inflate(parent, R.layout.travel_needed_maps_card));
|
||||
|
||||
|
@ -205,7 +202,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
if(onlyProgress) {
|
||||
TravelDownloadUpdateCard dc = this.downloadCard;
|
||||
if(dc != null) {
|
||||
dc.updateProgresBar();
|
||||
dc.updateView();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.wikivoyage.explore;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
|
@ -63,9 +62,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
private DownloadValidationManager downloadManager;
|
||||
@Nullable
|
||||
private IndexItem currentDownloadingIndexItem;
|
||||
@Nullable
|
||||
private IndexItem mainIndexItem;
|
||||
|
||||
private final List<IndexItem> mainIndexItems = new ArrayList<>();
|
||||
private final List<IndexItem> neededIndexItems = new ArrayList<>();
|
||||
private boolean waitForIndexes;
|
||||
|
||||
|
@ -199,17 +196,24 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
}
|
||||
|
||||
private void removeRedundantCards() {
|
||||
if (mainIndexItem != null && mainIndexItem.isDownloaded() && !mainIndexItem.isOutdated()) {
|
||||
removeDownloadUpdateCard();
|
||||
}
|
||||
boolean allMapsDownloaded = true;
|
||||
for (IndexItem item : neededIndexItems) {
|
||||
boolean allTravelGuideDownloaded = true;
|
||||
for (IndexItem item : mainIndexItems) {
|
||||
if (!item.isDownloaded()) {
|
||||
allMapsDownloaded = false;
|
||||
allTravelGuideDownloaded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allMapsDownloaded) {
|
||||
if (allTravelGuideDownloaded) {
|
||||
removeDownloadUpdateCard();
|
||||
}
|
||||
boolean neededMapsDownloaded = true;
|
||||
for (IndexItem item : neededIndexItems) {
|
||||
if (!item.isDownloaded()) {
|
||||
neededMapsDownloaded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (neededMapsDownloaded) {
|
||||
removeNeededMapsCard();
|
||||
}
|
||||
}
|
||||
|
@ -218,8 +222,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
new ProcessIndexItemsTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void addIndexItemCards(IndexItem mainIndexItem, List<IndexItem> neededIndexItems) {
|
||||
this.mainIndexItem = mainIndexItem;
|
||||
private void addIndexItemCards(List<IndexItem> mainIndexItem, List<IndexItem> neededIndexItems) {
|
||||
this.mainIndexItems.clear();
|
||||
this.mainIndexItems.addAll(mainIndexItem);
|
||||
this.neededIndexItems.clear();
|
||||
this.neededIndexItems.addAll(neededIndexItems);
|
||||
addDownloadUpdateCard();
|
||||
|
@ -228,53 +233,58 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
|
||||
private void addDownloadUpdateCard() {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
|
||||
boolean outdated = mainIndexItem != null && mainIndexItem.isOutdated();
|
||||
boolean needsDownloading = mainIndexItem != null && !mainIndexItem.isDownloaded();
|
||||
|
||||
if (!app.getTravelHelper().isAnyTravelBookPresent() || needsDownloading || (outdated && SHOW_TRAVEL_UPDATE_CARD)) {
|
||||
boolean showOtherMaps = false;
|
||||
if (needsDownloading) {
|
||||
List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems();
|
||||
showOtherMaps = items != null && items.size() > 1;
|
||||
}
|
||||
|
||||
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
|
||||
downloadUpdateCard.setShowOtherMapsBtn(showOtherMaps);
|
||||
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
|
||||
if (app != null && !mainIndexItems.isEmpty() && SHOW_TRAVEL_UPDATE_CARD) {
|
||||
boolean outdated = isMapsOutdated();
|
||||
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, mainIndexItems, !outdated);
|
||||
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.CardListener() {
|
||||
@Override
|
||||
public void onPrimaryButtonClick() {
|
||||
if (mainIndexItem != null && downloadManager != null) {
|
||||
downloadManager.startDownload(getMyActivity(), mainIndexItem);
|
||||
if (downloadManager != null) {
|
||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload(mainIndexItems));
|
||||
adapter.updateDownloadUpdateCard(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSecondaryButtonClick() {
|
||||
if (downloadUpdateCard.isLoading()) {
|
||||
downloadThread.cancelDownload(mainIndexItem);
|
||||
if (downloadUpdateCard.isDownloading()) {
|
||||
app.getDownloadThread().cancelDownload(mainIndexItems);
|
||||
adapter.updateDownloadUpdateCard(false);
|
||||
} else if (!downloadUpdateCard.isDownload()) {
|
||||
} else {
|
||||
SHOW_TRAVEL_UPDATE_CARD = false;
|
||||
removeDownloadUpdateCard();
|
||||
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Intent newIntent = new Intent(activity,
|
||||
((OsmandApplication) activity.getApplication()).getAppCustomization().getDownloadActivity());
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
activity.startActivity(newIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIndexItemClick(IndexItem item) {
|
||||
if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
||||
}
|
||||
} else {
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
if (downloadThread.isDownloading(item)) {
|
||||
downloadThread.cancelDownload(item);
|
||||
} else if (!item.isDownloaded() && downloadManager != null) {
|
||||
downloadManager.startDownload(getMyActivity(), item);
|
||||
}
|
||||
adapter.updateDownloadUpdateCard(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
downloadUpdateCard.setIndexItem(mainIndexItem);
|
||||
adapter.addDownloadUpdateCard(downloadUpdateCard);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMapsOutdated() {
|
||||
for (IndexItem indexItem : mainIndexItems) {
|
||||
if (indexItem.isOutdated()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addNeededMapsCard() {
|
||||
|
@ -285,7 +295,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
@Override
|
||||
public void onPrimaryButtonClick() {
|
||||
if (downloadManager != null) {
|
||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload(neededIndexItems));
|
||||
adapter.updateNeededMapsCard(false);
|
||||
}
|
||||
}
|
||||
|
@ -323,10 +333,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
}
|
||||
}
|
||||
|
||||
private IndexItem[] getAllItemsForDownload() {
|
||||
private IndexItem[] getAllItemsForDownload(List<IndexItem> indexItems) {
|
||||
boolean paidVersion = Version.isPaidVersion(getMyApplication());
|
||||
ArrayList<IndexItem> res = new ArrayList<>();
|
||||
for (IndexItem item : neededIndexItems) {
|
||||
for (IndexItem item : indexItems) {
|
||||
if (!item.isDownloaded() && (paidVersion || item.getType() != DownloadActivityType.WIKIPEDIA_FILE)) {
|
||||
res.add(item);
|
||||
}
|
||||
|
@ -344,7 +354,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
neededMapsCard = null;
|
||||
}
|
||||
|
||||
private static class ProcessIndexItemsTask extends AsyncTask<Void, Void, Pair<IndexItem, List<IndexItem>>> {
|
||||
private static class ProcessIndexItemsTask extends AsyncTask<Void, Void, Pair<List<IndexItem>, List<IndexItem>>> {
|
||||
|
||||
private static final DownloadActivityType[] types = new DownloadActivityType[]{
|
||||
DownloadActivityType.NORMAL_FILE,
|
||||
|
@ -354,19 +364,22 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
private final OsmandApplication app;
|
||||
private final WeakReference<ExploreTabFragment> weakFragment;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
ProcessIndexItemsTask(ExploreTabFragment fragment) {
|
||||
app = fragment.getMyApplication();
|
||||
weakFragment = new WeakReference<>(fragment);
|
||||
fileName = app != null ? app.getTravelHelper().getWikivoyageFileName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<IndexItem, List<IndexItem>> doInBackground(Void... voids) {
|
||||
if (fileName != null) {
|
||||
IndexItem mainItem = app.getDownloadThread().getIndexes().getWikivoyageItem(fileName);
|
||||
|
||||
protected Pair<List<IndexItem>, List<IndexItem>> doInBackground(Void... voids) {
|
||||
List<IndexItem> mainItems = new ArrayList<>();
|
||||
List<IndexItem> allWikivoyageItems = app.getDownloadThread().getIndexes().getWikivoyageItems();
|
||||
if (allWikivoyageItems != null) {
|
||||
for (IndexItem item : allWikivoyageItems) {
|
||||
if (!item.isDownloaded() && !mainItems.contains(item)) {
|
||||
mainItems.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<IndexItem> neededItems = new ArrayList<>();
|
||||
for (TravelArticle article : app.getTravelHelper().getBookmarksHelper().getSavedArticles()) {
|
||||
LatLon latLon = new LatLon(article.getLat(), article.getLon());
|
||||
|
@ -381,13 +394,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
// ignore
|
||||
}
|
||||
}
|
||||
return new Pair<>(mainItem, neededItems);
|
||||
}
|
||||
return null;
|
||||
return new Pair<>(mainItems, neededItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Pair<IndexItem, List<IndexItem>> res) {
|
||||
protected void onPostExecute(Pair<List<IndexItem>, List<IndexItem>> res) {
|
||||
ExploreTabFragment fragment = weakFragment.get();
|
||||
if (res != null && fragment != null && fragment.isResumed()) {
|
||||
fragment.addIndexItemCards(res.first, res.second);
|
||||
|
|
|
@ -1,257 +1,47 @@
|
|||
package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.DateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||
public class TravelDownloadUpdateCard extends TravelNeededMapsCard {
|
||||
|
||||
public static final int TYPE = 50;
|
||||
|
||||
private boolean download;
|
||||
private boolean showOtherMapsBtn;
|
||||
private WeakReference<DownloadUpdateVH> ref;
|
||||
private final boolean download;
|
||||
|
||||
private ClickListener listener;
|
||||
|
||||
@Nullable
|
||||
private IndexItem indexItem;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public boolean isDownload() {
|
||||
return download;
|
||||
}
|
||||
|
||||
public boolean isShowOtherMapsBtn() {
|
||||
return showOtherMapsBtn;
|
||||
}
|
||||
|
||||
public void setShowOtherMapsBtn(boolean showOtherMapsBtn) {
|
||||
this.showOtherMapsBtn = showOtherMapsBtn;
|
||||
}
|
||||
|
||||
public void setListener(ClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setIndexItem(@Nullable IndexItem indexItem) {
|
||||
this.indexItem = indexItem;
|
||||
}
|
||||
|
||||
public TravelDownloadUpdateCard(OsmandApplication app, boolean nightMode, boolean download) {
|
||||
super(app, nightMode);
|
||||
public TravelDownloadUpdateCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull List<IndexItem> items,
|
||||
boolean download) {
|
||||
super(app, nightMode, items);
|
||||
this.download = download;
|
||||
dateFormat = android.text.format.DateFormat.getMediumDateFormat(app);
|
||||
}
|
||||
|
||||
public int getTitle() {
|
||||
if (isDownloading()) {
|
||||
return R.string.shared_string_downloading;
|
||||
}
|
||||
return download ? R.string.download_file : R.string.update_is_available;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
|
||||
if (viewHolder instanceof DownloadUpdateVH) {
|
||||
boolean loading = isLoading();
|
||||
DownloadUpdateVH holder = (DownloadUpdateVH) viewHolder;
|
||||
this.ref = new WeakReference<TravelDownloadUpdateCard.DownloadUpdateVH>(holder);
|
||||
holder.title.setText(getTitle(loading));
|
||||
holder.icon.setImageResource(getIconRes());
|
||||
holder.description.setText(getDescription());
|
||||
if (indexItem == null) {
|
||||
holder.fileDataContainer.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.fileDataContainer.setVisibility(View.VISIBLE);
|
||||
holder.fileIcon.setImageDrawable(getFileIcon());
|
||||
holder.fileTitle.setText(getFileTitle());
|
||||
holder.fileDescription.setText(getFileDescription());
|
||||
holder.progressBar.setVisibility(loading ? View.VISIBLE : View.GONE);
|
||||
updateProgressBar(holder);
|
||||
}
|
||||
boolean primaryBtnVisible = updatePrimaryButton(holder, loading);
|
||||
boolean secondaryBtnVisible = updateSecondaryButton(holder, loading);
|
||||
holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE);
|
||||
public int getDescription() {
|
||||
if (!isInternetAvailable()) {
|
||||
return R.string.no_index_file_to_download;
|
||||
}
|
||||
return download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr;
|
||||
}
|
||||
|
||||
public void updateProgresBar() {
|
||||
if(ref != null) {
|
||||
DownloadUpdateVH holder = ref.get();
|
||||
if (holder != null && holder.itemView.isShown()) {
|
||||
updateProgressBar(holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgressBar(DownloadUpdateVH holder) {
|
||||
if (isLoadingInProgress()) {
|
||||
int progress = app.getDownloadThread().getCurrentDownloadingItemProgress();
|
||||
holder.progressBar.setProgress(progress < 0 ? 0 : progress);
|
||||
} else {
|
||||
holder.progressBar.setProgress(0);
|
||||
}
|
||||
@Override
|
||||
public int getIconRes() {
|
||||
return download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getTitle(boolean loading) {
|
||||
if (loading) {
|
||||
return app.getString(R.string.shared_string_downloading);
|
||||
}
|
||||
return app.getString(download ? R.string.download_file : R.string.update_is_available);
|
||||
}
|
||||
|
||||
private int getIconRes() {
|
||||
return download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getDescription() {
|
||||
if (!isInternetAvailable()) {
|
||||
return app.getString(R.string.no_index_file_to_download);
|
||||
}
|
||||
return app.getString(download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getFileTitle() {
|
||||
return indexItem == null ? "" : indexItem.getVisibleName(app, app.getRegions(), false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getFileDescription() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (indexItem != null) {
|
||||
sb.append(app.getString(R.string.file_size_in_mb, indexItem.getArchiveSizeMB()));
|
||||
sb.append(" • ");
|
||||
sb.append(indexItem.getRemoteDate(dateFormat));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private Drawable getFileIcon() {
|
||||
return getActiveIcon(R.drawable.ic_action_read_article);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if button is visible, false otherwise.
|
||||
*/
|
||||
private boolean updateSecondaryButton(DownloadUpdateVH vh, boolean loading) {
|
||||
if (loading || !download || showOtherMapsBtn) {
|
||||
vh.secondaryBtnContainer.setVisibility(View.VISIBLE);
|
||||
vh.secondaryBtn.setText(getSecondaryBtnTextId(loading));
|
||||
vh.secondaryBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.onSecondaryButtonClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
vh.secondaryBtnContainer.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
private int getSecondaryBtnTextId(boolean loading) {
|
||||
if (loading) {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
if (!download) {
|
||||
return R.string.later;
|
||||
}
|
||||
return R.string.download_select_map_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if button is visible, false otherwise.
|
||||
*/
|
||||
private boolean updatePrimaryButton(DownloadUpdateVH vh, boolean loading) {
|
||||
if (!loading) {
|
||||
boolean enabled = isInternetAvailable();
|
||||
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
|
||||
vh.primaryBtnContainer.setBackgroundResource(getPrimaryBtnBgRes(enabled));
|
||||
vh.primaryButton.setTextColor(getResolvedColor(getPrimaryBtnTextColorRes(enabled)));
|
||||
vh.primaryButton.setEnabled(enabled);
|
||||
vh.primaryButton.setText(download ? R.string.shared_string_download : R.string.shared_string_update);
|
||||
vh.primaryButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.onPrimaryButtonClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
vh.primaryBtnContainer.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return indexItem != null && app.getDownloadThread().isDownloading(indexItem);
|
||||
}
|
||||
|
||||
private boolean isLoadingInProgress() {
|
||||
IndexItem current = app.getDownloadThread().getCurrentDownloadingItem();
|
||||
return indexItem != null && current != null && indexItem == current;
|
||||
}
|
||||
|
||||
public interface ClickListener {
|
||||
|
||||
void onPrimaryButtonClick();
|
||||
|
||||
void onSecondaryButtonClick();
|
||||
}
|
||||
|
||||
public static class DownloadUpdateVH extends RecyclerView.ViewHolder {
|
||||
|
||||
final TextView title;
|
||||
final ImageView icon;
|
||||
final TextView description;
|
||||
final View fileDataContainer;
|
||||
final ImageView fileIcon;
|
||||
final TextView fileTitle;
|
||||
final TextView fileDescription;
|
||||
final ProgressBar progressBar;
|
||||
final View secondaryBtnContainer;
|
||||
final TextView secondaryBtn;
|
||||
final View buttonsDivider;
|
||||
final View primaryBtnContainer;
|
||||
final TextView primaryButton;
|
||||
|
||||
@SuppressWarnings("RedundantCast")
|
||||
public DownloadUpdateVH(View itemView) {
|
||||
super(itemView);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||
description = (TextView) itemView.findViewById(R.id.description);
|
||||
fileDataContainer = itemView.findViewById(R.id.file_data_container);
|
||||
fileIcon = (ImageView) itemView.findViewById(R.id.file_icon);
|
||||
fileTitle = (TextView) itemView.findViewById(R.id.file_title);
|
||||
fileDescription = (TextView) itemView.findViewById(R.id.file_description);
|
||||
progressBar = (ProgressBar) itemView.findViewById(R.id.progress_bar);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -60,8 +62,12 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
if (viewHolder instanceof NeededMapsVH) {
|
||||
NeededMapsVH holder = (NeededMapsVH) viewHolder;
|
||||
ref = new WeakReference<NeededMapsVH>(holder);
|
||||
holder.description.setText(isInternetAvailable()
|
||||
? R.string.maps_you_need_descr : R.string.no_index_file_to_download);
|
||||
holder.title.setText(getTitle());
|
||||
holder.description.setText(getDescription());
|
||||
int iconRes = getIconRes();
|
||||
if (iconRes > 0) {
|
||||
holder.icon.setImageResource(iconRes);
|
||||
}
|
||||
adjustChildCount(holder.itemsContainer);
|
||||
|
||||
updateView(holder);
|
||||
|
@ -72,6 +78,22 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
}
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getTitle() {
|
||||
return R.string.maps_you_need;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescription() {
|
||||
return isInternetAvailable()
|
||||
? R.string.maps_you_need_descr : R.string.no_index_file_to_download;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getIconRes() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
if (ref != null) {
|
||||
NeededMapsVH holder = ref.get();
|
||||
|
@ -227,7 +249,9 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
|
||||
public static class NeededMapsVH extends RecyclerView.ViewHolder {
|
||||
|
||||
final TextView title;
|
||||
final TextView description;
|
||||
final ImageView icon;
|
||||
final LinearLayout itemsContainer;
|
||||
final View secondaryBtnContainer;
|
||||
final TextView secondaryBtn;
|
||||
|
@ -238,7 +262,9 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
@SuppressWarnings("RedundantCast")
|
||||
public NeededMapsVH(View itemView) {
|
||||
super(itemView);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
description = (TextView) itemView.findViewById(R.id.description);
|
||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||
itemsContainer = (LinearLayout) itemView.findViewById(R.id.items_container);
|
||||
secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container);
|
||||
secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button);
|
||||
|
|
Loading…
Reference in a new issue