Search in sources :

Example 1 with TravelNeededMapsCard

use of net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard in project Osmand by osmandapp.

the class ExploreTabFragment method addNeededMapsCard.

private void addNeededMapsCard() {
    final OsmandApplication app = getMyApplication();
    if (app != null && !neededIndexItems.isEmpty() && SHOW_TRAVEL_NEEDED_MAPS_CARD) {
        neededMapsCard = new TravelNeededMapsCard(app, nightMode, neededIndexItems);
        neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() {

            @Override
            public void onPrimaryButtonClick() {
                if (downloadManager != null) {
                    downloadManager.startDownload(getMyActivity(), getAllItemsForDownload(neededIndexItems));
                    adapter.updateNeededMapsCard(false);
                }
            }

            @Override
            public void onSecondaryButtonClick() {
                if (neededMapsCard.isDownloading()) {
                    app.getDownloadThread().cancelDownload(neededIndexItems);
                    adapter.updateNeededMapsCard(false);
                } else {
                    SHOW_TRAVEL_NEEDED_MAPS_CARD = false;
                    removeNeededMapsCard();
                }
            }

            @Override
            public void onIndexItemClick(IndexItem item) {
                if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE || item.getType() == DownloadActivityType.TRAVEL_FILE) && !Version.isPaidVersion(app)) {
                    FragmentActivity activity = getActivity();
                    if (activity != null) {
                        ChoosePlanFragment.showInstance(activity, OsmAndFeature.WIKIPEDIA);
                    }
                } else {
                    DownloadIndexesThread downloadThread = app.getDownloadThread();
                    if (downloadThread.isDownloading(item)) {
                        downloadThread.cancelDownload(item);
                    } else if (!item.isDownloaded() && downloadManager != null) {
                        downloadManager.startDownload(getMyActivity(), item);
                    }
                    adapter.updateNeededMapsCard(false);
                }
            }
        });
        adapter.addNeededMapsCard(neededMapsCard);
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) OsmandApplication(net.osmand.plus.OsmandApplication) TravelNeededMapsCard(net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard) IndexItem(net.osmand.plus.download.IndexItem) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)1 IndexItem (net.osmand.plus.download.IndexItem)1 TravelNeededMapsCard (net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard)1