X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSoneAccessor.java;h=a9ee78bd35642a17aca97e655aa0a0a6718da568;hb=6f1e7806171eb6af95c8669f2ac0801e34b9246a;hp=b7e2282c22070e50eae0f250b62d0cfe34f939af;hpb=74334cabafbab7c43cc1fd47cb429f54470d0adb;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index b7e2282..a9ee78b 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.template; +import net.pterodactylus.sone.core.Core; +import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.template.Accessor; @@ -29,11 +31,11 @@ import net.pterodactylus.util.template.ReflectionAccessor; *
niceName
*
Will show a combination of first name, middle name, and last name, if * available, otherwise the username of the Sone is returned.
- *
isFriend
+ *
friend
*
Will return {@code true} if the sone in question is a friend of the * currently logged in Sone (as determined by accessing the “currentSone” * variable of the given {@link DataProvider}).
- *
isCurrent
+ *
current
*
Will return {@code true} if the sone in question is the currently logged * in Sone.
* @@ -42,6 +44,19 @@ import net.pterodactylus.util.template.ReflectionAccessor; */ public class SoneAccessor extends ReflectionAccessor { + /** The core. */ + private final Core core; + + /** + * Creates a new Sone accessor. + * + * @param core + * The Sone core + */ + public SoneAccessor(Core core) { + this.core = core; + } + /** * {@inheritDoc} */ @@ -49,25 +64,56 @@ public class SoneAccessor extends ReflectionAccessor { public Object get(DataProvider dataProvider, Object object, String member) { Sone sone = (Sone) object; if (member.equals("niceName")) { - Profile profile = sone.getProfile(); - String firstName = profile.getFirstName(); - String middleName = profile.getMiddleName(); - String lastName = profile.getLastName(); - if (firstName == null) { - if (lastName == null) { - return sone.getName(); - } - return lastName; - } - return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : ""); - } else if (member.equals("isFriend")) { + return getNiceName(sone); + } else if (member.equals("local")) { + return sone.getInsertUri() != null; + } else if (member.equals("friend")) { Sone currentSone = (Sone) dataProvider.getData("currentSone"); - return currentSone.hasFriendSone(sone) ? true : null; - } else if (member.equals("isCurrent")) { + return (currentSone != null) && currentSone.hasFriend(sone.getId()); + } else if (member.equals("current")) { Sone currentSone = (Sone) dataProvider.getData("currentSone"); - return currentSone.equals(sone); + return (currentSone != null) && currentSone.equals(sone); + } else if (member.equals("modified")) { + return sone.getModificationCounter() > 0; + } else if (member.equals("status")) { + return core.getSoneStatus(sone); + } else if (member.equals("unknown")) { + return core.getSoneStatus(sone) == SoneStatus.unknown; + } else if (member.equals("idle")) { + return core.getSoneStatus(sone) == SoneStatus.idle; + } else if (member.equals("inserting")) { + return core.getSoneStatus(sone) == SoneStatus.inserting; + } else if (member.equals("downloading")) { + return core.getSoneStatus(sone) == SoneStatus.downloading; + } else if (member.equals("new")) { + return core.isNewSone(sone); } return super.get(dataProvider, object, member); } + // + // STATIC METHODS + // + + /** + * Returns the nice name of the given Sone. + * + * @param sone + * The Sone to get the nice name for + * @return The nice name of the Sone + */ + public static String getNiceName(Sone sone) { + Profile profile = sone.getProfile(); + String firstName = profile.getFirstName(); + String middleName = profile.getMiddleName(); + String lastName = profile.getLastName(); + if (firstName == null) { + if (lastName == null) { + return String.valueOf(sone.getName()); + } + return lastName; + } + return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : ""); + } + }