Skip to content

Commit

Permalink
Fixed #99
Browse files Browse the repository at this point in the history
  • Loading branch information
heinrichreimer committed Jul 18, 2016
1 parent 28b4b33 commit bed1200
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1108,26 +1108,43 @@ public void lockSwipeIfNeeded() {
@SuppressWarnings("unused")
public void addSlide(int location, Slide object) {
adapter.addSlide(location, object);
notifyDataSetChanged();
}

@SuppressWarnings("unused")
public boolean addSlide(Slide object) {
return adapter.addSlide(object);
boolean modified = adapter.addSlide(object);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public boolean addSlides(int location, @NonNull Collection<? extends Slide> collection) {
return adapter.addSlides(location, collection);
boolean modified = adapter.addSlides(location, collection);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public boolean addSlides(@NonNull Collection<? extends Slide> collection) {
return adapter.addSlides(collection);
boolean modified = adapter.addSlides(collection);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public void clearSlides() {
adapter.clearSlides();
public boolean clearSlides() {
if (adapter.clearSlides()) {
notifyDataSetChanged();
return true;
}
return false;
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -1189,32 +1206,68 @@ public int lastIndexOfSlide(Object object) {

@SuppressWarnings("unused")
public Slide removeSlide(int location) {
return adapter.removeSlide(location);
Slide object = adapter.removeSlide(location);
notifyDataSetChanged();
return object;
}

@SuppressWarnings("unused")
public boolean removeSlide(Object object) {
return adapter.removeSlide(object);
boolean modified = adapter.removeSlide(object);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public boolean removeSlides(@NonNull Collection<?> collection) {
return adapter.removeSlides(collection);
boolean modified = adapter.removeSlides(collection);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public boolean retainSlides(@NonNull Collection<?> collection) {
return adapter.retainSlides(collection);
boolean modified = adapter.retainSlides(collection);
if (modified) {
notifyDataSetChanged();
}
return modified;
}

@SuppressWarnings("unused")
public Slide setSlide(int location, Slide object) {
return adapter.setSlide(location, object);
Slide oldObject = adapter.setSlide(location, object);
notifyDataSetChanged();
return oldObject;
}

@SuppressWarnings("unused")
public List<Slide> setSlides(List<? extends Slide> list) {
return adapter.setSlides(list);
List<Slide> oldList = adapter.setSlides(list);
notifyDataSetChanged();
return oldList;
}

public void notifyDataSetChanged() {
int position = this.position;
pager.setAdapter(adapter);
pager.setCurrentItem(position);

if (finishIfNeeded())
return;
updateBackground();
updateButtonBackDrawable();
updateButtonNextDrawable();
updateViewPositions();
if (position != getCount())
updateParallax();
updateFullscreen();
updateTaskDescription();
lockSwipeIfNeeded();
}

private class IntroPageChangeListener extends FadeableViewPager.SimpleOnOverscrollPageChangeListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@

public class SlideAdapter extends FragmentStatePagerAdapter {
private List<Slide> data = new ArrayList<>();
private FragmentManager fragmentManager;

public SlideAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
this.fragmentManager = fragmentManager;
data = new ArrayList<>();
}

public SlideAdapter(FragmentManager fragmentManager, @NonNull Collection<? extends Slide> collection) {
super(fragmentManager);
this.fragmentManager = fragmentManager;
data = new ArrayList<>(collection);
}

public void addSlide(int location, Slide object) {
data.add(location, object);
notifyDataSetChanged();
}

public boolean addSlide(Slide object) {
Expand All @@ -49,11 +51,12 @@ public boolean addSlides(@NonNull Collection<? extends Slide> collection) {
return modified;
}

public void clearSlides() {
public boolean clearSlides() {
if (!data.isEmpty()) {
data.clear();
notifyDataSetChanged();
return true;
}
return false;
}

@SuppressWarnings("SuspiciousMethodCalls")
Expand All @@ -74,6 +77,17 @@ public Fragment getItem(int position) {
return data.get(position).getFragment();
}

@Override
public int getItemPosition(Object object) {
if (object instanceof Fragment) {
fragmentManager.beginTransaction()
.detach((Fragment) object)
.attach((Fragment) object)
.commit();
}
return super.getItemPosition(object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment instantiatedFragment = (Fragment) super.instantiateItem(container, position);
Expand All @@ -88,6 +102,14 @@ public Object instantiateItem(ViewGroup container, int position) {
return instantiatedFragment;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (fragment == null)
return;
super.destroyItem(container, position, object);
}

@ColorRes
public int getBackground(int position) {
return data.get(position).getBackground();
Expand Down Expand Up @@ -122,17 +144,14 @@ public int lastIndexOfSlide(Object object) {
}

public Slide removeSlide(int location) {
Slide object = data.remove(location);
notifyDataSetChanged();
return object;
return data.remove(location);
}

@SuppressWarnings("SuspiciousMethodCalls")
public boolean removeSlide(Object object) {
int locationToRemove = data.indexOf(object);
if (locationToRemove >= 0) {
data.remove(locationToRemove);
notifyDataSetChanged();
return true;
}
return false;
Expand All @@ -148,7 +167,6 @@ public boolean removeSlides(@NonNull Collection<?> collection) {
modified = true;
}
}
if (modified) notifyDataSetChanged();
return modified;
}

Expand All @@ -161,20 +179,21 @@ public boolean retainSlides(@NonNull Collection<?> collection) {
i--;
}
}
if (modified) notifyDataSetChanged();
return modified;
}

public Slide setSlide(int location, Slide object) {
Slide oldObject = data.set(location, object);
notifyDataSetChanged();
return oldObject;
return data.set(location, object);
}

public List<Slide> setSlides(List<? extends Slide> list) {
List<Slide> oldList = new ArrayList<>(data);
data = new ArrayList<>(list);
notifyDataSetChanged();
return oldList;
}

@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
}

0 comments on commit bed1200

Please sign in to comment.