Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
public class Album implements JsonExtractable, Parcelable {
public int id;
public String name;
public int photosCount;
public boolean isCurrent;
public boolean isCanDeleted;
public boolean isEnabled;
public Album() {}
private Album(Parcel parcel) {
id = parcel.readInt();
name = parcel.readString();
photosCount = parcel.readInt();
isCurrent = parcel.readInt() == 1;
isCanDeleted = parcel.readInt() == 1;
isEnabled = parcel.readInt() == 1;
}
public String getNameWithCount(String photosSuffix) {
return name + " (" + photosCount + " " + photosSuffix + ")";
}
@Override
public void fromJson(JSONObject json) throws JSONException {
id = json.optInt("id", 0);
name = json.optString("name");
photosCount = json.optInt("photosCount", 0);
isCurrent = json.optBoolean("current");
isCanDeleted = json.optBoolean("canDeleted");
isEnabled = json.optBoolean("enabled");
}
@Override public String toString() { return name; }
public static final Creator<Album> CREATOR = new Parcelable.Creator<Album>() {
@Override
public Album createFromParcel(Parcel parcel) {
return new Album(parcel);
}
@Override
public Album[] newArray(int size) {
return new Album[size];
}
};
@Override public int describeContents() { return 0;}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(id);
parcel.writeString(name);
parcel.writeInt(photosCount);
parcel.writeInt(isCurrent ? 1 : 0);
parcel.writeInt(isCanDeleted ? 1 : 0);
parcel.writeInt(isEnabled ? 1 : 0);
}
}
Командный паттерн вызова удаленных процедур (RPC) в Android