Search in sources :

Example 1 with EntityHeader

use of com.mxt.anitrend.model.entity.group.EntityHeader in project anitrend-app by AniTrend.

the class GroupingUtil method groupMediaByRelationType.

public static List<EntityGroup> groupMediaByRelationType(List<MediaEdge> edges) {
    List<EntityGroup> entityMap = new ArrayList<>();
    for (MediaEdge edge : edges) {
        EntityHeader entityHeader = new EntityHeader(edge.getRelationType());
        if (!entityMap.contains(entityHeader))
            entityMap.add(entityHeader);
        else {
            entityHeader.setSize(entityHeader.getSize() + 1);
            entityMap.add(edge.getNode());
        }
    }
    return entityMap;
}
Also used : EntityHeader(com.mxt.anitrend.model.entity.group.EntityHeader) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) MediaEdge(com.mxt.anitrend.model.entity.anilist.edge.MediaEdge)

Example 2 with EntityHeader

use of com.mxt.anitrend.model.entity.group.EntityHeader in project anitrend-app by AniTrend.

the class GroupingUtil method groupStaffByLanguage.

/**
 * Groups media by the media format, assuming that the media has be sorted by language
 * @see KeyUtil.StaffSort
 * <br/>
 *
 * Only to be used when the sort type is @{@link KeyUtil.StaffSort#LANGUAGE}
 * which is the default sort type for the request @{@link KeyUtil#STAFF_MEDIA_REQ}
 * <br/>
 *
 * @param edges The potential external model response which needs to be grouped
 * @param model The current model item/s containing all data minus current mediaItems
 */
public static List<EntityGroup> groupStaffByLanguage(@NonNull List<StaffBase> edges, @Nullable List<EntityGroup> model) {
    List<EntityGroup> entityMap = new ArrayList<>();
    Map<String, List<StaffBase>> map = Stream.of(edges).filter(value -> !TextUtils.isEmpty(value.getLanguage())).collect(Collectors.groupingBy(StaffBase::getLanguage));
    for (Map.Entry<String, List<StaffBase>> entry : CompatUtil.getKeyFilteredMap(map)) {
        EntityHeader entityHeader = new EntityHeader(entry.getKey(), entry.getValue().size());
        if (model == null || !model.contains(entityHeader))
            entityMap.add(entityHeader);
        entityMap.addAll(entry.getValue());
    }
    return entityMap;
}
Also used : StaffEdge(com.mxt.anitrend.model.entity.anilist.edge.StaffEdge) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) CharacterActorsFragment(com.mxt.anitrend.view.fragment.group.CharacterActorsFragment) MediaEdge(com.mxt.anitrend.model.entity.anilist.edge.MediaEdge) StaffBase(com.mxt.anitrend.model.entity.base.StaffBase) EdgeContainer(com.mxt.anitrend.model.entity.container.body.EdgeContainer) EntityHeader(com.mxt.anitrend.model.entity.group.EntityHeader) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) CharacterEdge(com.mxt.anitrend.model.entity.anilist.edge.CharacterEdge) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) List(java.util.List) MediaBase(com.mxt.anitrend.model.entity.base.MediaBase) Map(java.util.Map) Nullable(android.support.annotation.Nullable) EntityHeader(com.mxt.anitrend.model.entity.group.EntityHeader) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with EntityHeader

use of com.mxt.anitrend.model.entity.group.EntityHeader in project anitrend-app by AniTrend.

the class GroupingUtil method groupMediaByFormat.

/**
 * Groups media by the media format, assuming that the media has be sorted by format
 * @see KeyUtil.MediaFormat
 * <br/>
 *
 * Only to be used when the sort type is @{@link KeyUtil.MediaSort#FORMAT}
 * which is the default sort type for the request @{@link KeyUtil#STAFF_MEDIA_REQ}
 * <br/>
 *
 * @param edges The potential external model response which needs to be grouped
 * @param model The current model item/s containing all data minus current mediaItems
 */
public static List<EntityGroup> groupMediaByFormat(@NonNull List<MediaBase> edges, @Nullable List<EntityGroup> model) {
    List<EntityGroup> entityMap = new ArrayList<>();
    Map<String, List<MediaBase>> map = Stream.of(edges).filter(value -> !TextUtils.isEmpty(value.getFormat())).collect(Collectors.groupingBy(MediaBase::getFormat));
    for (Map.Entry<String, List<MediaBase>> entry : CompatUtil.getKeyFilteredMap(map)) {
        EntityHeader entityHeader = new EntityHeader(entry.getKey(), entry.getValue().size());
        if (model == null || !model.contains(entityHeader))
            entityMap.add(entityHeader);
        entityMap.addAll(entry.getValue());
    }
    return entityMap;
}
Also used : StaffEdge(com.mxt.anitrend.model.entity.anilist.edge.StaffEdge) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) CharacterActorsFragment(com.mxt.anitrend.view.fragment.group.CharacterActorsFragment) MediaEdge(com.mxt.anitrend.model.entity.anilist.edge.MediaEdge) StaffBase(com.mxt.anitrend.model.entity.base.StaffBase) EdgeContainer(com.mxt.anitrend.model.entity.container.body.EdgeContainer) EntityHeader(com.mxt.anitrend.model.entity.group.EntityHeader) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) CharacterEdge(com.mxt.anitrend.model.entity.anilist.edge.CharacterEdge) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) List(java.util.List) MediaBase(com.mxt.anitrend.model.entity.base.MediaBase) Map(java.util.Map) Nullable(android.support.annotation.Nullable) EntityHeader(com.mxt.anitrend.model.entity.group.EntityHeader) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

MediaEdge (com.mxt.anitrend.model.entity.anilist.edge.MediaEdge)3 EntityGroup (com.mxt.anitrend.model.entity.group.EntityGroup)3 EntityHeader (com.mxt.anitrend.model.entity.group.EntityHeader)3 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 TextUtils (android.text.TextUtils)2 Collectors (com.annimon.stream.Collectors)2 Stream (com.annimon.stream.Stream)2 CharacterEdge (com.mxt.anitrend.model.entity.anilist.edge.CharacterEdge)2 StaffEdge (com.mxt.anitrend.model.entity.anilist.edge.StaffEdge)2 MediaBase (com.mxt.anitrend.model.entity.base.MediaBase)2 StaffBase (com.mxt.anitrend.model.entity.base.StaffBase)2 EdgeContainer (com.mxt.anitrend.model.entity.container.body.EdgeContainer)2 CharacterActorsFragment (com.mxt.anitrend.view.fragment.group.CharacterActorsFragment)2 List (java.util.List)2 Map (java.util.Map)2