1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
package ml.docilealligator.infinityforreddit.account;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
@Entity(tableName = "accounts")
public class Account implements Parcelable {
public static final String ANONYMOUS_ACCOUNT = "-";
@PrimaryKey
@NonNull
@ColumnInfo(name = "username")
private final String accountName;
@ColumnInfo(name = "profile_image_url")
private final String profileImageUrl;
@ColumnInfo(name = "banner_image_url")
private final String bannerImageUrl;
@ColumnInfo(name = "karma")
private final int karma;
@ColumnInfo(name = "access_token")
private String accessToken;
@ColumnInfo(name = "refresh_token")
private final String refreshToken;
@ColumnInfo(name = "code")
private final String code;
@ColumnInfo(name = "is_current_user")
private final boolean isCurrentUser;
@Ignore
protected Account(Parcel in) {
accountName = in.readString();
profileImageUrl = in.readString();
bannerImageUrl = in.readString();
karma = in.readInt();
accessToken = in.readString();
refreshToken = in.readString();
code = in.readString();
isCurrentUser = in.readByte() != 0;
}
public static final Creator<Account> CREATOR = new Creator<Account>() {
@Override
public Account createFromParcel(Parcel in) {
return new Account(in);
}
@Override
public Account[] newArray(int size) {
return new Account[size];
}
};
@Ignore
public static Account getAnonymousAccount() {
return new Account(Account.ANONYMOUS_ACCOUNT, null, null, null, null, null, 0, false);
}
public Account(@NonNull String accountName, String accessToken, String refreshToken, String code,
String profileImageUrl, String bannerImageUrl, int karma, boolean isCurrentUser) {
this.accountName = accountName;
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.code = code;
this.profileImageUrl = profileImageUrl;
this.bannerImageUrl = bannerImageUrl;
this.karma = karma;
this.isCurrentUser = isCurrentUser;
}
@NonNull
public String getAccountName() {
return accountName;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public String getBannerImageUrl() {
return bannerImageUrl;
}
public int getKarma() {
return karma;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getRefreshToken() {
return refreshToken;
}
public String getCode() {
return code;
}
public boolean isCurrentUser() {
return isCurrentUser;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(accountName);
dest.writeString(profileImageUrl);
dest.writeString(bannerImageUrl);
dest.writeInt(karma);
dest.writeString(accessToken);
dest.writeString(refreshToken);
dest.writeString(code);
dest.writeByte((byte) (isCurrentUser ? 1 : 0));
}
public String getJSONModel() {
return new Gson().toJson(this);
}
public static Account fromJson(String json) throws JsonParseException {
return new Gson().fromJson(json, Account.class);
}
}
|