Search in sources :

Example 16 with FavoriteGroup

use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.

the class FavoritePointEditor method add.

public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, boolean autoFill) {
    MapActivity mapActivity = getMapActivity();
    if (latLon == null || mapActivity == null) {
        return;
    }
    isNew = true;
    if (categoryName != null && !categoryName.isEmpty()) {
        FavoriteGroup category = mapActivity.getMyApplication().getFavoritesHelper().getGroup(categoryName);
        if (category == null) {
            mapActivity.getMyApplication().getFavoritesHelper().addEmptyCategory(categoryName, categoryColor);
        }
    } else {
        categoryName = "";
    }
    favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName);
    favorite.setDescription("");
    favorite.setAddress("");
    favorite.setOriginObjectName(originObjectName);
    FavoritePointEditorFragment.showAutoFillInstance(mapActivity, autoFill);
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) MapActivity(net.osmand.plus.activities.MapActivity)

Example 17 with FavoriteGroup

use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.

the class FavoriteDialogs method createAddFavouriteDialog.

public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
    final OsmandApplication app = (OsmandApplication) activity.getApplication();
    boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    final Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
    AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
    builder.setTitle(R.string.favourites_context_menu_edit);
    final View v = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_edit_dialog, null, false);
    final FavouritesHelper helper = app.getFavoritesHelper();
    builder.setView(v);
    final EditText editText = (EditText) v.findViewById(R.id.Name);
    final EditText description = (EditText) v.findViewById(R.id.description);
    final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
    List<FavoriteGroup> gs = helper.getFavoriteGroups();
    final String[] list = new String[gs.size()];
    for (int i = 0; i < list.length; i++) {
        list[i] = gs.get(i).getName();
    }
    cat.setAdapter(new ArrayAdapter<>(activity, R.layout.list_textview, list));
    if (app.accessibilityEnabled()) {
        final TextView textButton = (TextView) v.findViewById(R.id.TextButton);
        textButton.setClickable(true);
        textButton.setFocusable(true);
        textButton.setOnClickListener(view -> {
            AlertDialog.Builder b = new AlertDialog.Builder(themedContext);
            b.setTitle(R.string.access_category_choice);
            b.setItems(list, (dialog, which) -> cat.setText(list[which]));
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.show();
        });
    }
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setNeutralButton(R.string.update_existing, (dialog, which) -> {
        // Don't use showDialog because it is impossible to refresh favorite items list
        Dialog dlg = createReplaceFavouriteDialog(activity, args);
        if (dlg != null) {
            dlg.show();
        }
    // mapActivity.showDialog(DIALOG_REPLACE_FAVORITE);
    });
    builder.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
            String categoryStr = cat.getText().toString().trim();
            final FavouritesHelper helper = app.getFavoritesHelper();
            app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
            point.setName(editText.getText().toString().trim());
            point.setDescription(description.getText().toString().trim());
            point.setCategory(categoryStr);
            AlertDialog.Builder bld = checkDuplicates(point, activity);
            if (bld != null) {
                bld.setPositiveButton(R.string.shared_string_ok, (dialog1, which1) -> addFavorite(activity, point, helper));
                bld.show();
            } else {
                addFavorite(activity, point, helper);
            }
        }

        protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesHelper helper) {
            boolean added = helper.addFavourite(point);
            if (added) {
                Toast.makeText(activity, MessageFormat.format(activity.getString(R.string.add_favorite_dialog_favourite_added_template), point.getName()), Toast.LENGTH_SHORT).show();
            }
            if (activity instanceof MapActivity) {
                ((MapActivity) activity).getMapView().refreshMap(true);
            }
        }
    });
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) NonNull(androidx.annotation.NonNull) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) R(net.osmand.plus.R) Dialog(android.app.Dialog) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) FavouritesAdapter(net.osmand.plus.myplaces.ui.FavoritesListFragment.FavouritesAdapter) UiUtilities(net.osmand.plus.utils.UiUtilities) FavouritePoint(net.osmand.data.FavouritePoint) Toast(android.widget.Toast) FavoritePointEditorFragment(net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment) Fragment(androidx.fragment.app.Fragment) View(android.view.View) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) Algorithms(net.osmand.util.Algorithms) DialogInterface(android.content.DialogInterface) AndroidUtils(net.osmand.plus.utils.AndroidUtils) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) PointDescription(net.osmand.data.PointDescription) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) TextView(android.widget.TextView) FavoritePointEditor(net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor) OnDismissListener(android.content.DialogInterface.OnDismissListener) ListView(android.widget.ListView) Activity(android.app.Activity) EditText(android.widget.EditText) Resources(android.content.res.Resources) MapActivity(net.osmand.plus.activities.MapActivity) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) MapActivity(net.osmand.plus.activities.MapActivity) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) MapActivity(net.osmand.plus.activities.MapActivity) Context(android.content.Context) EditText(android.widget.EditText) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) FavouritePoint(net.osmand.data.FavouritePoint) OnClickListener(android.content.DialogInterface.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 18 with FavoriteGroup

use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.

the class SelectPointsCategoryBottomSheet method attachFavoriteCategories.

private void attachFavoriteCategories(@NonNull ViewGroup container) {
    FavouritesHelper favoritesHelper = requiredMyApplication().getFavoritesHelper();
    List<FavoriteGroup> favoriteGroups = favoritesHelper.getFavoriteGroups();
    for (FavoriteGroup category : favoriteGroups) {
        String displayName = category.getDisplayName(getContext());
        String categoryCount = Algorithms.isEmpty(category.getPoints()) ? getString(R.string.shared_string_empty) : String.valueOf(category.getPoints().size());
        container.addView(createCategoryItem(displayName, category.getColor(), categoryCount, !category.isVisible()));
    }
}
Also used : FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup)

Example 19 with FavoriteGroup

use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.

the class WptPtEditor method add.

public void add(@NonNull GPXFile gpxFile, @NonNull WptPt wpt, String categoryName, int categoryColor, boolean skipDialog) {
    if (mapActivity == null) {
        return;
    }
    isNew = true;
    this.categoryColor = 0;
    this.gpxFile = gpxFile;
    SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
    gpxSelected = selectedGpxFile != null;
    if (!Algorithms.isEmpty(categoryName)) {
        FavoriteGroup category = mapActivity.getMyApplication().getFavoritesHelper().getGroup(categoryName);
        if (category == null) {
            mapActivity.getMyApplication().getFavoritesHelper().addEmptyCategory(categoryName, categoryColor);
        }
    } else {
        categoryName = "";
    }
    wpt.category = categoryName;
    this.wpt = wpt;
    showEditorFragment(skipDialog);
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup)

Example 20 with FavoriteGroup

use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.

the class FavoritePointEditorFragment method getCategories.

@NonNull
@Override
public Set<String> getCategories() {
    Set<String> categories = new LinkedHashSet<>();
    Set<String> categoriesHidden = new LinkedHashSet<>();
    FavouritesHelper helper = getHelper();
    if (helper != null && editor != null) {
        OsmandApplication app = getMyApplication();
        FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup());
        if (lastUsedGroup != null) {
            categories.add(lastUsedGroup.getDisplayName(app));
        }
        for (FavoriteGroup fg : helper.getFavoriteGroups()) {
            if (!fg.equals(lastUsedGroup)) {
                if (fg.isVisible()) {
                    categories.add(fg.getDisplayName(app));
                } else {
                    categoriesHidden.add(fg.getDisplayName(app));
                }
            }
        }
        categories.addAll(categoriesHidden);
    }
    return categories;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) OsmandApplication(net.osmand.plus.OsmandApplication) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) NonNull(androidx.annotation.NonNull)

Aggregations

FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)29 FavouritePoint (net.osmand.data.FavouritePoint)15 ArrayList (java.util.ArrayList)10 FavouritesHelper (net.osmand.plus.myplaces.FavouritesHelper)9 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)8 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)7 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)7 File (java.io.File)6 MapMarker (net.osmand.plus.mapmarkers.MapMarker)6 QuickAction (net.osmand.plus.quickaction.QuickAction)6 NonNull (androidx.annotation.NonNull)5 ITileSource (net.osmand.map.ITileSource)5 MapActivity (net.osmand.plus.activities.MapActivity)5 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)5 Context (android.content.Context)4 View (android.view.View)4 List (java.util.List)4