Skip to content

Comments

Switch to ViewPager2 (got a deprecation warning for ViewPager)#36

Merged
atorch merged 4 commits intomasterfrom
nov_2024
Aug 27, 2025
Merged

Switch to ViewPager2 (got a deprecation warning for ViewPager)#36
atorch merged 4 commits intomasterfrom
nov_2024

Conversation

@atorch
Copy link
Owner

@atorch atorch commented Nov 3, 2024

Some of this code was originally written in 2014, it might be quite stale

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
Copy link
Owner Author

Choose a reason for hiding this comment

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

there might be some other unused imports I can remove

@atorch atorch changed the title Switch to ViewPager2 (got a deprecation waring for ViewPager) Switch to ViewPager2 (got a deprecation warning for ViewPager) Nov 3, 2024
@atorch atorch requested a review from Copilot August 27, 2025 04:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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'
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.viewpager2:viewpager2:1.1.0'

Copilot uses AI. Check for mistakes.
}

public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {
// TODO FragmentPagerAdapter is deprecated
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

This TODO comment is now obsolete since the code has been updated to use FragmentStateAdapter. The comment should be removed.

Suggested change
// TODO FragmentPagerAdapter is deprecated

Copilot uses AI. Check for mistakes.
private int puzzleIndex;
private double correctAnswer;
private ViewPager mViewPager;
private ViewPager2 mViewPager;
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The mViewPager field appears to be unused in the SolvePuzzleFragment class. Consider removing it if it's not needed.

Suggested change
private ViewPager2 mViewPager;

Copilot uses AI. Check for mistakes.
atorch added 2 commits August 26, 2025 22:08
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.
@atorch atorch merged commit 372f3c3 into master Aug 27, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant