Skip to content

Conversation

leonardo2204
Copy link
Contributor

As in #34.

@leonardo2204 leonardo2204 changed the title Further abstraction [WIP]Further abstraction Dec 18, 2016
@leonardo2204 leonardo2204 changed the title [WIP]Further abstraction Further abstraction Dec 18, 2016
@leonardo2204
Copy link
Contributor Author

Added a very simple example.

Copy link
Contributor

@zawadz88 zawadz88 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Please review the comments I've made. I guess the README file will also need to be updated before we publish these changes to JCenter as well.

*/
public abstract class AbstractFragmentStepAdapter<T extends Fragment & Step> extends FragmentPagerAdapter implements StepAdapter<T> {

public static final int DEFAULT_NEXT_BUTTON_TEXT = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be moved to StepAdapter now? The one from AbstractStepAdapter could be removed?

import com.stepstone.stepper.Step;

/**
* Created by leonardo on 18/12/16.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some JavaDoc to the new/changed classes, please?

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 !

compile project(':material-stepper')
compile ("com.android.support:appcompat-v7:$androidSupportLibraryVersion")
compile ("com.jakewharton:butterknife:$butterknifeVersion")
compile 'com.facebook.stetho:stetho:1.4.2'
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move the library version to the root build.gradle as the dependencies above?

* Created by leonardo on 18/12/16.
*/

public class NoFragAdapter extends AbstractStepAdapter<NoFragView> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe some of the logic from here could be actually moved to the AbstractStepAdapter?

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 thought about it and I can't seem to figure out what else is possible to move up. Any suggestion ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the instantiateItem method just as getItem in FragmentPagerAdapter was moved inside of the Fragment version of StepAdapter?
findStep also looks like a good candidate.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general it might be good to make AbstractStepAdapter be declared as:

public abstract class AbstractStepAdapter<T extends View & Step> extends PagerAdapter implements StepAdapter<T>

similar to how the Fragment version is declared?

return createStep(position);
}

public abstract T createStep(int position);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer needed here since it's in StepAdapter?

final int stepCount = stepAdapter.getCount();
for (int i = 0; i < stepCount; i++) {
final Step step = stepAdapter.getItem(i);
final Step step = (Step) stepAdapter.createStep(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Due to the fact that StepAdapter no longer gets a this is needed, however this feels kind of nasty. I'm wondering if there's a better way of handling this. @fabiozo @leonardo2204 any ideas?

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'm not sure what you mean here, do you mean the casting ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The object returned from stepAdapter.createStep(i) is casted to Step. This seems kind of weird since I would assume the createStep method to actually return a Step instance. I'm not sure if I explained this well enough :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I get it, you're right. I was thinking about making public interface StepAdapter<T extends Step>, but then all the Frags example would break.
Do you have any ideas ? Gonna think about it for a time!

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've given some thought about it, maybe throwing an error on getItem because of invalid cast ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added a new proposition: leonardo2204#1 please give me your thoughts ;)

android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.stepstone.stepper.sample.MainActivity">

<Button
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move the button somewhere near the bottom, please? The idea is to have most common examples at the top and I think that most people still rely on Fragments

}

private static class MyStepperAdapter extends AbstractStepAdapter {
private static class MyStepperAdapterFragment extends AbstractFragmentStepAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably this should be named MyStepperFragmentAdapter instead of MyStepperAdapterFragment?

@leonardo2204
Copy link
Contributor Author

As of the docs, once you think the PR is good to go, I'll add :)

@leonardo2204
Copy link
Contributor Author

leonardo2204 commented Jan 10, 2017

@zawadz88 Done :)
Waiting for review and merge !

Thanks

@leonardo2204 leonardo2204 mentioned this pull request Jan 11, 2017
@zawadz88 zawadz88 merged commit b2664f5 into stepstone-tech:master Jan 11, 2017
@zawadz88
Copy link
Contributor

@leonardo2204 thanks for the changes!
This will be published to JCenter in version 2.0.0 as there are some breaking API changes.
I'm planning to release it by the end of January as there are some other improvements I want to add + update the documentation.

@leonardo2204
Copy link
Contributor Author

leonardo2204 commented Jan 11, 2017

Sure, really appreciate all the help and attention !
Do you want me to update the docs also ?

@leonardo2204 leonardo2204 mentioned this pull request Jan 11, 2017
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.

2 participants