00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package org.xbmc.android.jsonrpc.api.model;
00022
00023 import android.os.Parcel;
00024 import android.os.Parcelable;
00025 import java.util.ArrayList;
00026 import java.util.Arrays;
00027 import java.util.HashSet;
00028 import java.util.List;
00029 import java.util.Set;
00030 import org.codehaus.jackson.JsonNode;
00031 import org.codehaus.jackson.node.ArrayNode;
00032 import org.codehaus.jackson.node.IntNode;
00033 import org.codehaus.jackson.node.ObjectNode;
00034 import org.codehaus.jackson.node.TextNode;
00035 import org.xbmc.android.jsonrpc.api.AbstractModel;
00036
00037 public final class PVRModel {
00038
00045 public static class ChannelGroupId extends AbstractModel {
00046 public final static String API_TYPE = "PVR.ChannelGroup.Id";
00047
00048
00049 public final Integer id;
00050 public final String stringArg;
00051
00055 public ChannelGroupId(Integer id) {
00056 this.id = id;
00057 this.stringArg = null;
00058 }
00059
00063 public ChannelGroupId(String stringArg) {
00064 this.stringArg = stringArg;
00065 this.id = null;
00066 }
00067
00068 @Override
00069 public JsonNode toJsonNode() {
00070 if (id != null) {
00071 return new IntNode(id);
00072 }
00073 if (stringArg != null) {
00074 return new TextNode(stringArg);
00075 }
00076 return null;
00077 }
00078
00084 @Override
00085 public void writeToParcel(Parcel parcel, int flags) {
00086 parcel.writeValue(id);
00087 parcel.writeValue(stringArg);
00088 }
00089
00093 protected ChannelGroupId(Parcel parcel) {
00094 id = parcel.readInt();
00095 stringArg = parcel.readString();
00096 }
00097
00101 public static final Parcelable.Creator<ChannelGroupId> CREATOR = new Parcelable.Creator<ChannelGroupId>() {
00102 @Override
00103 public ChannelGroupId createFromParcel(Parcel parcel) {
00104 return new ChannelGroupId(parcel);
00105 }
00106 @Override
00107 public ChannelGroupId[] newArray(int n) {
00108 return new ChannelGroupId[n];
00109 }
00110 };
00111
00112 @Override
00113 public int describeContents() {
00114 return 0;
00115 }
00116
00120 public interface StringArg {
00121
00122 public final String ALLTV = "alltv";
00123 public final String ALLRADIO = "allradio";
00124
00125 public final static Set<String> values = new HashSet<String>(Arrays.asList(ALLTV, ALLRADIO));
00126 }
00127 }
00128
00135 public static class ChannelDetail extends ItemModel.BaseDetail {
00136 public final static String API_TYPE = "PVR.Details.Channel";
00137
00138
00139 public static final String CHANNEL = "channel";
00140 public static final String CHANNELID = "channelid";
00141 public static final String CHANNELTYPE = "channeltype";
00142 public static final String HIDDEN = "hidden";
00143 public static final String LASTPLAYED = "lastplayed";
00144 public static final String LOCKED = "locked";
00145 public static final String THUMBNAIL = "thumbnail";
00146
00147
00148 public final String channel;
00149 public final Integer channelid;
00150 public final String channeltype;
00151 public final Boolean hidden;
00152 public final String lastplayed;
00153 public final Boolean locked;
00154 public final String thumbnail;
00155
00160 public ChannelDetail(JsonNode node) {
00161 super(node);
00162 channel = parseString(node, CHANNEL);
00163 channelid = parseInt(node, CHANNELID);
00164 channeltype = parseString(node, CHANNELTYPE);
00165 hidden = parseBoolean(node, HIDDEN);
00166 lastplayed = parseString(node, LASTPLAYED);
00167 locked = parseBoolean(node, LOCKED);
00168 thumbnail = parseString(node, THUMBNAIL);
00169 }
00170
00171 @Override
00172 public JsonNode toJsonNode() {
00173 final ObjectNode node = (ObjectNode)super.toJsonNode();
00174 node.put(CHANNEL, channel);
00175 node.put(CHANNELID, channelid);
00176 node.put(CHANNELTYPE, channeltype);
00177 node.put(HIDDEN, hidden);
00178 node.put(LASTPLAYED, lastplayed);
00179 node.put(LOCKED, locked);
00180 node.put(THUMBNAIL, thumbnail);
00181 return node;
00182 }
00183
00189 static List<ChannelDetail> getPVRModelChannelDetailList(JsonNode node, String key) {
00190 if (node.has(key)) {
00191 final ArrayNode a = (ArrayNode)node.get(key);
00192 final List<ChannelDetail> l = new ArrayList<ChannelDetail>(a.size());
00193 for (int i = 0; i < a.size(); i++) {
00194 l.add(new ChannelDetail((JsonNode)a.get(i)));
00195 }
00196 return l;
00197 }
00198 return new ArrayList<ChannelDetail>(0);
00199 }
00200
00206 @Override
00207 public void writeToParcel(Parcel parcel, int flags) {
00208 super.writeToParcel(parcel, flags);
00209 parcel.writeValue(channel);
00210 parcel.writeValue(channelid);
00211 parcel.writeValue(channeltype);
00212 parcel.writeInt(hidden ? 1 : 0);
00213 parcel.writeValue(lastplayed);
00214 parcel.writeInt(locked ? 1 : 0);
00215 parcel.writeValue(thumbnail);
00216 }
00217
00221 protected ChannelDetail(Parcel parcel) {
00222 super(parcel);
00223 channel = parcel.readString();
00224 channelid = parcel.readInt();
00225 channeltype = parcel.readString();
00226 hidden = parcel.readInt() == 1;
00227 lastplayed = parcel.readString();
00228 locked = parcel.readInt() == 1;
00229 thumbnail = parcel.readString();
00230 }
00231
00235 public static final Parcelable.Creator<ChannelDetail> CREATOR = new Parcelable.Creator<ChannelDetail>() {
00236 @Override
00237 public ChannelDetail createFromParcel(Parcel parcel) {
00238 return new ChannelDetail(parcel);
00239 }
00240 @Override
00241 public ChannelDetail[] newArray(int n) {
00242 return new ChannelDetail[n];
00243 }
00244 };
00245
00246 @Override
00247 public int describeContents() {
00248 return 0;
00249 }
00250
00254 public interface Channeltype {
00255
00256 public final String TV = "tv";
00257 public final String RADIO = "radio";
00258
00259 public final static Set<String> values = new HashSet<String>(Arrays.asList(TV, RADIO));
00260 }
00261 }
00262
00269 public static class ChannelGroupDetail extends ItemModel.BaseDetail {
00270 public final static String API_TYPE = "PVR.Details.ChannelGroup";
00271
00272
00273 public static final String CHANNELGROUPID = "channelgroupid";
00274 public static final String CHANNELTYPE = "channeltype";
00275
00276
00277 public final Integer channelgroupid;
00278 public final String channeltype;
00279
00284 public ChannelGroupDetail(JsonNode node) {
00285 super(node);
00286 channelgroupid = parseInt(node, CHANNELGROUPID);
00287 channeltype = parseString(node, CHANNELTYPE);
00288 }
00289
00290 @Override
00291 public JsonNode toJsonNode() {
00292 final ObjectNode node = (ObjectNode)super.toJsonNode();
00293 node.put(CHANNELGROUPID, channelgroupid);
00294 node.put(CHANNELTYPE, channeltype);
00295 return node;
00296 }
00297
00303 static List<ChannelGroupDetail> getPVRModelChannelGroupDetailList(JsonNode node, String key) {
00304 if (node.has(key)) {
00305 final ArrayNode a = (ArrayNode)node.get(key);
00306 final List<ChannelGroupDetail> l = new ArrayList<ChannelGroupDetail>(a.size());
00307 for (int i = 0; i < a.size(); i++) {
00308 l.add(new ChannelGroupDetail((JsonNode)a.get(i)));
00309 }
00310 return l;
00311 }
00312 return new ArrayList<ChannelGroupDetail>(0);
00313 }
00314
00320 @Override
00321 public void writeToParcel(Parcel parcel, int flags) {
00322 super.writeToParcel(parcel, flags);
00323 parcel.writeValue(channelgroupid);
00324 parcel.writeValue(channeltype);
00325 }
00326
00330 protected ChannelGroupDetail(Parcel parcel) {
00331 super(parcel);
00332 channelgroupid = parcel.readInt();
00333 channeltype = parcel.readString();
00334 }
00335
00339 public static final Parcelable.Creator<ChannelGroupDetail> CREATOR = new Parcelable.Creator<ChannelGroupDetail>() {
00340 @Override
00341 public ChannelGroupDetail createFromParcel(Parcel parcel) {
00342 return new ChannelGroupDetail(parcel);
00343 }
00344 @Override
00345 public ChannelGroupDetail[] newArray(int n) {
00346 return new ChannelGroupDetail[n];
00347 }
00348 };
00349
00350 @Override
00351 public int describeContents() {
00352 return 0;
00353 }
00354
00358 public interface Channeltype {
00359
00360 public final String TV = "tv";
00361 public final String RADIO = "radio";
00362
00363 public final static Set<String> values = new HashSet<String>(Arrays.asList(TV, RADIO));
00364 }
00365 }
00366
00373 public static class ChannelGroupExtendedDetail extends ChannelGroupDetail {
00374 public final static String API_TYPE = "PVR.Details.ChannelGroup.Extended";
00375
00376
00377 public static final String CHANNELS = "channels";
00378 public static final String LIMITS = "limits";
00379
00380
00381 public final List<ChannelDetail> channels;
00382 public final ListModel.LimitsReturned limits;
00383
00388 public ChannelGroupExtendedDetail(JsonNode node) {
00389 super(node);
00390 channels = ChannelDetail.getPVRModelChannelDetailList(node, CHANNELS);
00391 limits = node.has(LIMITS) ? new ListModel.LimitsReturned(node.get(LIMITS)) : null;
00392 }
00393
00394 @Override
00395 public JsonNode toJsonNode() {
00396 final ObjectNode node = (ObjectNode)super.toJsonNode();
00397 final ArrayNode channelsArray = OM.createArrayNode();
00398 for (ChannelDetail item : channels) {
00399 channelsArray.add(item.toJsonNode());
00400 }
00401 node.put(CHANNELS, channelsArray);
00402 node.put(LIMITS, limits.toJsonNode());
00403 return node;
00404 }
00405
00411 static List<ChannelGroupExtendedDetail> getPVRModelChannelGroupExtendedDetailList(JsonNode node, String key) {
00412 if (node.has(key)) {
00413 final ArrayNode a = (ArrayNode)node.get(key);
00414 final List<ChannelGroupExtendedDetail> l = new ArrayList<ChannelGroupExtendedDetail>(a.size());
00415 for (int i = 0; i < a.size(); i++) {
00416 l.add(new ChannelGroupExtendedDetail((JsonNode)a.get(i)));
00417 }
00418 return l;
00419 }
00420 return new ArrayList<ChannelGroupExtendedDetail>(0);
00421 }
00422
00428 @Override
00429 public void writeToParcel(Parcel parcel, int flags) {
00430 super.writeToParcel(parcel, flags);
00431 parcel.writeInt(channels.size());
00432 for (ChannelDetail item : channels) {
00433 parcel.writeParcelable(item, flags);
00434 }
00435 parcel.writeValue(limits);
00436 }
00437
00441 protected ChannelGroupExtendedDetail(Parcel parcel) {
00442 super(parcel);
00443 final int channelsSize = parcel.readInt();
00444 channels = new ArrayList<ChannelDetail>(channelsSize);
00445 for (int i = 0; i < channelsSize; i++) {
00446 channels.add(parcel.<ChannelDetail>readParcelable(ChannelDetail.class.getClassLoader()));
00447 }
00448 limits = parcel.<ListModel.LimitsReturned>readParcelable(ListModel.LimitsReturned.class.getClassLoader());
00449 }
00450
00454 public static final Parcelable.Creator<ChannelGroupExtendedDetail> CREATOR = new Parcelable.Creator<ChannelGroupExtendedDetail>() {
00455 @Override
00456 public ChannelGroupExtendedDetail createFromParcel(Parcel parcel) {
00457 return new ChannelGroupExtendedDetail(parcel);
00458 }
00459 @Override
00460 public ChannelGroupExtendedDetail[] newArray(int n) {
00461 return new ChannelGroupExtendedDetail[n];
00462 }
00463 };
00464
00465 @Override
00466 public int describeContents() {
00467 return 0;
00468 }
00469 }
00470
00477 public static class PropertyValue extends AbstractModel {
00478 public final static String API_TYPE = "PVR.Property.Value";
00479
00480
00481 public static final String AVAILABLE = "available";
00482 public static final String RECORDING = "recording";
00483 public static final String SCANNING = "scanning";
00484
00485
00486 public final Boolean available;
00487 public final Boolean recording;
00488 public final Boolean scanning;
00489
00495 public PropertyValue(Boolean available, Boolean recording, Boolean scanning) {
00496 this.available = available;
00497 this.recording = recording;
00498 this.scanning = scanning;
00499 }
00500
00505 public PropertyValue(JsonNode node) {
00506 available = parseBoolean(node, AVAILABLE);
00507 recording = parseBoolean(node, RECORDING);
00508 scanning = parseBoolean(node, SCANNING);
00509 }
00510
00511 @Override
00512 public JsonNode toJsonNode() {
00513 final ObjectNode node = OM.createObjectNode();
00514 node.put(AVAILABLE, available);
00515 node.put(RECORDING, recording);
00516 node.put(SCANNING, scanning);
00517 return node;
00518 }
00519
00525 static List<PropertyValue> getPVRModelPropertyValueList(JsonNode node, String key) {
00526 if (node.has(key)) {
00527 final ArrayNode a = (ArrayNode)node.get(key);
00528 final List<PropertyValue> l = new ArrayList<PropertyValue>(a.size());
00529 for (int i = 0; i < a.size(); i++) {
00530 l.add(new PropertyValue((JsonNode)a.get(i)));
00531 }
00532 return l;
00533 }
00534 return new ArrayList<PropertyValue>(0);
00535 }
00536
00542 @Override
00543 public void writeToParcel(Parcel parcel, int flags) {
00544 parcel.writeInt(available ? 1 : 0);
00545 parcel.writeInt(recording ? 1 : 0);
00546 parcel.writeInt(scanning ? 1 : 0);
00547 }
00548
00552 protected PropertyValue(Parcel parcel) {
00553 available = parcel.readInt() == 1;
00554 recording = parcel.readInt() == 1;
00555 scanning = parcel.readInt() == 1;
00556 }
00557
00561 public static final Parcelable.Creator<PropertyValue> CREATOR = new Parcelable.Creator<PropertyValue>() {
00562 @Override
00563 public PropertyValue createFromParcel(Parcel parcel) {
00564 return new PropertyValue(parcel);
00565 }
00566 @Override
00567 public PropertyValue[] newArray(int n) {
00568 return new PropertyValue[n];
00569 }
00570 };
00571
00572 @Override
00573 public int describeContents() {
00574 return 0;
00575 }
00576 }
00577
00581 public interface ChannelType {
00582
00583 public final String TV = "tv";
00584 public final String RADIO = "radio";
00585
00586 public final static Set<String> values = new HashSet<String>(Arrays.asList(TV, RADIO));
00587 }
00588
00592 public interface ChannelFields {
00593
00594 public final String THUMBNAIL = "thumbnail";
00595 public final String CHANNELTYPE = "channeltype";
00596 public final String HIDDEN = "hidden";
00597 public final String LOCKED = "locked";
00598 public final String CHANNEL = "channel";
00599 public final String LASTPLAYED = "lastplayed";
00600
00601 public final static Set<String> values = new HashSet<String>(Arrays.asList(THUMBNAIL, CHANNELTYPE, HIDDEN, LOCKED, CHANNEL, LASTPLAYED));
00602 }
00603
00607 public interface PropertyName {
00608
00609 public final String AVAILABLE = "available";
00610 public final String RECORDING = "recording";
00611 public final String SCANNING = "scanning";
00612
00613 public final static Set<String> values = new HashSet<String>(Arrays.asList(AVAILABLE, RECORDING, SCANNING));
00614 }
00615 }