Call new SendPoiBottomSheetFragment from My Places osm edits
This commit is contained in:
parent
291bed500b
commit
1472127ae2
4 changed files with 182 additions and 113 deletions
|
@ -57,13 +57,13 @@ public class EditPOIMenuController extends MenuController {
|
||||||
if (point instanceof OpenstreetmapPoint) {
|
if (point instanceof OpenstreetmapPoint) {
|
||||||
if (isLogin) {
|
if (isLogin) {
|
||||||
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
|
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
|
||||||
new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE);
|
new OsmPoint[]{getOsmPoint()});
|
||||||
} else {
|
} else {
|
||||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
|
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
|
||||||
}
|
}
|
||||||
} else if (point instanceof OsmNotesPoint) {
|
} else if (point instanceof OsmNotesPoint) {
|
||||||
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
|
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
|
||||||
new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE);
|
new OsmPoint[]{getOsmPoint()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ import net.osmand.osm.edit.Node;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
|
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
|
||||||
|
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
||||||
|
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -625,23 +627,38 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
||||||
return (OsmandApplication) getActivity().getApplication();
|
return (OsmandApplication) getActivity().getApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadItems(final OsmPoint[] items) {
|
private void uploadItems(final OsmPoint[] points) {
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
OsmandSettings settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||||
if (authorizationAdapter.isValidToken()
|
boolean isLogin = authorizationAdapter.isValidToken()
|
||||||
|| !Algorithms.isEmpty(settings.USER_NAME.get())
|
|| !Algorithms.isEmpty(settings.USER_NAME.get())
|
||||||
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get())) {
|
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
||||||
SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT)
|
if (hasPoiGroup(points)) {
|
||||||
.show(getChildFragmentManager(), SendPoiDialogFragment.TAG);
|
if (isLogin) {
|
||||||
|
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points);
|
||||||
|
} else {
|
||||||
|
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
|
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasPoiGroup(OsmPoint[] points) {
|
||||||
|
boolean hasPoiGroup = false;
|
||||||
|
for (OsmPoint p : points) {
|
||||||
|
if (p.getGroup() == OsmPoint.Group.POI) {
|
||||||
|
hasPoiGroup = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasPoiGroup;
|
||||||
|
}
|
||||||
|
|
||||||
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
|
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
|
||||||
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
|
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
|
||||||
R.string.uploading,
|
R.string.uploading,
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.view.ContextThemeWrapper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -25,7 +24,6 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
|
||||||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||||
import net.osmand.plus.osmedit.OsmPoint;
|
import net.osmand.plus.osmedit.OsmPoint;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||||
|
@ -47,7 +45,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName();
|
public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class);
|
||||||
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
||||||
public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
|
|
||||||
private OsmPoint[] poi;
|
private OsmPoint[] poi;
|
||||||
|
|
||||||
protected OsmandSettings settings;
|
protected OsmandSettings settings;
|
||||||
|
@ -56,23 +53,18 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
private LinearLayout signInView;
|
private LinearLayout signInView;
|
||||||
private SwitchCompat uploadAnonymously;
|
private SwitchCompat uploadAnonymously;
|
||||||
|
|
||||||
public enum PoiUploaderType {
|
|
||||||
SIMPLE,
|
|
||||||
FRAGMENT
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OsmandApplication getMyApplication() {
|
|
||||||
return (OsmandApplication) getActivity().getApplication();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLoginOAuth() {
|
private boolean isLoginOAuth() {
|
||||||
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
|
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settings = app.getSettings();
|
||||||
|
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
||||||
|
|
||||||
items.add(new TitleItem(getString(R.string.upload_osm_note)));
|
items.add(new TitleItem(getString(R.string.upload_osm_note)));
|
||||||
|
|
||||||
|
@ -87,8 +79,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
|
signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
|
||||||
uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
|
uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
|
||||||
accountName = sendOsmNoteView.findViewById(R.id.user_name);
|
accountName = sendOsmNoteView.findViewById(R.id.user_name);
|
||||||
|
|
||||||
settings = app.getSettings();
|
|
||||||
updateAccountName();
|
updateAccountName();
|
||||||
View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button);
|
View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button);
|
||||||
setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY,
|
setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY,
|
||||||
|
@ -105,8 +95,11 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA,
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
SendOsmNoteBottomSheetFragment.this, usedOnMap, null);
|
if (fragmentManager != null) {
|
||||||
|
OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA,
|
||||||
|
SendOsmNoteBottomSheetFragment.this, usedOnMap, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateSignIn(uploadAnonymously.isChecked());
|
updateSignIn(uploadAnonymously.isChecked());
|
||||||
|
@ -157,14 +150,12 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
setupDialogButton(nightMode, buttonView, buttonType, buttonTextId);
|
setupDialogButton(nightMode, buttonView, buttonType, buttonTextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points,
|
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||||
@NonNull PoiUploaderType uploaderType) {
|
|
||||||
try {
|
try {
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment();
|
SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
||||||
bundle.putString(POI_UPLOADER_TYPE, uploaderType.name());
|
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
|
@ -180,39 +171,9 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
View view = getView();
|
ProgressDialogPoiUploader progressDialogPoiUploader;
|
||||||
boolean hasPoiGroup = false;
|
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity());
|
||||||
assert poi != null;
|
progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked());
|
||||||
for (OsmPoint p : poi) {
|
|
||||||
if (p.getGroup() == OsmPoint.Group.POI) {
|
|
||||||
hasPoiGroup = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final boolean hasPOI = hasPoiGroup;
|
|
||||||
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
|
|
||||||
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
|
|
||||||
final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name()));
|
|
||||||
final ProgressDialogPoiUploader progressDialogPoiUploader;
|
|
||||||
if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
|
|
||||||
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity());
|
|
||||||
} else {
|
|
||||||
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
|
|
||||||
}
|
|
||||||
if (progressDialogPoiUploader != null) {
|
|
||||||
String comment = messageEditText.getText().toString();
|
|
||||||
if (comment.length() > 0) {
|
|
||||||
for (OsmPoint osmPoint : poi) {
|
|
||||||
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
|
|
||||||
((OpenstreetmapPoint) osmPoint).setComment(comment);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
progressDialogPoiUploader.showProgressDialog(poi,
|
|
||||||
false,
|
|
||||||
!hasPOI && uploadAnonymously.isChecked());
|
|
||||||
}
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import androidx.appcompat.widget.SwitchCompat;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.osm.PoiType;
|
||||||
|
import net.osmand.osm.edit.Entity;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
@ -25,56 +27,60 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*;
|
||||||
|
|
||||||
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName();
|
public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class);
|
||||||
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
||||||
public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
|
|
||||||
private OsmPoint[] poi;
|
private OsmPoint[] poi;
|
||||||
|
|
||||||
protected OsmandSettings settings;
|
private SwitchCompat closeChangeSet;
|
||||||
|
private EditText messageEditText;
|
||||||
|
|
||||||
public enum PoiUploaderType {
|
|
||||||
SIMPLE,
|
|
||||||
FRAGMENT
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OsmandApplication getMyApplication() {
|
private boolean isLoginOAuth(OsmandSettings settings) {
|
||||||
return (OsmandApplication) getActivity().getApplication();
|
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLoginOAuth() {
|
|
||||||
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
||||||
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
|
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||||
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||||
R.layout.send_poi_fragment, null);
|
R.layout.send_poi_fragment, null);
|
||||||
final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
||||||
|
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
|
||||||
|
String defaultChangeSet = createDefaultChangeSet(app);
|
||||||
|
messageEditText.setText(defaultChangeSet);
|
||||||
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
||||||
settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||||
String userNameOpenID = settings.USER_NAME.get();
|
String userNameOpenID = settings.USER_NAME.get();
|
||||||
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
|
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
|
||||||
accountName.setText(userName);
|
accountName.setText(userName);
|
||||||
closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
|
closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
|
||||||
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||||
closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0);
|
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||||
closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isNightMode) {
|
if (isNightMode) {
|
||||||
closeChangset.setBackgroundResource(
|
closeChangeSet.setBackgroundResource(
|
||||||
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
|
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
|
||||||
} else {
|
} else {
|
||||||
closeChangset.setBackgroundResource(
|
closeChangeSet.setBackgroundResource(
|
||||||
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
||||||
}
|
}
|
||||||
closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0);
|
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||||
|
@ -83,14 +89,12 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
items.add(titleItem);
|
items.add(titleItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points,
|
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||||
@NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) {
|
|
||||||
try {
|
try {
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment();
|
SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
||||||
bundle.putString(POI_UPLOADER_TYPE, uploaderType.name());
|
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
|
@ -106,40 +110,127 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
View view = getView();
|
final ProgressDialogPoiUploader progressDialogPoiUploader;
|
||||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity());
|
||||||
final SwitchCompat closeChangeSetCheckBox =
|
|
||||||
view.findViewById(R.id.close_change_set_checkbox);
|
String comment = messageEditText.getText().toString();
|
||||||
final EditText messageEditText = view.findViewById(R.id.message_field);
|
if (comment.length() > 0) {
|
||||||
final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name()));
|
for (OsmPoint osmPoint : poi) {
|
||||||
final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader;
|
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
|
||||||
if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
|
((OpenstreetmapPoint) osmPoint).setComment(comment);
|
||||||
progressDialogPoiUploader =
|
break;
|
||||||
new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
|
|
||||||
} else {
|
|
||||||
progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment();
|
|
||||||
}
|
|
||||||
if (progressDialogPoiUploader != null) {
|
|
||||||
String comment = messageEditText.getText().toString();
|
|
||||||
if (comment.length() > 0) {
|
|
||||||
for (OsmPoint osmPoint : poi) {
|
|
||||||
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
|
|
||||||
((OpenstreetmapPoint) osmPoint).setComment(comment);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
progressDialogPoiUploader.showProgressDialog(poi,
|
|
||||||
closeChangeSetCheckBox.isChecked(),
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
dismiss();
|
progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false);
|
||||||
}
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getRightBottomButtonTextId() {
|
protected int getRightBottomButtonTextId() {
|
||||||
return R.string.shared_string_upload;
|
return R.string.shared_string_upload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createDefaultChangeSet(OsmandApplication app) {
|
||||||
|
Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
|
||||||
|
if (allTranslatedSubTypes == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Map<String, Integer> addGroup = new HashMap<>();
|
||||||
|
Map<String, Integer> editGroup = new HashMap<>();
|
||||||
|
Map<String, Integer> deleteGroup = new HashMap<>();
|
||||||
|
Map<String, Integer> reopenGroup = new HashMap<>();
|
||||||
|
String comment = "";
|
||||||
|
for (OsmPoint p : poi) {
|
||||||
|
if (p.getGroup() == OsmPoint.Group.POI) {
|
||||||
|
OsmPoint.Action action = p.getAction();
|
||||||
|
String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG);
|
||||||
|
if (type == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
|
||||||
|
if (localizedPoiType != null) {
|
||||||
|
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
|
||||||
|
}
|
||||||
|
if (action == OsmPoint.Action.CREATE) {
|
||||||
|
if (!addGroup.containsKey(type)) {
|
||||||
|
addGroup.put(type, 1);
|
||||||
|
} else {
|
||||||
|
addGroup.put(type, addGroup.get(type) + 1);
|
||||||
|
}
|
||||||
|
} else if (action == OsmPoint.Action.MODIFY) {
|
||||||
|
if (!editGroup.containsKey(type)) {
|
||||||
|
editGroup.put(type, 1);
|
||||||
|
} else {
|
||||||
|
editGroup.put(type, editGroup.get(type) + 1);
|
||||||
|
}
|
||||||
|
} else if (action == OsmPoint.Action.DELETE) {
|
||||||
|
if (!deleteGroup.containsKey(type)) {
|
||||||
|
deleteGroup.put(type, 1);
|
||||||
|
} else {
|
||||||
|
deleteGroup.put(type, deleteGroup.get(type) + 1);
|
||||||
|
}
|
||||||
|
} else if (action == OsmPoint.Action.REOPEN) {
|
||||||
|
if (!reopenGroup.containsKey(type)) {
|
||||||
|
reopenGroup.put(type, 1);
|
||||||
|
} else {
|
||||||
|
reopenGroup.put(type, reopenGroup.get(type) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int modifiedItemsOutOfLimit = 0;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
String action;
|
||||||
|
Map<String, Integer> group;
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
action = getString(R.string.default_changeset_add);
|
||||||
|
group = addGroup;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
action = getString(R.string.default_changeset_edit);
|
||||||
|
group = editGroup;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
action = getString(R.string.default_changeset_delete);
|
||||||
|
group = deleteGroup;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
action = getString(R.string.default_changeset_reopen);
|
||||||
|
group = reopenGroup;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action = "";
|
||||||
|
group = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!group.isEmpty()) {
|
||||||
|
int pos = 0;
|
||||||
|
for (Map.Entry<String, Integer> entry : group.entrySet()) {
|
||||||
|
String type = entry.getKey();
|
||||||
|
int quantity = entry.getValue();
|
||||||
|
if (comment.length() > 200) {
|
||||||
|
modifiedItemsOutOfLimit += quantity;
|
||||||
|
} else {
|
||||||
|
if (pos == 0) {
|
||||||
|
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ")
|
||||||
|
.concat(quantity == 1 ? "" : quantity + " ").concat(type);
|
||||||
|
} else {
|
||||||
|
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (modifiedItemsOutOfLimit != 0) {
|
||||||
|
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ")
|
||||||
|
.concat(getString(R.string.items_modified)).concat(".");
|
||||||
|
} else if (!comment.equals("")) {
|
||||||
|
comment = comment.concat(".");
|
||||||
|
}
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue