Merge pull request #9814 from osmandapp/favorites_allow_to_edit_address

Edit_favorite_screen
This commit is contained in:
Vitaliy 2020-09-16 16:37:39 +03:00 committed by GitHub
commit 4553732b59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 42 deletions

View file

@ -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"
@ -147,25 +148,51 @@
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/address_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/address_button"
android:layout_width="wrap_content"
android:layout_height="@dimen/setting_list_item_small_height"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:drawablePadding="8dp"
android:duplicateParentState="true"
android:gravity="center"
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" />
<ImageButton
android:id="@+id/delete_address_icon"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="@dimen/setting_list_item_small_height"
android:layout_height="@dimen/setting_list_item_small_height"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/list_item_button_padding"
android:layout_marginLeft="@dimen/list_item_button_padding"
android:layout_marginEnd="@dimen/list_item_button_padding"
android:layout_marginRight="@dimen/list_item_button_padding"
android:contentDescription="@string/delete_address"
app:srcCompat="@drawable/ic_action_trash_basket_16" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"

View file

@ -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(getDescriptionTextValue());
point.setAddress(getAddressTextValue());
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(getDescriptionTextValue());
point.setAddress(getAddressTextValue());
point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null);
point.setAddress(isAddressAvailable() ? getAddressTextValue() : null);
point.setColor(color);
point.setBackgroundType(backgroundType);
point.setIconId(iconId);

View file

@ -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,56 +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);
addDelDescription.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_description_16, activeColorResId),null,null,null);
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);
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));
AndroidUiHelper.updateVisibility(deleteAddressIcon, false);
}
deleteAddressIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addressEdit.setText("");
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);
addAddressBtn.setText(view.getResources().getString(R.string.delete_address));
TextInputEditText addressEdit = view.findViewById(R.id.address_edit);
addressEdit.requestFocus();
addressEdit.setSelection(addressEdit.getText().length());
AndroidUtils.softKeyboardDelayed(requireActivity(), addressEdit);
AndroidUiHelper.updateVisibility(addressRow, false);
} else {
addressCaption.setVisibility(View.GONE);
addAddressBtn.setText(getAddressTextValue());
@ -371,6 +385,17 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return view;
}
private void updateDescriptionIcon() {
int iconId;
if (descriptionCaption.getVisibility() == View.VISIBLE) {
iconId = R.drawable.ic_action_trash_basket_16;
} else {
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));
@ -408,7 +433,20 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
descriptionCaption.setVisibility(View.GONE);
addDelDescription.setText(app.getString(R.string.add_description));
}
updateDescriptionIcon();
}
boolean isAddressAvailable() {
return addressCaption.getVisibility() == View.VISIBLE;
}
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() {