From 9b3e7136bd7fca3f5aee1e42450a2a94f6c73b29 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Thu, 7 Sep 2023 22:45:58 +0200 Subject: [PATCH] Introduce optional 'name' field for iconpack icons This introduces a new (optional) 'name' field for iconpack icons. It will be used to describe the icon in the icon selection dialog. If it is not present, the name of the icon will be derived from the filename, like before. Using this new field allows usage of more exotic characters in the icon name that are not allowed in a filename. --- .../com/beemdevelopment/aegis/icons/IconPack.java | 11 +++++++++-- .../beemdevelopment/aegis/ui/EditEntryActivity.java | 3 ++- .../beemdevelopment/aegis/ui/views/IconAdapter.java | 10 +--------- docs/iconpacks.md | 4 +++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/icons/IconPack.java b/app/src/main/java/com/beemdevelopment/aegis/icons/IconPack.java index 3e3f8424..9120a4e3 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/icons/IconPack.java +++ b/app/src/main/java/com/beemdevelopment/aegis/icons/IconPack.java @@ -3,6 +3,7 @@ package com.beemdevelopment.aegis.icons; 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; @@ -120,13 +121,15 @@ public class IconPack { public static class Icon implements Serializable { private final String _relFilename; + private final String _name; private final String _category; private final List _issuers; private File _file; - protected Icon(String filename, String category, List issuers) { + protected Icon(String filename, String name, String category, List issuers) { _relFilename = filename; + _name = name; _category = category; _issuers = issuers; } @@ -149,6 +152,9 @@ public class IconPack { } public String getName() { + if (_name != null) { + return _name; + } return Files.getNameWithoutExtension(new File(_relFilename).getName()); } @@ -169,6 +175,7 @@ public class IconPack { 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"); @@ -178,7 +185,7 @@ public class IconPack { issuers.add(issuer); } - return new Icon(filename, category, issuers); + return new Icon(filename, name, category, issuers); } } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java index 95de25e2..8812592b 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java @@ -852,11 +852,12 @@ public class EditEntryActivity extends AegisActivity { 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; } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/IconAdapter.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/IconAdapter.java index a35e7a01..2593197f 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/IconAdapter.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/IconAdapter.java @@ -232,16 +232,8 @@ public class IconAdapter extends RecyclerView.Adapter { } 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 diff --git a/docs/iconpacks.md b/docs/iconpacks.md index 2b98fe88..a3b72f8d 100644 --- a/docs/iconpacks.md +++ b/docs/iconpacks.md @@ -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" ] @@ -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: