Search in sources :

Example 1 with HeaderTravelCard

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

the class ExploreTabFragment method populateData.

public void populateData() {
    final List<BaseTravelCard> items = new ArrayList<>();
    final FragmentActivity activity = getActivity();
    final OsmandApplication app = activity != null ? (OsmandApplication) activity.getApplication() : null;
    if (app != null) {
        if (!Version.isPaidVersion(app) && !OpenBetaTravelCard.isClosed()) {
            items.add(new OpenBetaTravelCard(activity, nightMode));
        }
        final List<TravelArticle> popularArticles = app.getTravelHelper().getPopularArticles();
        if (!popularArticles.isEmpty()) {
            items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
            for (TravelArticle article : popularArticles) {
                if (article instanceof TravelGpx) {
                    items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, activity));
                } else {
                    items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager()));
                }
            }
        }
        if (!isOnlyDefaultTravelBookPresent()) {
            TravelButtonCard travelButtonCard = new TravelButtonCard(app, nightMode);
            travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() {

                @Override
                public void onPrimaryButtonClick() {
                    WikivoyageExploreActivity exploreActivity = getExploreActivity();
                    if (exploreActivity != null) {
                        exploreActivity.populateData(false);
                    }
                }

                @Override
                public void onSecondaryButtonClick() {
                }

                @Override
                public void onIndexItemClick(IndexItem item) {
                }
            });
            items.add(travelButtonCard);
        }
        items.add(new StartEditingTravelCard(activity, nightMode));
        adapter.setItems(items);
        final DownloadIndexesThread downloadThread = app.getDownloadThread();
        if (!downloadThread.getIndexes().isDownloadedFromInternet) {
            waitForIndexes = true;
            downloadThread.runReloadIndexFilesSilent();
        } else {
            checkDownloadIndexes();
        }
    }
}
Also used : ArticleTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard) TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) OsmandApplication(net.osmand.plus.OsmandApplication) TravelButtonCard(net.osmand.plus.wikivoyage.explore.travelcards.TravelButtonCard) ArrayList(java.util.ArrayList) TravelGpxCard(net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard) TravelNeededMapsCard(net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard) IndexItem(net.osmand.plus.download.IndexItem) BaseTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard) FragmentActivity(androidx.fragment.app.FragmentActivity) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) OpenBetaTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard) HeaderTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard) StartEditingTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Example 2 with HeaderTravelCard

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

the class ExploreRvAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
    BaseTravelCard item = getItem(position);
    if (viewHolder instanceof HeaderTravelVH && item instanceof HeaderTravelCard) {
        HeaderTravelCard headerTravelCard = (HeaderTravelCard) item;
        headerTravelCard.setArticleItemCount(getArticleItemCount());
        headerTravelCard.bindViewHolder(viewHolder);
    } else if (viewHolder instanceof ArticleTravelVH && item instanceof TravelGpxCard) {
        TravelGpxCard travelGpxCard = (TravelGpxCard) item;
        travelGpxCard.setLastItem(position == getLastArticleItemIndex());
        travelGpxCard.bindViewHolder(viewHolder);
    } else if (viewHolder instanceof ArticleTravelVH && item instanceof ArticleTravelCard) {
        ArticleTravelCard articleTravelCard = (ArticleTravelCard) item;
        articleTravelCard.setLastItem(position == getLastArticleItemIndex());
        articleTravelCard.bindViewHolder(viewHolder);
    } else {
        item.bindViewHolder(viewHolder);
    }
}
Also used : ArticleTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard) BaseTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard) HeaderTravelVH(net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard.HeaderTravelVH) HeaderTravelCard(net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard) TravelGpxCard(net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard) ArticleTravelVH(net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard.ArticleTravelVH)

Aggregations

ArticleTravelCard (net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard)2 BaseTravelCard (net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard)2 HeaderTravelCard (net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard)2 TravelGpxCard (net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard)2 FragmentActivity (androidx.fragment.app.FragmentActivity)1 ArrayList (java.util.ArrayList)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)1 IndexItem (net.osmand.plus.download.IndexItem)1 TravelArticle (net.osmand.plus.wikivoyage.data.TravelArticle)1 TravelGpx (net.osmand.plus.wikivoyage.data.TravelGpx)1 ArticleTravelVH (net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard.ArticleTravelVH)1 HeaderTravelVH (net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard.HeaderTravelVH)1 OpenBetaTravelCard (net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard)1 StartEditingTravelCard (net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard)1 TravelButtonCard (net.osmand.plus.wikivoyage.explore.travelcards.TravelButtonCard)1 TravelNeededMapsCard (net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard)1