From 14de918a79943e4961b09fa01ed320c6cad41f2e Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 28 六月 2023 17:14:51 +0800 Subject: [PATCH] Revert "Revert "Merge branch 'hxb' into wjc"" --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java | 73 ++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java new file mode 100644 index 0000000..57ca709 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java @@ -0,0 +1,73 @@ +package com.hdl.sdk.link.core.utils; + +import android.text.TextUtils; + +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; + +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.bean.response.BaseLocalWithCodeResponse; + +import java.lang.reflect.Type; + +/** + * Created by jlchen on 1/6/22. + */ +public class LinkResponseUtils<T> { + + public Type getType(){ + return new TypeToken<BaseLocalResponse<T>>() {}.getType(); + } + + /** + * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects + * + * @param msg + * @return + */ + public static <T> T convertLinkResponse(Object msg, Type type) { + T bean = null; + if (msg != null && msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + try { + final BaseLocalResponse<T> response = GsonConvert.getGson().fromJson(data, type); + if (response != null) { + bean = response.getObjects(); + } + } catch (Exception e) { + LogUtils.e("convertLinkResponse catch:" + e.getMessage()); + } + } + } + return bean; + } + + /** + * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects 鍙湁杩斿洖code 鍒ゆ柇200鏄垚鍔� + * + * @param msg + * @return + */ + public static <T> T convertLinkWithCodeResponse(Object msg, Type type) { + T bean = null; + if (msg != null && msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + try { + final BaseLocalWithCodeResponse<T> response = GsonConvert.getGson().fromJson(data, type); + if (response != null) { + bean = response.getCode(); + } + } catch (Exception e) { + LogUtils.e("convertLinkResponse catch:" + e.getMessage()); + } + } + } + return bean; + } +} -- Gitblit v1.8.0