aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
commit1ac5be485502e7d6d4c117335e083c684739e6af (patch)
tree279c22e269158dde838f31ebcf3daf4272573583 /src/eu/siacs/conversations/entities
parent8d456085e57334dc34707a49666006619e2c77c6 (diff)
some code cleanup
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/entities/AbstractEntity.java11
-rw-r--r--src/eu/siacs/conversations/entities/Account.java10
-rw-r--r--src/eu/siacs/conversations/entities/Bookmark.java41
-rw-r--r--src/eu/siacs/conversations/entities/Contact.java11
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java11
-rw-r--r--src/eu/siacs/conversations/entities/ListItem.java2
-rw-r--r--src/eu/siacs/conversations/entities/Message.java2
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java4
-rw-r--r--src/eu/siacs/conversations/entities/Presences.java17
-rw-r--r--src/eu/siacs/conversations/entities/Roster.java20
10 files changed, 71 insertions, 58 deletions
diff --git a/src/eu/siacs/conversations/entities/AbstractEntity.java b/src/eu/siacs/conversations/entities/AbstractEntity.java
index 4891723e..92b8a729 100644
--- a/src/eu/siacs/conversations/entities/AbstractEntity.java
+++ b/src/eu/siacs/conversations/entities/AbstractEntity.java
@@ -4,19 +4,18 @@ import android.content.ContentValues;
public abstract class AbstractEntity {
-
public static final String UUID = "uuid";
-
+
protected String uuid;
-
+
public String getUuid() {
return this.uuid;
}
-
+
public abstract ContentValues getContentValues();
-
+
public boolean equals(AbstractEntity entity) {
return this.getUuid().equals(entity.getUuid());
}
-
+
}
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java
index d31d2324..272cf379 100644
--- a/src/eu/siacs/conversations/entities/Account.java
+++ b/src/eu/siacs/conversations/entities/Account.java
@@ -82,11 +82,12 @@ public class Account extends AbstractEntity {
public Account(String username, String server, String password) {
this(java.util.UUID.randomUUID().toString(), username, server,
- password, 0, null, "",null);
+ password, 0, null, "", null);
}
public Account(String uuid, String username, String server,
- String password, int options, String rosterVersion, String keys, String avatar) {
+ String password, int options, String rosterVersion, String keys,
+ String avatar) {
this.uuid = uuid;
this.username = username;
this.server = server;
@@ -151,7 +152,10 @@ public class Account extends AbstractEntity {
public boolean errorStatus() {
int s = getStatus();
- return (s == STATUS_REGISTRATION_FAILED || s == STATUS_REGISTRATION_CONFLICT || s == STATUS_REGISTRATION_NOT_SUPPORTED || s == STATUS_SERVER_NOT_FOUND || s == STATUS_UNAUTHORIZED);
+ return (s == STATUS_REGISTRATION_FAILED
+ || s == STATUS_REGISTRATION_CONFLICT
+ || s == STATUS_REGISTRATION_NOT_SUPPORTED
+ || s == STATUS_SERVER_NOT_FOUND || s == STATUS_UNAUTHORIZED);
}
public boolean hasErrorStatus() {
diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java
index 38c03410..596cbe01 100644
--- a/src/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/eu/siacs/conversations/entities/Bookmark.java
@@ -8,30 +8,31 @@ import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
public class Bookmark implements ListItem {
-
+
private Account account;
private String jid;
private String nick;
private String name;
private boolean autojoin;
private Conversation mJoinedConversation;
-
+
public Bookmark(Account account, String jid) {
this.account = account;
this.jid = jid;
}
public static Bookmark parse(Element element, Account account) {
- Bookmark bookmark = new Bookmark(account,element.getAttribute("jid"));
+ Bookmark bookmark = new Bookmark(account, element.getAttribute("jid"));
bookmark.setName(element.getAttribute("name"));
String autojoin = element.getAttribute("autojoin");
- if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) {
+ if (autojoin != null
+ && (autojoin.equals("true") || autojoin.equals("1"))) {
bookmark.setAutojoin(true);
} else {
bookmark.setAutojoin(false);
}
Element nick = element.findChild("nick");
- if (nick!=null) {
+ if (nick != null) {
bookmark.setNick(nick.getContent());
}
return bookmark;
@@ -40,25 +41,27 @@ public class Bookmark implements ListItem {
public void setAutojoin(boolean autojoin) {
this.autojoin = autojoin;
}
-
+
public void setName(String name) {
this.name = name;
}
-
+
public void setNick(String nick) {
this.nick = nick;
}
@Override
public int compareTo(ListItem another) {
- return this.getDisplayName().compareToIgnoreCase(another.getDisplayName());
+ return this.getDisplayName().compareToIgnoreCase(
+ another.getDisplayName());
}
@Override
public String getDisplayName() {
- if (this.mJoinedConversation!=null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
+ if (this.mJoinedConversation != null
+ && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
return this.mJoinedConversation.getMucOptions().getSubject();
- } else if (name!=null) {
+ } else if (name != null) {
return name;
} else {
return this.jid.split("@")[0];
@@ -69,11 +72,11 @@ public class Bookmark implements ListItem {
public String getJid() {
return this.jid.toLowerCase(Locale.US);
}
-
+
public String getNick() {
return this.nick;
}
-
+
public boolean autojoin() {
return autojoin;
}
@@ -81,8 +84,8 @@ public class Bookmark implements ListItem {
public boolean match(String needle) {
return needle == null
|| getJid().contains(needle.toLowerCase(Locale.US))
- || getDisplayName().toLowerCase(Locale.US)
- .contains(needle.toLowerCase(Locale.US));
+ || getDisplayName().toLowerCase(Locale.US).contains(
+ needle.toLowerCase(Locale.US));
}
public Account getAccount() {
@@ -91,10 +94,12 @@ public class Bookmark implements ListItem {
@Override
public Bitmap getImage(int dpSize, Context context) {
- if (this.mJoinedConversation==null) {
- return UIHelper.getContactPicture(getDisplayName(), dpSize, context, false);
+ if (this.mJoinedConversation == null) {
+ return UIHelper.getContactPicture(getDisplayName(), dpSize,
+ context, false);
} else {
- return UIHelper.getContactPicture(this.mJoinedConversation, dpSize, context, false);
+ return UIHelper.getContactPicture(this.mJoinedConversation, dpSize,
+ context, false);
}
}
@@ -105,7 +110,7 @@ public class Bookmark implements ListItem {
public String getName() {
return name;
}
-
+
public Element toElement() {
Element element = new Element("conference");
element.setAttribute("jid", this.getJid());
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java
index ab05b9d1..ce697df4 100644
--- a/src/eu/siacs/conversations/entities/Contact.java
+++ b/src/eu/siacs/conversations/entities/Contact.java
@@ -106,7 +106,7 @@ public class Contact implements ListItem {
values.put(SYSTEMACCOUNT, systemAccount);
values.put(PHOTOURI, photoUri);
values.put(KEYS, keys.toString());
- values.put(AVATAR,avatar);
+ values.put(AVATAR, avatar);
return values;
}
@@ -138,7 +138,7 @@ public class Contact implements ListItem {
public Account getAccount() {
return this.account;
}
-
+
public Presences getPresences() {
return this.presences;
}
@@ -309,7 +309,8 @@ public class Contact implements ListItem {
@Override
public int compareTo(ListItem another) {
- return this.getDisplayName().compareToIgnoreCase(another.getDisplayName());
+ return this.getDisplayName().compareToIgnoreCase(
+ another.getDisplayName());
}
public String getServer() {
@@ -323,9 +324,9 @@ public class Contact implements ListItem {
@Override
public Bitmap getImage(int size, Context context) {
- if (this.avatar!=null) {
+ if (this.avatar != null) {
Bitmap bm = FileBackend.getAvatar(avatar, size, context);
- if (bm==null) {
+ if (bm == null) {
return UIHelper.getContactPicture(this, size, context, false);
} else {
return bm;
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index 439f9f22..4c55d5ee 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -88,7 +88,8 @@ public class Conversation extends AbstractEntity {
public List<Message> getMessages() {
if (messages == null) {
- this.messages = new CopyOnWriteArrayList<Message>(); // prevent null pointer
+ this.messages = new CopyOnWriteArrayList<Message>(); // prevent null
+ // pointer
}
// populate with Conversation (this)
@@ -287,7 +288,7 @@ public class Conversation extends AbstractEntity {
public String getOtrFingerprint() {
if (this.otrFingerprint == null) {
try {
- if (getOtrSession()== null) {
+ if (getOtrSession() == null) {
return "";
}
DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession()
@@ -403,15 +404,15 @@ public class Conversation extends AbstractEntity {
}
public Bitmap getImage(Context context, int size) {
- if (mode==MODE_SINGLE) {
+ if (mode == MODE_SINGLE) {
return getContact().getImage(size, context);
} else {
return UIHelper.getContactPicture(this, size, context, false);
}
}
-
+
public boolean hasDuplicateMessage(Message message) {
- for(int i = this.getMessages().size() -1; i >= 0; --i) {
+ for (int i = this.getMessages().size() - 1; i >= 0; --i) {
if (this.messages.get(i).equals(message)) {
return true;
}
diff --git a/src/eu/siacs/conversations/entities/ListItem.java b/src/eu/siacs/conversations/entities/ListItem.java
index c89c85d9..19089b28 100644
--- a/src/eu/siacs/conversations/entities/ListItem.java
+++ b/src/eu/siacs/conversations/entities/ListItem.java
@@ -5,6 +5,8 @@ import android.graphics.Bitmap;
public interface ListItem extends Comparable<ListItem> {
public String getDisplayName();
+
public String getJid();
+
public Bitmap getImage(int dpSize, Context context);
}
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index 09beff52..9e977911 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -142,7 +142,7 @@ public class Message extends AbstractEntity {
}
}
}
-
+
public String getBody() {
return body;
}
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 61b2732d..2958965c 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -299,9 +299,9 @@ public class MucOptions {
return this.conversation.getContactJid().split("/")[0] + "/"
+ this.joinnick;
}
-
+
public String getTrueCounterpart(String counterpart) {
- for(User user : this.getUsers()) {
+ for (User user : this.getUsers()) {
if (user.getName().equals(counterpart)) {
return user.getJid();
}
diff --git a/src/eu/siacs/conversations/entities/Presences.java b/src/eu/siacs/conversations/entities/Presences.java
index acd80735..b5899847 100644
--- a/src/eu/siacs/conversations/entities/Presences.java
+++ b/src/eu/siacs/conversations/entities/Presences.java
@@ -14,7 +14,7 @@ public class Presences {
public static final int XA = 2;
public static final int DND = 3;
public static final int OFFLINE = 4;
-
+
private Hashtable<String, Integer> presences = new Hashtable<String, Integer>();
public Hashtable<String, Integer> getPresences() {
@@ -28,23 +28,24 @@ public class Presences {
public void removePresence(String resource) {
this.presences.remove(resource);
}
-
+
public void clearPresences() {
this.presences.clear();
}
-
+
public int getMostAvailableStatus() {
int status = OFFLINE;
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Integer> entry = it.next();
- if (entry.getValue()<status) status = entry.getValue();
+ if (entry.getValue() < status)
+ status = entry.getValue();
}
return status;
}
public static int parseShow(Element show) {
- if ((show == null)||(show.getContent() == null)) {
+ if ((show == null) || (show.getContent() == null)) {
return Presences.ONLINE;
} else if (show.getContent().equals("away")) {
return Presences.AWAY;
@@ -53,16 +54,16 @@ public class Presences {
} else if (show.getContent().equals("chat")) {
return Presences.CHAT;
} else if (show.getContent().equals("dnd")) {
- return Presences.DND;
+ return Presences.DND;
} else {
return Presences.OFFLINE;
}
}
-
+
public int size() {
return presences.size();
}
-
+
public String[] asStringArray() {
final String[] presencesArray = new String[presences.size()];
presences.keySet().toArray(presencesArray);
diff --git a/src/eu/siacs/conversations/entities/Roster.java b/src/eu/siacs/conversations/entities/Roster.java
index aa328664..c6212f77 100644
--- a/src/eu/siacs/conversations/entities/Roster.java
+++ b/src/eu/siacs/conversations/entities/Roster.java
@@ -9,16 +9,16 @@ public class Roster {
Account account;
ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<String, Contact>();
private String version = null;
-
+
public Roster(Account account) {
this.account = account;
}
-
+
public boolean hasContact(String jid) {
String cleanJid = jid.split("/")[0];
return contacts.containsKey(cleanJid);
}
-
+
public Contact getContact(String jid) {
String cleanJid = jid.split("/")[0].toLowerCase(Locale.getDefault());
if (contacts.containsKey(cleanJid)) {
@@ -32,19 +32,19 @@ public class Roster {
}
public void clearPresences() {
- for(Contact contact : getContacts()) {
+ for (Contact contact : getContacts()) {
contact.clearPresences();
}
}
-
+
public void markAllAsNotInRoster() {
- for(Contact contact : getContacts()) {
+ for (Contact contact : getContacts()) {
contact.resetOption(Contact.Options.IN_ROSTER);
}
}
-
+
public void clearSystemAccounts() {
- for(Contact contact : getContacts()) {
+ for (Contact contact : getContacts()) {
contact.setPhotoUri(null);
contact.setSystemName(null);
contact.setSystemAccount(null);
@@ -58,13 +58,13 @@ public class Roster {
public void initContact(Contact contact) {
contact.setAccount(account);
contact.setOption(Contact.Options.IN_ROSTER);
- contacts.put(contact.getJid(),contact);
+ contacts.put(contact.getJid(), contact);
}
public void setVersion(String version) {
this.version = version;
}
-
+
public String getVersion() {
return this.version;
}