diff --git a/.idea/misc.xml b/.idea/misc.xml index 88818fd3e..a78297f29 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -36,6 +36,7 @@ + diff --git a/README.md b/README.md index 2846757d6..e3f26874d 100755 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ More features will be implemented as we continue to develop this app. - [ ] UI Designer - [x] Layout inflater - [ ] Resolve resource references + - [ ] Auto-complete resource values when user edits attributes using the attribute editor - [ ] Drag & Drop (*) - [ ] Visual attribute editor (*) - [ ] Android Widgets (*) diff --git a/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttrEditorSheet.java b/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttrEditorSheet.java index 7cb38f4ec..e58af2755 100644 --- a/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttrEditorSheet.java +++ b/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttrEditorSheet.java @@ -136,8 +136,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple } private void showEditorDialog (@NonNull XMLAttribute attribute) { - final var attr = attribute.getAttr (); - final AttributeDialogs.OnClickListener onDone = (dialog, which, newValue) -> { if (!this.selectedView.updateAttribute (attribute.getNamespace (), attribute.getAttributeName (), newValue)) { StudioApp.getInstance ().toast ("Unable to update this attribute", Toaster.Type.ERROR); @@ -150,11 +148,9 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple AlertDialog dialog = null; if (attribute.hasFormat (DIMENSION)) { - if (attr == null) { - throw new IllegalStateException ("The provided attribute has not been resolved."); - } - dialog = AttributeDialogs.dimensionEditor (attribute.getValue (), onDone); + } else if (attribute.hasFormat (STRING)) { + dialog = AttributeDialogs.stringEditor (onDone); } if (dialog != null) { diff --git a/app/src/main/java/com/itsaky/androidide/utils/AttributeDialogs.java b/app/src/main/java/com/itsaky/androidide/utils/AttributeDialogs.java index 95ce3ad15..c1a35b441 100644 --- a/app/src/main/java/com/itsaky/androidide/utils/AttributeDialogs.java +++ b/app/src/main/java/com/itsaky/androidide/utils/AttributeDialogs.java @@ -29,13 +29,14 @@ import androidx.appcompat.app.AlertDialog; import com.itsaky.androidide.R; import com.itsaky.androidide.app.StudioApp; -import com.itsaky.androidide.databinding.LayoutDimensionEditorBinding; +import com.itsaky.androidide.databinding.LayoutDimensionAttrEditorBinding; +import com.itsaky.androidide.databinding.LayoutStringAttrEditorBinding; import com.itsaky.toaster.Toaster; /** * Helper class for creating dialogs for editing view attributes. - * - * TODO Should we merge this into {@link DialogUtils} + *
+ * TODO Should we merge this into {@link DialogUtils}? * @author Akash Yadav */ public class AttributeDialogs { @@ -61,16 +62,50 @@ public class AttributeDialogs { /** * Release the context instance stored in this class. - * + * * @see #init(Context) */ public static void release () { mContext = null; } + /** + * Create a new value for editing an attribute with format STRING. + * @param onSubmit The listener that will be invoked when the user clicks the + * positive button. + * @return The newly created dialog instance. + */ + @NonNull + public static AlertDialog stringEditor (OnClickListener onSubmit) { + final var binding = LayoutStringAttrEditorBinding.inflate (LayoutInflater.from (mContext)); + final var builder = newMaterialDialogBuilder (mContext); + builder.setTitle (mContext.getString(R.string.msg_new_str_value)); + builder.setView (binding.getRoot ()); + builder.setPositiveButton (android.R.string.ok, (dialog, which) -> { + final var newValue = binding.valueField.getEditText ().getText ().toString ().trim (); + if (newValue.length () <= 0) { + StudioApp.getInstance ().toast (mContext.getString (R.string.msg_invalid_attr_value), Toaster.Type.ERROR); + return; + } + if (onSubmit != null) { + onSubmit.onClick (dialog, which, newValue); + } + }); + builder.setNegativeButton (android.R.string.cancel, (dialog, which) -> dialog.dismiss ()); + + return builder.create (); + } + + /** + * Create a new dialog for editing an attribute which accepts dimension values. + * @param value The current value of the attribute. Used for determining which item must be selected by default. + * @param onSubmit A listener that will be invoked when the user presses the positive button of the dialog. + * This listener is invoked only when the user passes a valid dimension value. + * @return The newly created dialog instance. Note that this dialog is not shown by default. + */ @NonNull public static AlertDialog dimensionEditor (CharSequence value, OnClickListener onSubmit) { - final var binding = LayoutDimensionEditorBinding.inflate(LayoutInflater.from (mContext)); + final var binding = LayoutDimensionAttrEditorBinding.inflate(LayoutInflater.from (mContext)); binding.choices.setOnCheckedChangeListener ((group, checkedId) -> { binding.otherValue.setVisibility (binding.other.isChecked () ? View.VISIBLE : View.GONE); }); diff --git a/app/src/main/res/layout/layout_dimension_editor.xml b/app/src/main/res/layout/layout_dimension_attr_editor.xml similarity index 100% rename from app/src/main/res/layout/layout_dimension_editor.xml rename to app/src/main/res/layout/layout_dimension_attr_editor.xml diff --git a/app/src/main/res/layout/layout_string_attr_editor.xml b/app/src/main/res/layout/layout_string_attr_editor.xml new file mode 100644 index 000000000..693919ecb --- /dev/null +++ b/app/src/main/res/layout/layout_string_attr_editor.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cae03d901..4093b3692 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -330,5 +330,6 @@ No attribute format is available for this attribute. Unable to create attribute editor for this attribute Invalid value + New string value