0

I am having an issue in understanding how epoxy works in Android. There is also a tutorial here

imagine i have an adapter as follows:

    public class PhotoAdapter extends EpoxyAdapter {
  private final LoaderModel loaderModel = new LoaderModel();

  public PhotoAdapter() {
    models.add(new HeaderModel("My Photos"));
    models.add(loaderModel);
    notifyItemRangeInserted(0, 2);
  }

  public void addPhotos(Collection<Photo> photos) {
    for (Photo photo : photos) {
      int loaderPosition = models.size() - 1;
      models.add(loaderPosition, photo);
      notifyItemInserted(loaderPosition);
    }
  }
}

This is as per the example here

How would i insert new items about "photos your friends like". So i'd like a new header to say "photos your friends like" and then i need to actually add the photos which i have stored in a model already.

would i just do the following to make it work:

public void addFriendsPhotos(Collection<Photo> photosOfFriends) {

models.add(new HeaderModel("photos your friends like"));
 for (Photo photo : photosOfFriends) {
      int loaderPosition = models.size() - 1;
      models.add(loaderPosition, photo);
      notifyItemInserted(loaderPosition);
    }
  }

I am a little confused about the "models" class. I thought for example there would be a PhotosModel class and a PhotoFriendsModel class etc. instead from the example i see a HeaderModel and LoaderModel. i thought there should be a model for every item row type. Can someone explain.

UPDATE:

let us say i have more information and its not photos. Lets say i have information about addresses where the photos were taken. so now after all the photos are displayed right below the photos i want to display a huge list of addresses where EACH photo was taken. Tell me how i would add the addresses list ?

Dmitrii Leonov
  • 1,331
  • 1
  • 15
  • 25
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • 1
    I have written a beginner friendly Airbnb Epoxy tutorial series. [Check it out here.](https://medium.com/@navendra/nachos-tutorial-for-airbnbs-epoxy-with-kotlin-d1e682fdeb05) – Navendra Sep 21 '18 at 00:08

2 Answers2

0

yes your right EpoxyModel is use for every view type used in your adapter

public void addFriendsPhotos(Collection<Photo> photosOfFriends) 
{

    addModel(new HeaderModel("photos your friends like"));

    for (Photo photo : photosOfFriends) 
    {
        addModel(new PhotModel(photo));
    }

 }
shakil.k
  • 1,623
  • 5
  • 17
  • 27
  • im still confused. let us say i have more information and its not photos. Lets say i have information about addresses where the photos were taken. so now after all the photos are displayed right below the photos i want to display a huge list of addresses where the photos were taken. Tell me how i would add the addresses list ? – j2emanue Dec 13 '16 at 20:21
  • @j2emanue you would ass that information in same EpoxyModel. Create a field 'address' in your photo model and fill that. – VipulKumar Jun 29 '18 at 13:39
0
public class PhotoAdapter extends EpoxyAdapter {
  private final LoaderModel loaderModel = new LoaderModel();

  public PhotoAdapter() {
    models.add(new HeaderModel("My Photos"));
    models.add(loaderModel);
    notifyItemRangeInserted(0, 2);
  }

  public void addPhotos(Collection<Photo> photos) {
    for (Photo photo : photos) {
      int loaderPosition = models.size() - 1;
      models.add(loaderPosition, photo);
      notifyItemInserted(loaderPosition);
    }
  }
}

You could just use models.add(loaderPosition, photo); to insert a new model.

See http://airbnb.io/projects/epoxy/

TonnyL
  • 1,226
  • 1
  • 12
  • 17