mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-03 16:48:52 +02:00
JsonSerialisable is also Parcelable
This commit is contained in:
parent
ec71c73e11
commit
1a40e8d633
4 changed files with 117 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
|||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -21,6 +24,30 @@ public class ClientInfo implements JsonSerialisable {
|
|||
fromJson(json);
|
||||
}
|
||||
|
||||
protected ClientInfo(Parcel in) {
|
||||
mac = in.readString();
|
||||
ip = in.readString();
|
||||
host = in.readString();
|
||||
version = in.readString();
|
||||
name = in.readString();
|
||||
volume = in.readParcelable(Volume.class.getClassLoader());
|
||||
lastSeen = in.readParcelable(Time_t.class.getClassLoader());
|
||||
connected = in.readByte() != 0;
|
||||
latency = in.readInt();
|
||||
}
|
||||
|
||||
public static final Creator<ClientInfo> CREATOR = new Creator<ClientInfo>() {
|
||||
@Override
|
||||
public ClientInfo createFromParcel(Parcel in) {
|
||||
return new ClientInfo(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientInfo[] newArray(int size) {
|
||||
return new ClientInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
|
@ -154,5 +181,24 @@ public class ClientInfo implements JsonSerialisable {
|
|||
result = 31 * result + latency;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mac);
|
||||
dest.writeString(ip);
|
||||
dest.writeString(host);
|
||||
dest.writeString(version);
|
||||
dest.writeString(name);
|
||||
dest.writeParcelable(volume, flags);
|
||||
dest.writeParcelable(lastSeen, flags);
|
||||
dest.writeByte((byte) (connected ? 1 : 0));
|
||||
dest.writeInt(latency);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 08.01.16.
|
||||
*/
|
||||
public interface JsonSerialisable {
|
||||
public interface JsonSerialisable extends Parcelable {
|
||||
public void fromJson(JSONObject json);
|
||||
public JSONObject toJson();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -7,6 +10,17 @@ import org.json.JSONObject;
|
|||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Time_t implements JsonSerialisable {
|
||||
public static final Creator<Time_t> CREATOR = new Creator<Time_t>() {
|
||||
@Override
|
||||
public Time_t createFromParcel(Parcel in) {
|
||||
return new Time_t(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time_t[] newArray(int size) {
|
||||
return new Time_t[size];
|
||||
}
|
||||
};
|
||||
private int sec;
|
||||
private int usec;
|
||||
|
||||
|
@ -19,6 +33,11 @@ public class Time_t implements JsonSerialisable {
|
|||
this.usec = usec;
|
||||
}
|
||||
|
||||
protected Time_t(Parcel in) {
|
||||
sec = in.readInt();
|
||||
usec = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
|
@ -45,14 +64,14 @@ public class Time_t implements JsonSerialisable {
|
|||
return sec;
|
||||
}
|
||||
|
||||
public int getUsec() {
|
||||
return usec;
|
||||
}
|
||||
|
||||
public void setSec(int sec) {
|
||||
this.sec = sec;
|
||||
}
|
||||
|
||||
public int getUsec() {
|
||||
return usec;
|
||||
}
|
||||
|
||||
public void setUsec(int usec) {
|
||||
this.usec = usec;
|
||||
}
|
||||
|
@ -83,4 +102,15 @@ public class Time_t implements JsonSerialisable {
|
|||
result = 31 * result + usec;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(sec);
|
||||
dest.writeInt(usec);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -7,6 +10,17 @@ import org.json.JSONObject;
|
|||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Volume implements JsonSerialisable {
|
||||
public static final Creator<Volume> CREATOR = new Creator<Volume>() {
|
||||
@Override
|
||||
public Volume createFromParcel(Parcel in) {
|
||||
return new Volume(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume[] newArray(int size) {
|
||||
return new Volume[size];
|
||||
}
|
||||
};
|
||||
private boolean muted;
|
||||
private int percent;
|
||||
|
||||
|
@ -19,6 +33,11 @@ public class Volume implements JsonSerialisable {
|
|||
this.muted = muted;
|
||||
}
|
||||
|
||||
protected Volume(Parcel in) {
|
||||
muted = in.readByte() != 0;
|
||||
percent = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
|
@ -45,6 +64,10 @@ public class Volume implements JsonSerialisable {
|
|||
return percent;
|
||||
}
|
||||
|
||||
public void setPercent(int percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
public boolean isMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
@ -53,10 +76,6 @@ public class Volume implements JsonSerialisable {
|
|||
this.muted = muted;
|
||||
}
|
||||
|
||||
public void setPercent(int percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Volume{" +
|
||||
|
@ -83,4 +102,15 @@ public class Volume implements JsonSerialisable {
|
|||
result = 31 * result + percent;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeByte((byte) (muted ? 1 : 0));
|
||||
dest.writeInt(percent);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue