Add checks for wikipedia maps
This commit is contained in:
parent
e14a998255
commit
5c50e7d096
3 changed files with 57 additions and 10 deletions
|
@ -73,6 +73,22 @@
|
|||
android:layout_marginStart="@dimen/content_padding"
|
||||
tools:src="@drawable/ic_action_import"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="33dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/content_padding"
|
||||
android:layout_marginStart="@dimen/content_padding"
|
||||
android:background="@drawable/buy_btn_background_light"
|
||||
android:minWidth="40dp"
|
||||
android:paddingLeft="18dp"
|
||||
android:paddingRight="18dp"
|
||||
android:text="@string/get_plugin"
|
||||
android:textColor="@color/buy_button_color"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
|
@ -228,8 +229,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() {
|
||||
@Override
|
||||
public void onPrimaryButtonClick() {
|
||||
IndexItem[] items = neededIndexItems.toArray(new IndexItem[neededIndexItems.size()]);
|
||||
downloadManager.startDownload(getMyActivity(), items);
|
||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
||||
adapter.updateNeededMapsCard();
|
||||
}
|
||||
|
||||
|
@ -245,19 +245,37 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
|
||||
@Override
|
||||
public void onIndexItemClick(IndexItem item) {
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
if (downloadThread.isDownloading(item)) {
|
||||
downloadThread.cancelDownload(item);
|
||||
if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
||||
}
|
||||
} else {
|
||||
downloadManager.startDownload(getMyActivity(), item);
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
if (downloadThread.isDownloading(item)) {
|
||||
downloadThread.cancelDownload(item);
|
||||
} else if (!item.isDownloaded()) {
|
||||
downloadManager.startDownload(getMyActivity(), item);
|
||||
}
|
||||
adapter.updateNeededMapsCard();
|
||||
}
|
||||
adapter.updateNeededMapsCard();
|
||||
}
|
||||
});
|
||||
adapter.setNeededMapsCard(neededMapsCard);
|
||||
}
|
||||
}
|
||||
|
||||
private IndexItem[] getAllItemsForDownload() {
|
||||
boolean paidVersion = Version.isPaidVersion(getMyApplication());
|
||||
ArrayList<IndexItem> res = new ArrayList<>();
|
||||
for (IndexItem item : neededIndexItems) {
|
||||
if (!item.isDownloaded() && (paidVersion || item.getType() != DownloadActivityType.WIKIPEDIA_FILE)) {
|
||||
res.add(item);
|
||||
}
|
||||
}
|
||||
return res.toArray(new IndexItem[res.size()]);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getWikivoyageFileName() {
|
||||
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -12,6 +13,8 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
|
||||
|
@ -59,6 +62,8 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
? R.string.maps_you_need_descr : R.string.no_index_file_to_download);
|
||||
adjustChildCount(holder.itemsContainer);
|
||||
|
||||
boolean paidVersion = Version.isPaidVersion(app);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
IndexItem item = items.get(i);
|
||||
boolean downloading = downloadThread.isDownloading(item);
|
||||
|
@ -80,9 +85,17 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
|||
((TextView) view.findViewById(R.id.description)).setText(getItemDescription(item));
|
||||
|
||||
ImageView iconAction = (ImageView) view.findViewById(R.id.icon_action);
|
||||
iconAction.setVisibility(item.isDownloaded() ? View.GONE : View.VISIBLE);
|
||||
if (!item.isDownloaded()) {
|
||||
iconAction.setImageDrawable(downloading ? cancelIcon : downloadIcon);
|
||||
Button buttonAction = (Button) view.findViewById(R.id.button_action);
|
||||
if (item.isDownloaded()) {
|
||||
iconAction.setVisibility(View.GONE);
|
||||
buttonAction.setVisibility(View.GONE);
|
||||
} else {
|
||||
boolean showBtn = !paidVersion && item.getType() == DownloadActivityType.WIKIPEDIA_FILE;
|
||||
iconAction.setVisibility(showBtn ? View.GONE : View.VISIBLE);
|
||||
buttonAction.setVisibility(showBtn ? View.VISIBLE : View.GONE);
|
||||
if (!showBtn) {
|
||||
iconAction.setImageDrawable(downloading ? cancelIcon : downloadIcon);
|
||||
}
|
||||
}
|
||||
|
||||
ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
|
||||
|
|
Loading…
Reference in a new issue