mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Filter already applied attributes from list in UI Designer
Renamed 'namespace' to 'namespacePrefix' in Attr
This commit is contained in:
Binary file not shown.
@@ -54,9 +54,12 @@ import com.itsaky.androidide.utils.AttributeDialogs;
|
||||
import com.itsaky.androidide.utils.DialogUtils;
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.attrinfo.models.Attr;
|
||||
import com.itsaky.inflater.INamespace;
|
||||
import com.itsaky.inflater.IView;
|
||||
import com.itsaky.toaster.Toaster;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -228,7 +231,7 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
}
|
||||
|
||||
final var sheet = getAttrListSheet ();
|
||||
sheet.setItems (new ArrayList<> (attributes));
|
||||
sheet.setItems (filterAppliedAttributes (attributes));
|
||||
sheet.show (getChildFragmentManager (), "attr_list_sheet");
|
||||
|
||||
} else if (position == 1) { // Delete
|
||||
@@ -256,6 +259,20 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Contract("_ -> new")
|
||||
private List<Attr> filterAppliedAttributes (@NonNull TreeSet<Attr> attributes) {
|
||||
attributes.removeIf (attr -> {
|
||||
var namespace = this.selectedView.findRegisteredNamespace (attr.namespacePrefix);
|
||||
if (namespace == null) {
|
||||
namespace = INamespace.ANDROID;
|
||||
}
|
||||
|
||||
return this.selectedView.hasAttribute (namespace, attr.name);
|
||||
});
|
||||
return new ArrayList<> (attributes);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private AttributeListSheet getAttrListSheet () {
|
||||
if (mAttrListSheet == null) {
|
||||
|
||||
@@ -226,13 +226,13 @@ public class CompletionProvider extends AbstractServiceProvider implements IComp
|
||||
@NonNull
|
||||
private String createAttributeInsertText(@NonNull Attr attr) {
|
||||
StringBuilder xml = new StringBuilder();
|
||||
xml.append(attr.namespace);
|
||||
xml.append(attr.namespacePrefix);
|
||||
xml.append(":");
|
||||
xml.append(attr.name);
|
||||
xml.append("=");
|
||||
xml.append("\"");
|
||||
|
||||
if(attr.namespace.equals("android")
|
||||
if(attr.namespacePrefix.equals("android")
|
||||
&& attr.name.equals("id")) {
|
||||
xml.append("@+id/");
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class AttrInfo {
|
||||
final var attribute = new Attr (attr.attr ("name"));
|
||||
if (attribute.name.contains (":")) {
|
||||
final var split = attribute.name.split (":", 2);
|
||||
attribute.namespace = split[0];
|
||||
attribute.namespacePrefix = split[0];
|
||||
attribute.name = split[1];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/************************************************************************************
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
*
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@@ -16,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
**************************************************************************************/
|
||||
*/
|
||||
package com.itsaky.attrinfo.models;
|
||||
|
||||
import android.text.TextUtils;
|
||||
@@ -51,66 +49,22 @@ public class Attr {
|
||||
public static final int ENUM = 1 << 8;
|
||||
public static final int FLAG = 1 << 9;
|
||||
public static final int UNKNOWN = 1 << 10;
|
||||
|
||||
public String namespace;
|
||||
private static final Logger LOG = Logger.instance ("AttrInfo::Attr");
|
||||
public String namespacePrefix;
|
||||
public String name;
|
||||
public Set<String> possibleValues;
|
||||
|
||||
public int format;
|
||||
|
||||
private static final Logger LOG = Logger.instance ("AttrInfo::Attr");
|
||||
|
||||
public Attr (String name) {
|
||||
this (name, true);
|
||||
}
|
||||
|
||||
public Attr (String name, boolean isAndroid) {
|
||||
this.name = name;
|
||||
this.namespace = isAndroid ? "android" : "app";
|
||||
this.namespacePrefix = isAndroid ? "android" : "app";
|
||||
this.possibleValues = new TreeSet<> ();
|
||||
}
|
||||
|
||||
public boolean hasPossibleValues () {
|
||||
return possibleValues != null && possibleValues.size () > 0;
|
||||
}
|
||||
|
||||
public boolean hasFormat (int format) {
|
||||
return (this.format & format) != 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString () {
|
||||
return "Attr [" +
|
||||
" name: " + name + "\n" +
|
||||
" namespace: " + namespace + "\n" +
|
||||
" values: " + TextUtils.join (", ", this.possibleValues) + "\n" +
|
||||
" format: " + format + "\n" +
|
||||
"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (o == null || getClass () != o.getClass ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Attr attr = (Attr) o;
|
||||
return format == attr.format
|
||||
&& Objects.equals (namespace, attr.namespace)
|
||||
&& Objects.equals (name, attr.name)
|
||||
&& Objects.equals (possibleValues, attr.possibleValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode () {
|
||||
return Objects.hash (namespace, name, possibleValues, format);
|
||||
}
|
||||
|
||||
public static int formatForName (@NonNull String names) {
|
||||
var result = 0;
|
||||
if (names.contains ("|")) {
|
||||
@@ -150,4 +104,45 @@ public class Attr {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPossibleValues () {
|
||||
return possibleValues != null && possibleValues.size () > 0;
|
||||
}
|
||||
|
||||
public boolean hasFormat (int format) {
|
||||
return (this.format & format) != 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString () {
|
||||
return "Attr [" +
|
||||
" name: " + name + "\n" +
|
||||
" namespace: " + namespacePrefix + "\n" +
|
||||
" values: " + TextUtils.join (", ", this.possibleValues) + "\n" +
|
||||
" format: " + format + "\n" +
|
||||
"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (o == null || getClass () != o.getClass ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Attr attr = (Attr) o;
|
||||
return format == attr.format
|
||||
&& Objects.equals (namespacePrefix, attr.namespacePrefix)
|
||||
&& Objects.equals (name, attr.name)
|
||||
&& Objects.equals (possibleValues, attr.possibleValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode () {
|
||||
return Objects.hash (namespacePrefix, name, possibleValues, format);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user