aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities/PresenceTemplate.java
blob: ab71a41fdf3896bc5221c5a864e130a813e7d707 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package de.pixart.messenger.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() {
        final String show = status.toShowString();
        ContentValues values = new ContentValues();
        values.put(LAST_USED, lastUsed);
        values.put(MESSAGE, statusMessage);
        values.put(STATUS, show == null ? "" : show);
        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;
    }

    @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;
    }
}