Create adapter in another class and refactor
This commit is contained in:
parent
ff8dd8957f
commit
6cf247efd8
2 changed files with 292 additions and 255 deletions
134
OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java
Normal file
134
OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||
|
||||
private List<OsmPoint> osmEdits;
|
||||
private OsmandApplication app;
|
||||
|
||||
private boolean selectionMode;
|
||||
private List<OsmPoint> selectedOsmEdits;
|
||||
|
||||
private OsmEditsAdapterListener listener;
|
||||
|
||||
public OsmEditsAdapter(OsmandApplication app, @NonNull List<OsmPoint> points) {
|
||||
super(app, R.layout.note, points);
|
||||
this.app = app;
|
||||
osmEdits = points;
|
||||
}
|
||||
|
||||
public List<OsmPoint> getOsmEdits() {
|
||||
return osmEdits;
|
||||
}
|
||||
|
||||
public void setOsmEdits(List<OsmPoint> osmEdits) {
|
||||
this.osmEdits = osmEdits;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean isSelectionMode() {
|
||||
return selectionMode;
|
||||
}
|
||||
|
||||
public void setSelectionMode(boolean selectionMode) {
|
||||
this.selectionMode = selectionMode;
|
||||
}
|
||||
|
||||
public void setSelectedOsmEdits(List<OsmPoint> selectedOsmEdits) {
|
||||
this.selectedOsmEdits = selectedOsmEdits;
|
||||
}
|
||||
|
||||
public void setAdapterListener(OsmEditsAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
final OsmPoint child = getItem(position);
|
||||
if (v == null) {
|
||||
v = LayoutInflater.from(getContext()).inflate(R.layout.note, parent, false);
|
||||
}
|
||||
OsmEditsFragment.getOsmEditView(v, child, app);
|
||||
|
||||
v.findViewById(R.id.play).setVisibility(View.GONE);
|
||||
|
||||
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_local_index);
|
||||
View options = v.findViewById(R.id.options);
|
||||
if (selectionMode) {
|
||||
options.setVisibility(View.GONE);
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setChecked(selectedOsmEdits.contains(child));
|
||||
v.findViewById(R.id.icon).setVisibility(View.GONE);
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectItem(ch, child);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
v.findViewById(R.id.icon).setVisibility(View.VISIBLE);
|
||||
options.setVisibility(View.VISIBLE);
|
||||
ch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
((ImageView) options).setImageDrawable(app.getIconsCache()
|
||||
.getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.onOptionsClick(v, child);
|
||||
}
|
||||
}
|
||||
});
|
||||
v.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (selectionMode) {
|
||||
ch.setChecked(!ch.isChecked());
|
||||
selectItem(ch, child);
|
||||
} else {
|
||||
if (listener != null) {
|
||||
listener.onItemShowMap(child);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
private void selectItem(CheckBox checkBox, OsmPoint note) {
|
||||
if (checkBox.isChecked()) {
|
||||
selectedOsmEdits.add(note);
|
||||
} else {
|
||||
selectedOsmEdits.remove(note);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onItemSelect(note);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OsmEditsAdapterListener {
|
||||
|
||||
void onItemSelect(OsmPoint point);
|
||||
|
||||
void onItemShowMap(OsmPoint point);
|
||||
|
||||
void onOptionsClick(View view, OsmPoint note);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
|
@ -30,7 +29,6 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -60,23 +58,44 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OsmEditsFragment extends OsmAndListFragment
|
||||
implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener {
|
||||
OsmEditingPlugin plugin;
|
||||
|
||||
private OsmEditsAdapter listAdapter;
|
||||
private View footerView;
|
||||
|
||||
private boolean selectionMode = false;
|
||||
|
||||
public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener {
|
||||
|
||||
private final static int MODE_DELETE = 100;
|
||||
private final static int MODE_UPLOAD = 101;
|
||||
|
||||
private ActionMode actionMode;
|
||||
private long refreshId;
|
||||
private OsmEditingPlugin plugin;
|
||||
|
||||
private View footerView;
|
||||
|
||||
private List<OsmPoint> osmEdits;
|
||||
private OsmEditsAdapter listAdapter;
|
||||
private ArrayList<OsmPoint> osmEditsSelected = new ArrayList<>();
|
||||
|
||||
private ActionMode actionMode;
|
||||
private long refreshId;
|
||||
|
||||
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);
|
||||
String name = OsmEditingPlugin.getEditName(child);
|
||||
viewName.setText(name);
|
||||
if (child.getGroup() == OsmPoint.Group.POI) {
|
||||
icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_info, R.color.color_distance));
|
||||
} else if (child.getGroup() == OsmPoint.Group.BUG) {
|
||||
icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance));
|
||||
}
|
||||
|
||||
TextView descr = (TextView) v.findViewById(R.id.description);
|
||||
if (child.getAction() == OsmPoint.Action.CREATE) {
|
||||
descr.setText(R.string.action_create);
|
||||
} else if (child.getAction() == OsmPoint.Action.MODIFY) {
|
||||
descr.setText(R.string.action_modify);
|
||||
} else if (child.getAction() == OsmPoint.Action.DELETE) {
|
||||
descr.setText(R.string.action_delete);
|
||||
} else if (child.getAction() == OsmPoint.Action.REOPEN) {
|
||||
descr.setText(R.string.action_modify);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -108,23 +127,24 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public android.widget.ArrayAdapter<?> getAdapter() {
|
||||
@Override
|
||||
public ArrayAdapter<?> getAdapter() {
|
||||
return listAdapter;
|
||||
}
|
||||
|
||||
|
||||
private void selectAll() {
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
OsmPoint point = listAdapter.getItem(i);
|
||||
for (int i = 0; i < osmEdits.size(); i++) {
|
||||
OsmPoint point = osmEdits.get(i);
|
||||
if (!osmEditsSelected.contains(point)) {
|
||||
osmEditsSelected.add(point);
|
||||
}
|
||||
}
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void deselectAll() {
|
||||
osmEditsSelected.clear();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,22 +167,22 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
return true;
|
||||
}
|
||||
});
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
item = menu.add(R.string.local_osm_changes_backup).
|
||||
setIcon(R.drawable.ic_action_gshare_dark);
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
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,
|
||||
listAdapter.dataPoints.toArray(new OsmPoint[listAdapter.dataPoints.size()]));
|
||||
osmEdits.toArray(new OsmPoint[osmEdits.size()]));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
item = menu.add(R.string.shared_string_delete_all).
|
||||
setIcon(R.drawable.ic_action_delete_dark);
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -178,8 +198,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
@Override
|
||||
public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
|
||||
enableSelectionMode(true);
|
||||
MenuItem item = menu.add(R.string.local_openstreetmap_uploadall).
|
||||
setIcon(R.drawable.ic_action_export);
|
||||
MenuItem item = menu.add(R.string.local_openstreetmap_uploadall).setIcon(R.drawable.ic_action_export);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -188,9 +207,9 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
return true;
|
||||
}
|
||||
});
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
osmEditsSelected.clear();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
@ -208,7 +227,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
enableSelectionMode(false);
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -240,9 +259,9 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
return true;
|
||||
}
|
||||
});
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
osmEditsSelected.clear();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
@ -260,7 +279,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
enableSelectionMode(false);
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -286,8 +305,8 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
return;
|
||||
}
|
||||
CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
OsmPoint point = listAdapter.getItem(i);
|
||||
for (int i = 0; i < osmEdits.size(); i++) {
|
||||
OsmPoint point = osmEdits.get(i);
|
||||
if (!osmEditsSelected.contains(point)) {
|
||||
selectAll.setChecked(false);
|
||||
return;
|
||||
|
@ -297,11 +316,10 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
|
||||
private void enableSelectionMode(boolean selectionMode) {
|
||||
this.selectionMode = selectionMode;
|
||||
listAdapter.setSelectionMode(selectionMode);
|
||||
//noinspection ConstantConditions
|
||||
getView().findViewById(R.id.select_all).setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
||||
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode &&
|
||||
AndroidUiHelper.isOrientationPortrait(getActivity()));
|
||||
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode && AndroidUiHelper.isOrientationPortrait(getActivity()));
|
||||
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
|
||||
}
|
||||
|
||||
|
@ -313,17 +331,15 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
|
||||
private void deleteItems(final ArrayList<OsmPoint> points) {
|
||||
DeleteOsmEditsConfirmDialogFragment.createInstance(points).
|
||||
show(getChildFragmentManager(), DeleteOsmEditsConfirmDialogFragment.TAG);
|
||||
DeleteOsmEditsConfirmDialogFragment.createInstance(points).show(getChildFragmentManager(), DeleteOsmEditsConfirmDialogFragment.TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getListView().setBackgroundColor(
|
||||
getResources().getColor(
|
||||
getMyApplication().getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light
|
||||
: R.color.ctx_menu_info_view_bg_dark));
|
||||
getListView().setBackgroundColor(getResources().getColor(getMyApplication().getSettings().isLightContent()
|
||||
? R.color.ctx_menu_info_view_bg_light
|
||||
: R.color.ctx_menu_info_view_bg_dark));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -333,15 +349,32 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
|
||||
private void fetchData() {
|
||||
ArrayList<OsmPoint> dataPoints = new ArrayList<>();
|
||||
osmEdits = new ArrayList<>();
|
||||
List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
|
||||
List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
|
||||
dataPoints.addAll(l1);
|
||||
dataPoints.addAll(l2);
|
||||
osmEdits.addAll(l1);
|
||||
osmEdits.addAll(l2);
|
||||
if (listAdapter == null) {
|
||||
listAdapter = new OsmEditsAdapter(dataPoints);
|
||||
listAdapter = new OsmEditsAdapter(getMyApplication(), osmEdits);
|
||||
listAdapter.setSelectedOsmEdits(osmEditsSelected);
|
||||
listAdapter.setAdapterListener(new OsmEditsAdapter.OsmEditsAdapterListener() {
|
||||
@Override
|
||||
public void onItemSelect(OsmPoint point) {
|
||||
updateSelectionMode(actionMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemShowMap(OsmPoint point) {
|
||||
showOnMap(point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOptionsClick(View view, OsmPoint note) {
|
||||
openPopUpMenu(view, note);
|
||||
}
|
||||
});
|
||||
ListView listView = getListView();
|
||||
if (dataPoints.size() > 0 && footerView == null) {
|
||||
if (osmEdits.size() > 0 && footerView == null) {
|
||||
//listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_header, null, false));
|
||||
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false);
|
||||
listView.addFooterView(footerView);
|
||||
|
@ -359,7 +392,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
});
|
||||
} else {
|
||||
listAdapter.setNewList(dataPoints);
|
||||
listAdapter.setOsmEdits(osmEdits);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,31 +423,6 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
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);
|
||||
String name = OsmEditingPlugin.getEditName(child);
|
||||
viewName.setText(name);
|
||||
if (child.getGroup() == OsmPoint.Group.POI) {
|
||||
icon.setImageDrawable(app.getIconsCache().
|
||||
getIcon(R.drawable.ic_type_info, R.color.color_distance));
|
||||
} else if (child.getGroup() == OsmPoint.Group.BUG) {
|
||||
icon.setImageDrawable(app.getIconsCache().
|
||||
getIcon(R.drawable.ic_type_bug, R.color.color_distance));
|
||||
}
|
||||
|
||||
TextView descr = (TextView) v.findViewById(R.id.description);
|
||||
if (child.getAction() == OsmPoint.Action.CREATE) {
|
||||
descr.setText(R.string.action_create);
|
||||
} else if (child.getAction() == OsmPoint.Action.MODIFY) {
|
||||
descr.setText(R.string.action_modify);
|
||||
} else if (child.getAction() == OsmPoint.Action.DELETE) {
|
||||
descr.setText(R.string.action_delete);
|
||||
} else if (child.getAction() == OsmPoint.Action.REOPEN) {
|
||||
descr.setText(R.string.action_modify);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoteCommitted() {
|
||||
getMyApplication().runInUIThread(new Runnable() {
|
||||
|
@ -425,107 +433,11 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
});
|
||||
}
|
||||
|
||||
protected class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||
private List<OsmPoint> dataPoints;
|
||||
|
||||
|
||||
public OsmEditsAdapter(List<OsmPoint> points) {
|
||||
super(getActivity(), net.osmand.plus.R.layout.note, points);
|
||||
dataPoints = points;
|
||||
}
|
||||
|
||||
public void setNewList(List<OsmPoint> dp) {
|
||||
dataPoints = dp;
|
||||
setNotifyOnChange(false);
|
||||
clear();
|
||||
for (OsmPoint pnt : dp) {
|
||||
add(pnt);
|
||||
}
|
||||
setNotifyOnChange(true);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<OsmPoint> getDataPoints() {
|
||||
return dataPoints;
|
||||
}
|
||||
|
||||
public void delete(OsmPoint i) {
|
||||
dataPoints.remove(i);
|
||||
remove(i);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
final OsmPoint child = getItem(position);
|
||||
if (v == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
v = inflater.inflate(net.osmand.plus.R.layout.note, parent, false);
|
||||
}
|
||||
getOsmEditView(v, child, getMyApplication());
|
||||
|
||||
v.findViewById(R.id.play).setVisibility(View.GONE);
|
||||
|
||||
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_local_index);
|
||||
View options = v.findViewById(R.id.options);
|
||||
if (selectionMode) {
|
||||
options.setVisibility(View.GONE);
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setChecked(osmEditsSelected.contains(child));
|
||||
v.findViewById(R.id.icon).setVisibility(View.GONE);
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onItemSelect(ch, child);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
v.findViewById(R.id.icon).setVisibility(View.VISIBLE);
|
||||
options.setVisibility(View.VISIBLE);
|
||||
ch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
((ImageView) options).setImageDrawable(getMyApplication().getIconsCache()
|
||||
.getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openPopUpMenu(v, child);
|
||||
}
|
||||
});
|
||||
v.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (selectionMode) {
|
||||
ch.setChecked(!ch.isChecked());
|
||||
onItemSelect(ch, child);
|
||||
} else {
|
||||
showOnMap(child);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
public void onItemSelect(CheckBox ch, OsmPoint child) {
|
||||
if (ch.isChecked()) {
|
||||
osmEditsSelected.add(child);
|
||||
} else {
|
||||
osmEditsSelected.remove(child);
|
||||
}
|
||||
updateSelectionMode(actionMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void openPopUpMenu(View v, final OsmPoint info) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
|
||||
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
||||
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).
|
||||
setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_show_on_map));
|
||||
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_show_on_map));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -536,25 +448,22 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
});
|
||||
if (info instanceof OpenstreetmapPoint && info.getAction() != Action.DELETE) {
|
||||
item = optionsMenu.getMenu().add(R.string.poi_context_menu_modify_osm_change)
|
||||
.setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item = optionsMenu.getMenu().add(R.string.poi_context_menu_modify_osm_change).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(info);
|
||||
final Node entity = i.getEntity();
|
||||
refreshId = entity.getId();
|
||||
EditPoiDialogFragment.createInstance(entity, false)
|
||||
.show(getActivity().getSupportFragmentManager(), "edit_poi");
|
||||
EditPoiDialogFragment.createInstance(entity, false).show(getActivity().getSupportFragmentManager(), "edit_poi");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (info instanceof OsmNotesPoint) {
|
||||
item = optionsMenu.getMenu().add(R.string.context_menu_item_modify_note)
|
||||
.setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item = optionsMenu.getMenu().add(R.string.context_menu_item_modify_note).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
|
||||
@Override
|
||||
|
@ -564,8 +473,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
});
|
||||
}
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete).
|
||||
setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark));
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -576,8 +484,7 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
|
||||
}
|
||||
});
|
||||
item = optionsMenu.getMenu().add(R.string.local_openstreetmap_upload).
|
||||
setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_export));
|
||||
item = optionsMenu.getMenu().add(R.string.local_openstreetmap_upload).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_export));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -589,9 +496,9 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
|
||||
protected OsmPoint getPointAfterModify(OsmPoint info) {
|
||||
if(info instanceof OpenstreetmapPoint && info.getId() == refreshId) {
|
||||
for(OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) {
|
||||
if(p.getId() == info.getId()) {
|
||||
if (info instanceof OpenstreetmapPoint && info.getId() == refreshId) {
|
||||
for (OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) {
|
||||
if (p.getId() == info.getId()) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
@ -623,22 +530,85 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
super.uploadEnded(loadErrorsMap);
|
||||
for (OsmPoint osmPoint : loadErrorsMap.keySet()) {
|
||||
if (loadErrorsMap.get(osmPoint) == null) {
|
||||
listAdapter.remove(osmPoint);
|
||||
osmEdits.remove(osmPoint);
|
||||
}
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
dialog.show(getActivity().getSupportFragmentManager(), ProgressDialogFragment.TAG);
|
||||
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
|
||||
dialog, listener, plugin, points.length, closeChangeSet, anonymously);
|
||||
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, listener, plugin, points.length, closeChangeSet, anonymously);
|
||||
uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points);
|
||||
}
|
||||
|
||||
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 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$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
||||
private void deletePoint(OsmPoint osmPoint) {
|
||||
osmEdits.remove(osmPoint);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void notifyDataSetChanged() {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment {
|
||||
public static final String TAG = "DeleteOsmEditsConfirmDialogFragment";
|
||||
private static final String POINTS_LIST = "points_list";
|
||||
|
||||
public static DeleteOsmEditsConfirmDialogFragment createInstance(
|
||||
ArrayList<OsmPoint> points) {
|
||||
DeleteOsmEditsConfirmDialogFragment fragment = new DeleteOsmEditsConfirmDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(POINTS_LIST, points);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final OsmEditsFragment parentFragment = (OsmEditsFragment) getParentFragment();
|
||||
final OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<OsmPoint> points = (ArrayList<OsmPoint>) getArguments().getSerializable(POINTS_LIST);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
assert points != null;
|
||||
builder.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, points.size()));
|
||||
builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Iterator<OsmPoint> it = points.iterator();
|
||||
while (it.hasNext()) {
|
||||
OsmPoint osmPoint = it.next();
|
||||
assert plugin != null;
|
||||
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
|
||||
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint);
|
||||
} else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
|
||||
plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint);
|
||||
}
|
||||
it.remove();
|
||||
parentFragment.deletePoint(osmPoint);
|
||||
}
|
||||
parentFragment.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
public class BackupOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPoint, String> {
|
||||
|
||||
|
||||
private File osmchange;
|
||||
|
||||
public BackupOpenstreetmapPointAsyncTask() {
|
||||
|
@ -745,71 +715,4 @@ public class OsmEditsFragment extends OsmAndListFragment
|
|||
}
|
||||
}
|
||||
|
||||
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 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$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
||||
private void deletePoint(OsmPoint osmPoint) {
|
||||
listAdapter.delete(osmPoint);
|
||||
}
|
||||
|
||||
private void notifyDataSetChanged() {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment {
|
||||
public static final String TAG = "DeleteOsmEditsConfirmDialogFragment";
|
||||
private static final String POINTS_LIST = "points_list";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final OsmEditsFragment parentFragment = (OsmEditsFragment) getParentFragment();
|
||||
final OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<OsmPoint> points =
|
||||
(ArrayList<OsmPoint>) getArguments().getSerializable(POINTS_LIST);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
assert points != null;
|
||||
builder.setMessage(getString(R.string.local_osm_changes_delete_all_confirm,
|
||||
points.size()));
|
||||
builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Iterator<OsmPoint> it = points.iterator();
|
||||
while (it.hasNext()) {
|
||||
OsmPoint osmPoint = it.next();
|
||||
assert plugin != null;
|
||||
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
|
||||
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint);
|
||||
} else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
|
||||
plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint);
|
||||
}
|
||||
it.remove();
|
||||
parentFragment.deletePoint(osmPoint);
|
||||
}
|
||||
parentFragment.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static DeleteOsmEditsConfirmDialogFragment createInstance(
|
||||
ArrayList<OsmPoint> points) {
|
||||
DeleteOsmEditsConfirmDialogFragment fragment = new DeleteOsmEditsConfirmDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(POINTS_LIST, points);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue