Skip to content

Commit

Permalink
Resolves #2307 make achievements activity more visible (#5442)
Browse files Browse the repository at this point in the history
* Resolves #2307 by adding user level in menu

* Formatted code as requested

* Start sentence with uppercase

* javadoc

* Fixed my typo

* javadoc

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
  • Loading branch information
ShashwatKedia and nicolas-raoul authored Jan 17, 2024
1 parent 56e21ab commit 1aa07f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import fr.free.nrw.commons.feedback.FeedbackContentCreator;
import fr.free.nrw.commons.feedback.model.Feedback;
import fr.free.nrw.commons.feedback.FeedbackDialog;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.logging.CommonsLogSender;
import fr.free.nrw.commons.profile.ProfileActivity;
Expand Down Expand Up @@ -91,17 +92,23 @@ public void onAttach(@NonNull final Context context) {
}

/**
* Set the username in navigationHeader.
* Set the username and user achievements level (if available) in navigationHeader.
*/
private void setUserName() {
moreProfile.setText(getUserName());
BasicKvStore store = new BasicKvStore(this.getContext(), getUserName());
String level = store.getString("userAchievementsLevel","0");
if (level.equals("0")) {
moreProfile.setText(getUserName() + " (" + getString(R.string.see_your_achievements) + ")");
}
else {
moreProfile.setText(getUserName() + " (" + getString(R.string.level) + " " + level + ")");
}
}

private String getUserName(){
final AccountManager accountManager = AccountManager.get(getActivity());
final Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
if (allAccounts.length != 0) {
moreProfile.setText(allAccounts[0].name);
return allAccounts[0].name;
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.databinding.FragmentAchievementsBinding;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import fr.free.nrw.commons.utils.ConfigUtils;
import fr.free.nrw.commons.utils.DialogUtil;
Expand Down Expand Up @@ -357,7 +358,7 @@ private void setImageRevertPercentage(int notRevertPercentage){

/**
* Used the inflate the fetched statistics of the images uploaded by user
* and assign badge and level
* and assign badge and level. Also stores the achievements level of the user in BasicKvStore to display in menu
* @param achievements
*/
private void inflateAchievements(Achievements achievements) {
Expand All @@ -377,6 +378,8 @@ private void inflateAchievements(Achievements achievements) {
binding.achievementBadgeImage.setImageDrawable(VectorDrawableCompat.create(getResources(), R.drawable.badge,
new ContextThemeWrapper(getActivity(), levelInfo.getLevelStyle()).getTheme()));
binding.achievementBadgeText.setText(Integer.toString(levelInfo.getLevelNumber()));
BasicKvStore store = new BasicKvStore(this.getContext(), userName);
store.putString("userAchievementsLevel", Integer.toString(levelInfo.getLevelNumber()));
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ Upload your first media by tapping on the add button.</string>
<string name="permissions_are_required_for_functionality">Permissions are required for functionality</string>
<string name="learn_how_to_write_a_useful_description">Learn how to write a useful description</string>
<string name="learn_how_to_write_a_useful_caption">Learn how to write a useful caption</string>
<string name="see_your_achievements">See your achievements</string>
<plurals name="custom_picker_images_selected_title_appendix">
<item quantity="one">%d image selected</item>
<item quantity="other">%d images selected</item>
Expand Down

0 comments on commit 1aa07f9

Please sign in to comment.