From 1aa07f9368c5c90c4fc71eab1d568b5a71a41443 Mon Sep 17 00:00:00 2001 From: Shashwat Kedia <142137555+ShashwatKedia@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:19:14 +0530 Subject: [PATCH] Resolves #2307 make achievements activity more visible (#5442) * 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 --- .../nrw/commons/navtab/MoreBottomSheetFragment.java | 13 ++++++++++--- .../profile/achievements/AchievementsFragment.java | 5 ++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.java b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.java index 2fece495ce..0b044565fa 100644 --- a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.java @@ -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; @@ -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 ""; diff --git a/app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementsFragment.java b/app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementsFragment.java index b2bcfc26d6..7b8568007f 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementsFragment.java @@ -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; @@ -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) { @@ -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())); } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 558508c5ba..558c1208e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -786,6 +786,7 @@ Upload your first media by tapping on the add button. Permissions are required for functionality Learn how to write a useful description Learn how to write a useful caption + See your achievements %d image selected %d images selected