update
This commit is contained in:
@@ -208,5 +208,6 @@ dependencies {
|
||||
api 'com.github.xuexiangjys.XUtil:xutil-core:2.0.0'
|
||||
|
||||
// api files('libs/svgaplayer-release-v1.2.1.aar')
|
||||
api 'com.blankj:utilcode:1.30.0'//獲取uuid
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yunbao.common.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.lxj.xpopup.core.BottomPopupView;
|
||||
import com.lxj.xpopup.impl.FullScreenPopupView;
|
||||
|
||||
/**
|
||||
* 全屏弹窗
|
||||
*/
|
||||
public abstract class AbsFullDialogPopupWindow extends FullScreenPopupView {
|
||||
public final Context mContext;
|
||||
|
||||
public AbsFullDialogPopupWindow(@NonNull Context context) {
|
||||
super(context);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://github.com/li-xiaojun/XPopup/wiki/5.-%E5%B8%B8%E7%94%A8%E8%AE%BE%E7%BD%AE">参考配置</a>
|
||||
*/
|
||||
public abstract void buildDialog(XPopup.Builder builder);
|
||||
public abstract int bindLayoutId();
|
||||
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return bindLayoutId();
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
XPopup.Builder builder = new XPopup.Builder(mContext);
|
||||
builder.isDestroyOnDismiss(true);
|
||||
builder.enableDrag(false);
|
||||
buildDialog(builder);
|
||||
builder.asCustom(this).show();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ public class ResponseModel<T> {
|
||||
@SerializedName("msg")
|
||||
private String msg;
|
||||
|
||||
private String jsonSrc;
|
||||
|
||||
public int getRet() {
|
||||
return ret;
|
||||
}
|
||||
@@ -46,4 +48,16 @@ public class ResponseModel<T> {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setJsonSrc(String jsonSrc) {
|
||||
this.jsonSrc = jsonSrc;
|
||||
}
|
||||
|
||||
public String getJsonSrc() {
|
||||
return jsonSrc;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return data == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yunbao.common.http.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class JsonConverterFactory extends Converter.Factory {
|
||||
private final Gson gson;
|
||||
|
||||
public static Converter.Factory create(Gson gson) {
|
||||
return new JsonConverterFactory(gson);
|
||||
}
|
||||
|
||||
private JsonConverterFactory(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations,
|
||||
Annotation[] methodAnnotations, Retrofit retrofit) {
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonRequestConverter<>(gson, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
|
||||
Retrofit retrofit) {
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonResponseBodyConverter<>(gson, adapter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.yunbao.common.http.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.Buffer;
|
||||
import retrofit2.Converter;
|
||||
|
||||
public class JsonRequestConverter<T> implements Converter<T, RequestBody> {
|
||||
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
|
||||
private static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||
|
||||
private final Gson gson;
|
||||
private final TypeAdapter<T> adapter;
|
||||
JsonRequestConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody convert(T value) throws IOException {
|
||||
Buffer buffer = new Buffer();
|
||||
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
|
||||
JsonWriter jsonWriter = gson.newJsonWriter(writer);
|
||||
adapter.write(jsonWriter, value);
|
||||
jsonWriter.close();
|
||||
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yunbao.common.http.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.yunbao.common.http.ResponseModel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
|
||||
public class JsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
private final Gson gson;
|
||||
private final TypeAdapter<T> adapter;
|
||||
|
||||
public JsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convert(ResponseBody value) throws IOException {
|
||||
byte[] copy=value.bytes().clone();
|
||||
value=ResponseBody.create(value.contentType(),copy.clone());
|
||||
JsonReader jsonReader = gson.newJsonReader(value.charStream());
|
||||
try {
|
||||
ResponseModel<T> model= (ResponseModel<T>) adapter.read(jsonReader);
|
||||
model.setJsonSrc(new String(copy));
|
||||
return (T) model;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
String src = new String(copy);
|
||||
ResponseModel<T> model = new ResponseModel<T>();
|
||||
model.setJsonSrc(src);
|
||||
return (T) model;
|
||||
} finally {
|
||||
value.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user