Skip to content

Commit 9932181

Browse files
authored
Update README.md
1 parent 214c434 commit 9932181

File tree

1 file changed

+111
-3
lines changed

1 file changed

+111
-3
lines changed

README.md

+111-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,115 @@
11
## DynamicPagerAdapter
22

3-
The DynamicPagerAdapter handles View caching and data set changes in a much more friendly way, as well as animations for dismissal of items in the ViewPager. These animations can be overriden to supply your own custom animations if you desire. DynamicPagerAdapter can be used with any ViewPager and is not dependent on the DynamicViewPager.
3+
The DynamicPagerAdapter extends Android's PagerAdapter to do four important things:
44

5-
## DynamicViewPager
5+
* **Has an accessible HashMap View cache using ViewHolders.** The default implementaiton has caching, but it isn't enforced and users of the PagerAdapter don't get access to it.
66

7-
The DynamicViewPager depends on the DynamicPagerAdapter. It adds helper methods for retrieving the current View from the cache, among other things. It also listens to vertical fling and drag-and-drop gestures on the ViewPager to do animated dismissal of Views in the pager.
7+
* **Provides the capability to use multiple view types just like RecyclerView.**
8+
9+
* **Handles data set changes in a much more friendly way,** allowing items to be removed, added, etc. with less issues and effort on your end.
10+
11+
* **Includes optional discard animations.** These are exposed for you to call when you want or to override and create your own.
12+
13+
14+
#### MyPagerAdapter.java
15+
16+
```
17+
public class MyPagerAdapter extends DynamicPagerAdapter {
18+
19+
private List<Integer> values;
20+
21+
public PagerAdapter(List<Integer> values) {
22+
this.values = values;
23+
}
24+
25+
@Override
26+
public ViewHolder onCreateViewHolder(ViewGroup container, int position, int viewType) {
27+
final PagerCardView pagerCardView = new PagerCardView(container.getContext());
28+
return new ViewHolder(pagerCardView) {};
29+
}
30+
31+
@Override
32+
public void onBindViewHolder(ViewHolder viewHolder, int position) {
33+
PagerCardView pagerCardView = (PagerCardView) viewHolder.view;
34+
pagerCardView.setViewData(values.get(position));
35+
}
36+
37+
@Override
38+
public int getCount() {
39+
return values.size();
40+
}
41+
42+
public void updateValues(List<Integer> values) {
43+
this.values = values;
44+
notifyDataSetChanged();
45+
}
46+
}
47+
```
48+
49+
#### SinglePagerActivity.java
50+
51+
```
52+
private MyPagerAdapter pagerAdapter;
53+
private List<Integer> values;
54+
55+
@Override
56+
protected void onCreate(@Nullable Bundle savedInstanceState) {
57+
super.onCreate(savedInstanceState);
58+
setContentView(R.layout.pager_activity);
59+
60+
ViewPager viewPager = (ViewPager) findViewById(R.id.pager_activity_view_pager);
61+
62+
pagerAdapter = new MyPagerAdapter(values);
63+
viewPager.setAdapter(pagerAdapter);
64+
65+
pagerAdapter.setCallbacks(new Callbacks() {
66+
@Override
67+
public void onDiscardFinished(int position, View view) {
68+
if (position != NO_POSITION) {
69+
values.remove(position);
70+
pagerAdapter.updateData(values);
71+
}
72+
}
73+
});
74+
}
75+
```
76+
77+
## SwipeRemovalViewPager
78+
79+
This ViewPager subclass leverages the DynamicPagerAdapter to call fold animations on the View set after the user flings a pager View off the screen (up or down) or performs a drag-and-drop over a certain distance. It also adds helper methods for retrieving the current View from the DynamicPagerAdapter cache, among other things.
80+
81+
Once you have the DynamicPagerAdapter set up, using the DynamicViewPager is as easy as changing the ViewPager reference in XML to SwipeRemovalViewPager.
82+
83+
```
84+
<com.quarkworks.dynamicviewpager.SwipeRemovalViewPager
85+
android:layout_width="match_parent"
86+
android:layout_height="match_parent"
87+
...
88+
/>
89+
```
90+
91+
## PagerContainer
92+
93+
This is a layout wrapper for ViewPagers that we have modified over the years. It passes touch events to the child ViewPager, allowing you to make the ViewPager whatever size you want while still accepting touches from larger areas.
94+
95+
# Including with Gradle
96+
97+
1. Add the JitPack repositorycneter to your project build.gradle:
98+
99+
```
100+
allprojects {
101+
repositories {
102+
...
103+
maven { url "https://jitpack.io" }
104+
}
105+
}
106+
}
107+
```
108+
109+
2. Add the dependency to your app build.gradle:
110+
111+
```
112+
dependencies {
113+
compile 'com.github.QuarkWorks:DynamicPagerAdapter-Android:0.9.6'
114+
}
115+
```

0 commit comments

Comments
 (0)