Merge pull request #9318 from osmandapp/not_scroll_list_on_osm_note_delete

keep list position on delete item
This commit is contained in:
vshcherb 2020-06-25 14:25:40 +02:00 committed by GitHub
commit 5f333e3141
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -667,10 +667,19 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
recreateAdapterData(); recreateAdapterData();
} }
private int getFirstVisible() {
return getListView().getFirstVisiblePosition();
}
private void notifyDataSetChanged() { private void notifyDataSetChanged() {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
private void notifyDataSetChangedWithSelection(int firstVisible) {
listAdapter.notifyDataSetChanged();
getListView().setSelection(firstVisible);
}
public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment { public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment {
public static final String TAG = "DeleteOsmEditsConfirmDialogFragment"; public static final String TAG = "DeleteOsmEditsConfirmDialogFragment";
private static final String POINTS_LIST = "points_list"; private static final String POINTS_LIST = "points_list";
@ -698,6 +707,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int firstVisible = parentFragment.getFirstVisible();
Iterator<OsmPoint> it = points.iterator(); Iterator<OsmPoint> it = points.iterator();
while (it.hasNext()) { while (it.hasNext()) {
OsmPoint osmPoint = it.next(); OsmPoint osmPoint = it.next();
@ -710,8 +720,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
it.remove(); it.remove();
parentFragment.deletePoint(osmPoint); parentFragment.deletePoint(osmPoint);
} }
parentFragment.notifyDataSetChanged(); parentFragment.notifyDataSetChangedWithSelection(firstVisible);
} }
}); });
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);