-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add http cache,update version 0.1.9 to 0.2.9
- Loading branch information
1 parent
67284de
commit 0fe9e1b
Showing
4 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
retrofitutils/src/main/java/com/itheima/retrofitutils/StringConverterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.itheima.retrofitutils; | ||
|
||
import java.io.IOException; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
import okhttp3.ResponseBody; | ||
import retrofit2.Converter; | ||
import retrofit2.Retrofit; | ||
|
||
public final class StringConverterFactory extends Converter.Factory { | ||
|
||
public static final StringConverterFactory INSTANCE = new StringConverterFactory(); | ||
|
||
public static StringConverterFactory create() { | ||
return INSTANCE; | ||
} | ||
|
||
// 我们只关实现从ResponseBody 到 String 的转换,所以其它方法可不覆盖 | ||
@Override | ||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { | ||
if (type == String.class) { | ||
return StringConverter.INSTANCE; | ||
} | ||
//其它类型我们不处理,返回null就行 | ||
return super.responseBodyConverter(type, annotations, retrofit); | ||
} | ||
} | ||
|
||
class StringConverter implements Converter<ResponseBody, String> { | ||
|
||
public static final StringConverter INSTANCE = new StringConverter(); | ||
|
||
@Override | ||
public String convert(ResponseBody value) throws IOException { | ||
return value.string(); | ||
} | ||
} |