Search in sources :

Example 1 with TravelHelper

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

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

the class WikivoyageArticleDialogFragment method onCreateView.

@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
    } else {
        Bundle args = getArguments();
        if (args != null) {
            selectedLang = args.getString(SELECTED_LANG_KEY);
        }
    }
    final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container);
    setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
    int appBarTextColor = nightMode ? R.color.wikivoyage_app_bar_text_dark : R.color.wikivoyage_app_bar_text_light;
    articleToolbarText = (TextView) mainView.findViewById(R.id.article_toolbar_text);
    articleToolbarText.setTextColor(ContextCompat.getColor(getContext(), appBarTextColor));
    ColorStateList selectedLangColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode, R.color.icon_color_default_light, R.color.wikivoyage_active_light, R.color.icon_color_default_dark, R.color.wikivoyage_active_dark);
    selectedLangTv = (TextView) mainView.findViewById(R.id.select_language_text_view);
    selectedLangTv.setTextColor(selectedLangColorStateList);
    selectedLangTv.setCompoundDrawablesWithIntrinsicBounds(getSelectedLangIcon(), null, null, null);
    selectedLangTv.setBackgroundResource(nightMode ? R.drawable.wikipedia_select_lang_bg_dark_n : R.drawable.wikipedia_select_lang_bg_light_n);
    selectedLangTv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showPopupLangMenu(v, selectedLang);
        }
    });
    TextView contentsBtn = (TextView) mainView.findViewById(R.id.contents_button);
    contentsBtn.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_action_contents), null, null, null);
    contentsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getFragmentManager();
            if (article == null || fm == null) {
                return;
            }
            Bundle args = new Bundle();
            args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson());
            WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment();
            fragment.setUsedOnMap(false);
            fragment.setArguments(args);
            fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, WikivoyageArticleContentsFragment.SHOW_CONTENT_ITEM_REQUEST_CODE);
            fragment.show(fm, WikivoyageArticleContentsFragment.TAG);
        }
    });
    trackButton = (TextView) mainView.findViewById(R.id.gpx_button);
    trackButton.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_action_markers_dark), null, null, null);
    trackButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity activity = getActivity();
            FragmentManager fm = getFragmentManager();
            if (article == null || activity == null || fm == null) {
                return;
            }
            if (activity instanceof WikivoyageExploreActivity) {
                WikivoyageExploreActivity exploreActivity = (WikivoyageExploreActivity) activity;
                exploreActivity.setArticle(article);
            }
            TravelHelper travelHelper = getMyApplication().getTravelHelper();
            File file = travelHelper.createGpxFile(article);
            openTrack(activity, new File(file.getAbsolutePath()), null, getString(R.string.icon_group_travel), TrackMenuType.POINTS);
        }
    });
    trackButton.setVisibility(View.GONE);
    gpxProgress = mainView.findViewById(R.id.gpx_progress);
    gpxProgress.setVisibility(View.GONE);
    saveBtn = (TextView) mainView.findViewById(R.id.save_button);
    contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
    WebSettings webSettings = contentWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setTextZoom((int) (getResources().getConfiguration().fontScale * 100f));
    updateWebSettings();
    contentWebView.addJavascriptInterface(new WikivoyageArticleWebAppInterface(), "Android");
    FragmentActivity activity = requireActivity();
    FragmentManager fragmentManager = requireFragmentManager();
    webViewClient = new WikivoyageWebViewClient(activity, fragmentManager, nightMode);
    contentWebView.setWebViewClient(webViewClient);
    contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(), nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
    return mainView;
}
Also used : Bundle(android.os.Bundle) ColorStateList(android.content.res.ColorStateList) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) WikivoyageWebViewClient(net.osmand.plus.wikivoyage.WikivoyageWebViewClient) WikivoyageExploreActivity(net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity) WebSettings(android.webkit.WebSettings) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Example 3 with TravelHelper

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

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

the class TravelGpxCard method updateSaveButton.

private void updateSaveButton(final TravelGpxVH holder) {
    if (article != null) {
        final TravelHelper helper = app.getTravelHelper();
        final boolean saved = helper.getBookmarksHelper().isArticleSaved(article);
        Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
        holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save);
        holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
        holder.rightButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                helper.saveOrRemoveArticle(article, !saved);
                updateSaveButton(holder);
            }
        });
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Example 5 with TravelHelper

use of net.osmand.plus.wikivoyage.data.TravelHelper 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;
}
Also used : TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) LatLon(net.osmand.data.LatLon) WptPt(net.osmand.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint) MapActivity(net.osmand.plus.activities.MapActivity) Pair(android.util.Pair) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Aggregations

TravelHelper (net.osmand.plus.wikivoyage.data.TravelHelper)12 View (android.view.View)4 TextView (android.widget.TextView)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 TravelArticle (net.osmand.plus.wikivoyage.data.TravelArticle)4 Drawable (android.graphics.drawable.Drawable)3 File (java.io.File)3 GPXFile (net.osmand.GPXUtilities.GPXFile)3 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)3 WebView (android.webkit.WebView)2 ImageView (android.widget.ImageView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 ArrayList (java.util.ArrayList)2 MapActivity (net.osmand.plus.activities.MapActivity)2 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)2 TravelGpx (net.osmand.plus.wikivoyage.data.TravelGpx)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 ColorStateList (android.content.res.ColorStateList)1 Bundle (android.os.Bundle)1