blob: 2bfd3c31819bf86f85915fe43969d9824cbad280 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package com.pinapelz.factory;
import com.pinapelz.datatypes.Paginated;
import com.pinapelz.datatypes.SimpleVideo;
import com.pinapelz.datatypes.VideoSearchResult;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
/**
* <p>VideoSearchResultConverterFactory class.</p>
*
* @author pinapelz
* @version $Id: $Id
*/
public class VideoSearchResultConverterFactory extends Converter.Factory {
/**
* <p>create.</p>
*
* @return a {@link com.pinapelz.factory.VideoSearchResultConverterFactory} object.
*/
public static VideoSearchResultConverterFactory create() {
return new VideoSearchResultConverterFactory();
}
/** {@inheritDoc} */
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
boolean isPaginated = false;
for (Annotation annotation : annotations) {
if (annotation instanceof Paginated) {
isPaginated = ((Paginated) annotation).value();
}
}
if (isPaginated) {
Type listType = new ParameterizedType() {
@Override
public Type[] getActualTypeArguments() {
return new Type[]{VideoSearchResult.class};
}
@Override
public Type getRawType() {
return List.class;
}
@Override
public Type getOwnerType() {
return null;
}
};
return retrofit.nextResponseBodyConverter(this, listType, annotations);
} else {
return retrofit.nextResponseBodyConverter(this, SimpleVideo.class, annotations);
}
}
}
|