Commit b397edac99f1af0b7a52fbdc0953ebb4ffe4a560
1 parent
5346c2c5
1 修复用户在首次打开蓝牙后,在设备搜索页,无法显示搜索结果的问题
Showing
4 changed files
with
48 additions
and
19 deletions
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SearchDevicefragmentView.java
| @@ -7,6 +7,7 @@ import android.support.v4.content.ContextCompat; | @@ -7,6 +7,7 @@ import android.support.v4.content.ContextCompat; | ||
| 7 | import android.support.v7.widget.DefaultItemAnimator; | 7 | import android.support.v7.widget.DefaultItemAnimator; |
| 8 | import android.support.v7.widget.LinearLayoutManager; | 8 | import android.support.v7.widget.LinearLayoutManager; |
| 9 | import android.text.TextUtils; | 9 | import android.text.TextUtils; |
| 10 | +import android.util.Log; | ||
| 10 | import android.view.View; | 11 | import android.view.View; |
| 11 | 12 | ||
| 12 | import com.clj.fastble.BleManager; | 13 | import com.clj.fastble.BleManager; |
| @@ -45,6 +46,12 @@ public class SearchDevicefragmentView implements MvpView { | @@ -45,6 +46,12 @@ public class SearchDevicefragmentView implements MvpView { | ||
| 45 | if (null == getContext()) { | 46 | if (null == getContext()) { |
| 46 | return; | 47 | return; |
| 47 | } | 48 | } |
| 49 | + //设置配对按钮不可点击 | ||
| 50 | + setBondDeviceCantClick(); | ||
| 51 | + //隐藏重试 | ||
| 52 | + hideView(fragment.binding.llRetry); | ||
| 53 | + //显示loading | ||
| 54 | + showView(fragment.binding.llLoading); | ||
| 48 | initWifiDialog(); | 55 | initWifiDialog(); |
| 49 | wifiUtils = new WifiUtils(getContext()); | 56 | wifiUtils = new WifiUtils(getContext()); |
| 50 | //重试按钮点击事件 | 57 | //重试按钮点击事件 |
| @@ -114,8 +121,6 @@ public class SearchDevicefragmentView implements MvpView { | @@ -114,8 +121,6 @@ public class SearchDevicefragmentView implements MvpView { | ||
| 114 | if (null == getContext()) { | 121 | if (null == getContext()) { |
| 115 | return; | 122 | return; |
| 116 | } | 123 | } |
| 117 | - //设置配对按钮不可点击 | ||
| 118 | - setBondDeviceCantClick(); | ||
| 119 | adapter = new BluetoothDeviceAdapter(getContext(), bleDevices); | 124 | adapter = new BluetoothDeviceAdapter(getContext(), bleDevices); |
| 120 | adapter.setHasStableIds(true); | 125 | adapter.setHasStableIds(true); |
| 121 | fragment.binding.rvBlueTooth.setLayoutManager(new LinearLayoutManager(getContext())); | 126 | fragment.binding.rvBlueTooth.setLayoutManager(new LinearLayoutManager(getContext())); |
| @@ -222,10 +227,8 @@ public class SearchDevicefragmentView implements MvpView { | @@ -222,10 +227,8 @@ public class SearchDevicefragmentView implements MvpView { | ||
| 222 | if (null == getContext()) { | 227 | if (null == getContext()) { |
| 223 | return; | 228 | return; |
| 224 | } | 229 | } |
| 225 | - if (fragment.binding.btnBondDevice.isClickable()) { | ||
| 226 | - fragment.binding.btnBondDevice.setClickable(false); | ||
| 227 | - fragment.binding.btnBondDevice.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_xiaojia_btn_press)); | ||
| 228 | - } | 230 | + fragment.binding.btnBondDevice.setClickable(false); |
| 231 | + fragment.binding.btnBondDevice.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_xiaojia_btn_press)); | ||
| 229 | } | 232 | } |
| 230 | 233 | ||
| 231 | /** | 234 | /** |
| @@ -235,9 +238,7 @@ public class SearchDevicefragmentView implements MvpView { | @@ -235,9 +238,7 @@ public class SearchDevicefragmentView implements MvpView { | ||
| 235 | if (null == getContext()) { | 238 | if (null == getContext()) { |
| 236 | return; | 239 | return; |
| 237 | } | 240 | } |
| 238 | - if (!fragment.binding.btnBondDevice.isClickable()) { | ||
| 239 | - fragment.binding.btnBondDevice.setClickable(true); | ||
| 240 | - fragment.binding.btnBondDevice.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.selector_xiaojia_btn_green)); | ||
| 241 | - } | 241 | + fragment.binding.btnBondDevice.setClickable(true); |
| 242 | + fragment.binding.btnBondDevice.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.selector_xiaojia_btn_green)); | ||
| 242 | } | 243 | } |
| 243 | } | 244 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SelectWifiFragmentView.java
| @@ -271,6 +271,7 @@ public class SelectWifiFragmentView implements MvpView { | @@ -271,6 +271,7 @@ public class SelectWifiFragmentView implements MvpView { | ||
| 271 | } | 271 | } |
| 272 | try { | 272 | try { |
| 273 | String result = new String(data, "UTF-8"); | 273 | String result = new String(data, "UTF-8"); |
| 274 | + Log.e(TAG, "onCharacteristicChanged: " + result); | ||
| 274 | if (result.indexOf(BlufiConstants.WIFI_LINK_OK) != -1) { | 275 | if (result.indexOf(BlufiConstants.WIFI_LINK_OK) != -1) { |
| 275 | isSetNetSuccess = true; | 276 | isSetNetSuccess = true; |
| 276 | BleManager.getInstance().stopNotify(bleDevice, BlufiConstants.UUID_WIFI_SERVICE.toString(), BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); | 277 | BleManager.getInstance().stopNotify(bleDevice, BlufiConstants.UUID_WIFI_SERVICE.toString(), BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/BluetoothDeviceAdapter.java
| @@ -60,10 +60,22 @@ import java.util.List; | @@ -60,10 +60,22 @@ import java.util.List; | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | public void addListData(BleDevice bleDevice) { | 62 | public void addListData(BleDevice bleDevice) { |
| 63 | + if (null == bleDevice) { | ||
| 64 | + return; | ||
| 65 | + } | ||
| 63 | if (null != bluetoothDeviceList) { | 66 | if (null != bluetoothDeviceList) { |
| 64 | - bluetoothDeviceList.add(bleDevice); | ||
| 65 | - hashMap.put(bleDevice, false); | ||
| 66 | - notifyDataSetChanged(); | 67 | + boolean isHave = false; |
| 68 | + for (int i = 0; i < bluetoothDeviceList.size(); i++) { | ||
| 69 | + if (bleDevice.getName().equals(bluetoothDeviceList.get(i).getName())) { | ||
| 70 | + isHave = true; | ||
| 71 | + break; | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + if (!isHave) { | ||
| 75 | + bluetoothDeviceList.add(bleDevice); | ||
| 76 | + hashMap.put(bleDevice, false); | ||
| 77 | + notifyDataSetChanged(); | ||
| 78 | + } | ||
| 67 | } | 79 | } |
| 68 | 80 | ||
| 69 | } | 81 | } |
| @@ -91,7 +103,7 @@ import java.util.List; | @@ -91,7 +103,7 @@ import java.util.List; | ||
| 91 | //设备名称 | 103 | //设备名称 |
| 92 | final BluetoothDevice bluetoothDevice = bluetoothDeviceList.get(position).getDevice(); | 104 | final BluetoothDevice bluetoothDevice = bluetoothDeviceList.get(position).getDevice(); |
| 93 | String deviceName = bluetoothDevice.getName(); | 105 | String deviceName = bluetoothDevice.getName(); |
| 94 | - binding.tvDeviceName.setText("小家智能音箱" + (position + 1)); | 106 | + binding.tvDeviceName.setText(deviceName); |
| 95 | String deviceAddress = bluetoothDevice.getAddress(); | 107 | String deviceAddress = bluetoothDevice.getAddress(); |
| 96 | //设备的状态(BOND_BONDED:已绑定 常量值:12, BOND_BONDING:绑定中 常量值:11, BOND_NONE:未匹配 常量值:10) | 108 | //设备的状态(BOND_BONDED:已绑定 常量值:12, BOND_BONDING:绑定中 常量值:11, BOND_NONE:未匹配 常量值:10) |
| 97 | binding.tvDeviceAddress.setText(deviceAddress); | 109 | binding.tvDeviceAddress.setText(deviceAddress); |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/SearchDevicefragment.java
| 1 | package com.cnlive.strike.xiaojiaspeaker.ui.fragment; | 1 | package com.cnlive.strike.xiaojiaspeaker.ui.fragment; |
| 2 | 2 | ||
| 3 | import android.os.Bundle; | 3 | import android.os.Bundle; |
| 4 | +import android.os.Handler; | ||
| 4 | import android.support.annotation.Nullable; | 5 | import android.support.annotation.Nullable; |
| 5 | import android.support.v4.content.ContextCompat; | 6 | import android.support.v4.content.ContextCompat; |
| 6 | import android.view.View; | 7 | import android.view.View; |
| @@ -38,11 +39,26 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | @@ -38,11 +39,26 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | ||
| 38 | EventBusUtil.register(this); | 39 | EventBusUtil.register(this); |
| 39 | 40 | ||
| 40 | initTopBar(); | 41 | initTopBar(); |
| 41 | - initBlueToothScanConfig(); | 42 | + if (BleManager.getInstance().isBlueEnable()) { |
| 43 | + initBlueToothScanConfig(); | ||
| 44 | + if (null != getMvpView()) { | ||
| 45 | + getMvpView().initListAdapter(); | ||
| 46 | + } | ||
| 47 | + } else { | ||
| 48 | + new Handler().postDelayed(new Runnable() { | ||
| 49 | + @Override | ||
| 50 | + public void run() { | ||
| 51 | + initBlueToothScanConfig(); | ||
| 52 | + if (null != getMvpView()) { | ||
| 53 | + getMvpView().initListAdapter(); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + }, 2 * 1000); | ||
| 57 | + } | ||
| 42 | if (null != getMvpView()) { | 58 | if (null != getMvpView()) { |
| 43 | getMvpView().initView(); | 59 | getMvpView().initView(); |
| 44 | - getMvpView().initListAdapter(); | ||
| 45 | } | 60 | } |
| 61 | + | ||
| 46 | } | 62 | } |
| 47 | 63 | ||
| 48 | @Override | 64 | @Override |
| @@ -50,6 +66,7 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | @@ -50,6 +66,7 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | ||
| 50 | super.onActivityCreated(savedInstanceState); | 66 | super.onActivityCreated(savedInstanceState); |
| 51 | StatusBarUtil.setStatusBarWrite(getActivity()); | 67 | StatusBarUtil.setStatusBarWrite(getActivity()); |
| 52 | StatusBarUtil2.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.white), 0); | 68 | StatusBarUtil2.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.white), 0); |
| 69 | + | ||
| 53 | } | 70 | } |
| 54 | 71 | ||
| 55 | private void initTopBar() { | 72 | private void initTopBar() { |
| @@ -81,8 +98,6 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | @@ -81,8 +98,6 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | ||
| 81 | .setScanTimeOut(1000 * 60) // 扫描超时时间,可选,默认10秒;小于等于0表示不限制扫描时间 | 98 | .setScanTimeOut(1000 * 60) // 扫描超时时间,可选,默认10秒;小于等于0表示不限制扫描时间 |
| 82 | .build(); | 99 | .build(); |
| 83 | BleManager.getInstance().initScanRule(scanRuleConfig); | 100 | BleManager.getInstance().initScanRule(scanRuleConfig); |
| 84 | - //检查蓝牙是否打开 | ||
| 85 | -// if (BleManager.getInstance().isBlueEnable()) | ||
| 86 | } | 101 | } |
| 87 | 102 | ||
| 88 | @Override | 103 | @Override |
| @@ -99,7 +114,7 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | @@ -99,7 +114,7 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen | ||
| 99 | public void event(EventMsg msg) { | 114 | public void event(EventMsg msg) { |
| 100 | if (EventMsg.CLOSE_BLUETOOTH_ACTIVITY == msg.getEventType()) { | 115 | if (EventMsg.CLOSE_BLUETOOTH_ACTIVITY == msg.getEventType()) { |
| 101 | getActivity().finish(); | 116 | getActivity().finish(); |
| 102 | - }else if (EventMsg.GO_TO_CHINA_LISTEN_PAGE== msg.getEventType()){ | 117 | + } else if (EventMsg.GO_TO_CHINA_LISTEN_PAGE == msg.getEventType()) { |
| 103 | getActivity().finish(); | 118 | getActivity().finish(); |
| 104 | } | 119 | } |
| 105 | } | 120 | } |