use of com.meniga.sdk.models.categories.MenigaCategory in project mobile-sdk-android by meniga.
the class MenigaCategoryConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfMenigaCategoryList = new TypeToken<List<MenigaCategory>>() {
}.getType();
Type typeOfMenigaCategory = new TypeToken<MenigaCategory>() {
}.getType();
Type typeOfMenigaUserCategoryList = new TypeToken<List<MenigaUserCategory>>() {
}.getType();
Type typeOfMenigaUserCategory = new TypeToken<MenigaUserCategory>() {
}.getType();
if (typeOfMenigaCategoryList.equals(type) || typeOfMenigaUserCategoryList.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public List<MenigaCategory> convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaCategory[] catsRaw = gson.fromJson(getAsArray(resBody.byteStream()), MenigaCategory[].class);
List<MenigaCategory> cats = new ArrayList<>();
for (MenigaCategory cat : catsRaw) {
if (cat.getIsPublic()) {
cats.add(cat);
} else {
cats.add(new MenigaUserCategory(cat));
}
for (int i = 0; i < cat.getChildren().size(); i++) {
MenigaCategory child = cat.getChildren().get(i);
if (!child.getIsPublic()) {
cat.getChildren().set(i, new MenigaUserCategory(child));
}
}
}
return cats;
}
};
} else if (typeOfMenigaCategory.equals(type) || typeOfMenigaUserCategory.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public MenigaCategory convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaCategory catRaw = gson.fromJson(getAsObject(resBody.byteStream()), MenigaCategory.class);
if (catRaw.getIsPublic()) {
return catRaw;
} else {
return new MenigaUserCategory(catRaw);
}
}
};
}
return null;
}
Aggregations