扫描二维码,连接配网1
This commit is contained in:
@@ -100,6 +100,10 @@ public abstract class BaseFragment<T extends ViewBinding,P extends IPresenter> e
|
||||
return EasyPermissions.hasPermissions(mContext, permission);
|
||||
}
|
||||
|
||||
public boolean hasRecordPermission(String[] permission) {
|
||||
return EasyPermissions.hasPermissions(mContext, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限
|
||||
*
|
||||
@@ -145,6 +149,50 @@ public abstract class BaseFragment<T extends ViewBinding,P extends IPresenter> e
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 一次获取多个权限
|
||||
*
|
||||
* @param permis
|
||||
* @param title
|
||||
* @param content
|
||||
* @param requestCode String... permis
|
||||
*/
|
||||
public void getMorePermissionRequst(String[] permis, String title, String content, int requestCode) {
|
||||
if (EasyPermissions.hasPermissions(mContext, permis)) {
|
||||
// 已有权限,不需要处理
|
||||
return;
|
||||
}
|
||||
// 还没权限,弹自定义确认弹窗
|
||||
showDialogtextInterBackKey(
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
title,
|
||||
content,
|
||||
getString(R.string.button_deny),
|
||||
getString(R.string.button_allow),
|
||||
new BaseFragment.OnDialogClick() {
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirmClick() {
|
||||
showPermissionDialog(mContext.getResources().getDrawable(R.mipmap.img_permission_file),
|
||||
true, title, content);
|
||||
boolean shouldShowRationale = false;
|
||||
for (String p : permis) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(mContext, p)) {
|
||||
shouldShowRationale = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 使用 EasyPermissions 请求权限(系统决定是否弹系统框)
|
||||
EasyPermissions.requestPermissions(mContext, content, requestCode, permis);
|
||||
}
|
||||
},false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Fragment是否真正对用户可见
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.ckkj.water.device;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
@@ -35,7 +33,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
/**
|
||||
@@ -190,7 +187,7 @@ public class AddDeviceActivity extends BaseActivity<AddDeviceLayoutBinding, Devi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,28 +7,24 @@ import android.Manifest;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.bluetooth.le.BluetoothLeScanner;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelUuid;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.ckkj.water.BuildConfig;
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
@@ -50,14 +46,12 @@ import com.maning.mlkitscanner.scan.callback.act.MNScanCallback;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.observer.ConnectionObserver;
|
||||
import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat;
|
||||
import no.nordicsemi.android.support.v18.scanner.ScanCallback;
|
||||
import no.nordicsemi.android.support.v18.scanner.ScanFilter;
|
||||
@@ -430,7 +424,7 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.ckkj.water.device;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
@@ -134,8 +133,8 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
@Override
|
||||
public void run() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("wifi_name", mWifiName);
|
||||
bundle.putString("wifi_password", mWifiPassword);
|
||||
mBleDeviceEntity.setWifiName(mWifiName);
|
||||
mBleDeviceEntity.setWifiPassword(mWifiPassword);
|
||||
bundle.putSerializable("ble_device_entity", mBleDeviceEntity);
|
||||
goTo(mContext, DeviceReNameActivity.class, bundle);
|
||||
finish();
|
||||
@@ -254,7 +253,7 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.ckkj.water.EventMessage;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.base.BaseFragment;
|
||||
import com.ckkj.water.custom.GridSpacingItemDecoration;
|
||||
import com.ckkj.water.custom.view.CustomBubbleAttachPopup;
|
||||
import com.ckkj.water.databinding.DeviceControlLayoutBinding;
|
||||
@@ -21,7 +20,6 @@ import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
import com.ckkj.water.device.mvp.DevicePresenter;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
||||
import com.ckkj.water.utils.manager.PowerIconManage;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
@@ -61,15 +59,27 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
showLoadingDialog();
|
||||
mPresenter.getDeviceDetailInfo(mDeviceEntity.getDeviceNo());
|
||||
viewBinding.includedTitle.tvTitle.setText(mDeviceEntity.getDeviceName());
|
||||
if(mDeviceEntity.getWorkStatus().equals("1")){
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_working));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_zhu));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.device_control_stop));
|
||||
if(mDeviceEntity.getStatus().equals("1") || mDeviceEntity.getStatus().equals("2")){
|
||||
if(mDeviceEntity.getWorkStatus().equals("1")){
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_working));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_zhu));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.device_control_stop));
|
||||
}else{
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_not_working));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.device_control_start));
|
||||
}
|
||||
viewBinding.linearWifi.setBackground(mContext.getResources().getDrawable(R.drawable.shape_device_ctrl_green_cor12));
|
||||
viewBinding.imgWifiLogo.setImageResource(R.mipmap.icon_ctrl_wifi_white);
|
||||
}else{
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_not_working));
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_offline));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.device_control_start));
|
||||
viewBinding.tvConfirm.setEnabled(false);
|
||||
viewBinding.tvConfirm.setBackgroundColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.linearWifi.setBackground(mContext.getResources().getDrawable(R.drawable.shape_device_ctrl_white_cor12));
|
||||
viewBinding.imgWifiLogo.setImageResource(R.mipmap.icon_ctrl_wifi_green);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
mTimeList.add("1min");
|
||||
@@ -307,7 +317,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ import com.gyf.immersionbar.ImmersionBar;
|
||||
*/
|
||||
public class DeviceInfoActivity extends BaseActivity<DeviceInfoLayoutBinding, DevicePresenter>
|
||||
implements DeviceContract.DeviceView {
|
||||
|
||||
private WaterDeviceEntity mDeviceEntity;
|
||||
|
||||
@Override
|
||||
public DevicePresenter createPresenter() {
|
||||
return new DevicePresenter(new DeviceImpl());
|
||||
@@ -27,7 +30,14 @@ public class DeviceInfoActivity extends BaseActivity<DeviceInfoLayoutBinding, De
|
||||
@Override
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
super.initData(savedInstanceState);
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if(bundle != null){
|
||||
mDeviceEntity = (WaterDeviceEntity) bundle.getSerializable("device_entity");
|
||||
viewBinding.tvDevCode.setText(mDeviceEntity.getDeviceNo());
|
||||
viewBinding.tvDevMod.setText(mDeviceEntity.getDeviceEm());
|
||||
viewBinding.tvDeviceSerial.setText(mDeviceEntity.getDeviceSn());
|
||||
viewBinding.tvDevVersion.setText(mDeviceEntity.getFwVer());
|
||||
}
|
||||
ImmersionBar.with(this)
|
||||
.statusBarDarkFont(ThemeManager.isAppThemeLight(mContext)) // 白色状态栏图标
|
||||
.navigationBarColor(R.color.mainBackgroundColor)
|
||||
@@ -69,7 +79,7 @@ public class DeviceInfoActivity extends BaseActivity<DeviceInfoLayoutBinding, De
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,11 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
super.initData(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if (bundle != null) {
|
||||
mWifiName = bundle.getString("wifi_name", "");
|
||||
mWifiPassword = bundle.getString("wifi_password", "");
|
||||
mBleDeviceEntity = (WaterDeviceEntity) bundle.getSerializable("ble_device_entity");
|
||||
if(mBleDeviceEntity != null){
|
||||
mWifiName = mBleDeviceEntity.getWifiName();
|
||||
mWifiPassword = mBleDeviceEntity.getWifiPassword();
|
||||
}
|
||||
}
|
||||
|
||||
ImmersionBar.with(this)
|
||||
@@ -86,7 +88,7 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext,"设备保存成功");
|
||||
ActivityManager.removeActivityByTag(ConstantUtil.ADD_DEVICE_FLAG);
|
||||
@@ -94,7 +96,7 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
@Override
|
||||
public void run() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("device_info",mBleDeviceEntity);
|
||||
bundle.putSerializable("device_info",bean);
|
||||
goTo(mContext,DeviceControlActivity.class,bundle);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,9 @@ public class DeviceSettingsActivity extends BaseActivity<DeviceSettingsLayoutBin
|
||||
break;
|
||||
|
||||
case R.id.rl_dev_info:
|
||||
goTo(mContext, DeviceInfoActivity.class,null);
|
||||
Bundle bundleDev = new Bundle();
|
||||
bundleDev.putSerializable("device_entity",mDeviceEntity);
|
||||
goTo(mContext, DeviceInfoActivity.class,bundleDev);
|
||||
break;
|
||||
|
||||
case R.id.rl_dev_wifi_manager:
|
||||
@@ -205,7 +207,7 @@ public class DeviceSettingsActivity extends BaseActivity<DeviceSettingsLayoutBin
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ public class SelectWifiActivity_copy extends BaseActivity<DeviceResetWifiBinding
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DeviceContract {
|
||||
|
||||
public interface DeviceView extends IView {
|
||||
//添加设备成功g
|
||||
void addDeviceSuccess(BaseBean bean);
|
||||
void addDeviceSuccess(WaterDeviceEntity bean);
|
||||
void getDeviceDetailInfo(WaterDeviceEntity bean);
|
||||
void editDeviceInfoSuccess(BaseBean bean);
|
||||
void deleteDeviceSuccess(BaseBean bean);
|
||||
|
||||
@@ -59,15 +59,15 @@ public class DeviceImpl implements DeviceContract.DataModel{
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean>() {
|
||||
.subscribe(new Observer<BaseBean<WaterDeviceEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean bean) {
|
||||
public void onNext(@NonNull BaseBean<WaterDeviceEntity> bean) {
|
||||
if (bean.getCode() == 200) {
|
||||
callBack.success(bean,0);
|
||||
callBack.success(bean.getData(),0);
|
||||
} else {
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
// json.put("deviceEm","213123123123");
|
||||
// json.put("deviceSn","sdfsd32423gdfgdf3");
|
||||
// json.put("fwVer","fwVer-56565644");
|
||||
impl.addDevice(json, new IndexContract.CallBack<BaseBean>() {
|
||||
impl.addDevice(json, new IndexContract.CallBack<WaterDeviceEntity>() {
|
||||
@Override
|
||||
public void success(BaseBean bean,int total) {
|
||||
public void success(WaterDeviceEntity bean,int total) {
|
||||
if(DevicePresenter.this.getView() != null){
|
||||
DevicePresenter.this.getView().addDeviceSuccess(bean);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.ckkj.water.index;
|
||||
|
||||
import android.Manifest;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
@@ -9,15 +14,19 @@ import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.ckkj.water.AppConfig;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseFragment;
|
||||
import com.ckkj.water.custom.view.CustomRefreshHeader;
|
||||
import com.ckkj.water.databinding.IndexFragmentLayoutBinding;
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.device.AddDeviceActivity;
|
||||
import com.ckkj.water.device.AddDeviceActivity_copy;
|
||||
import com.ckkj.water.device.DeviceControlActivity;
|
||||
import com.ckkj.water.device.DeviceReNameActivity;
|
||||
import com.ckkj.water.device.SelectWifiActivity;
|
||||
import com.ckkj.water.history.entity.WateringRecord;
|
||||
import com.ckkj.water.index.adapter.DeviceAdapter;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
@@ -49,6 +58,15 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
private List<WaterDeviceEntity> devList = new ArrayList<>();
|
||||
private int mCurrentPage = 1;
|
||||
|
||||
// 扫码待配网设备
|
||||
private WaterDeviceEntity pendingDeviceEntity = null;
|
||||
|
||||
// 蓝牙相关
|
||||
private static final int REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION = 10002;
|
||||
private static final int REQUEST_ENABLE_BT = 10003;
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
private boolean bluetoothReady = false;
|
||||
|
||||
@Override
|
||||
protected void initArgs(Bundle bundle) {
|
||||
}
|
||||
@@ -242,14 +260,119 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity entity) {
|
||||
switch (entity.getBindDeviceStatus()){
|
||||
case 302:
|
||||
//Todo 即这是一台没有在mqtt中注册的设备,App 需要通过蓝牙连接,并实现配网
|
||||
//Todo entity 中有Mac地址,和设备名称,根据代码中现有的扫描、连接、配网代码,实现功能
|
||||
|
||||
case 200:
|
||||
//该设备目前已经绑定了当前用户,直接跳转到设备控制页面
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("device_info",entity.getBindDevice());
|
||||
goTo(mContext, DeviceControlActivity.class,bundle);
|
||||
break;
|
||||
|
||||
case 302:
|
||||
// 这是一台没有在mqtt中注册的设备,需要通过蓝牙连接配网,(可理解为新设备,走蓝牙,配网)
|
||||
// 先检查蓝牙权限和开启状态
|
||||
pendingDeviceEntity = entity;
|
||||
checkBluetoothAndProceed();
|
||||
break;
|
||||
|
||||
case 304:
|
||||
//该设备目前在线,已经在mqtt注册,但是没有绑定用户,需要跳转到绑定页面
|
||||
Bundle bundleNoBind = new Bundle();
|
||||
bundleNoBind.putSerializable("ble_device_entity", entity.getBindDevice());
|
||||
goTo(mContext, DeviceReNameActivity.class, bundleNoBind);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查蓝牙权限和开启状态,然后跳转配网
|
||||
*/
|
||||
private void checkBluetoothAndProceed() {
|
||||
// 1. 检查蓝牙权限
|
||||
if (!checkBluetoothPermissions()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 检查蓝牙是否开启
|
||||
if (!initBluetooth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 权限和状态都正常,跳转配网页面
|
||||
goToDeviceProvisioning();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查蓝牙权限
|
||||
*/
|
||||
private boolean checkBluetoothPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
String[] permissions = {
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
};
|
||||
if (!hasRecordPermission(permissions)) {
|
||||
getMorePermissionRequst(permissions,
|
||||
"蓝牙权限申请",
|
||||
"智能浇水需要您的授权,获取蓝牙权限添加设备",
|
||||
REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Android 12 以下需要位置权限
|
||||
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
}, REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化蓝牙适配器并检查蓝牙是否开启
|
||||
* @return true 表示蓝牙已开启,false 表示未开启或不支持
|
||||
*/
|
||||
private boolean initBluetooth() {
|
||||
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
if (bluetoothManager != null) {
|
||||
bluetoothAdapter = bluetoothManager.getAdapter();
|
||||
}
|
||||
|
||||
if (bluetoothAdapter == null) {
|
||||
ToastUtil.showShort(mContext, "设备不支持蓝牙");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bluetoothAdapter.isEnabled()) {
|
||||
// 蓝牙未开启,请求开启
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
return false;
|
||||
}
|
||||
|
||||
bluetoothReady = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转设备配网页面
|
||||
*/
|
||||
private void goToDeviceProvisioning() {
|
||||
if (pendingDeviceEntity == null) {
|
||||
ToastUtil.showShort(mContext, "设备信息异常");
|
||||
return;
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(ConstantUtil.ACTIVITY_NAVIGATE_FLAG, 100); // 100 = 来自扫码添加
|
||||
bundle.putSerializable("ble_device_entity", pendingDeviceEntity);
|
||||
goTo(mContext, SelectWifiActivity.class, bundle);
|
||||
pendingDeviceEntity = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
@@ -270,13 +393,69 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
public void logOut(BaseBean bean) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
hidePermissionDialog();
|
||||
if (requestCode == REQUEST_EVENT_CODE_10001) {
|
||||
scanQrcode();
|
||||
} else if (requestCode == REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION) {
|
||||
// 蓝牙权限获取成功,检查蓝牙状态
|
||||
if (initBluetooth()) {
|
||||
goToDeviceProvisioning();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||
hidePermissionDialog();
|
||||
if (requestCode == REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION) {
|
||||
ToastUtil.showShort(mContext, "需要蓝牙权限才能添加设备");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
||||
hidePermissionDialog();
|
||||
|
||||
if (requestCode == REQUEST_EVENT_CODE_10001) {
|
||||
// 相机权限回调
|
||||
scanQrcode();
|
||||
} else if (requestCode == REQUEST_EVENT_CODE_BLUETOOTH_PERMISSION) {
|
||||
// 蓝牙权限回调
|
||||
boolean allGranted = true;
|
||||
for (int result : grantResults) {
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
allGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allGranted) {
|
||||
// 权限获取成功,检查蓝牙状态
|
||||
if (initBluetooth()) {
|
||||
goToDeviceProvisioning();
|
||||
}
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "需要蓝牙权限才能添加设备");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_ENABLE_BT) {
|
||||
if (resultCode == -1) { // RESULT_OK
|
||||
ToastUtil.showShort(mContext, "蓝牙已开启");
|
||||
bluetoothReady = true;
|
||||
if (pendingDeviceEntity != null) {
|
||||
goToDeviceProvisioning();
|
||||
}
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "请开启蓝牙以添加设备");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,26 @@ public class DeviceAdapter extends BaseQuickAdapter<WaterDeviceEntity, BaseViewH
|
||||
View viewStatus = holder.getView(R.id.view_status_dot);
|
||||
holder.setText(R.id.tv_device_name,item.getDeviceName());
|
||||
holder.setText(R.id.tv_device_serial,item.getDeviceSn());
|
||||
holder.setText(R.id.tv_device_status,item.getWorkStatus().equals("0") ?
|
||||
mContext.getString(R.string.device_status_not_working) :
|
||||
mContext.getString(R.string.device_status_working));
|
||||
holder.setTextColor(R.id.tv_device_status,item.getWorkStatus().equals("0") ?
|
||||
mContext.getResources().getColor(R.color.color_999999) :
|
||||
mContext.getResources().getColor(R.color.color_24B326));
|
||||
viewStatus.setBackground(item.getWorkStatus().equals("0") ?
|
||||
mContext.getResources().getDrawable(R.drawable.shape_status_dot_999999)
|
||||
: mContext.getResources().getDrawable(R.drawable.shape_status_dot_green));
|
||||
switch (item.getWorkStatus()){
|
||||
case "0"://待机
|
||||
holder.setText(R.id.tv_device_status,mContext.getString(R.string.device_status_not_working));
|
||||
holder.setTextColor(R.id.tv_device_status,mContext.getResources().getColor(R.color.color_999999));
|
||||
viewStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_status_dot_999999));
|
||||
break;
|
||||
|
||||
case "1"://工作中
|
||||
holder.setText(R.id.tv_device_status,mContext.getString(R.string.device_status_working));
|
||||
holder.setTextColor(R.id.tv_device_status,mContext.getResources().getColor(R.color.color_24B326));
|
||||
viewStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_status_dot_green));
|
||||
break;
|
||||
}
|
||||
// if(item.getStatus().equals("1") || item.getStatus().equals("2")){
|
||||
// }else{
|
||||
// holder.setText(R.id.tv_device_status,mContext.getString(R.string.device_status_offline));
|
||||
// holder.setTextColor(R.id.tv_device_status,mContext.getResources().getColor(R.color.color_999999));
|
||||
// viewStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_status_dot_999999));
|
||||
// }
|
||||
|
||||
holder.setText(R.id.tv_battery_level,item.getPowerLevel());
|
||||
imgPower.setImageResource(PowerIconManage.getInstance().getPowerIcon(Integer.parseInt(item.getPowerLevel())));
|
||||
}
|
||||
|
||||
@@ -47,9 +47,10 @@ public class WaterDeviceEntity implements Serializable {
|
||||
private List<DeviceListBean> deviceList;
|
||||
private int bindDeviceStatus;
|
||||
private String bindDeviceStatusName;
|
||||
private WaterDeviceEntity bindDevice;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class DeviceListBean implements Serializable{
|
||||
private String id;
|
||||
private String deviceNo;
|
||||
@@ -67,5 +68,14 @@ public class WaterDeviceEntity implements Serializable {
|
||||
private String fwVer;
|
||||
private String macAddress;
|
||||
private Object expirationTime;
|
||||
private int createDept;
|
||||
private int createBy;
|
||||
private String createTime;
|
||||
private int updateBy;
|
||||
private String updateTime;
|
||||
private Object bindTokenHash;
|
||||
private Object deviceImgX;
|
||||
private String powerLevelUpdatatimeX;
|
||||
private Object expirationTimeX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,10 @@ public class IndexPresenter extends BasePresenter<IndexContract.IndexView>{
|
||||
mImpl.queryDeviceBindStatus(json, new IndexContract.CallBack<WaterDeviceEntity>() {
|
||||
@Override
|
||||
public void success(WaterDeviceEntity bean, int total) {
|
||||
entity.setBindDeviceStatus(bean.getBindDeviceStatus());
|
||||
entity.setBindDeviceStatusName(bean.getBindDeviceStatusName());
|
||||
bean.setMacAddress(entity.getMacAddress());
|
||||
bean.setDeviceName(entity.getDeviceName());
|
||||
if(IndexPresenter.this.getView() != null){
|
||||
IndexPresenter.this.getView().queryDeviceBindStatusSuccess(entity);
|
||||
IndexPresenter.this.getView().queryDeviceBindStatusSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public interface Request {
|
||||
|
||||
//添加设备
|
||||
@POST("app/v1/addDevice")
|
||||
Observable<BaseBean> addDevice(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
Observable<BaseBean<WaterDeviceEntity>> addDevice(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
//获取设备详细信息
|
||||
@GET("app/v1/device/{deviceNo}")
|
||||
Observable<BaseBean<WaterDeviceEntity>> getDeviceDetailInfo(@HeaderMap Map<String, String> headMap, @Path("deviceNo") String id);
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
android:gravity="center"
|
||||
android:background="@drawable/shape_device_ctrl_green_cor12">
|
||||
<ImageView
|
||||
android:id="@+id/img_wifi_logo"
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_ctrl_wifi_white"/>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/device_info_code"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_dev_code"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
@@ -47,6 +48,7 @@
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/device_info_type"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_dev_mod"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
@@ -69,6 +71,7 @@
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/device_info_serial_number"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_device_serial"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
@@ -91,7 +94,7 @@
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/device_info_firmware_version"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_device_name"
|
||||
android:id="@+id/tv_dev_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
|
||||
@@ -100,6 +100,8 @@
|
||||
<string name="device_status_not_working">Idle</string>
|
||||
<string name="select_watering_duration">Select watering duration</string>
|
||||
<string name="start_watering">Start Watering</string>
|
||||
<string name="device_status_offline">Off line</string>
|
||||
|
||||
|
||||
<!-- Schedule -->
|
||||
<string name="input_plan_name">Enter schedule name</string>
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
<string name="device_info_firmware_version">固件版本</string>
|
||||
<string name="device_status_working">工作中</string>
|
||||
<string name="device_status_not_working">待机中</string>
|
||||
<string name="device_status_offline">离线</string>
|
||||
<string name="select_watering_duration">请选择浇水时长</string>
|
||||
<string name="start_watering">开始浇水</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user