use of net.osmand.plus.plugins.osmedit.data.OsmPoint in project Osmand by osmandapp.
the class OsmEditsFragment method showProgressDialog.
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(R.string.uploading, R.string.local_openstreetmap_uploading, ProgressDialog.STYLE_HORIZONTAL);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(), getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
for (Map.Entry<OsmPoint, String> entry : loadErrorsMap.entrySet()) {
if (entry.getValue() == null) {
osmEdits.remove(entry.getKey());
}
}
recreateAdapterData();
}
};
dialog.show(getActivity().getSupportFragmentManager(), ProgressDialogFragment.TAG);
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points);
}
use of net.osmand.plus.plugins.osmedit.data.OsmPoint in project Osmand by osmandapp.
the class OsmEditsFragment method createFileTypeFragmentListener.
private FileTypeFragmentListener createFileTypeFragmentListener() {
return new FileTypeFragmentListener() {
@Override
public void onClick(int type) {
List<OsmPoint> points = getPointsToExport();
ShareOsmPointsAsyncTask backupTask = new ShareOsmPointsAsyncTask(app, type, exportType, OsmEditsFragment.this);
backupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points.toArray(new OsmPoint[0]));
}
};
}
use of net.osmand.plus.plugins.osmedit.data.OsmPoint in project Osmand by osmandapp.
the class OsmEditOptionsBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
final OsmPoint osmPoint = (OsmPoint) args.getSerializable(OSM_POINT);
String name = OsmEditingPlugin.getName(osmPoint);
if (Algorithms.isEmpty(name)) {
name = OsmEditingPlugin.getCategory(osmPoint, getContext());
}
items.add(new TitleItem(name + ":"));
BaseBottomSheetItem uploadItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_export)).setTitle(getString(R.string.local_openstreetmap_upload)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onUploadClick(osmPoint);
}
dismiss();
}
}).create();
items.add(uploadItem);
BaseBottomSheetItem showOnMapItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_show_on_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onShowOnMapClick(osmPoint);
}
dismiss();
}
}).create();
items.add(showOnMapItem);
items.add(new DividerHalfItem(getContext()));
if (osmPoint instanceof OpenstreetmapPoint && osmPoint.getAction() != OsmPoint.Action.DELETE) {
BaseBottomSheetItem modifyOsmChangeItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.poi_context_menu_modify_osm_change)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onModifyOsmChangeClick(osmPoint);
}
dismiss();
}
}).create();
items.add(modifyOsmChangeItem);
}
if (osmPoint instanceof OsmNotesPoint) {
BaseBottomSheetItem modifyOsmNoteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.context_menu_item_modify_note)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onModifyOsmNoteClick(osmPoint);
}
dismiss();
}
}).create();
items.add(modifyOsmNoteItem);
}
BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_delete_dark)).setTitle(getString(R.string.shared_string_delete)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onDeleteClick(osmPoint);
}
dismiss();
}
}).create();
items.add(deleteItem);
}
}
use of net.osmand.plus.plugins.osmedit.data.OsmPoint in project Osmand by osmandapp.
the class SendOsmNoteBottomSheetFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = getMyApplication();
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (app == null || plugin == null)
return;
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
items.add(new TitleItem(getString(R.string.upload_osm_note)));
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_osm_note_fragment, null);
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
noteText = sendOsmNoteView.findViewById(R.id.note_text);
noteText.setText(((OsmNotesPoint) poi[0]).getText());
noteText.setSelection(noteText.getText().length());
TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint);
noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
accountBlockView = sendOsmNoteView.findViewById(R.id.account_container);
signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
accountName = sendOsmNoteView.findViewById(R.id.user_name);
updateAccountName();
View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button);
setupButton(signInButton, R.string.sign_in_with_open_street_map, DialogButtonType.PRIMARY, R.drawable.ic_action_openstreetmap_logo);
signInButton.setOnClickListener(v -> {
Fragment fragment = getParentFragment();
if (fragment instanceof OsmAuthorizationListener) {
app.getOsmOAuthHelper().addListener((OsmAuthorizationListener) fragment);
}
app.getOsmOAuthHelper().startOAuth((ViewGroup) getView(), nightMode);
});
View loginButton = sendOsmNoteView.findViewById(R.id.login_button);
setupButton(loginButton, R.string.use_login_password, DialogButtonType.SECONDARY, -1);
loginButton.setOnClickListener(v -> {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, SendOsmNoteBottomSheetFragment.this, usedOnMap, null);
}
});
updateSignIn(uploadAnonymously.isChecked());
uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateSignIn(isChecked);
if (nightMode) {
uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
} else {
uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0);
}
});
LinearLayout account = accountBlockView.findViewById(R.id.account_container);
account.setOnClickListener(v -> {
FragmentActivity activity = getActivity();
if (activity != null) {
showOpenStreetMapScreen(activity);
}
dismiss();
});
final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder().setCustomView(sendOsmNoteView).create();
items.add(bottomSheetItem);
}
use of net.osmand.plus.plugins.osmedit.data.OsmPoint in project Osmand by osmandapp.
the class SendPoiBottomSheetFragment method createDefaultChangeSet.
private String createDefaultChangeSet(OsmandApplication app) {
Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
if (allTranslatedSubTypes == null) {
return "";
}
Map<String, Integer> addGroup = new HashMap<>();
Map<String, Integer> editGroup = new HashMap<>();
Map<String, Integer> deleteGroup = new HashMap<>();
Map<String, Integer> reopenGroup = new HashMap<>();
String comment = "";
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
OsmPoint.Action action = p.getAction();
String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG);
if (type == null) {
continue;
}
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
if (localizedPoiType != null) {
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
}
if (action == OsmPoint.Action.CREATE) {
if (!addGroup.containsKey(type)) {
addGroup.put(type, 1);
} else {
addGroup.put(type, addGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.MODIFY) {
if (!editGroup.containsKey(type)) {
editGroup.put(type, 1);
} else {
editGroup.put(type, editGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.DELETE) {
if (!deleteGroup.containsKey(type)) {
deleteGroup.put(type, 1);
} else {
deleteGroup.put(type, deleteGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.REOPEN) {
if (!reopenGroup.containsKey(type)) {
reopenGroup.put(type, 1);
} else {
reopenGroup.put(type, reopenGroup.get(type) + 1);
}
}
}
}
int modifiedItemsOutOfLimit = 0;
for (int i = 0; i < 4; i++) {
String action;
Map<String, Integer> group;
switch(i) {
case 0:
action = getString(R.string.default_changeset_add);
group = addGroup;
break;
case 1:
action = getString(R.string.default_changeset_edit);
group = editGroup;
break;
case 2:
action = getString(R.string.default_changeset_delete);
group = deleteGroup;
break;
case 3:
action = getString(R.string.default_changeset_reopen);
group = reopenGroup;
break;
default:
action = "";
group = new HashMap<>();
}
if (!group.isEmpty()) {
int pos = 0;
for (Map.Entry<String, Integer> entry : group.entrySet()) {
String type = entry.getKey();
int quantity = entry.getValue();
if (comment.length() > 200) {
modifiedItemsOutOfLimit += quantity;
} else {
if (pos == 0) {
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
} else {
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
}
}
pos++;
}
}
}
if (modifiedItemsOutOfLimit != 0) {
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat(".");
} else if (!comment.isEmpty()) {
comment = comment.concat(".");
}
return comment;
}
Aggregations