Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Part of issue #5996: Fix IDE warnings in ContributionsListFragment #6542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

@ericlovetuna
Copy link
Contributor

@ericlovetuna ericlovetuna commented Oct 25, 2025
edited by coderabbitai bot
Loading

Description

Related to #5996

  • Cleaned IDE warnings in ContributionsListFragment.kt.
  • Aligned parameter names with their supertype definitions (numberOfUploads, contribution, isWikipediaPageExists) to improve consistency.
  • Fix the "isFabOpen always true" warning.
  • Verified that no logic or UI behaviour was changed — only code clarity and warning cleanup.

Tests performed

Tested ProdDebug build on Pixel 7 emulator with API level 34.

  • FAB open/close animation works correctly.
  • Gallery, Camera, and Custom Selector buttons still function as expected.
  • No runtime warnings or crashes observed.

Summary by CodeRabbit

  • Refactor
    • Modernized the contributions list component with updated Android framework APIs for improved compatibility and future-proofing.
    • Standardized internal code naming conventions and improved resource reference handling for better maintainability.
    • Enhanced fragment management and animation handling with contemporary best practices.

Copy link

✅ Generated APK variants!

Copy link

coderabbitai bot commented Oct 25, 2025
edited
Loading

Walkthrough

The file ContributionsListFragment.kt underwent a comprehensive refactoring including API modernizations (BundleCompat, parentFragmentManager), naming convention standardization (snake_case to camelCase), method signature refinements for semantic clarity, and simplified resource reference patterns throughout.

Changes

Cohort / File(s) Summary
API Modernization
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt
Replaced Uri.parse() with .toUri() extension, integrated BundleCompat for Parcelable state retrieval, updated fragment manager access from fragmentManager to this.parentFragmentManager
Naming Convention Refactoring
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt
Standardized private field names from snake_case to camelCase: fab_closefabClose, fab_openfabOpen, rotate_forwardrotateForward, rotate_backwardrotateBackward; renamed span count constants: SPAN_COUNT_LANDSCAPE/PORTRAITspanCountLandscape/spanCountPortrait
Method Signature & Resource Updates
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt
Updated method signatures for openMediaDetail(), showDetail(), and showWelcomeTip() with clarified parameter names; simplified resource references from fr.free.nrw.commons.R.* to R.* across toast messages and dialog resources

Sequence Diagram(s)

This change set consists primarily of internal refactoring and modernization of existing functionality without introducing new features or altering primary control flow patterns, so sequence diagram generation is not applicable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Naming pattern verification: Ensure all snake_case field references have been converted to camelCase throughout the file and no residual references remain
  • Method signature impact: Verify that all call sites of openMediaDetail(), showDetail(), and showWelcomeTip() have been updated with the new parameter names and semantic meanings
  • API modernization correctness: Confirm BundleCompat usage follows Android guidelines, toUri() behaves identically to Uri.parse() in context, and parentFragmentManager is the appropriate choice
  • Resource reference completeness: Cross-check that all resource accesses have been simplified and no mixed reference patterns (qualified vs. unqualified) remain

Poem

🐰 Fields hop from snake to camel with glee,
APIs modernized, as modern can be,
Methods renamed with meanings so clear,
Resources simplified, refactoring cheer!
A cleanup so thorough, the code shines pristine. 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Part of issue #5996: Fix IDE warnings in ContributionsListFragment" accurately reflects the main objective described in the PR summary: cleaning up IDE warnings in the ContributionsListFragment file. The PR objectives explicitly state that changes include aligning parameter names with supertype definitions and fixing an "isFabOpen always true" warning, all targeting code clarity and warning cleanup. The extensive refactoring evident in the raw summary—including method signature updates, field renaming to camelCase conventions, constant naming improvements, API modernization, and resource reference cleanup—all serve the stated purpose of addressing IDE warnings. The title is concise, specific to the file being modified, and provides sufficient context for a teammate to understand the primary intent when scanning pull request history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt (6)

418-439: Simplify and correct FAB state toggle; remove redundant early flip

this.isFabOpen is flipped before verifying visibility, which can desync state when fabPlus isn’t shown. Flip once after animations only.

Apply:

- private fun animateFAB(isFabOpen: Boolean) {
- this.isFabOpen = !isFabOpen
+ private fun animateFAB(isFabOpen: Boolean) {
 if (binding!!.fabPlus.isShown) {
 if (isFabOpen) {
 binding!!.fabPlus.startAnimation(rotateBackward)
 binding!!.fabCamera.startAnimation(fabClose)
 binding!!.fabGallery.startAnimation(fabClose)
 binding!!.fabCustomGallery.startAnimation(fabClose)
 binding!!.fabCamera.hide()
 binding!!.fabGallery.hide()
 binding!!.fabCustomGallery.hide()
 } else {
 binding!!.fabPlus.startAnimation(rotateForward)
 binding!!.fabCamera.startAnimation(fabOpen)
 binding!!.fabGallery.startAnimation(fabOpen)
 binding!!.fabCustomGallery.startAnimation(fabOpen)
 binding!!.fabCamera.show()
 binding!!.fabGallery.show()
 binding!!.fabCustomGallery.show()
 }
 this.isFabOpen = !isFabOpen
 }
 }

466-468: Make RV state save null-safe

Prevent potential NPE if layoutManager is momentarily null.

Apply:

- val layoutManager = rvContributionsList?.layoutManager as GridLayoutManager?
- outState.putParcelable(RV_STATE, layoutManager!!.onSaveInstanceState())
+ (rvContributionsList?.layoutManager as? GridLayoutManager)
+ ?.onSaveInstanceState()
+ ?.let { outState.putParcelable(RV_STATE, it) }

473-476: Guard restore with null-safe call

Avoid passing null to onRestoreInstanceState and skip if state missing.

Apply:

- val savedRecyclerLayoutState =
- BundleCompat.getParcelable(savedInstanceState, RV_STATE, Parcelable::class.java)
- rvContributionsList!!.layoutManager!!.onRestoreInstanceState(savedRecyclerLayoutState)
+ val savedRecyclerLayoutState =
+ BundleCompat.getParcelable(savedInstanceState, RV_STATE, Parcelable::class.java)
+ savedRecyclerLayoutState?.let { state ->
+ rvContributionsList?.layoutManager?.onRestoreInstanceState(state)
+ }

99-101: Tiny polish: make span counts compile-time constants

Not urgent, but consider moving spanCountLandscape/spanCountPortrait to companion object as const val for clarity.

Example:

- private val spanCountLandscape = 3
- private val spanCountPortrait = 1
+ companion object {
+ private const val SPAN_COUNT_LANDSCAPE = 3
+ private const val SPAN_COUNT_PORTRAIT = 1
+ }

Then use SPAN_* in getSpanCount/onConfigurationChanged.

Also applies to: 348-352, 358-366


543-547: Optional guard: avoid opening "/wiki/null"

If getWikipediaPageTitle() can be null/blank, guard and inform the user before launching.

Apply:

- val url =
- languageWikipediaSite!!.mobileUrl() + "/wiki/" + (contribution!!.wikidataPlace
- ?.getWikipediaPageTitle())
- handleWebUrl(requireContext(), url.toUri())
+ val title = contribution!!.wikidataPlace?.getWikipediaPageTitle()
+ if (title.isNullOrBlank()) {
+ showShortToast(context, R.string.no_wikipedia_title_found)
+ return
+ }
+ val url = "${languageWikipediaSite!!.mobileUrl()}/wiki/$title"
+ handleWebUrl(requireContext(), url.toUri())

444-447: Add KDoc or plan interface rename to clarify misleading parameter name

The parameter numberOfUploads: Boolean is misleading—it reads like a count but is actually a boolean flag controlling visibility. Since there is only one implementation (in ContributionsListFragment.kt), renaming at the interface level in ContributionsListContract.kt would be straightforward. Add a KDoc to clarify that numberOfUploads controls whether to show the welcome message, or rename the parameter (e.g., shouldShowWelcome or isNewUser) in a follow-up.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28fa7b1 and 44bba01.

📒 Files selected for processing (1)
  • app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt (18 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt (2)
app/src/main/java/fr/free/nrw/commons/contributions/WikipediaInstructionsDialogFragment.kt (1)
  • newInstance (56-60)
app/src/main/java/fr/free/nrw/commons/utils/UrlUtils.kt (1)
  • handleWebUrl (16-33)
🔇 Additional comments (3)
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt (3)

22-24: Good modernization: BundleCompat + toUri

  • Using BundleCompat.getParcelable avoids Tiramisu warnings.
  • Switching to url.toUri() keeps Uri creation idiomatic.

Also applies to: 473-476, 543-547


479-482: LGTM: clearer names for openMediaDetail and callback forwarding

Renamed parameters improve readability; forwarding remains unchanged in behavior.


508-520: Good: parentFragmentManager and typed dialog callback

Using parentFragmentManager is the correct modern API; callback lambda signature is clear.

Comment on lines +238 to 242
adapter = ContributionsListAdapter(this,
mediaClient!!,
mediaDataExtractor!!,
compositeDisposable)
}
Copy link

@coderabbitai coderabbitai bot Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Avoid double-bangs on injected deps; verify adapter ctor matches

Use requireNotNull or early null checks to prevent NPEs from mediaClient!!/mediaDataExtractor!!, and confirm the ContributionsListAdapter signature matches these args.

Run to confirm constructor and usages:


🏁 Script executed:

#!/bin/bash
# Find adapter constructor and its params/usages
rg -nP -C3 'class\s+ContributionsListAdapter\b|new\s+ContributionsListAdapter|ContributionsListAdapter\(' --type=kt

Length of output: 26


Let me also try a more direct approach:


---
🏁 Script executed:
```shell
#!/bin/bash
# Search for ContributionsListAdapter class without file type restriction
# Try broader search pattern
rg -nP -C3 'class\s+ContributionsListAdapter' 
# Also search for the file separately
echo "---"
echo "Looking for Kotlin files containing ContributionsListAdapter:"
fd -e kt -e kt
x -exec rg -l 'ContributionsListAdapter' {} \;

Length of output: 55568


🏁 Script executed:

#!/bin/bash
# Search for ContributionsListAdapter definition
rg 'class ContributionsListAdapter' -A 10

Length of output: 1405



---
🏁 Script executed:
```shell
#!/bin/bash
# Find mediaClient and mediaDataExtractor field declarations in ContributionsListFragment
rg -n 'mediaClient|mediaDataExtractor' app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt -B 2 -A 2

Length of output: 398



---
🏁 Script executed:
```shell
#!/bin/bash
# Find where initAdapter() is called and check for null guards or context
rg -n 'initAdapter' app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt -B 5 -A 2

Length of output: 560


Replace double-bangs with requireNotNull() for injected dependencies

Fields mediaClient and mediaDataExtractor are nullable and injected via Dagger. Using !! on injected fields risks NPE if injection fails. Replace with requireNotNull() to provide explicit null safety and clearer error messages.

adapter = ContributionsListAdapter(this,
 requireNotNull(mediaClient) { "mediaClient must be injected" },
 requireNotNull(mediaDataExtractor) { "mediaDataExtractor must be injected" },
 compositeDisposable)
🤖 Prompt for AI Agents
In
app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.kt
around lines 238 to 242, the adapter initialization uses force-unwraps
(mediaClient!! and mediaDataExtractor!!) which can throw NPE if Dagger injection
fails; replace these with requireNotNull(mediaClient) { "mediaClient must be
injected" } and requireNotNull(mediaDataExtractor) { "mediaDataExtractor must be
injected" } when passing to ContributionsListAdapter so null failures produce
explicit, descriptive exceptions.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test with zero-contributions user, but otherwise it seems to be working, thanks a lot!

@nicolas-raoul nicolas-raoul merged commit e81f916 into commons-app:main Oct 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@RitikaPahwa4444 RitikaPahwa4444 RitikaPahwa4444 left review comments

@nicolas-raoul nicolas-raoul nicolas-raoul approved these changes

+1 more reviewer

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /