diff --git a/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java b/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java index 1ac4c8f4e..70b1dccd6 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java @@ -30,7 +30,7 @@ public class ProfileActivity extends NavigationBaseActivity { @BindView(R.id.tab_layout) TabLayout tabLayout; - ViewPagerAdapter viewPagerAdapter; + private ViewPagerAdapter viewPagerAdapter; private AchievementsFragment achievementsFragment; private LeaderboardFragment leaderboardFragment; diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardConstants.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardConstants.java index c32d84352..9b0fa0f6e 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardConstants.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardConstants.java @@ -5,18 +5,41 @@ package fr.free.nrw.commons.profile.leaderboard; */ public class LeaderboardConstants { + /** + * This is the size of the page i.e. number items to load in a batch when pagination is performed + */ public static final int PAGE_SIZE = 10; + /** + * This is the starting offset, we set it to 0 to start loading from rank 1 + */ public static final int START_OFFSET = 0; + /** + * This is the prefix of the user's homepage url, appending the username will give us complete url + */ public static final String USER_LINK_PREFIX = "https://commons.wikimedia.org/wiki/User:"; + /** + * This is the a constant string for the state loading, when the pages are getting loaded we can + * use this constant to identify if we need to show the progress bar or not + */ public final static String LOADING = "Loading"; + /** + * This is the a constant string for the state loaded, when the pages are loaded we can + * use this constant to identify if we need to show the progress bar or not + */ public final static String LOADED = "Loaded"; + /** + * This API endpoint is to update the leaderboard avatar + */ public final static String UPDATE_AVATAR_END_POINT = "/update_avatar.py"; + /** + * This API endpoint is to get leaderboard data + */ public final static String LEADERBOARD_END_POINT = "/leaderboard.py"; } diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java index 253fd4730..305907aff 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardFragment.java @@ -98,7 +98,16 @@ public class LeaderboardFragment extends CommonsDaggerSupportFragment { hideLayouts(); setSpinners(); + /** + * This array is for the duration filter, we have three filters weekly, yearly and all-time + * each filter have a key and value pair, the value represents the param of the API + */ String[] durationValues = getContext().getResources().getStringArray(R.array.leaderboard_duration_values); + + /** + * This array is for the category filter, we have three filters upload, used and nearby + * each filter have a key and value pair, the value represents the param of the API + */ String[] categoryValues = getContext().getResources().getStringArray(R.array.leaderboard_category_values); duration = durationValues[0]; diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardList.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardList.java index 799e7623b..5558f3d9e 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardList.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardList.java @@ -13,50 +13,90 @@ import com.google.gson.annotations.SerializedName; */ public class LeaderboardList { + /** + * Username of the user + * Example value - Syced + */ @SerializedName("username") @Expose private String username; + /** + * Count in the category + * Example value - 10 + */ @SerializedName("category_count") @Expose private Integer categoryCount; + /** + * URL of the avatar of user + * Example value = https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Gnome-stock_person.svg/200px-Gnome-stock_person.svg.png + */ @SerializedName("avatar") @Expose private String avatar; + /** + * Rank of the user + * Example value - 1 + */ @SerializedName("rank") @Expose private Integer rank; + /** + * @return the username of the user in the leaderboard list + */ public String getUsername() { return username; } + /** + * Sets the username of the user in the leaderboard list + */ public void setUsername(String username) { this.username = username; } + /** + * @return the category count of the user in the leaderboard list + */ public Integer getCategoryCount() { return categoryCount; } + /** + * Sets the category count of the user in the leaderboard list + */ public void setCategoryCount(Integer categoryCount) { this.categoryCount = categoryCount; } + /** + * @return the avatar of the user in the leaderboard list + */ public String getAvatar() { return avatar; } + /** + * Sets the avatar of the user in the leaderboard list + */ public void setAvatar(String avatar) { this.avatar = avatar; } + /** + * @return the rank of the user in the leaderboard list + */ public Integer getRank() { return rank; } + /** + * Sets the rank of the user in the leaderboard list + */ public void setRank(Integer rank) { this.rank = rank; } @@ -80,6 +120,11 @@ public class LeaderboardList { } }; + /** + * Returns true if two objects are equal, false otherwise + * @param obj + * @return + */ @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardResponse.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardResponse.java index f19c43203..34294fca9 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardResponse.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardResponse.java @@ -9,122 +9,227 @@ import com.google.gson.annotations.SerializedName; */ public class LeaderboardResponse { + /** + * Status Code returned from the API + * Example value - 200 + */ @SerializedName("status") @Expose private Integer status; + /** + * Username returned from the API + * Example value - Syced + */ @SerializedName("username") @Expose private String username; + /** + * Category count returned from the API + * Example value - 10 + */ @SerializedName("category_count") @Expose private Integer categoryCount; + /** + * Limit returned from the API + * Example value - 10 + */ @SerializedName("limit") @Expose private int limit; + /** + * Avatar returned from the API + * Example value - https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Gnome-stock_person.svg/200px-Gnome-stock_person.svg.png + */ @SerializedName("avatar") @Expose private String avatar; + /** + * Offset returned from the API + * Example value - 0 + */ @SerializedName("offset") @Expose private int offset; + /** + * Duration returned from the API + * Example value - yearly + */ @SerializedName("duration") @Expose private String duration; + /** + * Leaderboard list returned from the API + * Example value - [{ + * "username": "Fæ", + * "category_count": 107147, + * "avatar": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Gnome-stock_person.svg/200px-Gnome-stock_person.svg.png", + * "rank": 1 + * }] + */ @SerializedName("leaderboard_list") @Expose private List leaderboardList = null; + /** + * Category returned from the API + * Example value - upload + */ @SerializedName("category") @Expose private String category; + /** + * Rank returned from the API + * Example value - 1 + */ @SerializedName("rank") @Expose private Integer rank; + /** + * @return the status code + */ public Integer getStatus() { return status; } + /** + * Sets the status code + */ public void setStatus(Integer status) { this.status = status; } + /** + * @return the username + */ public String getUsername() { return username; } + /** + * Sets the username + */ public void setUsername(String username) { this.username = username; } + /** + * @return the category count + */ public Integer getCategoryCount() { return categoryCount; } + /** + * Sets the category count + */ public void setCategoryCount(Integer categoryCount) { this.categoryCount = categoryCount; } + /** + * @return the limit + */ public int getLimit() { return limit; } + /** + * Sets the limit + */ public void setLimit(int limit) { this.limit = limit; } + /** + * @return the avatar + */ public String getAvatar() { return avatar; } + /** + * Sets the avatar + */ public void setAvatar(String avatar) { this.avatar = avatar; } + /** + * @return the offset + */ public int getOffset() { return offset; } + /** + * Sets the offset + */ public void setOffset(int offset) { this.offset = offset; } + /** + * @return the duration + */ public String getDuration() { return duration; } + /** + * Sets the duration + */ public void setDuration(String duration) { this.duration = duration; } + /** + * @return the leaderboard list + */ public List getLeaderboardList() { return leaderboardList; } + /** + * Sets the leaderboard list + */ public void setLeaderboardList(List leaderboardList) { this.leaderboardList = leaderboardList; } + /** + * @return the category + */ public String getCategory() { return category; } + /** + * Sets the category + */ public void setCategory(String category) { this.category = category; } + /** + * @return the rank + */ public Integer getRank() { return rank; } + /** + * Sets the rank + */ public void setRank(Integer rank) { this.rank = rank; } diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UpdateAvatarResponse.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UpdateAvatarResponse.java index ce6cceb22..15449a488 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UpdateAvatarResponse.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UpdateAvatarResponse.java @@ -8,38 +8,68 @@ import com.google.gson.annotations.SerializedName; */ public class UpdateAvatarResponse { + /** + * Status Code returned from the API + * Example value - 200 + */ @SerializedName("status") @Expose private String status; + /** + * Message returned from the API + * Example value - Avatar Updated + */ @SerializedName("message") @Expose private String message; + /** + * Username returned from the API + * Example value - Syced + */ @SerializedName("user") @Expose private String user; + /** + * @return the status code + */ public String getStatus() { return status; } + /** + * Sets the status code + */ public void setStatus(String status) { this.status = status; } + /** + * @return the message + */ public String getMessage() { return message; } + /** + * Sets the message + */ public void setMessage(String message) { this.message = message; } + /** + * @return the username + */ public String getUser() { return user; } + /** + * Sets the username + */ public void setUser(String user) { this.user = user; } diff --git a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UserDetailAdapter.java b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UserDetailAdapter.java index 0c7efa146..f5e31b782 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UserDetailAdapter.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/leaderboard/UserDetailAdapter.java @@ -16,7 +16,7 @@ import fr.free.nrw.commons.R; */ public class UserDetailAdapter extends RecyclerView.Adapter { - LeaderboardResponse leaderboardResponse; + private LeaderboardResponse leaderboardResponse; public UserDetailAdapter(LeaderboardResponse leaderboardResponse) { this.leaderboardResponse = leaderboardResponse; @@ -24,10 +24,10 @@ public class UserDetailAdapter extends RecyclerView.Adapter