diff --git a/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/ListViewFragment.java b/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/ListViewFragment.java index 2234889..ca1c828 100644 --- a/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/ListViewFragment.java +++ b/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/ListViewFragment.java @@ -62,12 +62,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - // Animate in the visible children - spruceAnimator = new Spruce.SpruceBuilder(listView) - .sortWith(new DefaultSort(100)) - .animateWith(DefaultAnimations.shrinkAnimator(listView, 800), - ObjectAnimator.ofFloat(listView, "translationX", -listView.getWidth(), 0f).setDuration(800)) - .start(); + initSpruce(); } }); @@ -93,6 +88,14 @@ public void onResume() { } } + private void initSpruce() { + spruceAnimator = new Spruce.SpruceBuilder(listView) + .sortWith(new DefaultSort(100)) + .animateWith(DefaultAnimations.shrinkAnimator(listView, 800), + ObjectAnimator.ofFloat(listView, "translationX", -listView.getWidth(), 0f).setDuration(800)) + .start(); + } + private class ListViewAdapter extends BaseAdapter { private List placeholderList; @@ -114,9 +117,7 @@ class ViewHolder implements View.OnClickListener{ @Override public void onClick(View v) { - if (spruceAnimator != null) { - spruceAnimator.start(); - } + initSpruce(); } } diff --git a/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/RecyclerFragment.java b/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/RecyclerFragment.java index b95b776..bc38ea4 100644 --- a/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/RecyclerFragment.java +++ b/app/src/main/java/com/willowtreeapps/spurceexampleapp/fragments/RecyclerFragment.java @@ -63,13 +63,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable @Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { super.onLayoutChildren(recycler, state); - // Animate in the visible children - spruceAnimator = new Spruce.SpruceBuilder(recyclerView) - .sortWith(new DefaultSort(100)) - .animateWith(DefaultAnimations.shrinkAnimator(recyclerView, 800), - ObjectAnimator.ofFloat(recyclerView, "translationX", -recyclerView.getWidth(), 0f).setDuration(800)) - .start(); - + initSpruce(); } }; @@ -93,6 +87,14 @@ public void onResume() { } } + private void initSpruce() { + spruceAnimator = new Spruce.SpruceBuilder(recyclerView) + .sortWith(new DefaultSort(100)) + .animateWith(DefaultAnimations.shrinkAnimator(recyclerView, 800), + ObjectAnimator.ofFloat(recyclerView, "translationX", -recyclerView.getWidth(), 0f).setDuration(800)) + .start(); + } + private class RecyclerAdapter extends RecyclerView.Adapter { List placeholderList; @@ -109,9 +111,7 @@ class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener @Override public void onClick(View v) { - if (spruceAnimator != null) { - spruceAnimator.start(); - } + initSpruce(); } }