|
4 | 4 | import android.graphics.Color;
|
5 | 5 | import android.os.Bundle;
|
6 | 6 | import android.os.Handler;
|
7 |
| -import androidx.appcompat.app.AppCompatActivity; |
8 |
| -import androidx.recyclerview.widget.GridLayoutManager; |
9 |
| -import androidx.recyclerview.widget.LinearLayoutManager; |
10 |
| -import androidx.recyclerview.widget.RecyclerView; |
11 |
| -import androidx.appcompat.widget.Toolbar; |
12 | 7 | import android.view.Menu;
|
13 | 8 | import android.view.MenuInflater;
|
14 | 9 | import android.view.MenuItem;
|
|
44 | 39 |
|
45 | 40 | import java.util.List;
|
46 | 41 |
|
| 42 | +import androidx.appcompat.app.AppCompatActivity; |
| 43 | +import androidx.appcompat.widget.Toolbar; |
| 44 | +import androidx.recyclerview.widget.GridLayoutManager; |
| 45 | +import androidx.recyclerview.widget.LinearLayoutManager; |
| 46 | +import androidx.recyclerview.widget.RecyclerView; |
| 47 | + |
47 | 48 | public class SampleActivity extends AppCompatActivity {
|
48 | 49 | enum Type {
|
49 | 50 | CrossFade(new AlphaCrossFadeAnimator()),
|
@@ -74,7 +75,7 @@ public BaseItemAnimator getAnimator() {
|
74 | 75 | //save our FastAdapter
|
75 | 76 | private FastAdapter mFastAdapter;
|
76 | 77 | //save our FastAdapter
|
77 |
| - private ItemAdapter mItemAdapter; |
| 78 | + private ItemAdapter<IItem> mItemAdapter; |
78 | 79 |
|
79 | 80 | @Override
|
80 | 81 | protected void onCreate(Bundle savedInstanceState) {
|
@@ -121,20 +122,21 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
|
121 | 122 | })
|
122 | 123 | .build();
|
123 | 124 |
|
| 125 | + //create our ItemAdapter which will host our items |
| 126 | + mItemAdapter = new ItemAdapter<>(); |
| 127 | + |
124 | 128 | //create our FastAdapter which will manage everything
|
125 |
| - mFastAdapter = new FastAdapter(); |
| 129 | + mFastAdapter = FastAdapter.with(mItemAdapter); |
126 | 130 | mFastAdapter.withSelectable(true);
|
127 | 131 | mFastAdapter.withMultiSelect(true);
|
128 | 132 | mFastAdapter.withSelectOnLongClick(false);
|
129 |
| - //create our ItemAdapter which will host our items |
130 |
| - mItemAdapter = new ItemAdapter(); |
131 | 133 |
|
132 | 134 | //configure our fastAdapter
|
133 | 135 | //get our recyclerView and do basic setup
|
134 | 136 | mRecyclerView = (RecyclerView) findViewById(R.id.rv);
|
135 | 137 | mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
|
136 | 138 | //mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
137 |
| - mRecyclerView.setAdapter(mItemAdapter.wrap(mFastAdapter)); |
| 139 | + mRecyclerView.setAdapter(mFastAdapter); |
138 | 140 | mRecyclerView.setItemAnimator(new AlphaCrossFadeAnimator());
|
139 | 141 | mRecyclerView.getItemAnimator().setAddDuration(500);
|
140 | 142 | mRecyclerView.getItemAnimator().setRemoveDuration(500);
|
@@ -207,7 +209,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
|
207 | 209 | return true;
|
208 | 210 | case R.id.item_change:
|
209 | 211 | for (Integer pos : (Iterable<Integer>) mFastAdapter.getSelections()) {
|
210 |
| - ImageItem i = (ImageItem) mItemAdapter.getItem(pos); |
| 212 | + ImageItem i = (ImageItem) mItemAdapter.getAdapterItem(pos); |
211 | 213 | i.withName("CHANGED");
|
212 | 214 | i.withDescription("This item was modified");
|
213 | 215 | mItemAdapter.set(pos, i);
|
|
0 commit comments