From b02ee229ea95bb073aad6138fce256567899d625 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 30 Jan 2018 17:45:07 +0200 Subject: [PATCH] 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");