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);
}
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();
}
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()));
}
}
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);
}
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;
}
Aggregations