9 changed files with 1136 additions and 49 deletions
-
2app/build.gradle
-
108app/src/main/java/com/ouxuan/oxface/MainActivity.java
-
4app/src/main/java/com/ouxuan/oxface/OxFaceApplication.java
-
491app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java
-
1app/src/main/java/com/ouxuan/oxface/device/DeviceUtils.java
-
112app/src/main/java/com/ouxuan/oxface/example/ApiResponseDataExample.java
-
323app/src/main/java/com/ouxuan/oxface/network/api/PadApiService.java
-
47app/src/main/java/com/ouxuan/oxface/network/callback/CompleteApiResponseCallback.java
-
97app/src/main/java/com/ouxuan/oxface/network/utils/NetworkUtils.java
@ -0,0 +1,491 @@ |
|||
package com.ouxuan.oxface.data; |
|||
|
|||
import android.content.Context; |
|||
import android.content.SharedPreferences; |
|||
import android.util.Log; |
|||
|
|||
import com.google.gson.Gson; |
|||
import com.google.gson.JsonObject; |
|||
import com.google.gson.JsonParser; |
|||
import com.ouxuan.oxface.network.api.PadApiService; |
|||
import com.ouxuan.oxface.network.model.ApiResponse; |
|||
|
|||
/** |
|||
* 设备选择数据管理器 |
|||
* 单例模式,用于持久化保存和管理设备选择相关数据 |
|||
*/ |
|||
public class DeviceSelectDataManager { |
|||
|
|||
private static final String TAG = "DeviceSelectDataManager"; |
|||
private static final String PREFS_NAME = "device_select_prefs"; |
|||
private static final String KEY_SELECT_RESPONSE = "select_response"; |
|||
private static final String KEY_SELECTED_HARDWARE_ID = "selected_hardware_id"; |
|||
private static final String KEY_SELECTED_HARDWARE_NAME = "selected_hardware_name"; |
|||
private static final String KEY_SESSION_TOKEN = "session_token"; |
|||
private static final String KEY_VALID_UNTIL = "valid_until"; |
|||
private static final String KEY_SELECT_TIME = "select_time"; |
|||
private static final String KEY_IS_DEVICE_SELECTED = "is_device_selected"; |
|||
|
|||
// API响应存储相关常量 |
|||
private static final String KEY_API_RESPONSE_CODE = "api_response_code"; |
|||
private static final String KEY_API_RESPONSE_DATA_JSON = "api_response_data_json"; |
|||
private static final String KEY_API_RESPONSE_MESSAGE = "api_response_message"; |
|||
private static final String KEY_API_FULL_RESPONSE = "api_full_response"; |
|||
|
|||
private SharedPreferences preferences; |
|||
private Gson gson; |
|||
|
|||
// 单例实例 |
|||
private static volatile DeviceSelectDataManager instance; |
|||
|
|||
// 内存缓存 |
|||
private PadApiService.PadSelectResponse currentSelectResponse; |
|||
private PadApiService.PadInfo currentSelectedPadInfo; |
|||
private boolean isDeviceSelected = false; |
|||
|
|||
// API响应存储 |
|||
private int apiResponseCode; |
|||
private String apiResponseDataJson; |
|||
private String apiResponseMessage; |
|||
private String apiFullResponse; |
|||
|
|||
private DeviceSelectDataManager(Context context) { |
|||
preferences = context.getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); |
|||
gson = new Gson(); |
|||
loadSelectDataFromPrefs(); |
|||
} |
|||
|
|||
/** |
|||
* 获取DeviceSelectDataManager单例实例 |
|||
* @param context 上下文 |
|||
* @return DeviceSelectDataManager实例 |
|||
*/ |
|||
public static DeviceSelectDataManager getInstance(Context context) { |
|||
if (instance == null) { |
|||
synchronized (DeviceSelectDataManager.class) { |
|||
if (instance == null) { |
|||
instance = new DeviceSelectDataManager(context); |
|||
} |
|||
} |
|||
} |
|||
return instance; |
|||
} |
|||
|
|||
/** |
|||
* 保存完整的API响应数据(包括code和data) |
|||
* @param apiResponse 完整的API响应 |
|||
* @param selectedPadInfo 选中的设备信息 |
|||
*/ |
|||
public void saveCompleteApiResponse(ApiResponse<PadApiService.PadSelectResponse> apiResponse, PadApiService.PadInfo selectedPadInfo) { |
|||
if (apiResponse == null) { |
|||
Log.w(TAG, "API响应数据为空,无法保存"); |
|||
return; |
|||
} |
|||
|
|||
try { |
|||
// 保存到内存缓存 |
|||
this.currentSelectResponse = apiResponse.getData(); |
|||
this.currentSelectedPadInfo = selectedPadInfo; |
|||
this.isDeviceSelected = apiResponse.isSuccess(); |
|||
this.apiResponseCode = apiResponse.getCode(); |
|||
this.apiResponseMessage = apiResponse.getMessage(); |
|||
|
|||
// 将data对象转换为JSON字符串 |
|||
if (apiResponse.getData() != null) { |
|||
this.apiResponseDataJson = gson.toJson(apiResponse.getData()); |
|||
} |
|||
|
|||
// 将完整响应转换为JSON字符串 |
|||
this.apiFullResponse = gson.toJson(apiResponse); |
|||
|
|||
// 保存到持久化存储 |
|||
SharedPreferences.Editor editor = preferences.edit(); |
|||
|
|||
// 保存原有的设备选择数据 |
|||
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(currentSelectResponse)); |
|||
|
|||
if (selectedPadInfo != null) { |
|||
editor.putInt(KEY_SELECTED_HARDWARE_ID, selectedPadInfo.getHardwareId()); |
|||
editor.putString(KEY_SELECTED_HARDWARE_NAME, selectedPadInfo.getHardwareName()); |
|||
} |
|||
|
|||
if (currentSelectResponse != null && currentSelectResponse.getSessionToken() != null) { |
|||
editor.putString(KEY_SESSION_TOKEN, currentSelectResponse.getSessionToken()); |
|||
} |
|||
|
|||
editor.putLong(KEY_VALID_UNTIL, currentSelectResponse != null ? currentSelectResponse.getValidUntil() : 0); |
|||
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|||
editor.putBoolean(KEY_IS_DEVICE_SELECTED, isDeviceSelected); |
|||
|
|||
// 保存API响应数据 |
|||
editor.putInt(KEY_API_RESPONSE_CODE, apiResponseCode); |
|||
editor.putString(KEY_API_RESPONSE_DATA_JSON, apiResponseDataJson); |
|||
editor.putString(KEY_API_RESPONSE_MESSAGE, apiResponseMessage); |
|||
editor.putString(KEY_API_FULL_RESPONSE, apiFullResponse); |
|||
|
|||
editor.apply(); |
|||
|
|||
Log.d(TAG, "完整API响应数据保存成功"); |
|||
logCompleteApiResponseInfo(); |
|||
|
|||
} catch (Exception e) { |
|||
Log.e(TAG, "保存API响应数据失败: " + e.getMessage(), e); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取当前选择响应数据 |
|||
* @return 选择响应数据,如果未选择返回null |
|||
*/ |
|||
public PadApiService.PadSelectResponse getSelectResponse() { |
|||
return currentSelectResponse; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前选中的设备信息 |
|||
* @return 选中的设备信息,如果未选择返回null |
|||
*/ |
|||
public PadApiService.PadInfo getSelectedPadInfo() { |
|||
return currentSelectedPadInfo; |
|||
} |
|||
|
|||
/** |
|||
* 获取会话Token |
|||
* @return 会话Token |
|||
*/ |
|||
public String getSessionToken() { |
|||
if (currentSelectResponse != null) { |
|||
return currentSelectResponse.getSessionToken(); |
|||
} |
|||
return preferences.getString(KEY_SESSION_TOKEN, ""); |
|||
} |
|||
|
|||
/** |
|||
* 获取选中的硬件ID |
|||
* @return 硬件ID |
|||
*/ |
|||
public int getSelectedHardwareId() { |
|||
if (currentSelectedPadInfo != null) { |
|||
return currentSelectedPadInfo.getHardwareId(); |
|||
} |
|||
return preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0); |
|||
} |
|||
|
|||
/** |
|||
* 获取选中的硬件名称 |
|||
* @return 硬件名称 |
|||
*/ |
|||
public String getSelectedHardwareName() { |
|||
if (currentSelectedPadInfo != null) { |
|||
return currentSelectedPadInfo.getHardwareName(); |
|||
} |
|||
return preferences.getString(KEY_SELECTED_HARDWARE_NAME, ""); |
|||
} |
|||
|
|||
/** |
|||
* 获取有效期至 |
|||
* @return 有效期时间戳 |
|||
*/ |
|||
public long getValidUntil() { |
|||
if (currentSelectResponse != null) { |
|||
return currentSelectResponse.getValidUntil(); |
|||
} |
|||
return preferences.getLong(KEY_VALID_UNTIL, 0); |
|||
} |
|||
|
|||
/** |
|||
* 检查是否已选择设备 |
|||
* @return true如果已选择设备 |
|||
*/ |
|||
public boolean isDeviceSelected() { |
|||
return isDeviceSelected && currentSelectResponse != null; |
|||
} |
|||
|
|||
/** |
|||
* 检查会话是否有效 |
|||
* @return true如果会话有效 |
|||
*/ |
|||
public boolean isSessionValid() { |
|||
long validUntil = getValidUntil(); |
|||
if (validUntil <= 0) { |
|||
return false; |
|||
} |
|||
|
|||
long currentTime = System.currentTimeMillis(); |
|||
boolean isValid = currentTime < validUntil; |
|||
|
|||
Log.d(TAG, "会话有效性检查 - 当前时间: " + currentTime + ", 有效期至: " + validUntil + ", 有效: " + isValid); |
|||
return isValid; |
|||
} |
|||
|
|||
/** |
|||
* 检查是否可以继续使用当前设备 |
|||
* @return true如果可以继续使用 |
|||
*/ |
|||
public boolean canContinueUsingDevice() { |
|||
return isDeviceSelected() && isSessionValid(); |
|||
} |
|||
|
|||
/** |
|||
* 清除设备选择数据 |
|||
*/ |
|||
public void clearDeviceSelectData() { |
|||
// 清除内存缓存 |
|||
this.currentSelectResponse = null; |
|||
this.currentSelectedPadInfo = null; |
|||
this.isDeviceSelected = false; |
|||
this.apiResponseCode = 0; |
|||
this.apiResponseDataJson = null; |
|||
this.apiResponseMessage = null; |
|||
this.apiFullResponse = null; |
|||
|
|||
// 清除持久化存储 |
|||
SharedPreferences.Editor editor = preferences.edit(); |
|||
editor.remove(KEY_SELECT_RESPONSE); |
|||
editor.remove(KEY_SELECTED_HARDWARE_ID); |
|||
editor.remove(KEY_SELECTED_HARDWARE_NAME); |
|||
editor.remove(KEY_SESSION_TOKEN); |
|||
editor.remove(KEY_VALID_UNTIL); |
|||
editor.remove(KEY_SELECT_TIME); |
|||
editor.putBoolean(KEY_IS_DEVICE_SELECTED, false); |
|||
|
|||
// 清除API响应数据 |
|||
editor.remove(KEY_API_RESPONSE_CODE); |
|||
editor.remove(KEY_API_RESPONSE_DATA_JSON); |
|||
editor.remove(KEY_API_RESPONSE_MESSAGE); |
|||
editor.remove(KEY_API_FULL_RESPONSE); |
|||
|
|||
editor.apply(); |
|||
|
|||
Log.d(TAG, "设备选择数据已清除"); |
|||
} |
|||
|
|||
/** |
|||
* 从SharedPreferences加载设备选择数据 |
|||
*/ |
|||
private void loadSelectDataFromPrefs() { |
|||
try { |
|||
String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); |
|||
boolean savedIsDeviceSelected = preferences.getBoolean(KEY_IS_DEVICE_SELECTED, false); |
|||
|
|||
if (!selectResponseJson.isEmpty() && savedIsDeviceSelected) { |
|||
currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); |
|||
|
|||
// 重建PadInfo对象 |
|||
int hardwareId = preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0); |
|||
String hardwareName = preferences.getString(KEY_SELECTED_HARDWARE_NAME, ""); |
|||
if (hardwareId > 0) { |
|||
currentSelectedPadInfo = new PadApiService.PadInfo(); |
|||
currentSelectedPadInfo.setHardwareId(hardwareId); |
|||
currentSelectedPadInfo.setHardwareName(hardwareName); |
|||
} |
|||
|
|||
isDeviceSelected = true; |
|||
Log.d(TAG, "从本地存储恢复设备选择数据成功"); |
|||
} else { |
|||
Log.d(TAG, "本地无有效设备选择数据"); |
|||
} |
|||
|
|||
// 加载API响应数据 |
|||
apiResponseCode = preferences.getInt(KEY_API_RESPONSE_CODE, 0); |
|||
apiResponseDataJson = preferences.getString(KEY_API_RESPONSE_DATA_JSON, null); |
|||
apiResponseMessage = preferences.getString(KEY_API_RESPONSE_MESSAGE, null); |
|||
apiFullResponse = preferences.getString(KEY_API_FULL_RESPONSE, null); |
|||
|
|||
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { |
|||
Log.d(TAG, "从本地存储恢复API响应数据成功"); |
|||
} |
|||
} catch (Exception e) { |
|||
Log.e(TAG, "加载设备选择数据失败: " + e.getMessage()); |
|||
// 清除可能损坏的数据 |
|||
clearDeviceSelectData(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 打印选择信息到日志 |
|||
*/ |
|||
private void logSelectInfo() { |
|||
if (currentSelectResponse != null) { |
|||
Log.i(TAG, "=== 当前设备选择信息 ==="); |
|||
Log.i(TAG, "选择结果: " + currentSelectResponse.getResult()); |
|||
Log.i(TAG, "响应消息: " + currentSelectResponse.getMessage()); |
|||
Log.i(TAG, "选中设备ID: " + getSelectedHardwareId()); |
|||
Log.i(TAG, "选中设备名称: " + getSelectedHardwareName()); |
|||
Log.i(TAG, "会话Token: " + (getSessionToken() != null && !getSessionToken().isEmpty() ? "已设置" : "未设置")); |
|||
Log.i(TAG, "有效期至: " + getValidUntil()); |
|||
Log.i(TAG, "会话是否有效: " + isSessionValid()); |
|||
Log.i(TAG, "========================"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取选择时间 |
|||
* @return 选择时间戳 |
|||
*/ |
|||
public long getSelectTime() { |
|||
return preferences.getLong(KEY_SELECT_TIME, 0); |
|||
} |
|||
|
|||
// ========== API响应数据相关方法 ========== |
|||
|
|||
/** |
|||
* 保存设备选择响应数据(兼容旧代码) |
|||
* @param selectResponse 选择响应数据 |
|||
* @param selectedPadInfo 选中的设备信息 |
|||
*/ |
|||
public void saveDeviceSelectData(PadApiService.PadSelectResponse selectResponse, PadApiService.PadInfo selectedPadInfo) { |
|||
if (selectResponse == null) { |
|||
Log.w(TAG, "选择响应数据为空,无法保存"); |
|||
return; |
|||
} |
|||
|
|||
// 保存到内存缓存 |
|||
this.currentSelectResponse = selectResponse; |
|||
this.currentSelectedPadInfo = selectedPadInfo; |
|||
this.isDeviceSelected = true; |
|||
|
|||
// 保存到持久化存储 |
|||
SharedPreferences.Editor editor = preferences.edit(); |
|||
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(selectResponse)); |
|||
|
|||
if (selectedPadInfo != null) { |
|||
editor.putInt(KEY_SELECTED_HARDWARE_ID, selectedPadInfo.getHardwareId()); |
|||
editor.putString(KEY_SELECTED_HARDWARE_NAME, selectedPadInfo.getHardwareName()); |
|||
} |
|||
|
|||
if (selectResponse.getSessionToken() != null) { |
|||
editor.putString(KEY_SESSION_TOKEN, selectResponse.getSessionToken()); |
|||
} |
|||
|
|||
editor.putLong(KEY_VALID_UNTIL, selectResponse.getValidUntil()); |
|||
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|||
editor.putBoolean(KEY_IS_DEVICE_SELECTED, true); |
|||
editor.apply(); |
|||
|
|||
Log.d(TAG, "设备选择数据保存成功"); |
|||
logSelectInfo(); |
|||
} |
|||
|
|||
/** |
|||
* 获取API响应的Code |
|||
* @return API响应的Code |
|||
*/ |
|||
public int getApiResponseCode() { |
|||
return apiResponseCode != 0 ? apiResponseCode : preferences.getInt(KEY_API_RESPONSE_CODE, -1); |
|||
} |
|||
|
|||
/** |
|||
* 获取API响应的Data(JSON形式) |
|||
* @return API响应的Data,以JSON字符串形式返回 |
|||
*/ |
|||
public String getApiResponseDataJson() { |
|||
return apiResponseDataJson != null ? apiResponseDataJson : preferences.getString(KEY_API_RESPONSE_DATA_JSON, ""); |
|||
} |
|||
|
|||
/** |
|||
* 获取API响应的Message |
|||
* @return API响应的Message |
|||
*/ |
|||
public String getApiResponseMessage() { |
|||
return apiResponseMessage != null ? apiResponseMessage : preferences.getString(KEY_API_RESPONSE_MESSAGE, ""); |
|||
} |
|||
|
|||
/** |
|||
* 获取完整的API响应(JSON形式) |
|||
* @return 完整的API响应,以JSON字符串形式返回 |
|||
*/ |
|||
public String getApiFullResponse() { |
|||
return apiFullResponse != null ? apiFullResponse : preferences.getString(KEY_API_FULL_RESPONSE, ""); |
|||
} |
|||
|
|||
/** |
|||
* 解析API响应的Data为PadConfig对象 |
|||
* @return PadConfig对象,如果解析失败返回null |
|||
*/ |
|||
public PadApiService.PadConfig getPadConfig() { |
|||
try { |
|||
String dataJson = getApiResponseDataJson(); |
|||
if (!dataJson.isEmpty()) { |
|||
PadApiService.PadSelectResponse response = gson.fromJson(dataJson, PadApiService.PadSelectResponse.class); |
|||
return response != null ? response.getPadConfig() : null; |
|||
} |
|||
} catch (Exception e) { |
|||
Log.e(TAG, "解析PadConfig失败: " + e.getMessage()); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 获取店铺信息 |
|||
* @return 包含店铺名称和Logo的数组,[name, logo] |
|||
*/ |
|||
public String[] getStoreInfo() { |
|||
try { |
|||
String dataJson = getApiResponseDataJson(); |
|||
if (!dataJson.isEmpty()) { |
|||
PadApiService.PadSelectResponse response = gson.fromJson(dataJson, PadApiService.PadSelectResponse.class); |
|||
if (response != null) { |
|||
return new String[]{response.getName(), response.getLogo()}; |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
Log.e(TAG, "获取店铺信息失败: " + e.getMessage()); |
|||
} |
|||
return new String[]{"", ""}; |
|||
} |
|||
|
|||
/** |
|||
* 检查是否有完整的API响应数据 |
|||
* @return true如果有完整的API响应数据 |
|||
*/ |
|||
public boolean hasCompleteApiResponse() { |
|||
return getApiResponseCode() >= 0 && !getApiResponseDataJson().isEmpty(); |
|||
} |
|||
|
|||
/** |
|||
* 清除API响应数据 |
|||
*/ |
|||
public void clearApiResponseData() { |
|||
// 清除内存缓存 |
|||
this.apiResponseCode = 0; |
|||
this.apiResponseDataJson = null; |
|||
this.apiResponseMessage = null; |
|||
this.apiFullResponse = null; |
|||
|
|||
// 清除持久化存储 |
|||
SharedPreferences.Editor editor = preferences.edit(); |
|||
editor.remove(KEY_API_RESPONSE_CODE); |
|||
editor.remove(KEY_API_RESPONSE_DATA_JSON); |
|||
editor.remove(KEY_API_RESPONSE_MESSAGE); |
|||
editor.remove(KEY_API_FULL_RESPONSE); |
|||
editor.apply(); |
|||
|
|||
Log.d(TAG, "API响应数据已清除"); |
|||
} |
|||
|
|||
/** |
|||
* 打印完整API响应信息到日志 |
|||
*/ |
|||
private void logCompleteApiResponseInfo() { |
|||
Log.i(TAG, "=== 完整API响应信息 ==="); |
|||
Log.i(TAG, "API响应Code: " + getApiResponseCode()); |
|||
Log.i(TAG, "API响应Message: " + getApiResponseMessage()); |
|||
Log.i(TAG, "API响应Data长度: " + getApiResponseDataJson().length() + " 字符"); |
|||
Log.i(TAG, "API完整响应长度: " + getApiFullResponse().length() + " 字符"); |
|||
|
|||
// 打印设备配置信息 |
|||
PadApiService.PadConfig padConfig = getPadConfig(); |
|||
if (padConfig != null) { |
|||
Log.i(TAG, "设备配置 - ID: " + padConfig.getId() + ", 用户名: " + padConfig.getUsername()); |
|||
Log.i(TAG, "设备配置 - 人脸识别: " + (padConfig.getIsCheckFace() == 1 ? "开启" : "关闭")); |
|||
Log.i(TAG, "设备配置 - 使用场景: " + padConfig.getPadUseScene()); |
|||
} |
|||
|
|||
// 打印店铺信息 |
|||
String[] storeInfo = getStoreInfo(); |
|||
Log.i(TAG, "店铺信息 - 名称: " + storeInfo[0] + ", Logo: " + (storeInfo[1].length() > 0 ? "已设置" : "未设置")); |
|||
|
|||
Log.i(TAG, "=============================="); |
|||
} |
|||
} |
@ -0,0 +1,112 @@ |
|||
package com.ouxuan.oxface.example; |
|||
|
|||
import android.content.Context; |
|||
import android.util.Log; |
|||
|
|||
import com.ouxuan.oxface.data.DeviceSelectDataManager; |
|||
import com.ouxuan.oxface.network.api.PadApiService; |
|||
|
|||
/** |
|||
* API响应数据使用示例 |
|||
* 展示如何使用DeviceSelectDataManager获取保存的API响应数据 |
|||
*/ |
|||
public class ApiResponseDataExample { |
|||
|
|||
private static final String TAG = "ApiResponseExample"; |
|||
|
|||
/** |
|||
* 展示如何获取和使用保存的API响应数据 |
|||
* @param context 上下文 |
|||
*/ |
|||
public static void demonstrateApiResponseData(Context context) { |
|||
DeviceSelectDataManager dataManager = DeviceSelectDataManager.getInstance(context); |
|||
|
|||
// 检查是否有完整的API响应数据 |
|||
if (dataManager.hasCompleteApiResponse()) { |
|||
Log.d(TAG, "=== API响应数据使用示例 ==="); |
|||
|
|||
// 获取API响应的Code和Message |
|||
int apiCode = dataManager.getApiResponseCode(); |
|||
String apiMessage = dataManager.getApiResponseMessage(); |
|||
Log.d(TAG, "API Code: " + apiCode); |
|||
Log.d(TAG, "API Message: " + apiMessage); |
|||
|
|||
// 获取API响应的Data(JSON形式) |
|||
String dataJson = dataManager.getApiResponseDataJson(); |
|||
Log.d(TAG, "API Data (JSON): " + dataJson.substring(0, Math.min(100, dataJson.length())) + "..."); |
|||
|
|||
// 获取设备配置信息 |
|||
PadApiService.PadConfig padConfig = dataManager.getPadConfig(); |
|||
if (padConfig != null) { |
|||
Log.d(TAG, "设备配置 - ID: " + padConfig.getId()); |
|||
Log.d(TAG, "设备配置 - 用户名: " + padConfig.getUsername()); |
|||
Log.d(TAG, "设备配置 - 人脸识别: " + (padConfig.getIsCheckFace() == 1 ? "开启" : "关闭")); |
|||
Log.d(TAG, "设备配置 - 使用场景: " + padConfig.getPadUseScene()); |
|||
Log.d(TAG, "设备配置 - 设备ID: " + padConfig.getDeviceId()); |
|||
} |
|||
|
|||
// 获取店铺信息 |
|||
String[] storeInfo = dataManager.getStoreInfo(); |
|||
Log.d(TAG, "店铺名称: " + storeInfo[0]); |
|||
Log.d(TAG, "店铺Logo: " + storeInfo[1]); |
|||
|
|||
// 获取选中的设备信息 |
|||
Log.d(TAG, "选中设备 - Hardware ID: " + dataManager.getSelectedHardwareId()); |
|||
Log.d(TAG, "选中设备 - 设备名称: " + dataManager.getSelectedHardwareName()); |
|||
|
|||
// 获取会话信息 |
|||
Log.d(TAG, "会话Token: " + (dataManager.getSessionToken().isEmpty() ? "未设置" : "已设置")); |
|||
Log.d(TAG, "会话有效期: " + dataManager.getValidUntil()); |
|||
Log.d(TAG, "会话是否有效: " + dataManager.isSessionValid()); |
|||
|
|||
Log.d(TAG, "========================"); |
|||
} else { |
|||
Log.d(TAG, "暂无完整的API响应数据"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 展示API响应数据的具体使用场景 |
|||
* @param context 上下文 |
|||
*/ |
|||
public static void useCaseExample(Context context) { |
|||
DeviceSelectDataManager dataManager = DeviceSelectDataManager.getInstance(context); |
|||
|
|||
// 使用场景1:检查人脸识别是否开启 |
|||
PadApiService.PadConfig padConfig = dataManager.getPadConfig(); |
|||
if (padConfig != null && padConfig.getIsCheckFace() == 1) { |
|||
Log.d(TAG, "人脸识别功能已开启,可以启动人脸识别模块"); |
|||
} |
|||
|
|||
// 使用场景2:根据使用场景调整UI |
|||
if (padConfig != null) { |
|||
String useScene = padConfig.getPadUseScene(); |
|||
switch (useScene) { |
|||
case "venue": |
|||
Log.d(TAG, "场馆模式:显示场馆相关功能"); |
|||
break; |
|||
case "store": |
|||
Log.d(TAG, "店铺模式:显示店铺相关功能"); |
|||
break; |
|||
default: |
|||
Log.d(TAG, "默认模式:显示通用功能"); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// 使用场景3:获取店铺Logo用于界面显示 |
|||
String[] storeInfo = dataManager.getStoreInfo(); |
|||
String logoUrl = storeInfo[1]; |
|||
if (!logoUrl.isEmpty()) { |
|||
Log.d(TAG, "可以使用Glide加载店铺Logo: " + logoUrl); |
|||
// 示例:Glide.with(context).load(logoUrl).into(imageView); |
|||
} |
|||
|
|||
// 使用场景4:检查会话有效性 |
|||
if (dataManager.canContinueUsingDevice()) { |
|||
Log.d(TAG, "可以继续使用当前设备"); |
|||
} else { |
|||
Log.d(TAG, "需要重新选择设备或重新登录"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
package com.ouxuan.oxface.network.callback; |
|||
|
|||
import com.ouxuan.oxface.network.model.ApiResponse; |
|||
|
|||
/** |
|||
* 完整API响应回调接口 |
|||
* 扩展NetworkCallback,支持获取完整的API响应对象(包含code和data) |
|||
*/ |
|||
public abstract class CompleteApiResponseCallback<T> { |
|||
|
|||
/** |
|||
* 成功回调,传递完整的API响应对象 |
|||
* @param apiResponse 完整的API响应对象,包含code、data、message等 |
|||
*/ |
|||
public abstract void onSuccessWithFullResponse(ApiResponse<T> apiResponse); |
|||
|
|||
/** |
|||
* 请求开始回调 |
|||
*/ |
|||
public void onStart() { |
|||
// 默认空实现,子类可以重写 |
|||
} |
|||
|
|||
/** |
|||
* 错误回调 |
|||
* @param errorCode 错误代码 |
|||
* @param errorMessage 错误消息 |
|||
*/ |
|||
public void onError(int errorCode, String errorMessage) { |
|||
// 默认空实现,子类可以重写 |
|||
} |
|||
|
|||
/** |
|||
* 异常回调 |
|||
* @param throwable 异常对象 |
|||
*/ |
|||
public void onException(Throwable throwable) { |
|||
// 默认空实现,子类可以重写 |
|||
} |
|||
|
|||
/** |
|||
* 请求完成回调(无论成功还是失败) |
|||
*/ |
|||
public void onComplete() { |
|||
// 默认空实现,子类可以重写 |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue