Refactor
This commit is contained in:
parent
908d4d1127
commit
7dfa873e39
7 changed files with 225 additions and 280 deletions
|
@ -193,6 +193,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
});
|
||||
}
|
||||
|
||||
protected ViewTreeObserver.OnGlobalLayoutListener getShadowLayoutListener(){
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
setShadowOnScrollableView();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void drawTopShadow(boolean showTopShadow) {
|
||||
final Activity activity = getActivity();
|
||||
View mainView = getView();
|
||||
|
|
|
@ -152,6 +152,11 @@ public class SaveGPXBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
doRename(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDismissButtonClickAction() {
|
||||
doRename(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
|
|
|
@ -4,8 +4,6 @@ import android.content.res.ColorStateList;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -58,7 +56,7 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
|
||||
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
|
||||
R.layout.open_osm_note_text, null);
|
||||
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
||||
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
|
||||
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
|
||||
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
|
||||
|
@ -75,14 +73,6 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small)));
|
||||
}
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override public void onGlobalLayout() {
|
||||
setShadowOnScrollableView();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return posButtonTextId;
|
||||
|
|
|
@ -5,9 +5,7 @@ import android.os.Bundle;
|
|||
import android.text.Editable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -53,7 +51,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
|
||||
private TextInputEditText tagsField;
|
||||
private TextInputEditText messageField;
|
||||
private ScrollView scrollView;
|
||||
|
||||
public void setGpxInfos(GpxInfo[] gpxInfos) {
|
||||
this.gpxInfos = gpxInfos;
|
||||
|
@ -66,7 +63,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
|
||||
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
|
||||
View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
|
||||
sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
||||
sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||
|
||||
tagsField = sendGpxView.findViewById(R.id.tags_field);
|
||||
messageField = sendGpxView.findViewById(R.id.message_field);
|
||||
|
@ -128,21 +125,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
items.add(titleItem);
|
||||
}
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
scrollView = getView().findViewById(R.id.scroll_view);
|
||||
if (scrollView.canScrollVertically(1) || scrollView.canScrollVertically(-1)) {
|
||||
drawTopShadow(false);
|
||||
scrollView.getChildAt(0).setPadding(0, 8, 0, 0);
|
||||
} else {
|
||||
drawTopShadow(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) {
|
||||
if (activity instanceof MapActivity) {
|
||||
BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
|||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -78,7 +77,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
|
||||
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.send_osm_note_fragment, null);
|
||||
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
||||
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||
|
||||
noteText = sendOsmNoteView.findViewById(R.id.note_text);
|
||||
noteText.setText(((OsmNotesPoint) poi[0]).getText());
|
||||
|
@ -150,14 +149,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
items.add(bottomSheetItem);
|
||||
}
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override public void onGlobalLayout() {
|
||||
setShadowOnScrollableView();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateAccountName() {
|
||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||
String userNameOpenID = settings.USER_NAME.get();
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
|||
import android.os.Bundle;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -38,230 +37,222 @@ import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpe
|
|||
|
||||
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class);
|
||||
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
||||
private OsmPoint[] poi;
|
||||
public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class);
|
||||
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
||||
private OsmPoint[] poi;
|
||||
|
||||
private SwitchCompat closeChangeSet;
|
||||
private EditText messageEditText;
|
||||
private SwitchCompat closeChangeSet;
|
||||
private EditText messageEditText;
|
||||
|
||||
|
||||
private boolean isLoginOAuth(OsmandSettings settings) {
|
||||
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
|
||||
}
|
||||
private boolean isLoginOAuth(OsmandSettings settings) {
|
||||
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) {
|
||||
return;
|
||||
}
|
||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
||||
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.send_poi_fragment, null);
|
||||
sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
||||
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
||||
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
|
||||
String defaultChangeSet = createDefaultChangeSet(app);
|
||||
messageEditText.setText(defaultChangeSet);
|
||||
messageEditText.setSelection(messageEditText.getText().length());
|
||||
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
||||
OsmandSettings settings = app.getSettings();
|
||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||
String userNameOpenID = settings.USER_NAME.get();
|
||||
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
|
||||
accountName.setText(userName);
|
||||
closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
|
||||
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||
closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isNightMode) {
|
||||
closeChangeSet.setBackgroundResource(
|
||||
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
|
||||
} else {
|
||||
closeChangeSet.setBackgroundResource(
|
||||
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
||||
}
|
||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||
}
|
||||
});
|
||||
LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container);
|
||||
account.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
showOpenStreetMapScreen(activity);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
.setCustomView(sendOsmPoiView)
|
||||
.create();
|
||||
items.add(titleItem);
|
||||
}
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) {
|
||||
return;
|
||||
}
|
||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
||||
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.send_poi_fragment, null);
|
||||
sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
||||
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
|
||||
String defaultChangeSet = createDefaultChangeSet(app);
|
||||
messageEditText.setText(defaultChangeSet);
|
||||
messageEditText.setSelection(messageEditText.getText().length());
|
||||
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
||||
OsmandSettings settings = app.getSettings();
|
||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||
String userNameOpenID = settings.USER_NAME.get();
|
||||
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
|
||||
accountName.setText(userName);
|
||||
closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
|
||||
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||
closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isNightMode) {
|
||||
closeChangeSet.setBackgroundResource(
|
||||
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
|
||||
} else {
|
||||
closeChangeSet.setBackgroundResource(
|
||||
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
||||
}
|
||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||
}
|
||||
});
|
||||
LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container);
|
||||
account.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
showOpenStreetMapScreen(activity);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
.setCustomView(sendOsmPoiView)
|
||||
.create();
|
||||
items.add(titleItem);
|
||||
}
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override public void onGlobalLayout() {
|
||||
setShadowOnScrollableView();
|
||||
}
|
||||
};
|
||||
}
|
||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||
try {
|
||||
if (!fm.isStateSaved()) {
|
||||
SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(fm, TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||
try {
|
||||
if (!fm.isStateSaved()) {
|
||||
SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(OPENSTREETMAP_POINT, points);
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(fm, TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
|
||||
return (UiUtilities.DialogButtonType.PRIMARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
|
||||
return (UiUtilities.DialogButtonType.PRIMARY);
|
||||
}
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
ProgressDialogPoiUploader progressDialogPoiUploader = null;
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity);
|
||||
} else if (getParentFragment() instanceof ProgressDialogPoiUploader) {
|
||||
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, closeChangeSet.isChecked(), false);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
ProgressDialogPoiUploader progressDialogPoiUploader = null;
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity);
|
||||
} else if (getParentFragment() instanceof ProgressDialogPoiUploader) {
|
||||
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, closeChangeSet.isChecked(), false);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return R.string.shared_string_upload;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
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<>();
|
||||
}
|
||||
|
||||
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.isEmpty()) {
|
||||
comment = comment.concat(".");
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
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.isEmpty()) {
|
||||
comment = comment.concat(".");
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
package net.osmand.plus.settings.bottomsheets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
|
@ -52,6 +49,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
|
||||
View view = themedInflater.inflate(R.layout.osm_login_data, null);
|
||||
view.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||
|
||||
userNameEditText = view.findViewById(R.id.name_edit_text);
|
||||
passwordEditText = view.findViewById(R.id.password_edit_text);
|
||||
|
@ -81,27 +79,6 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
|||
items.add(titleItem);
|
||||
}
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
Rect visibleDisplayFrame = new Rect();
|
||||
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
|
||||
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
|
||||
scrollView = getView().findViewById(R.id.scroll_view);
|
||||
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
|
||||
int viewHeight = scrollView.getHeight();
|
||||
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
|
||||
if (contentHeightPrevious != contentHeight) {
|
||||
boolean showTopShadow;
|
||||
showTopShadow = viewHeight + shadowHeight < contentHeight;
|
||||
scrollView.requestLayout();
|
||||
contentHeightPrevious = contentHeight;
|
||||
drawTopShadow(showTopShadow);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
|
|
Loading…
Reference in a new issue