diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-04-16 12:34:40 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-04-16 12:34:40 -0700 |
| commit | 9c13697880b7dcb35c5ecf541e639998925380eb (patch) | |
| tree | 20685c91be753e3f882c44e677b3950fd9121502 /src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java | |
| parent | 01fa51f3fde9063b1a78c48ca32e9e121c61da2f (diff) | |
Change package path to domain url1.1
Diffstat (limited to 'src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java')
| -rw-r--r-- | src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java b/src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java new file mode 100644 index 0000000..0ab27c4 --- /dev/null +++ b/src/main/java/com/pinapelz/factory/VideoSearchResultConverterFactory.java @@ -0,0 +1,51 @@ +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; + +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); + } + } +} |
