Fix: prevent showing NearbyCard when seeing our contributions from Profile screen #6339
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description (required)
Fixes #6332
What changes did you make and why?
We shouldn't show
NearbyCardwhen seeing ourContributionsfromProfileActivityWe already have conditions to check if we are on the Profile screen by checking
userName != nullas we show our username on the Profile screenapps-android-commons/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt
Lines 182 to 185 in 06a613e
The above conditions set values some values if we are on the profile screen which is further used to conditionally show
NearbyCardView:apps-android-commons/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt
Line 402 in 06a613e
We were passing
KEY_USERNAMEfromProfileAcitivityso that it won't be null when creatingContributionsFragmentapps-android-commons/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.kt
Lines 108 to 111 in 06a613e
However, inside the apply block, we are indirectly accessing & passing the
userNameproperty ofContributionsFragment, which is null initially, instead of theProfileActivity'sproperty which leads to unexpected behaviors.To fix this we can either:
userNameproperty like this:putString(KEY_USERNAME, this@ProfileActivity.userName)userNameproperty private inContributionsFragmentas it's being used there onlySo, I make that property private because it also promotes encapsulation :)
Tests performed (required)
Tested prodDebug on Samsung A14 5G with API level 34.
Screenshots (for UI changes only)
Note that
NearbyCardViewcorrectly shows on the mainContributionsscreen but not on theProfilescreenAfter_Fix.mp4