From 312fb00037bbcdebc5bcee67a103469e7e28a484 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Nov 2026 11:56:14 +0800 Subject: [PATCH] vault backup: 2026-11-06 11:56:14 --- BtDevScanedAdapter.java | 104 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 BtDevScanedAdapter.java diff --git a/BtDevScanedAdapter.java b/BtDevScanedAdapter.java new file mode 100644 index 0000000..d18750b --- /dev/null +++ b/BtDevScanedAdapter.java @@ -0,0 +1,104 @@ +package com.yaxon.bluetooth.adapter; + +import android.content.Context; +import android.text.TextUtils; +import android.view.View; +import android.widget.TextView; + +import com.yaxon.bluetooth.R; +import com.yaxon.bluetoothsdk.constant.Constant; +import com.yaxon.bluetoothsdk.model.LinkedInfo; +import com.yaxon.common.base.adapter.CommonAdapter; +import com.yaxon.common.base.adapter.CommonViewHolder; +import com.yaxon.support.utils.YXLog; + +import java.util.Collections; +import java.util.List; + +/** + * ClassName: BtDeviceAdapter + * @author fanjinmin + * Date: 2026/01/15 14:04 + * Description: 可用设备适配器 + */ +public class BtDevScanedAdapter extends CommonAdapter { + + private static final String TAG = BtDevScanedAdapter.class.getSimpleName(); + + public BtDevScanedAdapter(Context context, List list) { + super(context, R.layout.item_btdev_scaned, list); + } + + @Override + protected void onBindItemViewHolder(CommonViewHolder holder, int position) { + LinkedInfo linkedInfo = mList.get(position); + TextView tvScanDev = holder.getViewById(R.id.tv_scan_dev); + TextView tvScanState = holder.getViewById(R.id.tv_scan_state); + tvScanDev.setText(linkedInfo.getLinkedName()); + if (linkedInfo.getLinkedStatus() == Constant.BluetoothConnectStatus.BLUETOOTH_PAIRING_BONDING + || linkedInfo.getLinkedStatus() == Constant.BluetoothConnectStatus.BLUETOOTH_CONNECTING) { + tvScanState.setVisibility(View.VISIBLE); + } else { + tvScanState.setVisibility(View.GONE); + } + } + + /** + * 刷新正在配对 + */ + public void refreshConnectingStatus(String mac) { + if (TextUtils.isEmpty(mac)) { + return; + } + if(mList == null){ + return; + } + for (LinkedInfo linkedInfoBean : mList) { + if (mac.equals(linkedInfoBean.getMacAddressStr())) { + linkedInfoBean.linkedStatus = Constant.BluetoothConnectStatus.BLUETOOTH_CONNECTING; + notifyDataSetChanged(); + } + } + } + + /** + * 更新连接成功的设备 + */ + public void refreshDeviceConnectData(String mac, boolean isConnected) { + if (mList == null) { + notifyDataSetChanged(); + return; + } + for (LinkedInfo linkedInfoBean : mList) { + if (linkedInfoBean.getMacAddressStr().equals(mac)) { + YXLog.d(TAG,"更新连接状态 Name = "+ linkedInfoBean.getLinkedName() + " Mac = "+ linkedInfoBean.getMacAddressStr() + " isConnected = "+isConnected); + int connectStatus = isConnected ? Constant.BluetoothConnectStatus.BLUETOOTH_CONNECTED : Constant.BluetoothConnectStatus.BLUETOOTH_DISCONNECT; + linkedInfoBean.setLinkedStatus(connectStatus); + } + } + + Collections.sort(mList, (o1, o2) -> o2.getLinkedStatus()-o1.getLinkedStatus()); + + notifyDataSetChanged(); + } + + /** + * 更新连接成功的设备 + */ + public void removeDeviceByMacAddress(String mac) { + if (mList == null) { + return; + } + LinkedInfo temp = null; + for (LinkedInfo linkedInfoBean : mList) { + if (linkedInfoBean.getMacAddressStr().equals(mac)) { + temp = linkedInfoBean; + } + } + if(temp != null){ + mList.remove(temp); + } + notifyDataSetChanged(); + } + +} \ No newline at end of file