Skip to content

Commit d072fbd

Browse files
committed
Make all relevant classes implement IdItem
- More minor cleanups - Renamed EntryDetails to EntryCore - getGenres of EntryCore now correctly returns an array instead of a single String
1 parent dc6336f commit d072fbd

8 files changed

Lines changed: 108 additions & 120 deletions

File tree

library/src/main/java/com/proxerme/library/connection/info/entity/EntryDetails.java renamed to library/src/main/java/com/proxerme/library/connection/info/entity/EntryCore.java

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,49 @@
66
import android.support.annotation.IntRange;
77
import android.support.annotation.NonNull;
88

9-
import com.proxerme.library.parameters.CategoryParameter;
9+
import com.proxerme.library.interfaces.IdItem;
10+
import com.proxerme.library.parameters.CategoryParameter.Category;
1011
import com.proxerme.library.parameters.FskParameter;
11-
import com.proxerme.library.parameters.GenreParameter;
12-
import com.proxerme.library.parameters.LicenseParameter;
13-
import com.proxerme.library.parameters.MediumParameter;
12+
import com.proxerme.library.parameters.GenreParameter.Genre;
13+
import com.proxerme.library.parameters.LicenseParameter.License;
14+
import com.proxerme.library.parameters.MediumParameter.Medium;
1415
import com.squareup.moshi.Json;
1516

1617
/**
1718
* Entity holding the detail data of an Entry (Anime, Manga)
1819
*
1920
* @author Desnoo
2021
*/
21-
public class EntryDetails implements Parcelable {
22+
public class EntryCore implements Parcelable, IdItem {
2223

23-
public static final Creator<EntryDetails> CREATOR = new Creator<EntryDetails>() {
24+
public static final Creator<EntryCore> CREATOR = new Creator<EntryCore>() {
2425
@Override
25-
public EntryDetails createFromParcel(Parcel in) {
26-
return new EntryDetails(in);
26+
public EntryCore createFromParcel(Parcel in) {
27+
return new EntryCore(in);
2728
}
2829

2930
@Override
30-
public EntryDetails[] newArray(int size) {
31-
return new EntryDetails[size];
31+
public EntryCore[] newArray(int size) {
32+
return new EntryCore[size];
3233
}
3334
};
3435

36+
private static final String DELIMITER = " ";
37+
3538
@Json(name = "id")
3639
private String id;
3740
@Json(name = "name")
3841
private String name;
3942
@Json(name = "genre")
40-
private String genre;
43+
private String genres;
4144
@Json(name = "fsk")
4245
private String fsk;
4346
@Json(name = "description")
4447
private String description;
4548
@Json(name = "medium")
4649
private String medium;
4750
@Json(name = "count")
48-
private int count;
51+
private int episodeAmount;
4952
@Json(name = "state")
5053
private int state;
5154
@Json(name = "rate_sum")
@@ -59,43 +62,40 @@ public EntryDetails[] newArray(int size) {
5962
@Json(name = "license")
6063
private int license;
6164

62-
/**
63-
* Private empty Constructor.
64-
*/
65-
private EntryDetails() {
65+
private EntryCore() {
6666
}
6767

6868
/**
6969
* Constructor of the entrycore data.
7070
*
7171
* @param id The entry id.
7272
* @param name The entry name.
73-
* @param genre The genre.
73+
* @param genres The genres.
7474
* @param fsk The fsk ratings.
7575
* @param description The description.
7676
* @param medium The medium.
77-
* @param count The number of episodes.
77+
* @param episodeAmount The number of episodes.
7878
* @param state The user view state.
7979
* @param rateSum The sum of all ratings.
8080
* @param rateCount The amount of ratings.
8181
* @param clicks The amount of clicks.
8282
* @param category The category name.
8383
* @param license The license id.
8484
*/
85-
public EntryDetails(@NonNull String id, @NonNull String name, @NonNull @GenreParameter.Genre String genre,
86-
@NonNull String fsk, @NonNull String description,
87-
@NonNull @MediumParameter.Medium String medium,
88-
@IntRange(from = 1) int count, @IntRange(from = 0) int state,
89-
@IntRange(from = 0) int rateSum, @IntRange(from = 0) int rateCount,
90-
@IntRange(from = 0) int clicks, @NonNull @CategoryParameter.Category String category,
91-
@IntRange(from = 0) @LicenseParameter.License int license) {
85+
public EntryCore(@NonNull String id, @NonNull String name,
86+
@NonNull @Genre String genres, @NonNull String fsk,
87+
@NonNull String description, @NonNull @Medium String medium,
88+
@IntRange(from = 1) int episodeAmount, @IntRange(from = 0) int state,
89+
@IntRange(from = 0) int rateSum, @IntRange(from = 0) int rateCount,
90+
@IntRange(from = 0) int clicks, @NonNull @Category String category,
91+
@License int license) {
9292
this.id = id;
9393
this.name = name;
94-
this.genre = genre;
94+
this.genres = genres;
9595
this.fsk = fsk;
9696
this.description = description;
9797
this.medium = medium;
98-
this.count = count;
98+
this.episodeAmount = episodeAmount;
9999
this.state = state;
100100
this.rateSum = rateSum;
101101
this.rateCount = rateCount;
@@ -104,19 +104,14 @@ public EntryDetails(@NonNull String id, @NonNull String name, @NonNull @GenrePar
104104
this.license = license;
105105
}
106106

107-
/**
108-
* Parser to retain the instance back from the parcel.
109-
*
110-
* @param in the parcel to parse.
111-
*/
112-
protected EntryDetails(Parcel in) {
107+
protected EntryCore(Parcel in) {
113108
id = in.readString();
114109
name = in.readString();
115-
genre = in.readString();
110+
genres = in.readString();
116111
fsk = in.readString();
117112
description = in.readString();
118113
medium = in.readString();
119-
count = in.readInt();
114+
episodeAmount = in.readInt();
120115
state = in.readInt();
121116
rateSum = in.readInt();
122117
rateCount = in.readInt();
@@ -130,6 +125,7 @@ protected EntryDetails(Parcel in) {
130125
* @return The id.
131126
*/
132127
@NonNull
128+
@Override
133129
public String getId() {
134130
return id;
135131
}
@@ -145,26 +141,27 @@ public String getName() {
145141
}
146142

147143
/**
148-
* Returns the genre of this entry.
144+
* Returns the genres of this entry.
149145
*
150-
* @return The genre.
146+
* @return The genres.
151147
*/
152148
@NonNull
153-
@GenreParameter.Genre
154-
public String getGenre() {
155-
return genre;
149+
@Genre
150+
public String[] getGenres() {
151+
//noinspection ResourceType
152+
return genres.split(DELIMITER);
156153
}
157154

158155
/**
159156
* Returns an array of fsk names of this entry.
160157
*
161158
* @return An array of fsk names.
162159
*/
163-
@SuppressWarnings("WrongConstant")
164160
@NonNull
165161
@FskParameter.FskConstraint
166162
public String[] getFsk() {
167-
return fsk.split(" ");
163+
//noinspection WrongConstant
164+
return fsk.split(DELIMITER);
168165
}
169166

170167
/**
@@ -183,19 +180,20 @@ public String getDescription() {
183180
* @return The medium.
184181
*/
185182
@NonNull
186-
@MediumParameter.Medium
183+
@Medium
187184
public String getMedium() {
188185
return medium;
189186
}
190187

191188
/**
192-
* Get the overall amount of episodes/chapters of this entry. It does include not available episodes.
189+
* Get the overall amount of episodes/chapters of this entry. It does include not available
190+
* episodes.
193191
*
194192
* @return The amount of episodes/chapters.
195193
*/
196194
@IntRange(from = 0)
197-
public int getCount() {
198-
return count;
195+
public int getEpisodeAmount() {
196+
return episodeAmount;
199197
}
200198

201199
/**
@@ -257,7 +255,8 @@ public int getClicks() {
257255
*
258256
* @return The name of the category.
259257
*/
260-
@CategoryParameter.Category
258+
@NonNull
259+
@Category
261260
public String getCategory() {
262261
return category;
263262
}
@@ -267,7 +266,7 @@ public String getCategory() {
267266
*
268267
* @return The license state.
269268
*/
270-
@LicenseParameter.License
269+
@License
271270
public int getLicense() {
272271
return license;
273272
}
@@ -276,11 +275,11 @@ public int getLicense() {
276275
public void writeToParcel(Parcel dest, int flags) {
277276
dest.writeString(id);
278277
dest.writeString(name);
279-
dest.writeString(genre);
278+
dest.writeString(genres);
280279
dest.writeString(fsk);
281280
dest.writeString(description);
282281
dest.writeString(medium);
283-
dest.writeInt(count);
282+
dest.writeInt(episodeAmount);
284283
dest.writeInt(state);
285284
dest.writeInt(rateSum);
286285
dest.writeInt(rateCount);
@@ -299,33 +298,33 @@ public boolean equals(Object o) {
299298
if (this == o) return true;
300299
if (o == null || getClass() != o.getClass()) return false;
301300

302-
EntryDetails entryDetails = (EntryDetails) o;
301+
EntryCore entryCore = (EntryCore) o;
303302

304-
if (!id.equals(entryDetails.id)) return false;
305-
if (count != entryDetails.count) return false;
306-
if (state != entryDetails.state) return false;
307-
if (rateSum != entryDetails.rateSum) return false;
308-
if (rateCount != entryDetails.rateCount) return false;
309-
if (clicks != entryDetails.clicks) return false;
310-
if (!name.equals(entryDetails.name)) return false;
311-
if (!genre.equals(entryDetails.genre)) return false;
312-
if (!fsk.equals(entryDetails.fsk)) return false;
313-
if (!description.equals(entryDetails.description)) return false;
314-
if (!medium.equals(entryDetails.medium)) return false;
315-
if (!category.equals(entryDetails.category)) return false;
316-
return license == entryDetails.license;
303+
if (!id.equals(entryCore.id)) return false;
304+
if (episodeAmount != entryCore.episodeAmount) return false;
305+
if (state != entryCore.state) return false;
306+
if (rateSum != entryCore.rateSum) return false;
307+
if (rateCount != entryCore.rateCount) return false;
308+
if (clicks != entryCore.clicks) return false;
309+
if (!name.equals(entryCore.name)) return false;
310+
if (!genres.equals(entryCore.genres)) return false;
311+
if (!fsk.equals(entryCore.fsk)) return false;
312+
if (!description.equals(entryCore.description)) return false;
313+
if (!medium.equals(entryCore.medium)) return false;
314+
if (!category.equals(entryCore.category)) return false;
315+
return license == entryCore.license;
317316

318317
}
319318

320319
@Override
321320
public int hashCode() {
322321
int result = id.hashCode();
323322
result = 31 * result + name.hashCode();
324-
result = 31 * result + genre.hashCode();
323+
result = 31 * result + genres.hashCode();
325324
result = 31 * result + fsk.hashCode();
326325
result = 31 * result + description.hashCode();
327326
result = 31 * result + medium.hashCode();
328-
result = 31 * result + count;
327+
result = 31 * result + episodeAmount;
329328
result = 31 * result + state;
330329
result = 31 * result + rateSum;
331330
result = 31 * result + rateCount;

library/src/main/java/com/proxerme/library/connection/info/entity/Season.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
import android.support.annotation.IntRange;
66
import android.support.annotation.NonNull;
77

8-
import com.proxerme.library.parameters.SeasonParameter;
9-
import com.proxerme.library.parameters.TypeParameter;
8+
import com.proxerme.library.interfaces.IdItem;
9+
import com.proxerme.library.parameters.SeasonParameter.SeasonConstraint;
10+
import com.proxerme.library.parameters.TypeParameter.Type;
1011
import com.squareup.moshi.Json;
1112

1213
/**
1314
* Entity holding the seasons of a entry.
1415
*
1516
* @author Desnoo
1617
*/
17-
public class Season implements Parcelable {
18+
public class Season implements Parcelable, IdItem {
1819

1920
public static final Creator<Season> CREATOR = new Creator<Season>() {
2021
@Override
@@ -39,9 +40,6 @@ public Season[] newArray(int size) {
3940
@Json(name = "season")
4041
private int season;
4142

42-
/**
43-
* The private constructor.
44-
*/
4543
private Season() {
4644
}
4745

@@ -54,20 +52,15 @@ private Season() {
5452
* @param year The year when the entry was released.
5553
* @param season The season in which the entry was released.
5654
*/
57-
public Season(@NonNull String id, @NonNull String entryId, @TypeParameter.Type String type,
58-
@IntRange(from = 1900) int year, @SeasonParameter.SeasonConstraint int season) {
55+
public Season(@NonNull String id, @NonNull String entryId, @Type String type,
56+
@IntRange(from = 1900) int year, @SeasonConstraint int season) {
5957
this.id = id;
6058
this.entryId = entryId;
6159
this.type = type;
6260
this.year = year;
6361
this.season = season;
6462
}
6563

66-
/**
67-
* Constructor to recreate season from parcel.
68-
*
69-
* @param in the parcel to parse.
70-
*/
7164
protected Season(Parcel in) {
7265
id = in.readString();
7366
entryId = in.readString();
@@ -82,6 +75,7 @@ protected Season(Parcel in) {
8275
* @return The id.
8376
*/
8477
@NonNull
78+
@Override
8579
public String getId() {
8680
return id;
8781
}
@@ -102,7 +96,7 @@ public String getEntryId() {
10296
* @return The type.
10397
*/
10498
@NonNull
105-
@TypeParameter.Type
99+
@Type
106100
public String getType() {
107101
return type;
108102
}
@@ -122,7 +116,7 @@ public int getYear() {
122116
*
123117
* @return The season. (Spring, Summer, Autumn, Winter)
124118
*/
125-
@SeasonParameter.SeasonConstraint
119+
@SeasonConstraint
126120
public int getSeason() {
127121
return season;
128122
}

0 commit comments

Comments
 (0)