aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java
diff options
context:
space:
mode:
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java')
-rw-r--r--WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java b/WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java
new file mode 100644
index 000000000..a855e716f
--- /dev/null
+++ b/WordPress/src/main/java/org/wordpress/android/models/CommentStatus.java
@@ -0,0 +1,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;
+ }
+} \ No newline at end of file