Browse Source

Make folder serializable

main
M66B 6 years ago
parent
commit
5fe713180d
2 changed files with 12 additions and 82 deletions
  1. +2
    -72
      app/src/main/java/eu/faircode/email/EntityFolder.java
  2. +10
    -10
      app/src/main/java/eu/faircode/email/FragmentAccount.java

+ 2
- 72
app/src/main/java/eu/faircode/email/EntityFolder.java View File

@ -19,12 +19,10 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B) Copyright 2018 by Marcel Bokhorst (M66B)
*/ */
import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -50,7 +48,7 @@ import static androidx.room.ForeignKey.CASCADE;
} }
) )
public class EntityFolder implements Parcelable {
public class EntityFolder implements Serializable {
static final String TABLE_NAME = "folder"; static final String TABLE_NAME = "folder";
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ -152,74 +150,6 @@ public class EntityFolder implements Parcelable {
return name; return name;
} }
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
if (id == null) {
parcel.writeByte((byte) 0);
} else {
parcel.writeByte((byte) 1);
parcel.writeLong(id);
}
if (account == null) {
parcel.writeByte((byte) 0);
} else {
parcel.writeByte((byte) 1);
parcel.writeLong(account);
}
parcel.writeString(name);
parcel.writeString(type);
parcel.writeByte((byte) (synchronize == null ? 0 : synchronize ? 1 : 2));
if (after == null) {
parcel.writeByte((byte) 0);
} else {
parcel.writeByte((byte) 1);
parcel.writeInt(after);
}
parcel.writeString(state);
parcel.writeString(error);
}
protected EntityFolder(Parcel in) {
if (in.readByte() == 0) {
id = null;
} else {
id = in.readLong();
}
if (in.readByte() == 0) {
account = null;
} else {
account = in.readLong();
}
name = in.readString();
type = in.readString();
byte tmpSynchronize = in.readByte();
synchronize = tmpSynchronize == 0 ? null : tmpSynchronize == 1;
if (in.readByte() == 0) {
after = null;
} else {
after = in.readInt();
}
state = in.readString();
error = in.readString();
}
public static final Creator<EntityFolder> CREATOR = new Creator<EntityFolder>() {
@Override
public EntityFolder createFromParcel(Parcel in) {
return new EntityFolder(in);
}
@Override
public EntityFolder[] newArray(int size) {
return new EntityFolder[size];
}
};
public JSONObject toJSON() throws JSONException { public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("name", name); json.put("name", name);


+ 10
- 10
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -583,11 +583,11 @@ public class FragmentAccount extends FragmentEx {
args.putBoolean("primary", cbPrimary.isChecked()); args.putBoolean("primary", cbPrimary.isChecked());
args.putString("interval", etInterval.getText().toString()); args.putString("interval", etInterval.getText().toString());
args.putParcelable("drafts", drafts);
args.putParcelable("sent", sent);
args.putParcelable("all", all);
args.putParcelable("trash", trash);
args.putParcelable("junk", junk);
args.putSerializable("drafts", drafts);
args.putSerializable("sent", sent);
args.putSerializable("all", all);
args.putSerializable("trash", trash);
args.putSerializable("junk", junk);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
@ -605,11 +605,11 @@ public class FragmentAccount extends FragmentEx {
boolean primary = args.getBoolean("primary"); boolean primary = args.getBoolean("primary");
String interval = args.getString("interval"); String interval = args.getString("interval");
EntityFolder drafts = args.getParcelable("drafts");
EntityFolder sent = args.getParcelable("sent");
EntityFolder all = args.getParcelable("all");
EntityFolder trash = args.getParcelable("trash");
EntityFolder junk = args.getParcelable("junk");
EntityFolder drafts = (EntityFolder) args.getSerializable("drafts");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
EntityFolder all = (EntityFolder) args.getSerializable("all");
EntityFolder trash = (EntityFolder) args.getSerializable("trash");
EntityFolder junk = (EntityFolder) args.getSerializable("junk");
if (TextUtils.isEmpty(host)) if (TextUtils.isEmpty(host))
throw new Throwable(getContext().getString(R.string.title_no_host)); throw new Throwable(getContext().getString(R.string.title_no_host));


Loading…
Cancel
Save