Edit_favorite_screen

This commit is contained in:
sergosm 2020-09-15 17:19:04 +03:00
parent d8bd5f936e
commit ce4fcc0ebe
4 changed files with 108 additions and 32 deletions

View file

@ -142,29 +142,62 @@
android:paddingEnd="@dimen/content_padding_small" android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
android:gravity="left"
tools:text="@string/lorem_ipsum" /> tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>
<net.osmand.plus.widgets.TextViewEx <LinearLayout
android:id="@+id/address_button" android:id="@+id/address_row"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="@dimen/context_menu_buttons_bottom_height" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_half" android:orientation="horizontal">
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginTop="@dimen/content_padding_small" <net.osmand.plus.widgets.TextViewEx
android:drawablePadding="8dp" android:id="@+id/address_button"
android:duplicateParentState="true" android:layout_width="0dp"
android:gravity="center" android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding_half" android:minHeight="@dimen/setting_list_item_small_height"
android:paddingLeft="@dimen/content_padding_half" android:layout_weight="1"
android:paddingEnd="@dimen/content_padding_half" android:layout_marginStart="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half" android:layout_marginLeft="@dimen/content_padding_half"
android:text="@string/add_address" android:layout_marginEnd="@dimen/content_padding"
android:textSize="@dimen/default_desc_text_size" android:layout_marginRight="@dimen/content_padding"
osmand:typeface="@string/font_roboto_medium" android:paddingTop="@dimen/content_padding_half"
tools:text="@string/add_address" /> android:paddingBottom="@dimen/content_padding_half"
android:drawablePadding="8dp"
android:duplicateParentState="true"
android:gravity="center_vertical"
android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half"
android:paddingRight="@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" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/delete_address_icon"
android:layout_width="@dimen/content_padding"
android:layout_height="@dimen/content_padding"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:contentDescription="@string/shared_string_list"
app:srcCompat="@drawable/ic_action_trash_basket_16" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:background="?attr/dashboard_divider" />
<LinearLayout <LinearLayout
android:id="@+id/description" android:id="@+id/description"

View file

@ -160,11 +160,13 @@ public class FavouritePointMenuController extends MenuController {
@NonNull @NonNull
@Override @Override
public CharSequence getSubtypeStr() { public CharSequence getSubtypeStr() {
Typeface typeface = FontCache.getRobotoRegular(getMapActivity()); if (fav.getAddress() != null) {Typeface typeface = FontCache.getRobotoRegular(getMapActivity());
SpannableString addressSpannable = new SpannableString(fav.getAddress()); SpannableString addressSpannable = new SpannableString(fav.getAddress());
addressSpannable.setSpan(new CustomTypefaceSpan(typeface), 0, addressSpannable.length(), 0); addressSpannable.setSpan(new CustomTypefaceSpan(typeface), 0, addressSpannable.length(), 0);
return addressSpannable;
return addressSpannable; } else {
return "";
}
} }
@Override @Override

View file

@ -243,8 +243,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
if (favorite != null) { if (favorite != null) {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue()); getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue()); point.setDescription(isDescriptionAvailable()?getDescriptionTextValue():null);
point.setAddress(getAddressTextValue()); point.setAddress(isAddressAvailable()?getAddressTextValue():null);
point.setColor(color); point.setColor(color);
point.setBackgroundType(backgroundType); point.setBackgroundType(backgroundType);
point.setIconId(iconId); point.setIconId(iconId);
@ -259,8 +259,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
if (favorite != null) { if (favorite != null) {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue()); getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue()); point.setDescription(isDescriptionAvailable()?getDescriptionTextValue():null);
point.setAddress(getAddressTextValue()); point.setAddress(isAddressAvailable()?getAddressTextValue():null);
point.setColor(color); point.setColor(color);
point.setBackgroundType(backgroundType); point.setBackgroundType(backgroundType);
point.setIconId(iconId); point.setIconId(iconId);

View file

@ -243,9 +243,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
addDelDescription.setTextColor(getResources().getColor(activeColorResId)); addDelDescription.setTextColor(getResources().getColor(activeColorResId));
addAddressBtn.setTextColor(getResources().getColor(activeColorResId)); addAddressBtn.setTextColor(getResources().getColor(activeColorResId));
addAddressBtn.setCompoundDrawablesWithIntrinsicBounds( addAddressBtn.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_location_16, activeColorResId),null,null,null); app.getUIUtilities().getIcon(R.drawable.ic_action_location_16,
addDelDescription.setCompoundDrawablesWithIntrinsicBounds( activeColorResId),null,null,null);
app.getUIUtilities().getIcon(R.drawable.ic_action_description_16, activeColorResId),null,null,null); selectIconDescription(activeColorResId);
addDelDescription.setOnClickListener(new View.OnClickListener() { addDelDescription.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -270,13 +270,36 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
} }
}); });
AndroidUiHelper.updateVisibility(addressCaption, false); AndroidUiHelper.updateVisibility(addressCaption, false);
addAddressBtn.setText(getAddressInitValue()); if(!Algorithms.isEmpty(getAddressInitValue())){
addAddressBtn.setText(getAddressInitValue());
} 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);
}
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.setOnClickListener(new View.OnClickListener() { addAddressBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (addressCaption.getVisibility() != View.VISIBLE) { if (addressCaption.getVisibility() != View.VISIBLE) {
addressCaption.setVisibility(View.VISIBLE); addressCaption.setVisibility(View.VISIBLE);
addAddressBtn.setText(view.getResources().getString(R.string.delete_address)); addAddressBtn.setText(view.getResources().getString(R.string.delete_address));
View row = view.findViewById(R.id.address_row);
row.setVisibility(View.GONE);
addAddressBtn.setText(getString(R.string.add_address));
View addressEdit = view.findViewById(R.id.address_edit); View addressEdit = view.findViewById(R.id.address_edit);
addressEdit.requestFocus(); addressEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(requireActivity(),addressEdit); AndroidUtils.softKeyboardDelayed(requireActivity(),addressEdit);
@ -354,6 +377,19 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return view; 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);
} else {
addDelDescription.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16,
activeColorResId),null,null,null);
}
}
private void checkEmptyName(Editable name, TextInputLayout nameCaption, View saveButton) { private void checkEmptyName(Editable name, TextInputLayout nameCaption, View saveButton) {
if (name.toString().trim().isEmpty()) { if (name.toString().trim().isEmpty()) {
nameCaption.setError(app.getString(R.string.please_provide_point_name_error)); nameCaption.setError(app.getString(R.string.please_provide_point_name_error));
@ -393,7 +429,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
} }
} }
boolean isAddressAvailable(){
return addressCaption.getVisibility() == View.VISIBLE;
}
boolean isDescriptionAvailable(){
return descriptionCaption.getVisibility() == View.VISIBLE;
}
private void createGroupSelector() { private void createGroupSelector() {
groupListAdapter = new GroupAdapter(); groupListAdapter = new GroupAdapter();
groupRecyclerView = view.findViewById(R.id.group_recycler_view); groupRecyclerView = view.findViewById(R.id.group_recycler_view);