code cleanup in Contact class
This commit is contained in:
parent
ce00767777
commit
acdf822415
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -37,18 +38,18 @@ public class Contact implements ListItem, Blockable {
|
|||
public static final String LAST_PRESENCE = "last_presence";
|
||||
public static final String LAST_TIME = "last_time";
|
||||
public static final String GROUPS = "groups";
|
||||
protected String accountUuid;
|
||||
protected String systemName;
|
||||
protected String serverName;
|
||||
protected String presenceName;
|
||||
protected String commonName;
|
||||
private String accountUuid;
|
||||
private String systemName;
|
||||
private String serverName;
|
||||
private String presenceName;
|
||||
private String commonName;
|
||||
protected Jid jid;
|
||||
protected int subscription = 0;
|
||||
protected String systemAccount;
|
||||
protected String photoUri;
|
||||
protected JSONObject keys = new JSONObject();
|
||||
protected JSONArray groups = new JSONArray();
|
||||
protected final Presences presences = new Presences();
|
||||
private int subscription = 0;
|
||||
private String systemAccount;
|
||||
private String photoUri;
|
||||
private final JSONObject keys;
|
||||
private JSONArray groups = new JSONArray();
|
||||
private final Presences presences = new Presences();
|
||||
protected Account account;
|
||||
protected Avatar avatar;
|
||||
|
||||
|
@ -67,11 +68,13 @@ public class Contact implements ListItem, Blockable {
|
|||
this.subscription = subscription;
|
||||
this.photoUri = photoUri;
|
||||
this.systemAccount = systemAccount;
|
||||
JSONObject tmpJsonObject;
|
||||
try {
|
||||
this.keys = (keys == null ? new JSONObject("") : new JSONObject(keys));
|
||||
tmpJsonObject = (keys == null ? new JSONObject("") : new JSONObject(keys));
|
||||
} catch (JSONException e) {
|
||||
this.keys = new JSONObject();
|
||||
tmpJsonObject = new JSONObject();
|
||||
}
|
||||
this.keys = tmpJsonObject;
|
||||
if (avatar != null) {
|
||||
this.avatar = new Avatar();
|
||||
this.avatar.sha1sum = avatar;
|
||||
|
@ -88,6 +91,7 @@ public class Contact implements ListItem, Blockable {
|
|||
|
||||
public Contact(final Jid jid) {
|
||||
this.jid = jid;
|
||||
this.keys = new JSONObject();
|
||||
}
|
||||
|
||||
public static Contact fromCursor(final Cursor cursor) {
|
||||
|
@ -119,7 +123,7 @@ public class Contact implements ListItem, Blockable {
|
|||
return this.systemName;
|
||||
} else if (!TextUtils.isEmpty(this.serverName)) {
|
||||
return this.serverName;
|
||||
} else if (!TextUtils.isEmpty(this.presenceName) && mutualPresenceSubscription() ) {
|
||||
} else if (!TextUtils.isEmpty(this.presenceName) && mutualPresenceSubscription()) {
|
||||
return this.presenceName;
|
||||
} else if (jid.getLocal() != null) {
|
||||
return JidHelper.localPartOrFallback(jid);
|
||||
|
@ -159,8 +163,8 @@ public class Contact implements ListItem, Blockable {
|
|||
needle = needle.toLowerCase(Locale.US).trim();
|
||||
String[] parts = needle.split("\\s+");
|
||||
if (parts.length > 1) {
|
||||
for(int i = 0; i < parts.length; ++i) {
|
||||
if (!match(context, parts[i])) {
|
||||
for (String part : parts) {
|
||||
if (!match(context, part)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -277,8 +281,8 @@ public class Contact implements ListItem, Blockable {
|
|||
this.systemAccount = account;
|
||||
}
|
||||
|
||||
public List<String> getGroups() {
|
||||
ArrayList<String> groups = new ArrayList<String>();
|
||||
private List<String> getGroups() {
|
||||
ArrayList<String> groups = new ArrayList<>();
|
||||
for (int i = 0; i < this.groups.length(); ++i) {
|
||||
try {
|
||||
groups.add(this.groups.getString(i));
|
||||
|
@ -390,7 +394,7 @@ public class Contact implements ListItem, Blockable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ListItem another) {
|
||||
public int compareTo(@NonNull final ListItem another) {
|
||||
return this.getDisplayName().compareToIgnoreCase(
|
||||
another.getDisplayName());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue