diff --git a/OsmAnd/res/layout/point_editor_fragment_new.xml b/OsmAnd/res/layout/point_editor_fragment_new.xml index 6e00c48bfd..21c6396c53 100644 --- a/OsmAnd/res/layout/point_editor_fragment_new.xml +++ b/OsmAnd/res/layout/point_editor_fragment_new.xml @@ -135,6 +135,7 @@ android:id="@+id/address_edit" android:layout_width="match_parent" android:layout_height="wrap_content" + android:gravity="start" android:maxLines="4" android:minHeight="@dimen/favorites_list_item_height" android:paddingStart="@dimen/content_padding_small" @@ -142,7 +143,6 @@ android:paddingEnd="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small" android:textSize="@dimen/default_list_text_size" - android:gravity="left" tools:text="@string/lorem_ipsum" /> @@ -158,36 +158,37 @@ android:id="@+id/address_button" android:layout_width="0dp" android:layout_height="wrap_content" - android:minHeight="@dimen/setting_list_item_small_height" - android:layout_weight="1" android:layout_marginStart="@dimen/content_padding_half" android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginEnd="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding" - android:paddingTop="@dimen/content_padding_half" - android:paddingBottom="@dimen/content_padding_half" + android:layout_weight="1" android:drawablePadding="8dp" android:duplicateParentState="true" android:gravity="center_vertical" + android:minHeight="@dimen/setting_list_item_small_height" android:paddingStart="@dimen/content_padding_half" android:paddingLeft="@dimen/content_padding_half" + android:paddingTop="@dimen/content_padding_half" android:paddingEnd="@dimen/content_padding_half" android:paddingRight="@dimen/content_padding_half" + android:paddingBottom="@dimen/content_padding_half" android:text="@string/add_address" android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_medium" tools:text="@string/add_address" /> - diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index cd1910f929..9bfe58324a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -243,8 +243,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { if (favorite != null) { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getNameTextValue(), getCategoryTextValue()); - point.setDescription(isDescriptionAvailable()?getDescriptionTextValue():null); - point.setAddress(isAddressAvailable()?getAddressTextValue():null); + point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null); + point.setAddress(isAddressAvailable() ? getAddressTextValue() : null); point.setColor(color); point.setBackgroundType(backgroundType); point.setIconId(iconId); @@ -259,8 +259,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { if (favorite != null) { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getNameTextValue(), getCategoryTextValue()); - point.setDescription(isDescriptionAvailable()?getDescriptionTextValue():null); - point.setAddress(isAddressAvailable()?getAddressTextValue():null); + point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null); + point.setAddress(isAddressAvailable() ? getAddressTextValue() : null); point.setColor(color); point.setBackgroundType(backgroundType); point.setIconId(iconId); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 9856f907e1..3214817780 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -27,6 +27,7 @@ import android.widget.TextView; import androidx.activity.OnBackPressedCallback; import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -39,7 +40,6 @@ import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; import net.osmand.AndroidUtils; @@ -81,6 +81,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private TextView addDelDescription; private TextView addAddressBtn; private TextView addToHiddenGroupInfo; + private ImageView deleteAddressIcon; private boolean cancelled; private boolean nightMode; @DrawableRes @@ -167,7 +168,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { } }); - final int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + final int activeColorResId = getActiveColorRes(); ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action); view.findViewById(R.id.background_layout).setBackgroundResource(nightMode ? R.color.app_bar_color_dark : R.color.list_background_color_light); @@ -247,78 +248,69 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { if (getDescriptionInitValue() != null) { descriptionEdit.setText(getDescriptionInitValue()); } - if (getAddressInitValue() != null){ - addressEdit.setText(getAddressInitValue()); - addressEdit.setSelection(addressEdit.getText().length()); - } descriptionCaption = view.findViewById(R.id.description); addressCaption = view.findViewById(R.id.address); addDelDescription = (TextView) view.findViewById(R.id.description_button); addAddressBtn = view.findViewById(R.id.address_button); + deleteAddressIcon = view.findViewById(R.id.delete_address_icon); + deleteAddressIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, activeColorResId)); + addDelDescription.setTextColor(getResources().getColor(activeColorResId)); addAddressBtn.setTextColor(getResources().getColor(activeColorResId)); - addAddressBtn.setCompoundDrawablesWithIntrinsicBounds( - app.getUIUtilities().getIcon(R.drawable.ic_action_location_16, - activeColorResId),null,null,null); - selectIconDescription(activeColorResId); + Drawable addressIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_location_16, activeColorResId); + addAddressBtn.setCompoundDrawablesWithIntrinsicBounds(addressIcon, null, null, null); addDelDescription.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (descriptionCaption.getVisibility() != View.VISIBLE) { descriptionCaption.setVisibility(View.VISIBLE); addDelDescription.setText(view.getResources().getString(R.string.delete_description)); - addDelDescription.setCompoundDrawablesWithIntrinsicBounds( - app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, - activeColorResId),null,null,null); View descriptionEdit = view.findViewById(R.id.description_edit); descriptionEdit.requestFocus(); AndroidUtils.softKeyboardDelayed(getActivity(), descriptionEdit); } else { descriptionCaption.setVisibility(View.GONE); addDelDescription.setText(view.getResources().getString(R.string.add_description)); - addDelDescription.setCompoundDrawablesWithIntrinsicBounds( - app.getUIUtilities().getIcon(R.drawable.ic_action_description_16, - activeColorResId),null,null,null); AndroidUtils.hideSoftKeyboard(requireActivity(), descriptionEdit); descriptionEdit.clearFocus(); } + updateDescriptionIcon(); } }); AndroidUiHelper.updateVisibility(addressCaption, false); - if(!Algorithms.isEmpty(getAddressInitValue())){ - addAddressBtn.setText(getAddressInitValue()); + + String addressInitValue = getAddressInitValue(); + if (!Algorithms.isEmpty(addressInitValue)) { + addressEdit.setText(addressInitValue); + addAddressBtn.setText(addressInitValue); + addressEdit.setSelection(addressInitValue.length()); + AndroidUiHelper.updateVisibility(deleteAddressIcon, true); } else { addAddressBtn.setText(getString(R.string.add_address)); - }; - final ImageView deleteAddressIcon = (ImageView) view.findViewById(R.id.delete_address_icon); - deleteAddressIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, activeColorResId)); - if(!Algorithms.isEmpty(getAddressInitValue())){ - deleteAddressIcon.setVisibility(View.VISIBLE); - } else { - deleteAddressIcon.setVisibility(View.GONE); + AndroidUiHelper.updateVisibility(deleteAddressIcon, false); } + deleteAddressIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - addressCaption.setVisibility(View.GONE); - addAddressBtn.setText(view.getResources().getString(R.string.add_address)); addressEdit.setText(""); - deleteAddressIcon.setVisibility(View.GONE); + addAddressBtn.setText(view.getResources().getString(R.string.add_address)); + AndroidUiHelper.updateVisibility(addressCaption, false); + AndroidUiHelper.updateVisibility(deleteAddressIcon, false); } }); + + final View addressRow = view.findViewById(R.id.address_row); addAddressBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (addressCaption.getVisibility() != View.VISIBLE) { addressCaption.setVisibility(View.VISIBLE); - TextInputEditText addressEdit = view.findViewById(R.id.address_edit); - View row = view.findViewById(R.id.address_row); - row.setVisibility(View.GONE); - addAddressBtn.setText(getString(R.string.add_address)); addressEdit.requestFocus(); addressEdit.setSelection(addressEdit.getText().length()); - AndroidUtils.softKeyboardDelayed(requireActivity(),addressEdit); + AndroidUtils.softKeyboardDelayed(requireActivity(), addressEdit); + AndroidUiHelper.updateVisibility(addressRow, false); } else { addressCaption.setVisibility(View.GONE); addAddressBtn.setText(getAddressTextValue()); @@ -393,19 +385,17 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { return view; } - - private void selectIconDescription(int activeColorResId) { - if (descriptionCaption.getVisibility() != View.VISIBLE) { - addDelDescription.setCompoundDrawablesWithIntrinsicBounds( - app.getUIUtilities().getIcon(R.drawable.ic_action_description_16, activeColorResId),null,null,null); + private void updateDescriptionIcon() { + int iconId; + if (descriptionCaption.getVisibility() == View.VISIBLE) { + iconId = R.drawable.ic_action_trash_basket_16; } else { - addDelDescription.setCompoundDrawablesWithIntrinsicBounds( - app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, - activeColorResId),null,null,null); + iconId = R.drawable.ic_action_description_16; } + Drawable icon = app.getUIUtilities().getIcon(iconId, getActiveColorRes()); + addDelDescription.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); } - private void checkEmptyName(Editable name, TextInputLayout nameCaption, View saveButton) { if (name.toString().trim().isEmpty()) { nameCaption.setError(app.getString(R.string.please_provide_point_name_error)); @@ -443,14 +433,22 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { descriptionCaption.setVisibility(View.GONE); addDelDescription.setText(app.getString(R.string.add_description)); } - + updateDescriptionIcon(); } - boolean isAddressAvailable(){ + + boolean isAddressAvailable() { return addressCaption.getVisibility() == View.VISIBLE; } - boolean isDescriptionAvailable(){ + + boolean isDescriptionAvailable() { return descriptionCaption.getVisibility() == View.VISIBLE; } + + @ColorRes + private int getActiveColorRes() { + return nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + } + private void createGroupSelector() { groupListAdapter = new GroupAdapter(); groupRecyclerView = view.findViewById(R.id.group_recycler_view);