2016-04-22 19:25:06 +00:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
|
|
|
|
public class PresenceTemplate extends AbstractEntity {
|
|
|
|
|
|
|
|
public static final String TABELNAME = "presence_templates";
|
|
|
|
public static final String LAST_USED = "last_used";
|
|
|
|
public static final String MESSAGE = "message";
|
|
|
|
public static final String STATUS = "status";
|
|
|
|
|
|
|
|
private long lastUsed = 0;
|
|
|
|
private String statusMessage;
|
|
|
|
private Presence.Status status = Presence.Status.ONLINE;
|
|
|
|
|
|
|
|
public PresenceTemplate(Presence.Status status, String statusMessage) {
|
|
|
|
this.status = status;
|
|
|
|
this.statusMessage = statusMessage;
|
|
|
|
this.lastUsed = System.currentTimeMillis();
|
|
|
|
this.uuid = java.util.UUID.randomUUID().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private PresenceTemplate() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ContentValues getContentValues() {
|
2016-05-03 20:16:51 +00:00
|
|
|
final String show = status.toShowString();
|
2016-04-22 19:25:06 +00:00
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(LAST_USED, lastUsed);
|
|
|
|
values.put(MESSAGE, statusMessage);
|
2016-05-03 20:16:51 +00:00
|
|
|
values.put(STATUS, show == null ? "" : show);
|
2016-04-22 19:25:06 +00:00
|
|
|
values.put(UUID, uuid);
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PresenceTemplate fromCursor(Cursor cursor) {
|
|
|
|
PresenceTemplate template = new PresenceTemplate();
|
|
|
|
template.uuid = cursor.getString(cursor.getColumnIndex(UUID));
|
|
|
|
template.lastUsed = cursor.getLong(cursor.getColumnIndex(LAST_USED));
|
|
|
|
template.statusMessage = cursor.getString(cursor.getColumnIndex(MESSAGE));
|
|
|
|
template.status = Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndex(STATUS)));
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Presence.Status getStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getStatusMessage() {
|
|
|
|
return statusMessage;
|
|
|
|
}
|
2016-05-13 08:45:30 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
|
|
|
|
PresenceTemplate template = (PresenceTemplate) o;
|
|
|
|
|
|
|
|
if (statusMessage != null ? !statusMessage.equals(template.statusMessage) : template.statusMessage != null)
|
|
|
|
return false;
|
|
|
|
return status == template.status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = statusMessage != null ? statusMessage.hashCode() : 0;
|
|
|
|
result = 31 * result + status.hashCode();
|
|
|
|
return result;
|
|
|
|
}
|
2018-03-03 11:27:46 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return statusMessage;
|
|
|
|
}
|
2016-04-22 19:25:06 +00:00
|
|
|
}
|