Skip to content
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

Carousel helper infinite in MotionLayout by Rodrigo Dominguez #39

Merged

Conversation

rodrigomartind
Copy link
Contributor

I add a new attribute to configure the infinite carousel.
app:carousel_infinite="true"
With this attribute, transition backwardTransition and forwardTransition are enabled always.
The iteration of the items is given in the same way as the following sequence: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5].

Demos

Demo name Normal Infinite
Demo 010 carousel
Demo 020 carousel
Demo 030 carousel
Demo 040 carousel
Demo 060 carousel
Demo colors carousel

@google-cla
Copy link

google-cla bot commented Nov 30, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@rodrigomartind
Copy link
Contributor Author

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Nov 30, 2020

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Nov 30, 2020

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@rodrigomartind
Copy link
Contributor Author

@googlebot I fixed it

@google-cla
Copy link

google-cla bot commented Nov 30, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Nov 30, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@rodrigomartindMeli
Copy link
Contributor

@googlebot I consent

@@ -294,9 +312,36 @@ private void updateItems() {
View view = mList.get(i);
int index = mIndex + i - startIndex;
if (index < 0) {
updateViewVisibility(view, emptyViewBehavior);
if (infiniteCarousel) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of this -- would it be simpler to check if infiniteCarousel is true and then compute index as the modulo of the count? then the bulk of the code would stay the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, refactoring done.

@@ -0,0 +1,49 @@
package androidx.constraintlayout.experiments
Copy link
Collaborator

Choose a reason for hiding this comment

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

(c) notice missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✅

@@ -85,6 +85,7 @@
app:carousel_backwardTransition="@+id/backward"
app:carousel_previousState="@+id/previous"
app:carousel_nextState="@+id/next"
app:carousel_infinite="true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably don't want to have all examples using infinite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have left four infinite examples, and three normals.

button.setOnClickListener(v -> {
Intent intent = new Intent(mainActivity, CarouselHelperActivity.class);
mainActivity.startActivity(intent);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be worth instead to modify the Loader.normalMenuStartUp to get an array of activity classes as a parameter instead, and then add them? Something around those lines, so that next demo that wants to be a separate activity would be easy to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactoring done, in MainActivity you can load the activity classes with examples activitiesDemo

@@ -143,13 +149,24 @@ public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
mIndex--;
System.out.println("decrement index...");
Copy link
Collaborator

Choose a reason for hiding this comment

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

while here, can you remove the printfs? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done✅

if (infiniteCarousel) {
if (mIndex >= mAdapter.count()) {
mIndex = 0;
System.out.println("index capped... " + mIndex);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same thing, we can remove those printfs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✅

@@ -309,17 +360,19 @@ private void updateItems() {
}

final int count = mAdapter.count();
Copy link
Collaborator

Choose a reason for hiding this comment

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

can move the count variable inside the if block, or maybe simpler, add if (infiniteCarousel) { return; } before final int count

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✅

updateViewVisibility(view, emptyViewBehavior);
} else if (index >= mAdapter.count()) {
updateViewVisibility(view, emptyViewBehavior);
if (infiniteCarousel) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh what I meant was more something like:
if (infiniteCarousel) {
index = index % mAdapter.count();
}

but that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🚀

@camaelon camaelon merged commit f10ce02 into androidx:main Dec 1, 2020
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.

None yet

3 participants