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