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
Adopt the project with ViewPager2 #4020
Conversation
app/build.gradle
Outdated
implementation "android.arch.work:work-runtime:$workManagerVersion" | ||
implementation "com.google.android.material:material:1.0.0" | ||
implementation "com.google.android.material:material:1.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to upgrade material version to use TabLayoutMediator which is added in 1.1.0.
import androidx.annotation.Nullable; | ||
import androidx.vectordrawable.graphics.drawable.ArgbEvaluator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't build with the change and androidx
one is apparently declared for internal use of the package.
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
PagerIndicatorView.this.position = position + positionOffset; | ||
if (ViewCompat.getLayoutDirection(pager) == ViewCompat.LAYOUT_DIRECTION_RTL) { | ||
PagerIndicatorView.this.position = numPages - 1 - PagerIndicatorView.this.position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flips the pager dots for RTL languages, it can't be done once for the view as direction isn't specified at that time and should be done when the view is attached.
core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
Outdated
Show resolved
Hide resolved
Thank you very much for your pull request! It fixes many bugs that must have been there for a long time. It would be easier to merge if you separated the changes to multiple pull requests. For example, the SQL changes are independent from ViewPager2 and I would directly merge those without discussion ;) Some things I noticed while skimming the code:
|
Thanks for the quick review! :)
Yes, or copying it into the project, guess we have to adopt that version anyway. Will apply the rest. Just was in hurry to fix things I see while testing :) |
AFAIK all of them, will provide the patch separately.
I am not sure where the hack is but viewpager2 has an advantage on being able to resize its height in a better way so guess need some help here.
Will apply.
It is understandable that you are trying to avoid, not sure what to suggest :/
Would you please handle this if won't take much time? Other I will do of course.
Just started translation there. Thanks! |
BottomSheetBehavior only allows one scrolling child but we use a ViewPager with multiple scrolling children (shownotes, chapters). So in order to support that, we subclassed Have a look at ViewPagerBottomSheetBehavior. That class is pretty short and I hope that it can be adapted to ViewPager2 with only a few changes. |
Dropped the unrelated changes (and added your multidex check to my app :) persian-calendar/persian-calendar@4859aa8) |
Used a local copy of TabLayoutMediator instead upgrading material, guess should work now |
Bots are OK now! PTAL |
It looks interesting, will investigate what more can be done about but in theory it should work now just like what was before, let's see. |
app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java
Outdated
Show resolved
Hide resolved
* {@link #attach()} call. Changing the ViewPager2 or TabLayout will require a new instantiation of | ||
* TabLayoutMediator. | ||
*/ | ||
public final class TabLayoutMediator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I want to keep the amount of code that we need to take care of as small as possible. At some point, we have to upgrade the dependencies. We already use 64,945 out of 65,536 methods, so we can not go much longer without multidex, anyway.
I will play around with ProGuard to see if we can get a bit more room for new methods without enabling MultiDex. I mean, even big apps like WhatsApp work without MultiDex. Something seems to waste methods...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I want to keep the amount of code that we need to take care of as small as possible. At some point, we have to upgrade the dependencies. We already use 64,945 out of 65,536 methods, so we can not go much longer without multidex, anyway.
So what do you suggest? It isn't a fork (except a new line that had added because of local lints), can (and should) be deleted after the upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will play around with ProGuard to see if we can get a bit more room for new methods without enabling MultiDex. I mean, even big apps like WhatsApp work without MultiDex. Something seems to waste methods...
They may rely more on native codes I believe. I will also check what has consumed the methods number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I brought it down to around 44k by removing -keep class androidx.** { *; }
from the proguard config. Currently fine-tuning the proguard settings so that the tests pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know when you landed it. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :) #4035 is merged, so we have a bit more room for library updates now
ace47d0
to
3b1737e
Compare
private static final int NUM_PAGES = 2; | ||
private static final int POS_TOPLIST = 0; | ||
private static final int POS_TAGS = 1; | ||
private static final int POS_SUGGESTIONS = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in scope of this change but weird that NUM_PAGES is 2 but we have three pages here. Guess better to fix it after the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ByteHamster while this may take time if possile please have a look if NUM_PAGES = 2 is really desired and nothing has got hide by mistake if possible thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created issue #4093 for this.
Bots are happy and did manual testing also. PTAL |
Have updated trasifex with improved messages, wish to see the update soon also. |
app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java
Show resolved
Hide resolved
accc97e
to
0416230
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for rebasing. I have noticed some bugs while testing this PR.
The fragments store the last-used tab. With this PR, the indicator still shows the saved tab but the page that is actually displayed is always the first one. The displayed highlight is corrected after touching the screen for the first time.
How the log screen actually looks like:
While scrolling, the menu is sometimes duplicated (when showing that page for the first time). In previous versions, this was not the case.
If you have shownotes with a big width (more than the screen width), you can no longer scroll their content horizontally.
app/src/main/java/com/google/android/material/bottomsheet/ViewPagerBottomSheetBehavior.java
Outdated
Show resolved
Hide resolved
// FragmentStatePagerAdapter documentation: | ||
// > When using FragmentStatePagerAdapter the host ViewPager must have a valid ID set. | ||
// When opening multiple ItemPagerFragments by clicking "item" -> "visit podcast" -> "item" -> etc, | ||
// the ID is no longer unique and FragmentStatePagerAdapter does not display any pages. | ||
int newId = ViewCompat.generateViewId(); | ||
pager.setId(newId); | ||
pager.setAdapter(new ItemPagerAdapter()); | ||
pager.setAdapter(new ItemPagerAdapter(this)); | ||
pager.setCurrentItem(feedItemPos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When clicking an episode (not the first one in the list), I now see an animation scrolling through the pages of other episodes. Not sure what to do about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done e2ff176
Reverted ViewPager2 adoption in ItemPagerFragment, I understand if you don't see this as a solution so will investigate how it can be fixed properly, but lack of RTL adoption isn't that issue here as there is not tablayout indicator to make things confusing. |
As was requested in AntennaPod#4020 (comment)
As was suggested in AntennaPod#4020 (comment)
As ViewPager2 different lifecycle apparently setHasOptionsMenu needs to be called from onResume() from now on.
cd93435
to
885f333
Compare
Now manages nested child scrolling when the orientation isn't perpendicular
@ByteHamster (posting again, sorry for the spamming) Played some more time with it and now it looks good AFAICT, feel free to have a look to see if you also feel that way. Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks a lot for all the work! Ready for merging?
I believe so. Thanks :) |
ViewPager2 is a recently added component to fix different issues of ViewPager which is itself built upon RecyclerView (though we haven't used this property of it here).
The specific thing that has motivated me to adopt the project with ViewPager2 is lack of RTL languages support on ViewPager which now is supported by ViewPager2, most annoying thing for me when I use the app with a device that uses Persian for its UI, see this for example,
This patch turns it into: (which is the correct scrolling for touch screens)
So the scrolling won't be confusing for RTL languages users anymore. I've fixed minor things which will explain as comment for the patch.
Thanks!