aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java
blob: a855e716f2a1ff862a7d43461d102dd8440f102b (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
77
78
79
80
81
82
83
package org.wordpress.android.models;

import android.support.annotation.StringRes;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;

public enum CommentStatus implements FilterCriteria {
    UNKNOWN(R.string.comment_status_all),
    UNAPPROVED(R.string.comment_status_unapproved),
    APPROVED(R.string.comment_status_approved),
    TRASH(R.string.comment_status_trash),
    SPAM(R.string.comment_status_spam),
    DELETE(R.string.comment_status_trash);

    private final int mLabelResId;

    CommentStatus(@StringRes int labelResId) {
        mLabelResId = labelResId;
    }

    @Override
    public String getLabel() {
        return WordPress.getContext().getString(mLabelResId);
    }

    /*
     * returns the string representation of the passed status, as used by the XMLRPC API
     */
    public static String toString(CommentStatus status) {
        if (status == null){
            return "";
        }

        switch (status) {
            case UNAPPROVED:
                return "hold";
            case APPROVED:
                return "approve";
            case SPAM:
                return "spam";
            case TRASH:
                return "trash";
            default:
                return "";
        }
    }

    /*
     * returns the string representation of the passed status, as used by the REST API
     */
    public static String toRESTString(CommentStatus status) {
        switch (status) {
            case UNAPPROVED:
                return "unapproved";
            case APPROVED:
                return "approved";
            case SPAM:
                return "spam";
            case TRASH:
                return "trash";
            default:
                return "all";
        }
    }

    /*
     * returns the status associated with the passed strings - handles both XMLRPC and REST
     */
    public static CommentStatus fromString(String value) {
        if (value == null)
            return CommentStatus.UNKNOWN;
        if (value.equals("approve") || value.equals("approved"))
            return CommentStatus.APPROVED;
        if (value.equals("hold") || value.equals("unapproved"))
            return CommentStatus.UNAPPROVED;
        if (value.equals("spam"))
            return SPAM;
        if (value.equals("trash"))
            return TRASH;
        return CommentStatus.UNKNOWN;
    }
}