Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce optional 'name' field for iconpack icons #1179

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/src/main/java/com/beemdevelopment/aegis/icons/IconPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.beemdevelopment.aegis.util.JsonUtils;
import com.google.common.base.Objects;
import com.google.common.io.Files;

Expand Down Expand Up @@ -120,13 +121,15 @@ public static IconPack fromBytes(byte[] data) throws JSONException {

public static class Icon implements Serializable {
private final String _relFilename;
private final String _name;
private final String _category;
private final List<String> _issuers;

private File _file;

protected Icon(String filename, String category, List<String> issuers) {
protected Icon(String filename, String name, String category, List<String> issuers) {
_relFilename = filename;
_name = name;
_category = category;
_issuers = issuers;
}
Expand All @@ -149,6 +152,9 @@ public IconType getIconType() {
}

public String getName() {
if (_name != null) {
return _name;
}
return Files.getNameWithoutExtension(new File(_relFilename).getName());
}

Expand All @@ -169,6 +175,7 @@ public boolean isSuggestedFor(String issuer) {

public static Icon fromJson(JSONObject obj) throws JSONException {
String filename = obj.getString("filename");
String name = JsonUtils.optString(obj, "name");
String category = obj.isNull("category") ? null : obj.getString("category");
JSONArray array = obj.getJSONArray("issuer");

Expand All @@ -178,7 +185,7 @@ public static Icon fromJson(JSONObject obj) throws JSONException {
issuers.add(issuer);
}

return new Icon(filename, category, issuers);
return new Icon(filename, name, category, issuers);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,12 @@ private static class CustomSvgIcon extends IconPack.Icon {
private final File _file;

protected CustomSvgIcon(File file) {
super(file.getAbsolutePath(), null, null);
super(file.getAbsolutePath(), null, null, null);
_file = file;
}

@Nullable
@Override
public File getFile() {
return _file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,8 @@ public interface Listener {
}

public static class DummyIcon extends IconPack.Icon {
private final String _name;

protected DummyIcon(String name) {
super(null, null, null);
_name = name;
}

@Override
public String getName() {
return _name;
super(name, null, null, null);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion docs/iconpacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ is randomly generated once and stays the same across different versions.
"version": 1,
"icons": [
{
"name": "Google",
"filename": "services/Google.png",
"category": "Services",
"issuer": [ "google" ]
},
{
"name": "Blizzard",
"filename": "services/Blizzard.png",
"category": "Gaming",
"issuer": [ "blizzard", "battle.net" ]
Expand All @@ -32,7 +34,7 @@ Every icon definition contains the filename of the icon file, relative to the
root of the .ZIP archive. Icon definitions also have a list of strings that the
Issuer field in Aegis is matched against for automatic selection of an icon for
new entries. Matching is done in a case-insensitive manner. There's also a
category field.
category field. Optionally, icons can also have a name.

The following image formats are supported, in order of preference:

Expand Down