Skip to content

Commit

Permalink
Fix #54
Browse files Browse the repository at this point in the history
  • Loading branch information
Relex committed Apr 20, 2016
1 parent c02e7ee commit 6003196
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
ChangeLog
--------

##### 1.2.0
* Add properties : ```orientation```(default:horizontal) , ```gravity```(default:center)
* Remove auto register DataSetObserver. [#54](https://github.com/ongakuer/CircleIndicator/issues/54)

<b>Please change like this if you used dynamic adapter:</b>
```java
viewpager.setAdapter(mAdapter);
indicator.setViewPager(viewpager);
mAdapter.registerDataSetObserver(indicator.getDataSetObserver());
```

##### 1.1.9 (2016-04-16)
* Fix bug ([#51](https://github.com/ongakuer/CircleIndicator/issues/51))
* Add Reset Adapter Sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public void setViewPager(ViewPager viewPager) {
createIndicators();
mViewpager.removeOnPageChangeListener(mInternalPageChangeListener);
mViewpager.addOnPageChangeListener(mInternalPageChangeListener);
mViewpager.getAdapter().registerDataSetObserver(mInternalDataSetObserver);
mInternalPageChangeListener.onPageSelected(mViewpager.getCurrentItem());
}
}
Expand All @@ -193,28 +192,36 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
mAnimatorOut.cancel();
}

if (mLastPosition >= 0) {
View currentIndicator = getChildAt(mLastPosition);
View currentIndicator;
if (mLastPosition >= 0 && (currentIndicator = getChildAt(mLastPosition)) != null) {
currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
mAnimatorIn.setTarget(currentIndicator);
mAnimatorIn.start();
}

View selectedIndicator = getChildAt(position);
selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
mAnimatorOut.setTarget(selectedIndicator);
mAnimatorOut.start();

if (selectedIndicator != null) {
selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
mAnimatorOut.setTarget(selectedIndicator);
mAnimatorOut.start();
}
mLastPosition = position;
}

@Override public void onPageScrollStateChanged(int state) {
}
};

public DataSetObserver getDataSetObserver() {
return mInternalDataSetObserver;
}

private DataSetObserver mInternalDataSetObserver = new DataSetObserver() {
@Override public void onChanged() {
super.onChanged();
if (mViewpager == null) {
return;
}

int newCount = mViewpager.getAdapter().getCount();
int currentCount = getChildCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public SamplePagerAdapter(int count) {
return textView;
}

@Override public int getItemPosition(Object object) {
return POSITION_NONE;
}

public void addItem() {
mSize++;
notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import android.view.View;
import android.view.ViewGroup;
import me.relex.circleindicator.CircleIndicator;
import me.relex.circleindicator.sample.SamplePagerAdapter;
import me.relex.circleindicator.sample.R;
import me.relex.circleindicator.sample.SamplePagerAdapter;

public class DynamicAdapterFragment extends Fragment implements View.OnClickListener {

Expand All @@ -26,12 +26,17 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
view.findViewById(R.id.add).setOnClickListener(this);
view.findViewById(R.id.remove).setOnClickListener(this);

mAdapter = new SamplePagerAdapter(1);
mAdapter = new SamplePagerAdapter(1) {
@Override public int getItemPosition(Object object) {
return POSITION_NONE;
}
};

ViewPager viewpager = (ViewPager) view.findViewById(R.id.viewpager);
CircleIndicator indicator = (CircleIndicator) view.findViewById(R.id.indicator);
viewpager.setAdapter(mAdapter);
indicator.setViewPager(viewpager);
mAdapter.registerDataSetObserver(indicator.getDataSetObserver());
}

@Override public void onClick(View v) {
Expand Down

0 comments on commit 6003196

Please sign in to comment.