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) {
|
protected void drawTopShadow(boolean showTopShadow) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
View mainView = getView();
|
View mainView = getView();
|
||||||
|
|
|
@ -152,6 +152,11 @@ public class SaveGPXBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
doRename(true);
|
doRename(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDismissButtonClickAction() {
|
||||||
|
doRename(false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
super.onDismiss(dialog);
|
super.onDismiss(dialog);
|
||||||
|
|
|
@ -4,8 +4,6 @@ import android.content.res.ColorStateList;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.ScrollView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
@ -58,7 +56,7 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
|
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
|
||||||
R.layout.open_osm_note_text, null);
|
R.layout.open_osm_note_text, null);
|
||||||
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||||
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
|
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
|
||||||
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
|
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
|
||||||
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
|
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)));
|
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
|
@Override
|
||||||
protected int getRightBottomButtonTextId() {
|
protected int getRightBottomButtonTextId() {
|
||||||
return posButtonTextId;
|
return posButtonTextId;
|
||||||
|
|
|
@ -5,9 +5,7 @@ import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ScrollView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -53,7 +51,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
private TextInputEditText tagsField;
|
private TextInputEditText tagsField;
|
||||||
private TextInputEditText messageField;
|
private TextInputEditText messageField;
|
||||||
private ScrollView scrollView;
|
|
||||||
|
|
||||||
public void setGpxInfos(GpxInfo[] gpxInfos) {
|
public void setGpxInfos(GpxInfo[] gpxInfos) {
|
||||||
this.gpxInfos = gpxInfos;
|
this.gpxInfos = gpxInfos;
|
||||||
|
@ -66,7 +63,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
|
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
|
||||||
View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
|
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);
|
tagsField = sendGpxView.findViewById(R.id.tags_field);
|
||||||
messageField = sendGpxView.findViewById(R.id.message_field);
|
messageField = sendGpxView.findViewById(R.id.message_field);
|
||||||
|
@ -128,21 +125,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
items.add(titleItem);
|
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) {
|
protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) {
|
||||||
if (activity instanceof MapActivity) {
|
if (activity instanceof MapActivity) {
|
||||||
BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);
|
BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -78,7 +77,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
|
|
||||||
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||||
R.layout.send_osm_note_fragment, null);
|
R.layout.send_osm_note_fragment, null);
|
||||||
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||||
|
|
||||||
noteText = sendOsmNoteView.findViewById(R.id.note_text);
|
noteText = sendOsmNoteView.findViewById(R.id.note_text);
|
||||||
noteText.setText(((OsmNotesPoint) poi[0]).getText());
|
noteText.setText(((OsmNotesPoint) poi[0]).getText());
|
||||||
|
@ -150,14 +149,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
||||||
items.add(bottomSheetItem);
|
items.add(bottomSheetItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
|
||||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
||||||
@Override public void onGlobalLayout() {
|
|
||||||
setShadowOnScrollableView();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateAccountName() {
|
private void updateAccountName() {
|
||||||
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();
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -38,230 +37,222 @@ import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpe
|
||||||
|
|
||||||
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";
|
||||||
private OsmPoint[] poi;
|
private OsmPoint[] poi;
|
||||||
|
|
||||||
private SwitchCompat closeChangeSet;
|
private SwitchCompat closeChangeSet;
|
||||||
private EditText messageEditText;
|
private EditText messageEditText;
|
||||||
|
|
||||||
|
|
||||||
private boolean isLoginOAuth(OsmandSettings settings) {
|
private boolean isLoginOAuth(OsmandSettings settings) {
|
||||||
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
|
return !Algorithms.isEmpty(settings.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) {
|
if (app == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
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);
|
||||||
sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
|
sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||||
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
|
||||||
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
|
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
|
||||||
String defaultChangeSet = createDefaultChangeSet(app);
|
String defaultChangeSet = createDefaultChangeSet(app);
|
||||||
messageEditText.setText(defaultChangeSet);
|
messageEditText.setText(defaultChangeSet);
|
||||||
messageEditText.setSelection(messageEditText.getText().length());
|
messageEditText.setSelection(messageEditText.getText().length());
|
||||||
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
|
||||||
OsmandSettings 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(settings) ? userNameOAuth : userNameOpenID;
|
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
|
||||||
accountName.setText(userName);
|
accountName.setText(userName);
|
||||||
closeChangeSet.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);
|
||||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||||
closeChangeSet.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) {
|
||||||
closeChangeSet.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 {
|
||||||
closeChangeSet.setBackgroundResource(
|
closeChangeSet.setBackgroundResource(
|
||||||
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
|
||||||
}
|
}
|
||||||
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container);
|
LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container);
|
||||||
account.setOnClickListener(new View.OnClickListener() {
|
account.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
showOpenStreetMapScreen(activity);
|
showOpenStreetMapScreen(activity);
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||||
.setCustomView(sendOsmPoiView)
|
.setCustomView(sendOsmPoiView)
|
||||||
.create();
|
.create();
|
||||||
items.add(titleItem);
|
items.add(titleItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
|
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||||
return new ViewTreeObserver.OnGlobalLayoutListener() {
|
try {
|
||||||
@Override public void onGlobalLayout() {
|
if (!fm.isStateSaved()) {
|
||||||
setShadowOnScrollableView();
|
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) {
|
@Override
|
||||||
try {
|
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
|
||||||
if (!fm.isStateSaved()) {
|
return (UiUtilities.DialogButtonType.PRIMARY);
|
||||||
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
|
@Override
|
||||||
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
|
protected void onRightBottomButtonClick() {
|
||||||
return (UiUtilities.DialogButtonType.PRIMARY);
|
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
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected int getRightBottomButtonTextId() {
|
||||||
ProgressDialogPoiUploader progressDialogPoiUploader = null;
|
return R.string.shared_string_upload;
|
||||||
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
|
private String createDefaultChangeSet(OsmandApplication app) {
|
||||||
protected int getRightBottomButtonTextId() {
|
Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
|
||||||
return R.string.shared_string_upload;
|
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) {
|
if (!group.isEmpty()) {
|
||||||
Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
|
int pos = 0;
|
||||||
if (allTranslatedSubTypes == null) {
|
for (Map.Entry<String, Integer> entry : group.entrySet()) {
|
||||||
return "";
|
String type = entry.getKey();
|
||||||
}
|
int quantity = entry.getValue();
|
||||||
Map<String, Integer> addGroup = new HashMap<>();
|
if (comment.length() > 200) {
|
||||||
Map<String, Integer> editGroup = new HashMap<>();
|
modifiedItemsOutOfLimit += quantity;
|
||||||
Map<String, Integer> deleteGroup = new HashMap<>();
|
} else {
|
||||||
Map<String, Integer> reopenGroup = new HashMap<>();
|
if (pos == 0) {
|
||||||
String comment = "";
|
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ")
|
||||||
for (OsmPoint p : poi) {
|
.concat(quantity == 1 ? "" : quantity + " ").concat(type);
|
||||||
if (p.getGroup() == OsmPoint.Group.POI) {
|
} else {
|
||||||
OsmPoint.Action action = p.getAction();
|
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
|
||||||
String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG);
|
}
|
||||||
if (type == null) {
|
}
|
||||||
continue;
|
pos++;
|
||||||
}
|
}
|
||||||
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
|
}
|
||||||
if (localizedPoiType != null) {
|
}
|
||||||
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
|
if (modifiedItemsOutOfLimit != 0) {
|
||||||
}
|
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ")
|
||||||
if (action == OsmPoint.Action.CREATE) {
|
.concat(getString(R.string.items_modified)).concat(".");
|
||||||
if (!addGroup.containsKey(type)) {
|
} else if (!comment.isEmpty()) {
|
||||||
addGroup.put(type, 1);
|
comment = comment.concat(".");
|
||||||
} else {
|
}
|
||||||
addGroup.put(type, addGroup.get(type) + 1);
|
return comment;
|
||||||
}
|
}
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
package net.osmand.plus.settings.bottomsheets;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.content.res.AppCompatResources;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
@ -52,6 +49,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
|
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
|
||||||
View view = themedInflater.inflate(R.layout.osm_login_data, null);
|
View view = themedInflater.inflate(R.layout.osm_login_data, null);
|
||||||
|
view.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
|
||||||
|
|
||||||
userNameEditText = view.findViewById(R.id.name_edit_text);
|
userNameEditText = view.findViewById(R.id.name_edit_text);
|
||||||
passwordEditText = view.findViewById(R.id.password_edit_text);
|
passwordEditText = view.findViewById(R.id.password_edit_text);
|
||||||
|
@ -81,27 +79,6 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
||||||
items.add(titleItem);
|
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
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
|
Loading…
Reference in a new issue