Skip to content
This repository was archived by the owner on Aug 22, 2020. It is now read-only.

Commit eeeeff7

Browse files
committed
VerticalStepperView: notifyItemRangeChanged instead (Better animation)
Signed-off-by: Fung <fython@163.com>
1 parent 78767ae commit eeeeff7

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

demo/src/main/res/layout/fragment_vertical_stepper_adapter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<moe.feng.common.stepperview.VerticalStepperView
99
android:id="@+id/vertical_stepper_view"
1010
android:layout_width="match_parent"
11-
android:layout_height="wrap_content"
11+
android:layout_height="match_parent"
1212
app:step_done_icon="@drawable/ic_done_white_16dp"
1313
app:step_animation_duration="@android:integer/config_mediumAnimTime"/>
1414

library/src/main/java/moe/feng/common/stepperview/StepperViewAdapter.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.content.Context;
44
import android.view.View;
5-
import android.view.ViewGroup;
65

76
public abstract class StepperViewAdapter implements IStepperViewAdapter {
87

@@ -24,11 +23,6 @@ public View getView(int index) {
2423
return mViews[index];
2524
}
2625

27-
@Override
28-
public String getTitle(int index) {
29-
return "Step " + index;
30-
}
31-
3226
@Override
3327
public int size() {
3428
return mViews.length;

library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void prepareListView(Context context) {
6767
mListView.setLayoutManager(new LinearLayoutManager(context));
6868
mListView.setAdapter(mAdapter);
6969

70-
addView(mListView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
70+
addView(mListView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
7171
}
7272

7373
public void setViewAdapter(IStepperViewAdapter viewAdapter) {
@@ -90,7 +90,7 @@ public boolean canPrev() {
9090
public boolean nextStep() {
9191
if (canNext()) {
9292
mCurrentStep++;
93-
mAdapter.notifyDataSetChanged();
93+
mAdapter.notifyItemRangeChanged(mCurrentStep - 1, 2);
9494
return true;
9595
}
9696
return false;
@@ -99,7 +99,7 @@ public boolean nextStep() {
9999
public boolean prevStep() {
100100
if (canPrev()) {
101101
mCurrentStep--;
102-
mAdapter.notifyDataSetChanged();
102+
mAdapter.notifyItemRangeChanged(mCurrentStep, 2);
103103
return true;
104104
}
105105
return false;
@@ -136,8 +136,11 @@ public Drawable getDoneIcon() {
136136
}
137137

138138
public void setCurrentStep(int currentStep) {
139+
int minIndex = Math.min(currentStep, mCurrentStep);
140+
int count = Math.abs(mCurrentStep - currentStep) + 1;
141+
139142
mCurrentStep = currentStep;
140-
mAdapter.notifyDataSetChanged();
143+
mAdapter.notifyItemRangeChanged(minIndex, count);
141144
}
142145

143146
class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemHolder> {

0 commit comments

Comments
 (0)