Search in sources :

Example 16 with OsmPoint

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);
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmEditsUploadListenerHelper(net.osmand.plus.plugins.osmedit.helpers.OsmEditsUploadListenerHelper) ProgressDialogFragment(net.osmand.plus.dialogs.ProgressDialogFragment) OsmEditsUploadListener(net.osmand.plus.plugins.osmedit.OsmEditsUploadListener) Map(java.util.Map) UploadOpenstreetmapPointAsyncTask(net.osmand.plus.plugins.osmedit.asynctasks.UploadOpenstreetmapPointAsyncTask)

Example 17 with OsmPoint

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]));
        }
    };
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) ShareOsmPointsAsyncTask(net.osmand.plus.plugins.osmedit.asynctasks.ShareOsmPointsAsyncTask) FileTypeFragmentListener(net.osmand.plus.plugins.osmedit.dialogs.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener)

Example 18 with OsmPoint

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);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) Bundle(android.os.Bundle) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) View(android.view.View)

Example 19 with OsmPoint

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);
}
Also used : SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmAuthorizationListener(net.osmand.plus.plugins.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) View(android.view.View) TextView(android.widget.TextView) Fragment(androidx.fragment.app.Fragment) DashOsmEditsFragment(net.osmand.plus.plugins.osmedit.fragments.DashOsmEditsFragment) MenuBottomSheetDialogFragment(net.osmand.plus.base.MenuBottomSheetDialogFragment) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) ContextThemeWrapper(android.view.ContextThemeWrapper) TextInputLayout(com.google.android.material.textfield.TextInputLayout) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 20 with OsmPoint

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;
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) HashMap(java.util.HashMap) PoiType(net.osmand.osm.PoiType) HashMap(java.util.HashMap) Map(java.util.Map) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

Aggregations

OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)29 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)21 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)15 PoiType (net.osmand.osm.PoiType)6 Map (java.util.Map)5 Entity (net.osmand.osm.edit.Entity)5 View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 LatLon (net.osmand.data.LatLon)4 TextView (android.widget.TextView)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MapActivity (net.osmand.plus.activities.MapActivity)3 SimpleBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem)3 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)3 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)3 ContextThemeWrapper (android.view.ContextThemeWrapper)2 CompoundButton (android.widget.CompoundButton)2 ImageButton (android.widget.ImageButton)2