use of net.osmand.plus.wikivoyage.data.TravelGpx 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();
}
}
}
use of net.osmand.plus.wikivoyage.data.TravelGpx 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);
}
}
use of net.osmand.plus.wikivoyage.data.TravelGpx in project Osmand by osmandapp.
the class GPXLayer method showMenuAction.
@Override
public boolean showMenuAction(@Nullable Object object) {
OsmandApplication app = view.getApplication();
MapActivity mapActivity = view.getMapActivity();
if (mapActivity != null) {
if (object instanceof Pair && ((Pair<?, ?>) object).first instanceof TravelGpx && ((Pair<?, ?>) object).second instanceof SelectedGpxPoint) {
Pair<TravelGpx, SelectedGpxPoint> pair = (Pair) object;
LatLon latLon = new LatLon(pair.second.getSelectedPoint().lat, pair.second.getSelectedPoint().lon);
TravelHelper travelHelper = app.getTravelHelper();
travelHelper.openTrackMenu(pair.first, mapActivity, pair.first.getRouteId(), latLon);
return true;
} else if (object instanceof SelectedGpxPoint) {
SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) object;
if (selectedGpxPoint.shouldShowTrackPointMenu()) {
WptPt selectedWptPt = selectedGpxPoint.getSelectedPoint();
LatLon latLon = new LatLon(selectedWptPt.lat, selectedWptPt.lon);
contextMenuLayer.showContextMenu(latLon, getObjectName(selectedGpxPoint), selectedGpxPoint, null);
} else {
SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile();
TrackMenuFragment.showInstance(mapActivity, selectedGpxFile, selectedGpxPoint);
}
return true;
}
}
return false;
}
use of net.osmand.plus.wikivoyage.data.TravelGpx 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;
}
use of net.osmand.plus.wikivoyage.data.TravelGpx in project Osmand by osmandapp.
the class ContextMenuLayer method isUniqueGpx.
private boolean isUniqueGpx(Map<Object, IContextMenuProvider> selectedObjects, TravelGpx travelGpx) {
String tracksDir = view.getApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR).getPath();
File file = new File(tracksDir, travelGpx.getRouteId() + GPX_FILE_EXT);
if (file.exists()) {
return false;
}
for (Map.Entry<Object, IContextMenuProvider> entry : selectedObjects.entrySet()) {
if (entry.getKey() instanceof Pair && entry.getValue() instanceof GPXLayer && ((Pair<?, ?>) entry.getKey()).first instanceof TravelGpx) {
TravelGpx object = (TravelGpx) ((Pair<?, ?>) entry.getKey()).first;
if (travelGpx.equals(object)) {
return false;
}
}
}
return true;
}
Aggregations