Search in sources :

Example 1 with EntityGroup

use of com.mxt.anitrend.model.entity.group.EntityGroup 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 EntityGroup

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

the class CharacterActorsFragment method updateUI.

@Override
protected void updateUI() {
    if (mAdapter == null) {
        mAdapter = new GroupActorAdapter(model, getContext());
        ((GroupActorAdapter) mAdapter).setMediaClickListener(new ItemClickListener<EntityGroup>() {

            /**
             * When the target view from {@link View.OnClickListener}
             * is clicked from a view holder this method will be called
             *
             * @param target view that has been clicked
             * @param data   the model that at the click index
             */
            @Override
            public void onItemClick(View target, EntityGroup data) {
                switch(target.getId()) {
                    case R.id.container:
                        Intent intent = new Intent(getActivity(), MediaActivity.class);
                        intent.putExtra(KeyUtil.arg_id, ((MediaBase) data).getId());
                        intent.putExtra(KeyUtil.arg_mediaType, ((MediaBase) data).getType());
                        CompatUtil.startRevealAnim(getActivity(), target, intent);
                        break;
                }
            }

            /**
             * When the target view from {@link View.OnLongClickListener}
             * is clicked from a view holder this method will be called
             *
             * @param target view that has been long clicked
             * @param data   the model that at the long click index
             */
            @Override
            public void onItemLongClick(View target, EntityGroup data) {
                switch(target.getId()) {
                    case R.id.container:
                        if (getPresenter().getApplicationPref().isAuthenticated()) {
                            mediaActionUtil = new MediaActionUtil.Builder().setModel((MediaBase) data).build(getActivity());
                            mediaActionUtil.startSeriesAction();
                        } else
                            NotifyUtil.makeText(getContext(), R.string.info_login_req, R.drawable.ic_group_add_grey_600_18dp, Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
    }
    setSwipeRefreshLayoutEnabled(false);
    injectAdapter();
}
Also used : GroupActorAdapter(com.mxt.anitrend.adapter.recycler.group.GroupActorAdapter) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) QueryContainerBuilder(com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder) Intent(android.content.Intent) MediaActivity(com.mxt.anitrend.view.activity.detail.MediaActivity) MediaBase(com.mxt.anitrend.model.entity.base.MediaBase) View(android.view.View)

Example 3 with EntityGroup

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

the class GroupSeriesListAdapter method getFilter.

@Override
public Filter getFilter() {
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            String filter = constraint.toString();
            if (filter.isEmpty()) {
                data = clone;
            } else {
                data = new ArrayList<>();
                for (EntityGroup model : clone) {
                    if (model instanceof MediaList) {
                        MediaBase mediaBase = ((MediaList) model).getMedia();
                        if (mediaBase.getTitle().getEnglish().toLowerCase(Locale.getDefault()).contains(filter) || mediaBase.getTitle().getRomaji().toLowerCase(Locale.getDefault()).contains(filter) || mediaBase.getTitle().getOriginal().toLowerCase(Locale.getDefault()).contains(filter))
                            data.add(model);
                    }
                }
            }
            FilterResults results = new FilterResults();
            results.values = data;
            return results;
        }

        @Override
        @SuppressWarnings("unchecked")
        protected void publishResults(CharSequence constraint, FilterResults results) {
            data = new ArrayList<>((List<EntityGroup>) results.values);
            notifyDataSetChanged();
        }
    };
}
Also used : MediaList(com.mxt.anitrend.model.entity.anilist.MediaList) Filter(android.widget.Filter) EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) MediaList(com.mxt.anitrend.model.entity.anilist.MediaList) ArrayList(java.util.ArrayList) List(java.util.List) MediaBase(com.mxt.anitrend.model.entity.base.MediaBase)

Example 4 with EntityGroup

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

the class GroupingUtil method groupActorMediaEdge.

/**
 * Groups edge container items their media/node and the character role
 * N.B. In this use case the main model is not used to check for existence
 * of a given role because the voiceActors and characterRoles are grouped by media
 * <br/>
 *
 * @see CharacterActorsFragment restricted and should only be used by this
 * @see EdgeContainer
 * <br/>
 *
 * @param edges The potential external model response which needs to be grouped
 */
public static List<EntityGroup> groupActorMediaEdge(List<MediaEdge> edges) {
    List<EntityGroup> entityMap = new ArrayList<>();
    for (MediaEdge edge : edges) {
        if (edge.getNode() != null) {
            if (!TextUtils.isEmpty(edge.getCharacterRole()))
                edge.getNode().setSubGroupTitle(edge.getCharacterRole());
            edge.getNode().setContentType(KeyUtil.RECYCLER_TYPE_HEADER);
            entityMap.add(edge.getNode());
        }
        if (!CompatUtil.isEmpty(edge.getVoiceActors()))
            entityMap.addAll(edge.getVoiceActors());
    }
    return entityMap;
}
Also used : EntityGroup(com.mxt.anitrend.model.entity.group.EntityGroup) ArrayList(java.util.ArrayList) MediaEdge(com.mxt.anitrend.model.entity.anilist.edge.MediaEdge)

Example 5 with EntityGroup

use of com.mxt.anitrend.model.entity.group.EntityGroup 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)

Aggregations

EntityGroup (com.mxt.anitrend.model.entity.group.EntityGroup)6 ArrayList (java.util.ArrayList)5 MediaEdge (com.mxt.anitrend.model.entity.anilist.edge.MediaEdge)4 MediaBase (com.mxt.anitrend.model.entity.base.MediaBase)4 EntityHeader (com.mxt.anitrend.model.entity.group.EntityHeader)3 List (java.util.List)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 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 Map (java.util.Map)2 Intent (android.content.Intent)1 View (android.view.View)1 Filter (android.widget.Filter)1