This commit is contained in:
马增飞
2025-12-30 16:28:35 +08:00
parent aff3d5cc69
commit 5b0b98c8b8
6 changed files with 76 additions and 41 deletions
+1
View File
@@ -73,6 +73,7 @@ dependencies {
implementation("com.geyifeng.immersionbar:immersionbar-ktx:3.2.2") implementation("com.geyifeng.immersionbar:immersionbar-ktx:3.2.2")
implementation("com.squareup.okhttp3:okhttp:4.9.1") implementation("com.squareup.okhttp3:okhttp:4.9.1")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
implementation("com.google.code.gson:gson:2.10.1") implementation("com.google.code.gson:gson:2.10.1")
implementation("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0") implementation("com.squareup.retrofit2:converter-gson:2.9.0")
@@ -183,8 +183,25 @@ class HomeActivity : BaseActivity() {
// viewModel.getAccessToken(App.deviceId) // viewModel.getAccessToken(App.deviceId)
viewModel.getShelfList(deviceId = App.deviceId) // viewModel.getShelfList(deviceId = App.deviceId)
binding.root.postDelayed({
loadTestData()
}, 30*1000)
}
private fun loadTestData() {
list.add(ShelfModel(deviceNo = 1, goodsName = "鸡蛋", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 6, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 2, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 7, goodsName = "生姜", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 3, goodsName = "黄瓜", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 8, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 4, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 9, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 5, goodsName = "", deviceId = App.deviceId))
list.add(ShelfModel(deviceNo = 10, goodsName = "", deviceId = App.deviceId))
shelfAdapter.notifyDataSetChanged()
} }
private fun getTokenSuccess(data: RespData<*>) { private fun getTokenSuccess(data: RespData<*>) {
@@ -318,7 +335,7 @@ class HomeActivity : BaseActivity() {
"0101", "8101" -> { "0101", "8101" -> {
//心跳0102${p1}${p2}${version} //心跳0102${p1}${p2}${version}
//心跳81(终端发起,当终端发送此命令时需要服务端存储串口屏显示信息) //心跳81(终端发起,当终端发送此命令时需要服务端存储串口屏显示信息)
val respCmd = "${HEADER}01020906${terminalVersion}$FOOTER" val respCmd = "${HEADER}01020506${terminalVersion}$FOOTER"
log("${LOG_PREFIX}[心跳]${cmdFlag}指令:${data},发送应答指令:${respCmd}") log("${LOG_PREFIX}[心跳]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
sendCmd(respCmd) sendCmd(respCmd)
heartBeat(data) heartBeat(data)
@@ -375,6 +375,9 @@ class ShelfActivity : BaseActivity() {
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}" val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
log("编号${shelfNo}货架执行清零指令:${zeroClearingCmd}") log("编号${shelfNo}货架执行清零指令:${zeroClearingCmd}")
sendCmd(zeroClearingCmd) sendCmd(zeroClearingCmd)
sendCmd(
if (shelfNo in 1..5) HomeActivity.LEFT_SHELF_OPEN_CMD else HomeActivity.RIGHT_SHELF_OPEN_CMD
)
//清零 //清零
realWeight = 0 realWeight = 0
// binding.tvFoodWeight.text = "${realWeight}克" // binding.tvFoodWeight.text = "${realWeight}克"
@@ -45,6 +45,7 @@ interface ApiService {
@Url url: String = UrlConfig.GET_SHELF_LIST, @Url url: String = UrlConfig.GET_SHELF_LIST,
@Query("deviceId") deviceId: String, @Query("deviceId") deviceId: String,
@Query("x-access-token") token: String = App.accessToken, @Query("x-access-token") token: String = App.accessToken,
@Header("X-DEVICE-CODE") deviceCode:String = App.deviceId,
@Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d" @Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d"
): RespData<ShelfResult> ): RespData<ShelfResult>
@@ -56,6 +57,7 @@ interface ApiService {
@Query("pageNo") pageNo: Int = 1, @Query("pageNo") pageNo: Int = 1,
@Query("pageSize") pageSize: Int = 50, @Query("pageSize") pageSize: Int = 50,
@Query("x-access-token") token: String = App.accessToken, @Query("x-access-token") token: String = App.accessToken,
@Header("X-DEVICE-CODE") deviceCode:String = App.deviceId,
@Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d" @Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d"
): RespData<MutableList<GoodsModel>?> ): RespData<MutableList<GoodsModel>?>
@@ -64,6 +66,7 @@ interface ApiService {
@Url url: String = UrlConfig.SAVE_SHELF_GOODS_LIST, @Url url: String = UrlConfig.SAVE_SHELF_GOODS_LIST,
@Body body: ShelfBody, @Body body: ShelfBody,
@Query("x-access-token") token: String = App.accessToken, @Query("x-access-token") token: String = App.accessToken,
@Header("X-DEVICE-CODE") deviceCode:String = App.deviceId,
@Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d" @Header("authorization") authorization: String = "57ee87183f2a4fa59683ec9ef41c8f5d"
): RespData<Any?> ): RespData<Any?>
@@ -6,6 +6,7 @@ import com.shuwei.intelligent.shelves.App
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Response import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@@ -33,6 +34,16 @@ class HttpManager private constructor() {
sslSocketFactory(createSSLSocketFactory(), TrustAllCerts()) sslSocketFactory(createSSLSocketFactory(), TrustAllCerts())
hostnameVerifier { _, _ -> true } hostnameVerifier { _, _ -> true }
addInterceptor(LoggingInterceptor()) addInterceptor(LoggingInterceptor())
addNetworkInterceptor(HttpLoggingInterceptor(logger = {
Log.d("HttpManager","okhttp logger ==>${it}")
}).apply {
level =
// if (MyApp.DEBUG) {
HttpLoggingInterceptor.Level.BODY
// } else {
// HttpLoggingInterceptor.Level.NONE
// }
})
// addInterceptor { chain -> // addInterceptor { chain ->
// val request = chain.request().newBuilder() // val request = chain.request().newBuilder()
// .header("x-access-token", App.accessToken) // .header("x-access-token", App.accessToken)
@@ -406,45 +406,45 @@ public class AppUtil {
*/ */
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
public static String getUDID(Context context) { public static String getUDID(Context context) {
// return "SWZC-HG-001"; return "SWZC-HG-001";
// //"test111"; //// //"test111";
String androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // String androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
if (!androidID.equals("")) { // if (!androidID.equals("")) {
try { // try {
if (!"9774d56d682e549c".equals(androidID)) { // if (!"9774d56d682e549c".equals(androidID)) {
androidID = UUID.nameUUIDFromBytes(androidID.getBytes("utf8")).toString(); // androidID = UUID.nameUUIDFromBytes(androidID.getBytes("utf8")).toString();
} else { // } else {
@SuppressLint("MissingPermission") final String deviceId = ((TelephonyManager) context.getSystemService(TELEPHONY_SERVICE)).getDeviceId(); // @SuppressLint("MissingPermission") final String deviceId = ((TelephonyManager) context.getSystemService(TELEPHONY_SERVICE)).getDeviceId();
androidID = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")).toString() : UUID.randomUUID().toString(); // androidID = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")).toString() : UUID.randomUUID().toString();
} // }
} catch (UnsupportedEncodingException e) { // } catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
return androidID; // return androidID;
} // }
//
//需要权限 android.permission.READ_PHONE_STATE // //需要权限 android.permission.READ_PHONE_STATE
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE); // TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
String szImei = TelephonyMgr.getDeviceId(); // String szImei = TelephonyMgr.getDeviceId();
if (!szImei.equals("")) { // if (!szImei.equals("")) {
return szImei; // return szImei;
} // }
//
//需要权限 android.permission.ACCESS_WIFI_STATE // //需要权限 android.permission.ACCESS_WIFI_STATE
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String m_szWLANMAC = wm.getConnectionInfo().getMacAddress(); // String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
if (!m_szWLANMAC.equals("")) { // if (!m_szWLANMAC.equals("")) {
return m_szWLANMAC; // return m_szWLANMAC;
} // }
//
//需要权限 android.permission.BLUETOOTH // //需要权限 android.permission.BLUETOOTH
BluetoothAdapter m_BluetoothAdapter = null; // BluetoothAdapter m_BluetoothAdapter = null;
m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String m_szBTMAC = m_BluetoothAdapter.getAddress(); // String m_szBTMAC = m_BluetoothAdapter.getAddress();
if (!m_szBTMAC.equals("")) { // if (!m_szBTMAC.equals("")) {
return m_szBTMAC; // return m_szBTMAC;
} // }
return getUniquePsuedoID(); // return getUniquePsuedoID();
} }
//获得 Psuedo ID //获得 Psuedo ID