Search in sources :

Example 1 with TravelArticle

use of net.osmand.plus.wikivoyage.data.TravelArticle in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method createDisplayGroups.

private void createDisplayGroups() {
    items = new ArrayList<>();
    MapMarkersHelper helper = app.getMapMarkersHelper();
    helper.updateGroups();
    List<MapMarkersGroup> groups = new ArrayList<>(helper.getVisibleMapMarkersGroups());
    groups.addAll(helper.getGroupsForDisplayedGpx());
    groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
    // evaluate time constants
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    long currentTimeMillis = System.currentTimeMillis();
    Calendar currentDateCalendar = Calendar.getInstance();
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    // evaluate today, yesterday, last 7 days
    String today = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -1);
    String yesterday = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
    currentDateCalendar.set(Calendar.MINUTE, 0);
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -6);
    long last7Days = currentDateCalendar.getTimeInMillis();
    // evaluate this year & last 3 months
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    String thisYear = dateFormat.format(currentDateCalendar.getTime()).substring(0, 5);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus1 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus2 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus3 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    Calendar markerCalendar = Calendar.getInstance();
    for (int i = 0; i < groups.size(); i++) {
        MapMarkersGroup group = groups.get(i);
        String markerGroupName = group.getName();
        if (markerGroupName == null) {
            int previousGroupDateId = 0;
            List<MapMarker> groupMarkers = group.getActiveMarkers();
            for (int j = 0; j < groupMarkers.size(); j++) {
                MapMarker marker = groupMarkers.get(j);
                String markerDate = dateFormat.format(new Date(marker.creationDate));
                int currentGroupDateId;
                MarkerGroupItem currentGroupItem = null;
                if (marker.creationDate >= currentTimeMillis || (today.equals(markerDate))) {
                    currentGroupDateId = -1;
                    currentGroupItem = MarkerGroupItem.TODAY_HEADER;
                } else if (yesterday.equals(markerDate)) {
                    currentGroupDateId = -2;
                    currentGroupItem = MarkerGroupItem.YESTERDAY_HEADER;
                } else if (marker.creationDate >= last7Days) {
                    currentGroupDateId = -3;
                    currentGroupItem = MarkerGroupItem.LAST_SEVEN_DAYS_HEADER;
                } else if (markerDate.startsWith(monthMinus1)) {
                    currentGroupDateId = -5;
                } else if (markerDate.startsWith(monthMinus2)) {
                    currentGroupDateId = -6;
                } else if (markerDate.startsWith(monthMinus3)) {
                    currentGroupDateId = -7;
                } else if (markerDate.startsWith(thisYear)) {
                    currentGroupItem = MarkerGroupItem.THIS_YEAR_HEADER;
                    currentGroupDateId = -4;
                } else {
                    markerCalendar.setTimeInMillis(marker.creationDate);
                    currentGroupDateId = markerCalendar.get(Calendar.YEAR);
                }
                if (previousGroupDateId != currentGroupDateId) {
                    if (currentGroupItem != null) {
                        items.add(currentGroupItem);
                    } else if (currentGroupDateId < 0) {
                        SimpleDateFormat monthdateFormat = new SimpleDateFormat("LLLL", Locale.getDefault());
                        String monthStr = monthdateFormat.format(new Date(marker.creationDate));
                        if (monthStr.length() > 1) {
                            monthStr = Algorithms.capitalizeFirstLetter(monthStr);
                        }
                        items.add(new MarkerGroupItem(monthStr));
                    } else {
                        items.add(new MarkerGroupItem(currentGroupDateId + ""));
                    }
                    previousGroupDateId = currentGroupDateId;
                }
                items.add(marker);
            }
        } else {
            items.add(new GroupHeader(group));
            if (!group.isDisabled()) {
                if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
                    CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(group);
                    items.add(categoriesSubHeader);
                }
                TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper();
                if (travelHelper.isAnyTravelBookPresent()) {
                    List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
                    for (TravelArticle art : savedArticles) {
                        String gpxName = travelHelper.getGPXName(art);
                        File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
                        if (path.getAbsolutePath().equals(group.getGpxPath(app))) {
                            group.setWikivoyageArticle(art);
                        }
                    }
                }
            }
            if (Algorithms.isEmpty(group.getWptCategories())) {
                helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath(app)).getPointsByCategories().keySet());
            }
            populateAdapterWithGroupMarkers(group, getItemCount());
        }
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) Calendar(java.util.Calendar) GroupHeader(net.osmand.plus.mapmarkers.GroupHeader) ArrayList(java.util.ArrayList) Date(java.util.Date) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) SimpleDateFormat(java.text.SimpleDateFormat) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Example 2 with TravelArticle

use of net.osmand.plus.wikivoyage.data.TravelArticle 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 3 with TravelArticle

use of net.osmand.plus.wikivoyage.data.TravelArticle in project Osmand by osmandapp.

the class AmenityMenuController method openTrack.

void openTrack() {
    OsmandApplication app = getMapActivity().getMyApplication();
    TravelHelper travelHelper = app.getTravelHelper();
    String lang = amenity.getTagSuffix(Amenity.LANG_YES + ":");
    String name = amenity.getTagContent(Amenity.ROUTE_NAME);
    TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null);
    if (article != null) {
        travelHelper.openTrackMenu(article, getMapActivity(), name, amenity.getLocation());
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Example 4 with TravelArticle

use of net.osmand.plus.wikivoyage.data.TravelArticle in project Osmand by osmandapp.

the class SavedArticlesRvAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
    if (viewHolder instanceof HeaderVH) {
        final HeaderVH holder = (HeaderVH) viewHolder;
        holder.title.setText((String) getItem(position));
        holder.description.setText(String.valueOf(items.size() - 1));
    } else if (viewHolder instanceof ItemVH) {
        final ItemVH holder = (ItemVH) viewHolder;
        TravelArticle article = (TravelArticle) getItem(position);
        final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
        Boolean loaded = picasso.isURLLoaded(url);
        boolean lastItem = position == getItemCount() - 1;
        RequestCreator rc = Picasso.get().load(url);
        WikivoyageUtils.setupNetworkPolicy(settings, rc);
        rc.transform(new CropCircleTransformation()).into(holder.icon, new Callback() {

            @Override
            public void onSuccess() {
                holder.icon.setVisibility(View.VISIBLE);
                picasso.setResultLoaded(url, true);
            }

            @Override
            public void onError(Exception e) {
                holder.icon.setVisibility(View.GONE);
                picasso.setResultLoaded(url, false);
            }
        });
        holder.icon.setVisibility(loaded == null || loaded.booleanValue() ? View.VISIBLE : View.GONE);
        holder.title.setText(article.getTitle());
        holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent()));
        holder.partOf.setText(article.getGeoDescription());
        holder.leftButton.setText(app.getString(R.string.shared_string_read));
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        holder.rightButton.setText(app.getString(R.string.shared_string_remove));
        holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
        holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    } else if (viewHolder instanceof TravelGpxVH) {
        final TravelGpx article = (TravelGpx) getItem(position);
        final TravelGpxVH holder = (TravelGpxVH) viewHolder;
        holder.title.setText(article.getTitle());
        holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
        holder.user.setText(article.user);
        String activityTypeKey = article.activityType;
        if (!Algorithms.isEmpty(activityTypeKey)) {
            RouteActivityType activityType = RouteActivityType.getOrCreateTypeFromName(activityTypeKey);
            int activityTypeIcon = getActivityTypeIcon(activityType);
            holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityTypeIcon));
            holder.activityType.setText(getActivityTypeTitle(activityType));
            holder.activityTypeLabel.setVisibility(View.VISIBLE);
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
        holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
        holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
        holder.leftButton.setText(app.getString(R.string.shared_string_view));
        View.OnClickListener readClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.openArticle(article);
                }
            }
        };
        holder.leftButton.setOnClickListener(readClickListener);
        holder.itemView.setOnClickListener(readClickListener);
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        updateSaveButton(holder, article);
    }
}
Also used : TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RequestCreator(com.squareup.picasso.RequestCreator) TravelGpxVH(net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH) Callback(com.squareup.picasso.Callback) RouteActivityType(net.osmand.osm.RouteActivityType) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation)

Example 5 with TravelArticle

use of net.osmand.plus.wikivoyage.data.TravelArticle in project Osmand by osmandapp.

the class POIMapLayer method showMenuAction.

@Override
public boolean showMenuAction(@Nullable Object object) {
    OsmandApplication app = view.getApplication();
    MapActivity mapActivity = view.getMapActivity();
    TravelHelper travelHelper = app.getTravelHelper();
    if (mapActivity != null && object instanceof Amenity) {
        Amenity amenity = (Amenity) object;
        if (amenity.getSubType().equals(ROUTE_TRACK)) {
            TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef());
            if (travelGpx == null) {
                return true;
            }
            travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation());
            return true;
        } else if (amenity.getSubType().equals(ROUTE_ARTICLE)) {
            String lang = app.getLanguage();
            lang = amenity.getContentLanguage(Amenity.DESCRIPTION, lang, "en");
            String name = amenity.getName(lang);
            TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null);
            if (article == null) {
                return true;
            }
            travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation());
            return true;
        }
    }
    return false;
}
Also used : Amenity(net.osmand.data.Amenity) TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) OsmandApplication(net.osmand.plus.OsmandApplication) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) MapActivity(net.osmand.plus.activities.MapActivity) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Aggregations

TravelArticle (net.osmand.plus.wikivoyage.data.TravelArticle)8 File (java.io.File)4 ArrayList (java.util.ArrayList)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 TravelGpx (net.osmand.plus.wikivoyage.data.TravelGpx)4 TravelHelper (net.osmand.plus.wikivoyage.data.TravelHelper)4 View (android.view.View)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 GPXFile (net.osmand.GPXUtilities.GPXFile)3 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)3 ImageView (android.widget.ImageView)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 Calendar (java.util.Calendar)2 GroupHeader (net.osmand.plus.mapmarkers.GroupHeader)2 MapMarker (net.osmand.plus.mapmarkers.MapMarker)2 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)2 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)2 Bundle (android.os.Bundle)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1