Skip to content

Commit

Permalink
Add update
Browse files Browse the repository at this point in the history
  • Loading branch information
CullyCross committed Nov 5, 2015
1 parent 49678be commit 357f79d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnPageChange;
import me.cullycross.test4tabs.R;
import me.cullycross.test4tabs.fragments.ContactsFragment;
Expand Down Expand Up @@ -87,6 +88,18 @@ public class FourTabsActivity extends AppCompatActivity
}
}

@OnClick(R.id.fab) public void fabClick() {
Object o = mViewPager.getAdapter().instantiateItem(mViewPager, mViewPager.getCurrentItem());

if (o != null && o instanceof FabClickListener) {
((FabClickListener) o).onFabClick();
}
}

public interface FabClickListener {
void onFabClick();
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public static final String CONTACTS = "Contacts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Code style: SquareAndroid (https://github.com/square/java-code-styles)
* Follow me: @tonyshkurenko
*/
public class DoggyAdapter extends RecyclerView.Adapter<DoggyAdapter.DogItem> {
public class PictureAdapter extends RecyclerView.Adapter<PictureAdapter.DogItem> {

private static final String URL = "http://lorempixel.com/200/200/food/%d/%s";

Expand All @@ -28,7 +28,7 @@ public class DoggyAdapter extends RecyclerView.Adapter<DoggyAdapter.DogItem> {

private int mCount = 50;

public DoggyAdapter(Context ctx) {
public PictureAdapter(Context ctx) {
super();
mContext = ctx;
mRandom = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import butterknife.Bind;
import butterknife.ButterKnife;
import me.cullycross.test4tabs.R;
import me.cullycross.test4tabs.adapters.DoggyAdapter;
import me.cullycross.test4tabs.activities.FourTabsActivity;
import me.cullycross.test4tabs.adapters.PictureAdapter;

public class PicturesFragment extends Fragment {
public class PicturesFragment extends Fragment implements FourTabsActivity.FabClickListener {

@Bind(R.id.recycler_view_images) RecyclerView mRecyclerViewImages;

private PictureAdapter mAdapter;

public static PicturesFragment newInstance() {
final PicturesFragment fragment = new PicturesFragment();
final Bundle args = new Bundle();
Expand All @@ -35,12 +38,17 @@ public PicturesFragment() {
View view = inflater.inflate(R.layout.fragment_pictures, container, false);
ButterKnife.bind(this, view);

mRecyclerViewImages.setAdapter(new DoggyAdapter(getContext()));
mAdapter = new PictureAdapter(getContext());
mRecyclerViewImages.setAdapter(mAdapter);
return view;
}

@Override public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}

@Override public void onFabClick() {
mAdapter.notifyDataSetChanged();
}
}

0 comments on commit 357f79d

Please sign in to comment.