Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

Expand All @@ -22,7 +22,7 @@ configure(allprojects) {
androidMinSdkVersion = 14
androidTargetSdkVersion = 24
androidCompileSdkVersion = 24
androidBuildToolsVersion = "25.0.0"
androidBuildToolsVersion = "25.0.2"
androidSupportLibraryVersion = "25.0.0"

/* Sample only */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import android.widget.Button;
import android.widget.LinearLayout;

import com.stepstone.stepper.adapter.AbstractStepAdapter;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.ColorableProgressBar;
import com.stepstone.stepper.internal.DottedProgressBar;
import com.stepstone.stepper.internal.RightNavigationButton;
Expand Down Expand Up @@ -197,7 +197,7 @@ public final void goToPrevStep() {

private int mTypeIdentifier = AbstractStepperType.PROGRESS_BAR;

private AbstractStepAdapter mStepAdapter;
private StepAdapter mStepAdapter;

private AbstractStepperType mStepperType;

Expand Down Expand Up @@ -249,9 +249,9 @@ public void setListener(@NonNull StepperListener listener) {
*
* @param stepAdapter step adapter
*/
public void setAdapter(@NonNull AbstractStepAdapter stepAdapter) {
public void setAdapter(@NonNull StepAdapter stepAdapter) {
this.mStepAdapter = stepAdapter;
mPager.setAdapter(stepAdapter);
mPager.setAdapter(stepAdapter.getPagerAdapter());

mStepperType.onNewAdapter(stepAdapter);

Expand All @@ -271,7 +271,7 @@ public void run() {
* @param stepAdapter step adapter
* @param currentStepPosition the initial step position, must be in the range of the adapter item count
*/
public void setAdapter(@NonNull AbstractStepAdapter stepAdapter, @IntRange(from = 0) int currentStepPosition) {
public void setAdapter(@NonNull StepAdapter stepAdapter, @IntRange(from = 0) int currentStepPosition) {
this.mCurrentStepPosition = currentStepPosition;
setAdapter(stepAdapter);
}
Expand Down Expand Up @@ -538,7 +538,7 @@ private void onUpdate(int newStepPosition) {

if (!isLast) {
int nextButtonTextForStep = mStepAdapter.getNextButtonText(newStepPosition);
if (nextButtonTextForStep == AbstractStepAdapter.DEFAULT_NEXT_BUTTON_TEXT) {
if (nextButtonTextForStep == StepAdapter.DEFAULT_NEXT_BUTTON_TEXT) {
mNextNavigationButton.setText(mNextButtonText);
} else {
mNextNavigationButton.setText(nextButtonTextForStep);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2016 StepStone Services

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.stepstone.stepper.adapter;

import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import com.stepstone.stepper.Step;

/**
* A base adapter class which returns step fragments to use inside of the {@link com.stepstone.stepper.StepperLayout}.
*/
public abstract class AbstractFragmentStepAdapter
extends FragmentPagerAdapter
implements StepAdapter {

private final FragmentManager mFragmentManager;

public AbstractFragmentStepAdapter(FragmentManager fm) {
super(fm);
mFragmentManager = fm;
}

@Override
public final Fragment getItem(int position) {
return (Fragment) createStep(position);
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public Step findStep(ViewPager viewPager, int position) {
String fragmentTag = "android:switcher:" + viewPager.getId() + ":" + this.getItemId(position);
return (Step) mFragmentManager.findFragmentByTag(fragmentTag);
}

/** {@inheritDoc} */
@StringRes
public int getNextButtonText(int position) {
return DEFAULT_NEXT_BUTTON_TEXT;
}

/** {@inheritDoc} */
@Override
public final PagerAdapter getPagerAdapter() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,75 +1,23 @@
/*
Copyright 2016 StepStone Services

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.stepstone.stepper.adapter;

import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.stepstone.stepper.Step;
import android.support.v4.view.PagerAdapter;

/**
* A base adapter class which returns step fragments to use inside of the {@link com.stepstone.stepper.StepperLayout}.
* A base adapter class which returns step to use inside of the {@link com.stepstone.stepper.StepperLayout}.
* This class is intended to be inherited if you need to use {@link com.stepstone.stepper.StepperLayout} without fragments.
* Otherwise, you should use {@link AbstractFragmentStepAdapter}
*/
public abstract class AbstractStepAdapter<T extends Fragment & Step> extends FragmentPagerAdapter {

public static final int DEFAULT_NEXT_BUTTON_TEXT = -1;

private final FragmentManager mFragmentManager;

public AbstractStepAdapter(FragmentManager fm) {
super(fm);
mFragmentManager = fm;
}
public abstract class AbstractStepAdapter extends PagerAdapter implements StepAdapter {

/** {@inheritDoc} */
@Override
public final T getItem(int position) {
return createStep(position);
}

protected abstract T createStep(int position);

/**
* Finds the given step without creating it.
* @see FragmentPagerAdapter#makeFragmentName(int, long)
* @param viewPager view pager to use for displaying step fragments
* @param position step position
* @return step fragment
*/
public Step findStep(ViewPager viewPager, int position) {
String fragmentTag = "android:switcher:" + viewPager.getId() + ":" + this.getItemId(position);
return (Step) mFragmentManager.findFragmentByTag(fragmentTag);
}

/**
* Allows to override the text on the Next button per step.
* For a given step position you need to return a String resource ID for the label to be used.
* If you wish to change the text for selected steps only (and leave the default for the rest)
* then return {@link #DEFAULT_NEXT_BUTTON_TEXT} for the default ones.
* By default this method returns {@link #DEFAULT_NEXT_BUTTON_TEXT} for all steps.
* This method is not invoked for the last step.
* @param position step position
* @return a String resource ID to override the default button text or {@link #DEFAULT_NEXT_BUTTON_TEXT} if the default text should be kept
*/
@StringRes
public int getNextButtonText(int position) {
return DEFAULT_NEXT_BUTTON_TEXT;
}

/** {@inheritDoc} */
@Override
public final PagerAdapter getPagerAdapter() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.stepstone.stepper.adapter;

import android.support.annotation.StringRes;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import com.stepstone.stepper.Step;

/**
* Interface to be used as model to {@link com.stepstone.stepper.StepperLayout}.
*/
public interface StepAdapter {

int DEFAULT_NEXT_BUTTON_TEXT = -1;

/**
* Create each step of the {@link com.stepstone.stepper.StepperLayout}.
* @param position The position of the {@link PagerAdapter} to be used inside the {@link ViewPager}.
* @return the step to be used inside the {@link com.stepstone.stepper.StepperLayout}.
*/
Step createStep(int position);

/**
* Finds the given step without creating it.
* @see FragmentPagerAdapter#makeFragmentName(int, long)
* @param viewPager view pager to use for displaying step fragments
* @param position step position
* @return step fragment
*/
Step findStep(ViewPager viewPager, int position);

/**
* Allows to override the text on the Next button per step.
* For a given step position you need to return a String resource ID for the label to be used.
* If you wish to change the text for selected steps only (and leave the default for the rest)
* then return {@link #DEFAULT_NEXT_BUTTON_TEXT} for the default ones.
* By default this method returns {@link #DEFAULT_NEXT_BUTTON_TEXT} for all steps.
* This method is not invoked for the last step.
* @param position step position
* @return a String resource ID to override the default button text or {@link #DEFAULT_NEXT_BUTTON_TEXT} if the default text should be kept
*/
@StringRes int getNextButtonText(int position);

/**
* Get the step count.
* @return the quantity of steps
*/
int getCount();

/**
* Method for internal purpose. Should not be inherited.
* @return the adapter to be used in the {@link ViewPager}.
*/
PagerAdapter getPagerAdapter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.support.annotation.NonNull;

import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.AbstractStepAdapter;
import com.stepstone.stepper.adapter.StepAdapter;

/**
* A base stepper type all stepper types must extend.
Expand Down Expand Up @@ -58,7 +58,7 @@ public AbstractStepperType(StepperLayout stepperLayout) {
* Called when {@link StepperLayout}'s adapter gets changed
* @param stepAdapter new stepper adapter
*/
public abstract void onNewAdapter(@NonNull AbstractStepAdapter<?> stepAdapter);
public abstract void onNewAdapter(@NonNull StepAdapter stepAdapter);

@ColorInt
protected int getSelectedColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.stepstone.stepper.R;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.AbstractStepAdapter;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.DottedProgressBar;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public void onStepSelected(int newStepPosition) {
* {@inheritDoc}
*/
@Override
public void onNewAdapter(@NonNull AbstractStepAdapter stepAdapter) {
public void onNewAdapter(@NonNull StepAdapter stepAdapter) {
final int stepCount = stepAdapter.getCount();
mDottedProgressBar.setDotCount(stepCount);
mDottedProgressBar.setVisibility(stepCount > 1 ? View.VISIBLE : View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.stepstone.stepper.R;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.AbstractStepAdapter;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.ColorableProgressBar;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public void onStepSelected(int newStepPosition) {
* {@inheritDoc}
*/
@Override
public void onNewAdapter(@NonNull AbstractStepAdapter stepAdapter) {
public void onNewAdapter(@NonNull StepAdapter stepAdapter) {
final int stepCount = stepAdapter.getCount();
mProgressBar.setMax(stepAdapter.getCount());
mProgressBar.setVisibility(stepCount > 1 ? View.VISIBLE : View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.stepstone.stepper.R;
import com.stepstone.stepper.Step;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.AbstractStepAdapter;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.TabsContainer;

import java.util.ArrayList;
Expand Down Expand Up @@ -57,11 +57,11 @@ public void onStepSelected(int newStepPosition) {
* {@inheritDoc}
*/
@Override
public void onNewAdapter(@NonNull AbstractStepAdapter<?> stepAdapter) {
public void onNewAdapter(@NonNull StepAdapter stepAdapter) {
List<Integer> titles = new ArrayList<>();
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 ;)

titles.add(step.getName());
}
mTabsContainer.setSteps(titles);
Expand Down
17 changes: 5 additions & 12 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,28 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".DefaultDotsActivity" />
<activity android:name=".StyledDotsActivity" />
<activity android:name=".ThemedDotsActivity" android:theme="@style/AppTheme.DotStepper" />

<activity
android:name=".ThemedDotsActivity"
android:theme="@style/AppTheme.DotStepper" />
<activity android:name=".DefaultProgressBarActivity" />
<activity android:name=".StyledProgressBarActivity" />

<activity android:name=".DefaultTabsActivity" />
<activity android:name=".StyledTabsActivity" />

<activity android:name=".CombinationActivity" />

<activity android:name=".CustomPageTransformerActivity" />

<activity android:name=".DelayedTransitionStepperActivity" />

<activity android:name=".DifferentNextButtonStepperActivity" />

<activity android:name=".ReturnButtonActivity" />

<activity android:name=".NoFragmentsActivity"/>
</application>

</manifest>
</manifest>
Loading