Conversation
| import androidx.fragment.app.FragmentActivity; | ||
| import androidx.fragment.app.FragmentManager; | ||
| import androidx.fragment.app.FragmentPagerAdapter; | ||
| import androidx.viewpager.widget.ViewPager; |
There was a problem hiding this comment.
there might be some other unused imports I can remove
There was a problem hiding this comment.
Pull Request Overview
This PR migrates from the deprecated ViewPager to ViewPager2 to address a deprecation warning. The changes modernize the pagination implementation by switching to the newer ViewPager2 API and its corresponding adapter pattern.
- Replaced ViewPager with ViewPager2 in layout and Java code
- Updated adapter to extend FragmentStateAdapter instead of FragmentPagerAdapter
- Refactored page change listener implementation to use the new callback pattern
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| activity_solve_puzzle.xml | Updated layout to use ViewPager2 widget instead of deprecated ViewPager |
| SolvePuzzle.java | Migrated from ViewPager/FragmentPagerAdapter to ViewPager2/FragmentStateAdapter with updated API calls |
| build.gradle | Added ViewPager2 dependency to support the new implementation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
app/build.gradle
Outdated
| implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
| implementation 'androidx.navigation:navigation-fragment:2.5.3' | ||
| implementation 'androidx.navigation:navigation-ui:2.5.3' | ||
| implementation 'androidx.viewpager2:viewpager2:1.0.0' |
There was a problem hiding this comment.
Consider using a more recent version of ViewPager2. Version 1.0.0 is quite old and newer versions may include important bug fixes and improvements.
| implementation 'androidx.viewpager2:viewpager2:1.0.0' | |
| implementation 'androidx.viewpager2:viewpager2:1.1.0' |
| } | ||
|
|
||
| public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { | ||
| // TODO FragmentPagerAdapter is deprecated |
There was a problem hiding this comment.
This TODO comment is now obsolete since the code has been updated to use FragmentStateAdapter. The comment should be removed.
| // TODO FragmentPagerAdapter is deprecated |
| private int puzzleIndex; | ||
| private double correctAnswer; | ||
| private ViewPager mViewPager; | ||
| private ViewPager2 mViewPager; |
There was a problem hiding this comment.
The mViewPager field appears to be unused in the SolvePuzzleFragment class. Consider removing it if it's not needed.
| private ViewPager2 mViewPager; |
Adds a new instrumented test to verify that swiping horizontally navigates to the next puzzle. The test is configured to run on puzzle level 1 to increase test coverage across different puzzle levels.
- Updates the androidx.viewpager2:viewpager2 dependency from 1.0.0 to 1.1.0. - Increases the minSdkVersion from 16 to 19 to support the updated ViewPager2 library. - Removes an obsolete TODO comment regarding FragmentPagerAdapter. - Refactors the mViewPager field in SolvePuzzleFragment to be a local variable, improving encapsulation.
Some of this code was originally written in 2014, it might be quite stale