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;
}
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();
}
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();
}
};
}
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;
}
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;
}
Aggregations