Add export options menu

This commit is contained in:
Alexander Sytnyk 2018-01-30 17:45:07 +02:00
parent ed99ee8c73
commit b02ee229ea
4 changed files with 362 additions and 12 deletions

View file

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="@string/shared_string_export"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_descr_height"
android:ellipsize="end"
android:maxLines="2"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:text="@string/osm_edits_export_desc"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
<LinearLayout
android:id="@+id/poi_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/poi_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_info_dark"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/poi"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/poi_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="13"/>
</LinearLayout>
<LinearLayout
android:id="@+id/osm_notes_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/osm_notes_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_bug_dark"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/osm_notes"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/osm_notes_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="5"/>
</LinearLayout>
<LinearLayout
android:id="@+id/all_data_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/all_data_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_folder"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/all_data"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/all_data_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="18"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/cancel_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -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
-->
<string name="osm_edits_export_desc">Select the import type: OSM notes, POI, or both.</string>
<string name="all_data">All data</string>
<string name="osm_notes">OSM Notes</string>
<string name="will_open_tomorrow_at">Will open tomorrow at</string>
<string name="rendering_attr_hidePOILabels_name">POI labels</string>
<string name="shared_string_without_name">Without name</string>

View file

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

View file

@ -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<OsmPoint> getOsmEditsByGroup(Group group) {
List<OsmPoint> 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");