mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-01 10:33:45 +00:00
[android] Use error in textfield instead alert dialog
Signed-off-by: Jean-Baptiste <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -12,15 +12,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
app:tint="@color/image_view"
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/save"
|
||||
app:srcCompat="@drawable/ic_done"
|
||||
app:icon="@drawable/ic_done"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="0dp"
|
||||
app:iconSize="24dp"
|
||||
android:layout_width="?actionBarSize"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:scaleType="centerInside"
|
||||
android:contentDescription="@string/save" />
|
||||
</com.google.android.material.appbar.MaterialToolbar>
|
||||
<FrameLayout
|
||||
|
||||
Reference in New Issue
Block a user