-
Notifications
You must be signed in to change notification settings - Fork 265
Further abstraction #37
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
Conversation
Added a very simple example. |
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 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; |
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.
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. |
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.
Could you add some JavaDoc to the new/changed classes, please?
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 !
sample/build.gradle
Outdated
compile project(':material-stepper') | ||
compile ("com.android.support:appcompat-v7:$androidSupportLibraryVersion") | ||
compile ("com.jakewharton:butterknife:$butterknifeVersion") | ||
compile 'com.facebook.stetho:stetho:1.4.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.
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> { |
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.
Maybe some of the logic from here could be actually moved to the AbstractStepAdapter?
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 thought about it and I can't seem to figure out what else is possible to move up. Any suggestion ?
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.
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.
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.
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); |
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.
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); |
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.
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?
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'm not sure what you mean here, do you mean the casting ?
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.
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
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.
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!
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've given some thought about it, maybe throwing an error on getItem because of invalid cast ?
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'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 |
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.
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 { |
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.
Probably this should be named MyStepperFragmentAdapter instead of MyStepperAdapterFragment?
As of the docs, once you think the PR is good to go, I'll add :) |
- removed most of the casting from adapters
- refactored step adapters in the sample app
refactorings for stepstone-tech#37
@zawadz88 Done :) Thanks |
@leonardo2204 thanks for the changes! |
Sure, really appreciate all the help and attention ! |
As in #34.