Compare commits

..

1 Commits

Author SHA1 Message Date
Jean-Baptiste
7822aeba56 [android] Use error in textfield instead alert dialog
Signed-off-by: Jean-Baptiste <jeanbaptiste.charron@outlook.fr>
2026-01-01 21:53:49 +01:00
3 changed files with 29 additions and 215 deletions

View File

@@ -16,8 +16,7 @@ import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
import app.organicmaps.util.InputUtils;
import app.organicmaps.util.Utils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.util.Objects;
@@ -38,7 +37,7 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
@NonNull
private TextInputEditText mEditCategoryNameView;
@NonNull
private ShapeableImageView mSaveView;
private MaterialButton mSaveView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
@@ -75,12 +74,32 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
{
clearNameBtn.setEndIconVisible(charSequence.length() > 0);
if (charSequence.length() >= 1)
{
clearNameBtn.setEndIconVisible(true);
mSaveView.setEnabled(true);
}
else
{
clearNameBtn.setEndIconVisible(false);
mSaveView.setEnabled(false);
mEditCategoryNameView.setError(getString(R.string.bookmarks_error_title_empty_list_name));
}
}
@Override
public void afterTextChanged(Editable editable)
{}
{
if (BookmarkManager.INSTANCE.isUsedCategoryName(getEditableCategoryName()) && !TextUtils.equals(getEditableCategoryName(), mCategory.getName()))
{
mEditCategoryNameView.setError(getString(R.string.bookmarks_error_title_list_name_already_taken));
mSaveView.setEnabled(false);
}
else
{
mSaveView.setEnabled(true);
}
}
});
mEditDescView = root.findViewById(R.id.edit_description);
mEditDescView.setText(mCategory.getDescription());
@@ -91,8 +110,6 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
private void onEditDoneClicked()
{
final String newCategoryName = getEditableCategoryName();
if (!validateCategoryName(newCategoryName))
return;
if (isCategoryNameChanged())
BookmarkManager.INSTANCE.setCategoryName(mCategory.getId(), newCategoryName);
@@ -109,30 +126,6 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
return !TextUtils.equals(categoryName, mCategory.getName());
}
private boolean validateCategoryName(@Nullable String name)
{
if (TextUtils.isEmpty(name))
{
new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
.setTitle(R.string.bookmarks_error_title_empty_list_name)
.setMessage(R.string.bookmarks_error_message_empty_list_name)
.setPositiveButton(R.string.ok, null)
.show();
return false;
}
if (BookmarkManager.INSTANCE.isUsedCategoryName(name) && !TextUtils.equals(name, mCategory.getName()))
{
new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
.setTitle(R.string.bookmarks_error_title_list_name_already_taken)
.setMessage(R.string.bookmarks_error_message_list_name_already_taken)
.setPositiveButton(R.string.ok, null)
.show();
return false;
}
return true;
}
@NonNull
private String getEditableCategoryName()
{

View File

@@ -1,181 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/routing_plan_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clipToPadding="false">
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:theme="@style/MwmWidget.ToolbarTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/back"
android:layout_width="wrap_content"
android:padding="@dimen/margin_half_plus_eight"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentStart="true"
android:background="?selectableItemBackgroundBorderless"
app:srcCompat="?homeAsUpIndicator"
android:scaleType="center" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<RadioGroup
android:id="@+id/route_type"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:contentDescription="@string/route_type"
android:orientation="horizontal">
<app.organicmaps.widget.RoutingToolbarButton
android:id="@+id/vehicle"
android:layout_width="@dimen/routing_toolbar_button"
android:layout_height="@dimen/routing_toolbar_button"
android:layout_marginStart="@dimen/routing_selector_wheel_margin"
android:contentDescription="@string/vehicle"
tools:button="@drawable/ic_car"
tools:buttonTint="?colorSecondary" />
<app.organicmaps.widget.RoutingToolbarButton
android:id="@+id/pedestrian"
android:layout_width="@dimen/routing_toolbar_button"
android:layout_height="@dimen/routing_toolbar_button"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:contentDescription="@string/pedestrian"
tools:button="@drawable/ic_pedestrian"
tools:buttonTint="?iconTintLight" />
<app.organicmaps.widget.RoutingToolbarButton
android:id="@+id/transit"
android:layout_width="@dimen/routing_toolbar_button"
android:layout_height="@dimen/routing_toolbar_button"
android:layout_marginEnd="@dimen/margin_half_plus"
android:contentDescription="@string/subway"
tools:button="@drawable/ic_route_planning_metro_40px"
tools:buttonTint="?iconTintLight" />
<app.organicmaps.widget.RoutingToolbarButton
android:id="@+id/bicycle"
android:layout_width="@dimen/routing_toolbar_button"
android:layout_height="@dimen/routing_toolbar_button"
android:layout_marginEnd="12dp"
android:contentDescription="@string/bicycle"
tools:button="@drawable/ic_bike"
tools:buttonTint="?iconTintLight" />
<app.organicmaps.widget.RoutingToolbarButton
android:id="@+id/ruler"
android:layout_width="@dimen/routing_toolbar_button"
android:layout_height="@dimen/routing_toolbar_button"
android:layout_marginEnd="12dp"
android:contentDescription="@string/ruler"
tools:button="@drawable/ic_ruler_route"
tools:buttonTint="?iconTintLight" />
</RadioGroup>
<LinearLayout
android:id="@+id/progress_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/route_type"
android:layout_centerInParent="true"
android:orientation="horizontal"
tools:background="#80FF0000">
<app.organicmaps.widget.WheelProgressView
android:id="@+id/progress_vehicle"
style="@style/MwmWidget.ProgressWheel.RoutingPlan"
android:layout_marginStart="@dimen/routing_selector_wheel_margin"
android:layout_marginTop="@dimen/routing_selector_wheel_margin"
android:layout_marginBottom="@dimen/routing_selector_wheel_margin"
tools:visibility="visible"/>
<app.organicmaps.widget.WheelProgressView
android:id="@+id/progress_pedestrian"
style="@style/MwmWidget.ProgressWheel.RoutingPlan"
android:layout_marginTop="@dimen/routing_selector_wheel_margin"
android:layout_marginBottom="@dimen/routing_selector_wheel_margin"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"/>
<app.organicmaps.widget.WheelProgressView
android:id="@+id/progress_transit"
style="@style/MwmWidget.ProgressWheel.RoutingPlan"
android:layout_marginTop="@dimen/routing_selector_wheel_margin"
android:layout_marginBottom="@dimen/routing_selector_wheel_margin"
android:layout_marginEnd="12dp"/>
<app.organicmaps.widget.WheelProgressView
android:id="@+id/progress_bicycle"
style="@style/MwmWidget.ProgressWheel.RoutingPlan"
android:layout_marginTop="@dimen/routing_selector_wheel_margin"
android:layout_marginBottom="@dimen/routing_selector_wheel_margin"
android:layout_marginEnd="12dp"/>
<app.organicmaps.widget.WheelProgressView
android:id="@+id/progress_ruler"
style="@style/MwmWidget.ProgressWheel.RoutingPlan"
android:layout_marginTop="@dimen/routing_selector_wheel_margin"
android:layout_marginBottom="@dimen/routing_selector_wheel_margin"
android:layout_marginEnd="12dp"/>
</LinearLayout>
</RelativeLayout>
</com.google.android.material.appbar.MaterialToolbar>
</FrameLayout>
<FrameLayout
android:id="@+id/driving_options_btn_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?drivingOptionsViewBg"
android:foreground="@drawable/shadow_top"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:id="@+id/driving_options_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:gravity="center"
android:minHeight="@dimen/height_block_base">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/driving_options_btn_img"
android:layout_width="@dimen/margin_base_plus"
android:layout_height="@dimen/margin_base_plus"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_half_plus_eight"
app:srcCompat="@drawable/ic_error_white" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/driving_options_btn_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@string/robotoMedium"
android:gravity="center"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/text_light"
tools:text="test" />
</LinearLayout>
</FrameLayout>
<FrameLayout
style="@style/MwmWidget.FrameLayout.Elevation"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@@ -12,13 +12,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MwmWidget.ToolbarTheme">
<com.google.android.material.imageview.ShapeableImageView
<com.google.android.material.button.MaterialButton
android:id="@+id/save"
android:layout_width="?actionBarSize"
android:layout_height="?actionBarSize"
android:scaleType="centerInside"
android:layout_gravity="end|center_vertical"
app:srcCompat="@drawable/ic_done"/>
app:icon="@drawable/ic_done"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="24dp" />
</com.google.android.material.appbar.MaterialToolbar>
<androidx.core.widget.NestedScrollView
android:scrollbars="none"