commit
3807156e22
3 changed files with 243 additions and 101 deletions
|
@ -4,7 +4,6 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:descendantFocusability="blocksDescendants"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package net.osmand.plus.osmedit;
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.system.Os;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
|
@ -20,18 +27,25 @@ import net.osmand.util.Algorithms;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
public class OsmEditsAdapter extends ArrayAdapter<Object> {
|
||||||
|
|
||||||
|
public static final int TYPE_HEADER = 0;
|
||||||
|
private static final int TYPE_ITEM = 1;
|
||||||
|
private static final int TYPE_COUNT = 2;
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
|
private List<Object> items;
|
||||||
private boolean selectionMode;
|
private boolean selectionMode;
|
||||||
private List<OsmPoint> selectedOsmEdits;
|
private List<OsmPoint> selectedOsmEdits;
|
||||||
|
private boolean portrait;
|
||||||
|
|
||||||
private OsmEditsAdapterListener listener;
|
private OsmEditsAdapterListener listener;
|
||||||
|
|
||||||
public OsmEditsAdapter(OsmandApplication app, @NonNull List<OsmPoint> points) {
|
public OsmEditsAdapter(OsmandApplication app, @NonNull List<Object> items) {
|
||||||
super(app, 0, points);
|
super(app, 0, items);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelectionMode() {
|
public boolean isSelectionMode() {
|
||||||
|
@ -46,6 +60,10 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
this.selectedOsmEdits = selectedOsmEdits;
|
this.selectedOsmEdits = selectedOsmEdits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPortrait(boolean portrait) {
|
||||||
|
this.portrait = portrait;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAdapterListener(OsmEditsAdapterListener listener) {
|
public void setAdapterListener(OsmEditsAdapterListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
@ -53,69 +71,173 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||||
View view = convertView;
|
if (portrait) {
|
||||||
if (view == null) {
|
if (convertView == null) {
|
||||||
view = LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false);
|
if (position == 0) {
|
||||||
OsmEditViewHolder holder = new OsmEditViewHolder(view);
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_header, parent, false);
|
||||||
view.setTag(holder);
|
HeaderViewHolder holder = new HeaderViewHolder(convertView);
|
||||||
}
|
convertView.setTag(holder);
|
||||||
final OsmPoint osmEdit = getItem(position);
|
} else {
|
||||||
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false);
|
||||||
if (osmEdit != null) {
|
OsmEditViewHolder holder = new OsmEditViewHolder(convertView);
|
||||||
final OsmEditViewHolder holder = (OsmEditViewHolder) view.getTag();
|
convertView.setTag(holder);
|
||||||
|
}
|
||||||
holder.titleTextView.setText(OsmEditingPlugin.getName(osmEdit));
|
|
||||||
holder.descriptionTextView.setText(getDescription(osmEdit));
|
|
||||||
Drawable icon = getIcon(osmEdit);
|
|
||||||
if (icon != null) {
|
|
||||||
holder.icon.setImageDrawable(icon);
|
|
||||||
}
|
}
|
||||||
if (selectionMode) {
|
if (position == 0) {
|
||||||
holder.optionsImageButton.setVisibility(View.GONE);
|
bindHeaderViewHolder((HeaderViewHolder) convertView.getTag());
|
||||||
holder.selectCheckBox.setVisibility(View.VISIBLE);
|
|
||||||
holder.selectCheckBox.setChecked(selectedOsmEdits.contains(osmEdit));
|
|
||||||
holder.icon.setVisibility(View.GONE);
|
|
||||||
holder.selectCheckBox.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onItemSelect(osmEdit, holder.selectCheckBox.isChecked());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
holder.icon.setVisibility(View.VISIBLE);
|
final Object item = getItem(position);
|
||||||
holder.optionsImageButton.setVisibility(View.VISIBLE);
|
if (item instanceof OsmPoint) {
|
||||||
holder.selectCheckBox.setVisibility(View.GONE);
|
final OsmEditViewHolder holder = (OsmEditViewHolder) convertView.getTag();
|
||||||
|
bindOsmEditViewHolder(holder, (OsmPoint) item, position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.optionsImageButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
return convertView;
|
||||||
holder.optionsImageButton.setOnClickListener(new View.OnClickListener() {
|
} else {
|
||||||
|
int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
|
int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10;
|
||||||
|
|
||||||
|
FrameLayout fl = new FrameLayout(getContext());
|
||||||
|
LinearLayout ll = new LinearLayout(getContext());
|
||||||
|
ll.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark);
|
||||||
|
fl.addView(ll);
|
||||||
|
((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, margin);
|
||||||
|
|
||||||
|
HeaderViewHolder headerViewHolder = new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.list_item_header, parent, false));
|
||||||
|
bindHeaderViewHolder(headerViewHolder);
|
||||||
|
ll.addView(headerViewHolder.mainView);
|
||||||
|
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
Object item = getItem(i);
|
||||||
|
if (item instanceof OsmPoint) {
|
||||||
|
OsmEditViewHolder viewHolder = new OsmEditViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false));
|
||||||
|
bindOsmEditViewHolder(viewHolder, (OsmPoint) item, i);
|
||||||
|
ll.addView(viewHolder.mainView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
if (portrait) {
|
||||||
|
return super.getCount();
|
||||||
|
} else {
|
||||||
|
return getHeadersCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
Object item = getItem(position);
|
||||||
|
if (item instanceof OsmPoint) {
|
||||||
|
return TYPE_ITEM;
|
||||||
|
}
|
||||||
|
return (int) item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getViewTypeCount() {
|
||||||
|
return TYPE_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getHeadersCount() {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
Object item = items.get(i);
|
||||||
|
if (item instanceof Integer) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindHeaderViewHolder(final HeaderViewHolder holder) {
|
||||||
|
holder.topDivider.setVisibility(portrait ? View.VISIBLE : View.GONE);
|
||||||
|
holder.title.setText(R.string.your_edits);
|
||||||
|
holder.checkBox.setChecked(isAllSelected());
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.checkBox.setVisibility(View.VISIBLE);
|
||||||
|
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onOptionsClick(osmEdit);
|
listener.onHeaderCheckboxClick(holder.checkBox.isChecked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
holder.mainView.setOnClickListener(new View.OnClickListener() {
|
} else {
|
||||||
|
holder.checkBox.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindOsmEditViewHolder(final OsmEditViewHolder holder, final OsmPoint osmEdit, int position) {
|
||||||
|
holder.titleTextView.setText(getTitle(osmEdit));
|
||||||
|
holder.descriptionTextView.setText(getDescription(osmEdit));
|
||||||
|
Drawable icon = getIcon(osmEdit);
|
||||||
|
if (icon != null) {
|
||||||
|
holder.icon.setImageDrawable(icon);
|
||||||
|
}
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.optionsImageButton.setVisibility(View.GONE);
|
||||||
|
holder.selectCheckBox.setVisibility(View.VISIBLE);
|
||||||
|
holder.selectCheckBox.setChecked(selectedOsmEdits.contains(osmEdit));
|
||||||
|
holder.icon.setVisibility(View.GONE);
|
||||||
|
holder.selectCheckBox.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (selectionMode) {
|
if (listener != null) {
|
||||||
holder.selectCheckBox.performClick();
|
listener.onItemSelect(osmEdit, holder.selectCheckBox.isChecked());
|
||||||
} else {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onItemShowMap(osmEdit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
boolean showDivider = getCount() > 1 && position != getCount() - 1;
|
} else {
|
||||||
holder.bottomDivider.setVisibility(showDivider ? View.VISIBLE : View.GONE);
|
holder.icon.setVisibility(View.VISIBLE);
|
||||||
|
holder.optionsImageButton.setVisibility(View.VISIBLE);
|
||||||
|
holder.selectCheckBox.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
holder.optionsImageButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||||
|
holder.optionsImageButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onOptionsClick(osmEdit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
holder.mainView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.selectCheckBox.performClick();
|
||||||
|
} else {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onItemShowMap(osmEdit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
boolean showDivider = getItemsCount() > 1 && position != getItemsCount() - 1;
|
||||||
|
holder.bottomDivider.setVisibility(showDivider ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getItemsCount() {
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private SpannableString getTitle(OsmPoint osmPoint) {
|
||||||
|
SpannableString title = new SpannableString(OsmEditingPlugin.getName(osmPoint));
|
||||||
|
if (TextUtils.isEmpty(title)) {
|
||||||
|
title = SpannableString.valueOf(getCategory(osmPoint));
|
||||||
|
title.setSpan(new StyleSpan(Typeface.ITALIC), 0, title.length(), 0);
|
||||||
|
}
|
||||||
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getIcon(OsmPoint point) {
|
private Drawable getIcon(OsmPoint point) {
|
||||||
|
@ -158,6 +280,26 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAllSelected() {
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
Object item = items.get(i);
|
||||||
|
if (item instanceof OsmPoint) {
|
||||||
|
if (!selectedOsmEdits.contains(item)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCategory(OsmPoint point) {
|
||||||
|
String category = "";
|
||||||
|
if (point.getGroup() == OsmPoint.Group.POI) {
|
||||||
|
category = ((OpenstreetmapPoint) point).getEntity().getTag(EditPoiData.POI_TYPE_TAG);
|
||||||
|
}
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
private String getDescription(OsmPoint point) {
|
private String getDescription(OsmPoint point) {
|
||||||
String action = "";
|
String action = "";
|
||||||
if (point.getAction() == OsmPoint.Action.CREATE) {
|
if (point.getAction() == OsmPoint.Action.CREATE) {
|
||||||
|
@ -170,10 +312,7 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
action = getContext().getString(R.string.shared_string_edited);
|
action = getContext().getString(R.string.shared_string_edited);
|
||||||
}
|
}
|
||||||
|
|
||||||
String category = "";
|
String category = getCategory(point);
|
||||||
if (point.getGroup() == OsmPoint.Group.POI) {
|
|
||||||
category = ((OpenstreetmapPoint) point).getEntity().getTag(EditPoiData.POI_TYPE_TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
String comment = "";
|
String comment = "";
|
||||||
if (point.getGroup() == OsmPoint.Group.BUG) {
|
if (point.getGroup() == OsmPoint.Group.BUG) {
|
||||||
|
@ -197,6 +336,20 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class HeaderViewHolder {
|
||||||
|
View mainView;
|
||||||
|
View topDivider;
|
||||||
|
CheckBox checkBox;
|
||||||
|
TextView title;
|
||||||
|
|
||||||
|
HeaderViewHolder(View view) {
|
||||||
|
mainView = view;
|
||||||
|
topDivider = view.findViewById(R.id.top_divider);
|
||||||
|
checkBox = (CheckBox) view.findViewById(R.id.check_box);
|
||||||
|
title = (TextView) view.findViewById(R.id.title_text_view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class OsmEditViewHolder {
|
private class OsmEditViewHolder {
|
||||||
View mainView;
|
View mainView;
|
||||||
ImageView icon;
|
ImageView icon;
|
||||||
|
@ -219,6 +372,8 @@ public class OsmEditsAdapter extends ArrayAdapter<OsmPoint> {
|
||||||
|
|
||||||
public interface OsmEditsAdapterListener {
|
public interface OsmEditsAdapterListener {
|
||||||
|
|
||||||
|
void onHeaderCheckboxClick(boolean checked);
|
||||||
|
|
||||||
void onItemSelect(OsmPoint point, boolean checked);
|
void onItemSelect(OsmPoint point, boolean checked);
|
||||||
|
|
||||||
void onItemShowMap(OsmPoint point);
|
void onItemShowMap(OsmPoint point);
|
||||||
|
|
|
@ -21,7 +21,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -64,7 +63,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
private OsmEditingPlugin plugin;
|
private OsmEditingPlugin plugin;
|
||||||
|
|
||||||
private View footerView;
|
private View footerView;
|
||||||
private View headerView;
|
|
||||||
private View emptyView;
|
private View emptyView;
|
||||||
|
|
||||||
private List<OsmPoint> osmEdits = new ArrayList<>();
|
private List<OsmPoint> osmEdits = new ArrayList<>();
|
||||||
|
@ -133,6 +131,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
return listAdapter;
|
return listAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void recreateAdapterData() {
|
||||||
|
listAdapter.clear();
|
||||||
|
listAdapter.addAll(createItemsList());
|
||||||
|
listAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
private void selectAll() {
|
private void selectAll() {
|
||||||
for (int i = 0; i < osmEdits.size(); i++) {
|
for (int i = 0; i < osmEdits.size(); i++) {
|
||||||
OsmPoint point = osmEdits.get(i);
|
OsmPoint point = osmEdits.get(i);
|
||||||
|
@ -285,7 +289,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
|
|
||||||
private void updateSelectionMode(ActionMode m) {
|
private void updateSelectionMode(ActionMode m) {
|
||||||
updateSelectionTitle(m);
|
updateSelectionTitle(m);
|
||||||
refreshSelectAll();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectionTitle(ActionMode m) {
|
private void updateSelectionTitle(ActionMode m) {
|
||||||
|
@ -296,28 +300,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSelectAll() {
|
|
||||||
View view = getView();
|
|
||||||
if (view == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CheckBox selectAll = (CheckBox) view.findViewById(R.id.check_box);
|
|
||||||
for (int i = 0; i < osmEdits.size(); i++) {
|
|
||||||
OsmPoint point = osmEdits.get(i);
|
|
||||||
if (!osmEditsSelected.contains(point)) {
|
|
||||||
selectAll.setChecked(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selectAll.setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableSelectionMode(boolean selectionMode) {
|
private void enableSelectionMode(boolean selectionMode) {
|
||||||
listAdapter.setSelectionMode(selectionMode);
|
listAdapter.setSelectionMode(selectionMode);
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
if (headerView != null) {
|
|
||||||
headerView.findViewById(R.id.check_box).setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode && AndroidUiHelper.isOrientationPortrait(getActivity()));
|
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode && AndroidUiHelper.isOrientationPortrait(getActivity()));
|
||||||
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
|
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
|
||||||
}
|
}
|
||||||
|
@ -348,6 +333,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchData() {
|
private void fetchData() {
|
||||||
|
boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||||
osmEdits = new ArrayList<>();
|
osmEdits = new ArrayList<>();
|
||||||
List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
|
List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
|
||||||
List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
|
List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
|
||||||
|
@ -357,32 +343,24 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
listView.setDivider(null);
|
listView.setDivider(null);
|
||||||
listView.setEmptyView(emptyView);
|
listView.setEmptyView(emptyView);
|
||||||
|
|
||||||
if (osmEdits.size() > 0) {
|
if (osmEdits.size() > 0 && footerView == null && portrait) {
|
||||||
if (footerView == null) {
|
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, listView, false);
|
||||||
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, listView, false);
|
listView.addFooterView(footerView);
|
||||||
listView.addFooterView(footerView);
|
|
||||||
}
|
|
||||||
if (headerView == null) {
|
|
||||||
headerView = getActivity().getLayoutInflater().inflate(R.layout.list_item_header, listView, false);
|
|
||||||
listView.addHeaderView(headerView);
|
|
||||||
((TextView) headerView.findViewById(R.id.title_text_view)).setText(R.string.your_edits);
|
|
||||||
final CheckBox selectAll = (CheckBox) headerView.findViewById(R.id.check_box);
|
|
||||||
selectAll.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (selectAll.isChecked()) {
|
|
||||||
selectAll();
|
|
||||||
} else {
|
|
||||||
deselectAll();
|
|
||||||
}
|
|
||||||
updateSelectionTitle(actionMode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
listAdapter = new OsmEditsAdapter(getMyApplication(), osmEdits);
|
List<Object> items = createItemsList();
|
||||||
|
listAdapter = new OsmEditsAdapter(getMyApplication(), items);
|
||||||
listAdapter.setSelectedOsmEdits(osmEditsSelected);
|
listAdapter.setSelectedOsmEdits(osmEditsSelected);
|
||||||
listAdapter.setAdapterListener(new OsmEditsAdapter.OsmEditsAdapterListener() {
|
listAdapter.setAdapterListener(new OsmEditsAdapter.OsmEditsAdapterListener() {
|
||||||
|
@Override
|
||||||
|
public void onHeaderCheckboxClick(boolean checked) {
|
||||||
|
if (checked) {
|
||||||
|
selectAll();
|
||||||
|
} else {
|
||||||
|
deselectAll();
|
||||||
|
}
|
||||||
|
updateSelectionTitle(actionMode);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelect(OsmPoint point, boolean checked) {
|
public void onItemSelect(OsmPoint point, boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
@ -403,9 +381,19 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
openPopUpMenu(note);
|
openPopUpMenu(note);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
listAdapter.setPortrait(portrait);
|
||||||
listView.setAdapter(listAdapter);
|
listView.setAdapter(listAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Object> createItemsList() {
|
||||||
|
List<Object> items = new ArrayList<>();
|
||||||
|
if (!osmEdits.isEmpty()) {
|
||||||
|
items.add(OsmEditsAdapter.TYPE_HEADER);
|
||||||
|
items.addAll(osmEdits);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
private void showBugDialog(final OsmNotesPoint point) {
|
private void showBugDialog(final OsmNotesPoint point) {
|
||||||
final View view = LayoutInflater.from(getActivity()).inflate(R.layout.open_bug, null);
|
final View view = LayoutInflater.from(getActivity()).inflate(R.layout.open_bug, null);
|
||||||
view.findViewById(R.id.user_name_field).setVisibility(View.GONE);
|
view.findViewById(R.id.user_name_field).setVisibility(View.GONE);
|
||||||
|
@ -527,7 +515,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
osmEdits.remove(osmPoint);
|
osmEdits.remove(osmPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetChanged();
|
recreateAdapterData();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dialog.show(getActivity().getSupportFragmentManager(), ProgressDialogFragment.TAG);
|
dialog.show(getActivity().getSupportFragmentManager(), ProgressDialogFragment.TAG);
|
||||||
|
@ -546,7 +534,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
|
|
||||||
private void deletePoint(OsmPoint osmPoint) {
|
private void deletePoint(OsmPoint osmPoint) {
|
||||||
osmEdits.remove(osmPoint);
|
osmEdits.remove(osmPoint);
|
||||||
listAdapter.notifyDataSetChanged();
|
recreateAdapterData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDataSetChanged() {
|
private void notifyDataSetChanged() {
|
||||||
|
|
Loading…
Reference in a new issue