From b02ee229ea95bb073aad6138fce256567899d625 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 30 Jan 2018 17:45:07 +0200 Subject: [PATCH 1/3] Add export options menu --- ...osm_export_options_bottom_sheet_dialog.xml | 195 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 3 + ...xportOptionsBottomSheetDialogFragment.java | 106 ++++++++++ .../osmand/plus/osmedit/OsmEditsFragment.java | 70 +++++-- 4 files changed, 362 insertions(+), 12 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml new file mode 100644 index 0000000000..db5d8c5b42 --- /dev/null +++ b/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a6bd3c28f5..12b04815c9 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Select the import type: OSM notes, POI, or both. + All data + OSM Notes Will open tomorrow at POI labels Without name diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java new file mode 100644 index 0000000000..94aa1c363c --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java @@ -0,0 +1,106 @@ +package net.osmand.plus.osmedit; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.widgets.TextViewEx; + +public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = "ExportOptionsBottomSheetDialogFragment"; + public static final String POI_COUNT_KEY = "poi_count"; + public static final String NOTES_COUNT_KEY = "notes_count"; + + private ExportOptionsFragmentListener listener; + + private int poiCount; + private int osmNotesCount; + + public void setListener(ExportOptionsFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.fragment_osm_export_options_bottom_sheet_dialog, container); + + Bundle args = getArguments(); + if (args != null) { + poiCount = args.getInt(POI_COUNT_KEY); + osmNotesCount = args.getInt(NOTES_COUNT_KEY); + } + + if (nightMode) { + ((TextViewEx) mainView.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + } + + ((ImageView) mainView.findViewById(R.id.poi_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_info_dark)); + ((ImageView) mainView.findViewById(R.id.osm_notes_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_bug_dark)); + ((ImageView) mainView.findViewById(R.id.all_data_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_folder)); + + ((TextView) mainView.findViewById(R.id.poi_count_text_view)).setText(String.valueOf(poiCount)); + ((TextView) mainView.findViewById(R.id.osm_notes_count_text_view)).setText(String.valueOf(osmNotesCount)); + ((TextView) mainView.findViewById(R.id.all_data_count_text_view)).setText(String.valueOf(poiCount + osmNotesCount)); + + mainView.findViewById(R.id.poi_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onPoiClick(); + } + dismiss(); + } + }); + + mainView.findViewById(R.id.osm_notes_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onOsmNotesClick(); + } + dismiss(); + } + }); + + mainView.findViewById(R.id.all_data_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onAllDataClick(); + } + dismiss(); + } + }); + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + setupHeightAndBackground(mainView, R.id.scroll_view); + + return mainView; + } + + public interface ExportOptionsFragmentListener { + + void onPoiClick(); + + void onOsmNotesClick(); + + void onAllDataClick(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 71e66f48da..e212edd8fa 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -10,6 +10,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; import android.util.Xml; @@ -40,9 +41,11 @@ import net.osmand.plus.base.OsmAndListFragment; import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.plus.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener; +import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; +import net.osmand.plus.osmedit.OsmPoint.Group; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType; -import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; import net.osmand.util.Algorithms; import org.xmlpull.v1.XmlSerializer; @@ -77,9 +80,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo ImageView icon = (ImageView) v.findViewById(R.id.icon); String name = OsmEditingPlugin.getEditName(child); viewName.setText(name); - if (child.getGroup() == OsmPoint.Group.POI) { + if (child.getGroup() == Group.POI) { icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_info, R.color.color_distance)); - } else if (child.getGroup() == OsmPoint.Group.BUG) { + } else if (child.getGroup() == Group.BUG) { icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance)); } @@ -111,10 +114,15 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo emptyView.setBackgroundColor(getResources().getColor(getMyApplication().getSettings() .isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark)); - Fragment optionsFragment = getChildFragmentManager().findFragmentByTag(OsmEditOptionsBottomSheetDialogFragment.TAG); + FragmentManager fm = getChildFragmentManager(); + Fragment optionsFragment = fm.findFragmentByTag(OsmEditOptionsBottomSheetDialogFragment.TAG); if (optionsFragment != null) { ((OsmEditOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOsmEditOptionsFragmentListener()); } + Fragment exportOptFragment = fm.findFragmentByTag(ExportOptionsBottomSheetDialogFragment.TAG); + if (exportOptFragment != null) { + ((ExportOptionsBottomSheetDialogFragment) exportOptFragment).setListener(createExportOptionsFragmentListener()); + } plugin.getPoiModificationLocalUtil().addNodeCommittedListener(this); return view; @@ -152,6 +160,16 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo listAdapter.notifyDataSetChanged(); } + private List getOsmEditsByGroup(Group group) { + List res = new ArrayList<>(); + for (OsmPoint point : osmEdits) { + if (point.getGroup() == group) { + res.add(point); + } + } + return res; + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); @@ -173,13 +191,21 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo }); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - item = menu.add(R.string.local_osm_changes_backup).setIcon(R.drawable.ic_action_gshare_dark); + item = menu.add(R.string.shared_string_export).setIcon(R.drawable.ic_action_gshare_dark); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - new BackupOpenstreetmapPointAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - osmEdits.toArray(new OsmPoint[osmEdits.size()])); + Bundle args = new Bundle(); + args.putInt(ExportOptionsBottomSheetDialogFragment.POI_COUNT_KEY, getOsmEditsByGroup(Group.POI).size()); + args.putInt(ExportOptionsBottomSheetDialogFragment.NOTES_COUNT_KEY, getOsmEditsByGroup(Group.BUG).size()); + ExportOptionsBottomSheetDialogFragment fragment = new ExportOptionsBottomSheetDialogFragment(); + fragment.setArguments(args); + fragment.setUsedOnMap(false); + fragment.setListener(createExportOptionsFragmentListener()); + fragment.show(getChildFragmentManager(), ExportOptionsBottomSheetDialogFragment.TAG); +// new BackupOpenstreetmapPointAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, +// osmEdits.toArray(new OsmPoint[osmEdits.size()])); return true; } }); @@ -485,6 +511,26 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo }; } + private ExportOptionsFragmentListener createExportOptionsFragmentListener() { + return new ExportOptionsFragmentListener() { + + @Override + public void onPoiClick() { + Toast.makeText(getContext(), "poi", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onOsmNotesClick() { + Toast.makeText(getContext(), "osm notes", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onAllDataClick() { + Toast.makeText(getContext(), "all data", Toast.LENGTH_SHORT).show(); + } + }; + } + protected OsmPoint getPointAfterModify(OsmPoint info) { if (info instanceof OpenstreetmapPoint && info.getId() == refreshId) { for (OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { @@ -533,7 +579,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private void showOnMap(OsmPoint osmPoint) { boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint; - String type = osmPoint.getGroup() == OsmPoint.Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; + String type = osmPoint.getGroup() == Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText()); getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15, new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ @@ -580,9 +626,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo while (it.hasNext()) { OsmPoint osmPoint = it.next(); assert plugin != null; - if (osmPoint.getGroup() == OsmPoint.Group.POI) { + if (osmPoint.getGroup() == Group.POI) { plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint); - } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) { + } else if (osmPoint.getGroup() == Group.BUG) { plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint); } it.remove(); @@ -647,7 +693,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private void writeContent(XmlSerializer sz, OsmPoint[] points, OsmPoint.Action a) throws IllegalArgumentException, IllegalStateException, IOException { for (OsmPoint point : points) { - if (point.getGroup() == OsmPoint.Group.POI) { + if (point.getGroup() == Group.POI) { OpenstreetmapPoint p = (OpenstreetmapPoint) point; if (p.getAction() == a) { sz.startTag("", "node"); @@ -667,7 +713,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo } sz.endTag("", "node"); } - } else if (point.getGroup() == OsmPoint.Group.BUG) { + } else if (point.getGroup() == Group.BUG) { OsmNotesPoint p = (OsmNotesPoint) point; if (p.getAction() == a) { sz.startTag("", "note"); From 4202179205554a74317af5dfae926cabcd1c47da Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 30 Jan 2018 18:47:21 +0200 Subject: [PATCH 2/3] Add menu for choosing export file type --- ...ment_osm_file_type_bottom_sheet_dialog.xml | 164 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 5 + .../FileTypeBottomSheetDialogFragment.java | 79 +++++++++ .../osmand/plus/osmedit/OsmEditsFragment.java | 29 ++++ 4 files changed, 277 insertions(+) create mode 100644 OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml new file mode 100644 index 0000000000..77911fdab2 --- /dev/null +++ b/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 12b04815c9..718b2ebf38 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,11 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + GPX - suitable for import to JOSM or other OSM editors. + OSC - suitable for import to OpenStreetMap. + GPX file + OSC file + Choose file type Select the import type: OSM notes, POI, or both. All data OSM Notes diff --git a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java new file mode 100644 index 0000000000..f4ed85f2e1 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java @@ -0,0 +1,79 @@ +package net.osmand.plus.osmedit; + +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.widgets.TextViewEx; + +public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = "FileTypeBottomSheetDialogFragment"; + + private FileTypeFragmentListener listener; + + public void setListener(FileTypeFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.fragment_osm_file_type_bottom_sheet_dialog, container); + + if (nightMode) { + ((TextViewEx) mainView.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + } + + Drawable fileIcon = getContentIcon(R.drawable.ic_type_file); + ((ImageView) mainView.findViewById(R.id.osc_file_icon)).setImageDrawable(fileIcon); + ((ImageView) mainView.findViewById(R.id.gpx_file_icon)).setImageDrawable(fileIcon); + + mainView.findViewById(R.id.osc_file_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onOscClick(); + } + dismiss(); + } + }); + + mainView.findViewById(R.id.gpx_file_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onGpxClick(); + } + dismiss(); + } + }); + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + setupHeightAndBackground(mainView, R.id.scroll_view); + + return mainView; + } + + public interface FileTypeFragmentListener { + + void onOscClick(); + + void onGpxClick(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index e212edd8fa..e489f5f1b5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -42,6 +42,7 @@ import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener; +import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener; import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; import net.osmand.plus.osmedit.OsmPoint.Group; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; @@ -123,6 +124,10 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo if (exportOptFragment != null) { ((ExportOptionsBottomSheetDialogFragment) exportOptFragment).setListener(createExportOptionsFragmentListener()); } + Fragment fileTypeFragment = fm.findFragmentByTag(FileTypeBottomSheetDialogFragment.TAG); + if (fileTypeFragment != null) { + ((FileTypeBottomSheetDialogFragment) fileTypeFragment).setListener(createFileTypeFragmentListener()); + } plugin.getPoiModificationLocalUtil().addNodeCommittedListener(this); return view; @@ -517,20 +522,44 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo @Override public void onPoiClick() { Toast.makeText(getContext(), "poi", Toast.LENGTH_SHORT).show(); + openFileTypeMenu(); } @Override public void onOsmNotesClick() { Toast.makeText(getContext(), "osm notes", Toast.LENGTH_SHORT).show(); + openFileTypeMenu(); } @Override public void onAllDataClick() { Toast.makeText(getContext(), "all data", Toast.LENGTH_SHORT).show(); + openFileTypeMenu(); } }; } + private FileTypeFragmentListener createFileTypeFragmentListener() { + return new FileTypeFragmentListener() { + @Override + public void onOscClick() { + Toast.makeText(getContext(), "osc", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onGpxClick() { + Toast.makeText(getContext(), "gpx", Toast.LENGTH_SHORT).show(); + } + }; + } + + private void openFileTypeMenu() { + FileTypeBottomSheetDialogFragment fragment = new FileTypeBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); + fragment.setListener(createFileTypeFragmentListener()); + fragment.show(getChildFragmentManager(), FileTypeBottomSheetDialogFragment.TAG); + } + protected OsmPoint getPointAfterModify(OsmPoint info) { if (info instanceof OpenstreetmapPoint && info.getId() == refreshId) { for (OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { From b3cc1dd61c45832e023f37d694a16b67b8dc4209 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 31 Jan 2018 11:42:26 +0200 Subject: [PATCH 3/3] Restore osm edits export to osc file --- ...xportOptionsBottomSheetDialogFragment.java | 13 +- .../FileTypeBottomSheetDialogFragment.java | 9 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 141 +++++++++++------- 3 files changed, 95 insertions(+), 68 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java index 94aa1c363c..89ca404573 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java @@ -11,6 +11,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.osmedit.OsmEditsFragment.ExportTypesDef; import net.osmand.plus.widgets.TextViewEx; public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -57,7 +58,7 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public void onClick(View v) { if (listener != null) { - listener.onPoiClick(); + listener.onClick(OsmEditsFragment.EXPORT_TYPE_POI); } dismiss(); } @@ -67,7 +68,7 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public void onClick(View v) { if (listener != null) { - listener.onOsmNotesClick(); + listener.onClick(OsmEditsFragment.EXPORT_TYPE_NOTES); } dismiss(); } @@ -77,7 +78,7 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public void onClick(View v) { if (listener != null) { - listener.onAllDataClick(); + listener.onClick(OsmEditsFragment.EXPORT_TYPE_ALL); } dismiss(); } @@ -97,10 +98,6 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo public interface ExportOptionsFragmentListener { - void onPoiClick(); - - void onOsmNotesClick(); - - void onAllDataClick(); + void onClick(@ExportTypesDef int type); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java index f4ed85f2e1..ce23d47238 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java @@ -11,6 +11,7 @@ import android.widget.ImageView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.osmedit.OsmEditsFragment.FileTypesDef; import net.osmand.plus.widgets.TextViewEx; public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -42,7 +43,7 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag @Override public void onClick(View v) { if (listener != null) { - listener.onOscClick(); + listener.onClick(OsmEditsFragment.FILE_TYPE_OSC); } dismiss(); } @@ -52,7 +53,7 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag @Override public void onClick(View v) { if (listener != null) { - listener.onGpxClick(); + listener.onClick(OsmEditsFragment.FILE_TYPE_GPX); } dismiss(); } @@ -72,8 +73,6 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag public interface FileTypeFragmentListener { - void onOscClick(); - - void onGpxClick(); + void onClick(@FileTypesDef int type); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index e489f5f1b5..47d2624d05 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -7,6 +7,7 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; @@ -54,6 +55,8 @@ import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -61,6 +64,25 @@ import java.util.Map; public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener { + public static final int EXPORT_TYPE_ALL = 0; + public static final int EXPORT_TYPE_POI = 1; + public static final int EXPORT_TYPE_NOTES = 2; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({EXPORT_TYPE_ALL, EXPORT_TYPE_POI, EXPORT_TYPE_NOTES}) + @interface ExportTypesDef { + } + + public static final int FILE_TYPE_OSC = 0; + public static final int FILE_TYPE_GPX = 1; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({FILE_TYPE_OSC, FILE_TYPE_GPX}) + @interface FileTypesDef { + } + + private static final String EXPORT_TYPE_KEY = "export_type"; + private final static int MODE_DELETE = 100; private final static int MODE_UPLOAD = 101; @@ -76,6 +98,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private ActionMode actionMode; private long refreshId; + private int exportType; + public static void getOsmEditView(View v, OsmPoint child, OsmandApplication app) { TextView viewName = ((TextView) v.findViewById(R.id.name)); ImageView icon = (ImageView) v.findViewById(R.id.icon); @@ -101,6 +125,10 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + if (savedInstanceState != null) { + exportType = savedInstanceState.getInt(EXPORT_TYPE_KEY); + } + setHasOptionsMenu(true); plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); @@ -133,6 +161,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return view; } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(EXPORT_TYPE_KEY, exportType); + } + @Override public void onDestroyView() { plugin.getPoiModificationLocalUtil().removeNodeCommittedListener(this); @@ -209,8 +243,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo fragment.setUsedOnMap(false); fragment.setListener(createExportOptionsFragmentListener()); fragment.show(getChildFragmentManager(), ExportOptionsBottomSheetDialogFragment.TAG); -// new BackupOpenstreetmapPointAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, -// osmEdits.toArray(new OsmPoint[osmEdits.size()])); return true; } }); @@ -518,22 +550,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private ExportOptionsFragmentListener createExportOptionsFragmentListener() { return new ExportOptionsFragmentListener() { - @Override - public void onPoiClick() { - Toast.makeText(getContext(), "poi", Toast.LENGTH_SHORT).show(); - openFileTypeMenu(); - } - - @Override - public void onOsmNotesClick() { - Toast.makeText(getContext(), "osm notes", Toast.LENGTH_SHORT).show(); - openFileTypeMenu(); - } - - @Override - public void onAllDataClick() { - Toast.makeText(getContext(), "all data", Toast.LENGTH_SHORT).show(); + public void onClick(int type) { + exportType = type; openFileTypeMenu(); } }; @@ -542,13 +561,10 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private FileTypeFragmentListener createFileTypeFragmentListener() { return new FileTypeFragmentListener() { @Override - public void onOscClick() { - Toast.makeText(getContext(), "osc", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onGpxClick() { - Toast.makeText(getContext(), "gpx", Toast.LENGTH_SHORT).show(); + public void onClick(int type) { + List points = getPointsToExport(); + new BackupOpenstreetmapPointAsyncTask(type).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, + points.toArray(new OsmPoint[points.size()])); } }; } @@ -560,6 +576,15 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo fragment.show(getChildFragmentManager(), FileTypeBottomSheetDialogFragment.TAG); } + private List getPointsToExport() { + if (exportType == EXPORT_TYPE_POI) { + return getOsmEditsByGroup(Group.POI); + } else if (exportType == EXPORT_TYPE_NOTES) { + return getOsmEditsByGroup(Group.BUG); + } + return osmEdits; + } + protected OsmPoint getPointAfterModify(OsmPoint info) { if (info instanceof OpenstreetmapPoint && info.getId() == refreshId) { for (OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { @@ -675,46 +700,52 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo public class BackupOpenstreetmapPointAsyncTask extends AsyncTask { private File osmchange; + private boolean oscFile; - public BackupOpenstreetmapPointAsyncTask() { + public BackupOpenstreetmapPointAsyncTask(int fileType) { OsmandApplication app = (OsmandApplication) getActivity().getApplication(); - osmchange = app.getAppPath("poi_modification.osc"); + oscFile = fileType == FILE_TYPE_OSC; + osmchange = app.getAppPath(oscFile ? "poi_modification.osc" : "poi_modifications.gpx"); } @Override protected String doInBackground(OsmPoint... points) { - FileOutputStream out = null; - try { - out = new FileOutputStream(osmchange); - XmlSerializer sz = Xml.newSerializer(); - - sz.setOutput(out, "UTF-8"); - sz.startDocument("UTF-8", true); - sz.startTag("", "osmChange"); - sz.attribute("", "generator", "OsmAnd"); - sz.attribute("", "version", "0.6"); - sz.startTag("", "create"); - writeContent(sz, points, OsmPoint.Action.CREATE); - sz.endTag("", "create"); - sz.startTag("", "modify"); - writeContent(sz, points, OsmPoint.Action.MODIFY); - writeContent(sz, points, OsmPoint.Action.REOPEN); - - sz.endTag("", "modify"); - sz.startTag("", "delete"); - writeContent(sz, points, OsmPoint.Action.DELETE); - sz.endTag("", "delete"); - sz.endTag("", "osmChange"); - sz.endDocument(); - } catch (Exception e) { - return e.getMessage(); - } finally { + if (oscFile) { + FileOutputStream out = null; try { - if (out != null) out.close(); - } catch (IOException e) { - e.printStackTrace(); + out = new FileOutputStream(osmchange); + XmlSerializer sz = Xml.newSerializer(); + + sz.setOutput(out, "UTF-8"); + sz.startDocument("UTF-8", true); + sz.startTag("", "osmChange"); + sz.attribute("", "generator", "OsmAnd"); + sz.attribute("", "version", "0.6"); + sz.startTag("", "create"); + writeContent(sz, points, OsmPoint.Action.CREATE); + sz.endTag("", "create"); + sz.startTag("", "modify"); + writeContent(sz, points, OsmPoint.Action.MODIFY); + writeContent(sz, points, OsmPoint.Action.REOPEN); + + sz.endTag("", "modify"); + sz.startTag("", "delete"); + writeContent(sz, points, OsmPoint.Action.DELETE); + sz.endTag("", "delete"); + sz.endTag("", "osmChange"); + sz.endDocument(); + } catch (Exception e) { + return e.getMessage(); + } finally { + try { + if (out != null) out.close(); + } catch (IOException e) { + e.printStackTrace(); + } } + } else { + return "gpx export not supported yet"; } return null;