diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-04-15 01:26:25 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-04-15 01:26:25 -0700 |
| commit | 802defe063ae34a349eb0f59da1100ddb50ea22a (patch) | |
| tree | 37d25107ec2abac76740df69544eadbe6882304e /src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java | |
| parent | 5cc27f5560c05befdee8cbd6db24fc0eaab87cb3 (diff) | |
Implemented VideoSearch Post Request
Diffstat (limited to 'src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java')
| -rw-r--r-- | src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java b/src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java new file mode 100644 index 0000000..de47303 --- /dev/null +++ b/src/main/java/com/pina/factory/VideoSearchResultConverterFactory.java @@ -0,0 +1,51 @@ +package com.pina.factory; + +import com.pina.datatypes.Paginated; +import com.pina.datatypes.SimpleVideo; +import com.pina.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; + +public class VideoSearchResultConverterFactory extends Converter.Factory { + + public static VideoSearchResultConverterFactory create() { + return new VideoSearchResultConverterFactory(); + } + + @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); + } + } +} |
