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.call;
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.ObjectNode;
00033 import org.xbmc.android.jsonrpc.api.AbstractCall;
00034 import org.xbmc.android.jsonrpc.api.AbstractModel;
00035 import org.xbmc.android.jsonrpc.api.model.ListModel;
00036 import org.xbmc.android.jsonrpc.api.model.PlaylistModel;
00037
00038 public final class Playlist {
00039
00047 public static class Add extends AbstractCall<String> {
00048 public final static String API_TYPE = "Playlist.Add";
00049
00050 @Override
00051 public void writeToParcel(Parcel parcel, int flags) {
00052 super.writeToParcel(parcel, flags);
00053 parcel.writeValue(mResult);
00054 }
00055
00059 protected Add(Parcel parcel) {
00060 super(parcel);
00061 }
00062
00066 public static final Parcelable.Creator<Add> CREATOR = new Parcelable.Creator<Add>() {
00067 @Override
00068 public Add createFromParcel(Parcel parcel) {
00069 return new Add(parcel);
00070 }
00071 @Override
00072 public Add[] newArray(int n) {
00073 return new Add[n];
00074 }
00075 };
00076
00082 public Add(Integer playlistid, PlaylistModel.Item item) {
00083 super();
00084 addParameter("playlistid", playlistid);
00085 addParameter("item", item);
00086 }
00087
00088 @Override
00089 protected String parseOne(JsonNode node) {
00090 return node.getTextValue();
00091 }
00092
00093 @Override
00094 public String getName() {
00095 return API_TYPE;
00096 }
00097
00098 @Override
00099 protected boolean returnsList() {
00100 return false;
00101 }
00102 }
00103
00111 public static class Clear extends AbstractCall<String> {
00112 public final static String API_TYPE = "Playlist.Clear";
00113
00114 @Override
00115 public void writeToParcel(Parcel parcel, int flags) {
00116 super.writeToParcel(parcel, flags);
00117 parcel.writeValue(mResult);
00118 }
00119
00123 protected Clear(Parcel parcel) {
00124 super(parcel);
00125 }
00126
00130 public static final Parcelable.Creator<Clear> CREATOR = new Parcelable.Creator<Clear>() {
00131 @Override
00132 public Clear createFromParcel(Parcel parcel) {
00133 return new Clear(parcel);
00134 }
00135 @Override
00136 public Clear[] newArray(int n) {
00137 return new Clear[n];
00138 }
00139 };
00140
00145 public Clear(Integer playlistid) {
00146 super();
00147 addParameter("playlistid", playlistid);
00148 }
00149
00150 @Override
00151 protected String parseOne(JsonNode node) {
00152 return node.getTextValue();
00153 }
00154
00155 @Override
00156 public String getName() {
00157 return API_TYPE;
00158 }
00159
00160 @Override
00161 protected boolean returnsList() {
00162 return false;
00163 }
00164 }
00165
00173 public static class GetItems extends AbstractCall<ListModel.AllItems> {
00174 public final static String API_TYPE = "Playlist.GetItems";
00175
00176 @Override
00177 public void writeToParcel(Parcel parcel, int flags) {
00178 super.writeToParcel(parcel, flags);
00179 parcel.writeParcelable(mResult, flags);
00180 }
00181
00185 protected GetItems(Parcel parcel) {
00186 super(parcel);
00187 }
00188
00192 public static final Parcelable.Creator<GetItems> CREATOR = new Parcelable.Creator<GetItems>() {
00193 @Override
00194 public GetItems createFromParcel(Parcel parcel) {
00195 return new GetItems(parcel);
00196 }
00197 @Override
00198 public GetItems[] newArray(int n) {
00199 return new GetItems[n];
00200 }
00201 };
00202 public final static String RESULT = "items";
00203
00211 public GetItems(Integer playlistid, ListModel.Limits limits, ListModel.Sort sort, String... properties) {
00212 super();
00213 addParameter("playlistid", playlistid);
00214 addParameter("limits", limits);
00215 addParameter("sort", sort);
00216 addParameter("properties", properties);
00217 }
00218
00224 public GetItems(Integer playlistid, String... properties) {
00225 super();
00226 addParameter("playlistid", playlistid);
00227 addParameter("properties", properties);
00228 }
00229
00236 public GetItems(Integer playlistid, ListModel.Limits limits, String... properties) {
00237 super();
00238 addParameter("playlistid", playlistid);
00239 addParameter("limits", limits);
00240 addParameter("properties", properties);
00241 }
00242
00249 public GetItems(Integer playlistid, ListModel.Sort sort, String... properties) {
00250 super();
00251 addParameter("playlistid", playlistid);
00252 addParameter("sort", sort);
00253 addParameter("properties", properties);
00254 }
00255
00256 @Override
00257 protected ArrayList<ListModel.AllItems> parseMany(JsonNode node) {
00258 final ArrayNode items = parseResults(node, RESULT);
00259 if (items != null) {
00260 final ArrayList<ListModel.AllItems> ret = new ArrayList<ListModel.AllItems>(items.size());
00261 for (int i = 0; i < items.size(); i++) {
00262 final ObjectNode item = (ObjectNode)items.get(i);
00263 ret.add(new ListModel.AllItems(item));
00264 }
00265 return ret;
00266 } else {
00267 return new ArrayList<ListModel.AllItems>(0);
00268 }
00269 }
00270
00271 @Override
00272 public String getName() {
00273 return API_TYPE;
00274 }
00275
00276 @Override
00277 protected boolean returnsList() {
00278 return true;
00279 }
00280 }
00281
00289 public static class GetPlaylists extends AbstractCall<GetPlaylists.GetPlaylistsResult> {
00290 public final static String API_TYPE = "Playlist.GetPlaylists";
00291
00292 @Override
00293 public void writeToParcel(Parcel parcel, int flags) {
00294 super.writeToParcel(parcel, flags);
00295 parcel.writeParcelable(mResult, flags);
00296 }
00297
00301 protected GetPlaylists(Parcel parcel) {
00302 super(parcel);
00303 }
00304
00308 public static final Parcelable.Creator<GetPlaylists> CREATOR = new Parcelable.Creator<GetPlaylists>() {
00309 @Override
00310 public GetPlaylists createFromParcel(Parcel parcel) {
00311 return new GetPlaylists(parcel);
00312 }
00313 @Override
00314 public GetPlaylists[] newArray(int n) {
00315 return new GetPlaylists[n];
00316 }
00317 };
00318
00322 public GetPlaylists() {
00323 super();
00324 }
00325
00326 @Override
00327 protected ArrayList<GetPlaylistsResult> parseMany(JsonNode node) {
00328 final ArrayNode results = (ArrayNode) node;
00329 if (results != null) {
00330 final ArrayList<GetPlaylistsResult> ret = new ArrayList<GetPlaylistsResult>(results.size());
00331 for (int i = 0; i < results.size(); i++) {
00332 final ObjectNode item = (ObjectNode)results.get(i);
00333 ret.add(new GetPlaylistsResult(item));
00334 }
00335 return ret;
00336 } else {
00337 return new ArrayList<GetPlaylistsResult>(0);
00338 }
00339 }
00340
00341 @Override
00342 public String getName() {
00343 return API_TYPE;
00344 }
00345
00346 @Override
00347 protected boolean returnsList() {
00348 return true;
00349 }
00350
00355 public static class GetPlaylistsResult extends AbstractModel {
00356
00357
00358 public static final String PLAYLISTID = "playlistid";
00359 public static final String TYPE = "type";
00360
00361
00362 public final Integer playlistid;
00363 public final String type;
00364
00369 public GetPlaylistsResult(Integer playlistid, String type) {
00370 this.playlistid = playlistid;
00371 this.type = type;
00372 }
00373
00378 public GetPlaylistsResult(JsonNode node) {
00379 playlistid = parseInt(node, PLAYLISTID);
00380 type = parseString(node, TYPE);
00381 }
00382
00383 @Override
00384 public JsonNode toJsonNode() {
00385 final ObjectNode node = OM.createObjectNode();
00386 node.put(PLAYLISTID, playlistid);
00387 node.put(TYPE, type);
00388 return node;
00389 }
00390
00396 static List<GetPlaylistsResult> getPlaylistGetPlaylistsResultList(JsonNode node, String key) {
00397 if (node.has(key)) {
00398 final ArrayNode a = (ArrayNode)node.get(key);
00399 final List<GetPlaylistsResult> l = new ArrayList<GetPlaylistsResult>(a.size());
00400 for (int i = 0; i < a.size(); i++) {
00401 l.add(new GetPlaylistsResult((JsonNode)a.get(i)));
00402 }
00403 return l;
00404 }
00405 return new ArrayList<GetPlaylistsResult>(0);
00406 }
00407
00413 @Override
00414 public void writeToParcel(Parcel parcel, int flags) {
00415 parcel.writeValue(playlistid);
00416 parcel.writeValue(type);
00417 }
00418
00422 protected GetPlaylistsResult(Parcel parcel) {
00423 playlistid = parcel.readInt();
00424 type = parcel.readString();
00425 }
00426
00430 public static final Parcelable.Creator<GetPlaylistsResult> CREATOR = new Parcelable.Creator<GetPlaylistsResult>() {
00431 @Override
00432 public GetPlaylistsResult createFromParcel(Parcel parcel) {
00433 return new GetPlaylistsResult(parcel);
00434 }
00435 @Override
00436 public GetPlaylistsResult[] newArray(int n) {
00437 return new GetPlaylistsResult[n];
00438 }
00439 };
00440
00441 @Override
00442 public int describeContents() {
00443 return 0;
00444 }
00445
00449 public interface Type {
00450
00451 public final String UNKNOWN = "unknown";
00452 public final String VIDEO = "video";
00453 public final String AUDIO = "audio";
00454 public final String PICTURE = "picture";
00455 public final String MIXED = "mixed";
00456
00457 public final static Set<String> values = new HashSet<String>(Arrays.asList(UNKNOWN, VIDEO, AUDIO, PICTURE, MIXED));
00458 }
00459 }
00460 }
00461
00469 public static class GetProperties extends AbstractCall<PlaylistModel.PropertyValue> {
00470 public final static String API_TYPE = "Playlist.GetProperties";
00471
00472 @Override
00473 public void writeToParcel(Parcel parcel, int flags) {
00474 super.writeToParcel(parcel, flags);
00475 parcel.writeParcelable(mResult, flags);
00476 }
00477
00481 protected GetProperties(Parcel parcel) {
00482 super(parcel);
00483 }
00484
00488 public static final Parcelable.Creator<GetProperties> CREATOR = new Parcelable.Creator<GetProperties>() {
00489 @Override
00490 public GetProperties createFromParcel(Parcel parcel) {
00491 return new GetProperties(parcel);
00492 }
00493 @Override
00494 public GetProperties[] newArray(int n) {
00495 return new GetProperties[n];
00496 }
00497 };
00498
00504 public GetProperties(Integer playlistid, String... properties) {
00505 super();
00506 addParameter("playlistid", playlistid);
00507 addParameter("properties", properties);
00508 }
00509
00510 @Override
00511 protected PlaylistModel.PropertyValue parseOne(JsonNode node) {
00512 return new PlaylistModel.PropertyValue(node);
00513 }
00514
00515 @Override
00516 public String getName() {
00517 return API_TYPE;
00518 }
00519
00520 @Override
00521 protected boolean returnsList() {
00522 return false;
00523 }
00524 }
00525
00533 public static class Insert extends AbstractCall<String> {
00534 public final static String API_TYPE = "Playlist.Insert";
00535
00536 @Override
00537 public void writeToParcel(Parcel parcel, int flags) {
00538 super.writeToParcel(parcel, flags);
00539 parcel.writeValue(mResult);
00540 }
00541
00545 protected Insert(Parcel parcel) {
00546 super(parcel);
00547 }
00548
00552 public static final Parcelable.Creator<Insert> CREATOR = new Parcelable.Creator<Insert>() {
00553 @Override
00554 public Insert createFromParcel(Parcel parcel) {
00555 return new Insert(parcel);
00556 }
00557 @Override
00558 public Insert[] newArray(int n) {
00559 return new Insert[n];
00560 }
00561 };
00562
00569 public Insert(Integer playlistid, Integer position, PlaylistModel.Item item) {
00570 super();
00571 addParameter("playlistid", playlistid);
00572 addParameter("position", position);
00573 addParameter("item", item);
00574 }
00575
00576 @Override
00577 protected String parseOne(JsonNode node) {
00578 return node.getTextValue();
00579 }
00580
00581 @Override
00582 public String getName() {
00583 return API_TYPE;
00584 }
00585
00586 @Override
00587 protected boolean returnsList() {
00588 return false;
00589 }
00590 }
00591
00599 public static class Remove extends AbstractCall<String> {
00600 public final static String API_TYPE = "Playlist.Remove";
00601
00602 @Override
00603 public void writeToParcel(Parcel parcel, int flags) {
00604 super.writeToParcel(parcel, flags);
00605 parcel.writeValue(mResult);
00606 }
00607
00611 protected Remove(Parcel parcel) {
00612 super(parcel);
00613 }
00614
00618 public static final Parcelable.Creator<Remove> CREATOR = new Parcelable.Creator<Remove>() {
00619 @Override
00620 public Remove createFromParcel(Parcel parcel) {
00621 return new Remove(parcel);
00622 }
00623 @Override
00624 public Remove[] newArray(int n) {
00625 return new Remove[n];
00626 }
00627 };
00628
00634 public Remove(Integer playlistid, Integer position) {
00635 super();
00636 addParameter("playlistid", playlistid);
00637 addParameter("position", position);
00638 }
00639
00640 @Override
00641 protected String parseOne(JsonNode node) {
00642 return node.getTextValue();
00643 }
00644
00645 @Override
00646 public String getName() {
00647 return API_TYPE;
00648 }
00649
00650 @Override
00651 protected boolean returnsList() {
00652 return false;
00653 }
00654 }
00655
00663 public static class Swap extends AbstractCall<String> {
00664 public final static String API_TYPE = "Playlist.Swap";
00665
00666 @Override
00667 public void writeToParcel(Parcel parcel, int flags) {
00668 super.writeToParcel(parcel, flags);
00669 parcel.writeValue(mResult);
00670 }
00671
00675 protected Swap(Parcel parcel) {
00676 super(parcel);
00677 }
00678
00682 public static final Parcelable.Creator<Swap> CREATOR = new Parcelable.Creator<Swap>() {
00683 @Override
00684 public Swap createFromParcel(Parcel parcel) {
00685 return new Swap(parcel);
00686 }
00687 @Override
00688 public Swap[] newArray(int n) {
00689 return new Swap[n];
00690 }
00691 };
00692
00699 public Swap(Integer playlistid, Integer position1, Integer position2) {
00700 super();
00701 addParameter("playlistid", playlistid);
00702 addParameter("position1", position1);
00703 addParameter("position2", position2);
00704 }
00705
00706 @Override
00707 protected String parseOne(JsonNode node) {
00708 return node.getTextValue();
00709 }
00710
00711 @Override
00712 public String getName() {
00713 return API_TYPE;
00714 }
00715
00716 @Override
00717 protected boolean returnsList() {
00718 return false;
00719 }
00720 }
00721 }