Compare commits
14 Commits
77f6001a31
...
133045fadd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
133045fadd | ||
|
|
5842837a9e | ||
|
|
bc3091ac02 | ||
|
|
d4cc897e26 | ||
|
|
8b3c6d1761 | ||
|
|
92ca8067d2 | ||
|
|
45dfc2d793 | ||
|
|
dab61da6c5 | ||
|
|
4d4df82c6e | ||
|
|
56af585524 | ||
|
|
02acc5403d | ||
|
|
2a933d09a4 | ||
|
|
121c69fdfc | ||
|
|
97ee780561 |
2
.idea/deploymentTargetSelector.xml
generated
2
.idea/deploymentTargetSelector.xml
generated
@@ -4,7 +4,7 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2026-06-06T06:46:42.891310900Z">
|
||||
<DropdownSelection timestamp="2026-06-10T01:13:16.309557300Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=D122222104A9" />
|
||||
|
||||
4
.idea/deviceManager.xml
generated
4
.idea/deviceManager.xml
generated
@@ -3,6 +3,10 @@
|
||||
<component name="DeviceTable">
|
||||
<option name="columnSorters">
|
||||
<list>
|
||||
<ColumnSorterState>
|
||||
<option name="column" value="Name" />
|
||||
<option name="order" value="ASCENDING" />
|
||||
</ColumnSorterState>
|
||||
<ColumnSorterState>
|
||||
<option name="column" value="API" />
|
||||
<option name="order" value="DESCENDING" />
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<!-- 蓝牙权限 -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
@@ -240,4 +241,4 @@
|
||||
android:windowSoftInputMode="adjustResize"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.ckkj.water.login.entity.LoginEntity;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
import com.ckkj.water.utils.dataUtil.SharePreUtil;
|
||||
import com.ckkj.water.utils.manager.LanguageManager;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.ckkj.water.utils.manager.WaterUserInfoManager;
|
||||
|
||||
import java.util.List;
|
||||
@@ -71,6 +72,9 @@ public class MyApplication extends Application {
|
||||
// 恢复应用语言设置
|
||||
applyStoredLocale();
|
||||
|
||||
// 检查并设置默认主题色(如果之前没有设置过,默认设为白色主题)
|
||||
applyDefaultTheme();
|
||||
|
||||
boolean isUserAgreed = SharePreUtil.getBoolean(ConstantUtil.SHARE_PRE_NAME,context,ConstantUtil.PRIVACY_POLICY_AGREED);
|
||||
if(isUserAgreed){
|
||||
initializeUmengSDK();
|
||||
@@ -190,4 +194,18 @@ public class MyApplication extends Application {
|
||||
private void applyStoredLocale() {
|
||||
LanguageManager.applyStoredLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并设置默认主题色
|
||||
* 如果之前没有设置过主题(默认为 MODE_FOLLOW_SYSTEM),则设置为白色主题(MODE_LIGHT)
|
||||
*/
|
||||
private void applyDefaultTheme() {
|
||||
int currentTheme = ThemeManager.getCurrentTheme(context);
|
||||
if (currentTheme == ThemeManager.MODE_FOLLOW_SYSTEM) {
|
||||
ThemeManager.setCurrentTheme(context, ThemeManager.MODE_LIGHT);
|
||||
ThemeManager.applyTheme(ThemeManager.MODE_LIGHT);
|
||||
} else {
|
||||
ThemeManager.applyTheme(currentTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,7 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
||||
|
||||
if (message.msg.equals(EventMessage.USER_LOGIN_LOST)) {
|
||||
Log.d("DINGDING","Activity接收一次");
|
||||
Log.d("DINGDING", "触发堆栈:", new Throwable("401触发堆栈追踪"));
|
||||
Log.d("DINGDING", "当前Activity状态: isFinishing=" + isFinishing() + ", isDestroyed=" + isDestroyed());
|
||||
|
||||
// 检查Activity状态,如果正在销毁则不处理
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
@@ -210,7 +207,12 @@ public class AddDeviceActivity extends BaseActivity<AddDeviceLayoutBinding, Devi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,27 +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;
|
||||
@@ -49,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;
|
||||
@@ -164,6 +159,7 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
.build();
|
||||
List<ScanFilter> filters = new ArrayList<>();
|
||||
filters.add(new ScanFilter.Builder().setServiceUuid(parcelUuid).build());
|
||||
// filters.add(new ScanFilter.Builder().setDeviceName("PROV_Water_01").build());
|
||||
Log.e("TEST", "开始扫描");
|
||||
mScanCallback = new ScanCallback() {
|
||||
@Override
|
||||
@@ -179,6 +175,10 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
discoveredMacSet.add(deviceAddress);
|
||||
|
||||
WaterDeviceEntity bean = new WaterDeviceEntity();
|
||||
ScanRecord record = result.getScanRecord();
|
||||
|
||||
SparseArray<byte[]> manufacturerData = record.getManufacturerSpecificData();
|
||||
|
||||
//设备名字
|
||||
String deviceName = result.getScanRecord() != null ?
|
||||
result.getScanRecord().getDeviceName() : "无名称";
|
||||
@@ -194,8 +194,8 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
AnimationDrawable animationDrawable = (AnimationDrawable) ivScanAnimation.getDrawable();
|
||||
if (animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
viewBinding.ivScanAnimation.setVisibility(GONE);
|
||||
}
|
||||
viewBinding.ivScanAnimation.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
ToastUtil.showShort(mContext, "扫描失败,错误码: " + errorCode);
|
||||
}
|
||||
};
|
||||
scanner.startScan(null, settings, mScanCallback);
|
||||
scanner.startScan(filters, settings, mScanCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,7 +424,7 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@@ -444,7 +444,12 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
@@ -15,9 +16,12 @@ import com.ckkj.water.databinding.DeviceConnectLayoutBinding;
|
||||
import com.ckkj.water.device.mvp.DeviceContract;
|
||||
import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
import com.ckkj.water.device.mvp.DevicePresenter;
|
||||
import com.ckkj.water.espBle.EspProvisionManager;
|
||||
import com.ckkj.water.espBle.ProvisionCallback;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.utils.manager.ActivityManager;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
/**
|
||||
@@ -30,6 +34,14 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
private static final long ANIMATION_DURATION = 5000L; // 5秒
|
||||
|
||||
private String mWifiName;
|
||||
private String mWifiPassword;
|
||||
private WaterDeviceEntity mBleDeviceEntity;
|
||||
private EspProvisionManager espProvisionManager;
|
||||
private boolean isBleConnecting = false;
|
||||
private boolean isBleConnected = false;
|
||||
private boolean provisioningStarted = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -38,6 +50,14 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
@Override
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
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");
|
||||
}
|
||||
|
||||
ActivityManager.addActivity(this,getClass().getSimpleName() + "_" + ConstantUtil.ADD_DEVICE_FLAG);
|
||||
ImmersionBar.with(this)
|
||||
.statusBarColor(R.color.color_F9F9F9)
|
||||
@@ -45,28 +65,158 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
.titleBar(viewBinding.rlTitle)
|
||||
.init();
|
||||
viewBinding.includedTitle.tvTitle.setText(R.string.select_wifi_tip);
|
||||
|
||||
initEspProvision();
|
||||
startConnectAnimation();
|
||||
startProvisionWhenReady();
|
||||
}
|
||||
|
||||
private void startConnectAnimation() {
|
||||
viewBinding.tvConnectProgress.setText("正在配置网络");
|
||||
if (animationDrawable != null && animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
}
|
||||
|
||||
viewBinding.ivConnectAnimation.setImageResource(R.drawable.anim_connect_device);
|
||||
animationDrawable = (AnimationDrawable) viewBinding.ivConnectAnimation.getDrawable();
|
||||
|
||||
if (animationDrawable != null) {
|
||||
animationDrawable.start();
|
||||
handler.postDelayed(() -> {
|
||||
if (animationDrawable != null && animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
}
|
||||
viewBinding.linearConnectIng.setVisibility(VISIBLE);
|
||||
viewBinding.linearSuccess.setVisibility(GONE);
|
||||
}
|
||||
|
||||
private void stopConnectAnimation() {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
if (animationDrawable != null) {
|
||||
animationDrawable.stop();
|
||||
animationDrawable = null;
|
||||
}
|
||||
viewBinding.linearConnectIng.setVisibility(GONE);
|
||||
viewBinding.linearSuccess.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initEspProvision() {
|
||||
espProvisionManager = EspProvisionManager.init(mContext).setCallback(new ProvisionCallback() {
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
isBleConnecting = true;
|
||||
isBleConnected = false;
|
||||
Log.i("TEST", "DeviceConnectActivity===== onConnecting");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = true;
|
||||
startProvisionWhenReady();
|
||||
Log.i("TEST", "DeviceConnectActivity===== onConnected设备连接成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvisioning(int progress) {
|
||||
Log.i("TEST", "DeviceConnectActivity===== WIFI连接进度 == " + progress);
|
||||
viewBinding.tvConnectProgress.setText("正在配置网络" + progress + "%");
|
||||
if(progress == 100){
|
||||
stopConnectAnimation();
|
||||
}
|
||||
viewBinding.linearConnectIng.setVisibility(GONE);
|
||||
viewBinding.linearSuccess.setVisibility(VISIBLE);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String deviceName, String deviceType) {
|
||||
Log.i("TEST", "DeviceConnectActivity===== deviceName:" + deviceName + "配网成功");
|
||||
ToastUtil.showShort(mContext, deviceName + "配网成功");
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
goTo(mContext, DeviceReNameActivity.class,null);
|
||||
Bundle bundle = new Bundle();
|
||||
mBleDeviceEntity.setWifiName(mWifiName);
|
||||
mBleDeviceEntity.setWifiPassword(mWifiPassword);
|
||||
bundle.putSerializable("ble_device_entity", mBleDeviceEntity);
|
||||
goTo(mContext, DeviceReNameActivity.class, bundle);
|
||||
finish();
|
||||
}
|
||||
},1000);
|
||||
}, ANIMATION_DURATION);
|
||||
}, 800);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int errorCode, String message) {
|
||||
isBleConnecting = false;
|
||||
if (errorCode != 0) {
|
||||
isBleConnected = espProvisionManager != null && espProvisionManager.isConnected();
|
||||
}
|
||||
Log.i("TEST", "DeviceConnectActivity===== errorCode == " + errorCode + " message == " + message);
|
||||
ToastUtil.showShort(mContext, message);
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = false;
|
||||
hideDialogLoading();
|
||||
Log.i("TEST", "DeviceConnectActivity===== onDisconnected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiListReceived(String[] wifiList) {
|
||||
Log.i("TEST", "DeviceConnectActivity===== onWifiListReceived" + wifiList.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiListFailed(String message) {
|
||||
Log.i("TEST", "DeviceConnectActivity===== onWifiListFailed-Msg==" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvisioningRejected() {
|
||||
Log.i("TEST", "DeviceConnectActivity===== onProvisioningRejected");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void connectBleDevice() {
|
||||
if (mBleDeviceEntity == null || espProvisionManager == null) {
|
||||
ToastUtil.showShort(mContext, "\u8bbe\u5907\u8fde\u63a5\u672a\u521d\u59cb\u5316");
|
||||
return;
|
||||
}
|
||||
if (isBleConnected || isBleConnecting) {
|
||||
return;
|
||||
}
|
||||
espProvisionManager.connect(mBleDeviceEntity.getMacAddress(), mBleDeviceEntity.getDeviceName());
|
||||
}
|
||||
|
||||
private void startProvisionWhenReady() {
|
||||
if (provisioningStarted || espProvisionManager == null) {
|
||||
return;
|
||||
}
|
||||
isBleConnected = espProvisionManager.isConnected();
|
||||
if (isBleConnected) {
|
||||
provisionWifi();
|
||||
return;
|
||||
}
|
||||
if (!isBleConnecting) {
|
||||
connectBleDevice();
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionWifi() {
|
||||
if (provisioningStarted) {
|
||||
return;
|
||||
}
|
||||
if (espProvisionManager == null) {
|
||||
ToastUtil.showShort(mContext, "设备连接未初始化");
|
||||
return;
|
||||
}
|
||||
if (!espProvisionManager.isConnected()) {
|
||||
startProvisionWhenReady();
|
||||
return;
|
||||
}
|
||||
provisioningStarted = true;
|
||||
espProvisionManager.provisionWifi(mWifiName, mWifiPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,6 +226,10 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
if (animationDrawable != null && animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
}
|
||||
if (espProvisionManager != null) {
|
||||
espProvisionManager.disconnect();
|
||||
espProvisionManager.setCallback(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +253,7 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +273,12 @@ public class DeviceConnectActivity extends BaseActivity<DeviceConnectLayoutBindi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ 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.ClickUtils;
|
||||
import com.ckkj.water.utils.manager.PowerIconManage;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
@@ -59,17 +59,30 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
mDeviceEntity = (WaterDeviceEntity) bundle.getSerializable("device_info");
|
||||
if(mDeviceEntity != null){
|
||||
showLoadingDialog();
|
||||
mPresenter.getDeviceDetailInfo(mDeviceEntity.getId());
|
||||
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.setTextColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.tvConfirm.setBackgroundResource((R.drawable.shape_gray_button_bg_enable));
|
||||
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");
|
||||
@@ -138,7 +151,21 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
break;
|
||||
|
||||
case R.id.linear_bt:
|
||||
showDialogtext(null, false, false, true,
|
||||
getString(R.string.tip_text),
|
||||
getString(R.string.reset_device_provision),
|
||||
getString(R.string.cancel_text),
|
||||
getString(R.string.confirm_text),
|
||||
new BaseFragment.OnDialogClick() {
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirmClick() {
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case R.id.linear_wifi:
|
||||
@@ -162,20 +189,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
break;
|
||||
|
||||
case R.id.tv_confirm:
|
||||
if(mCustomDuration == 0 && mAdapter.getmSelPostion() == -1){
|
||||
ToastUtil.showShort(mContext,getString(R.string.select_watering_duration));
|
||||
return;
|
||||
}
|
||||
showCenterTipDialog(R.mipmap.icon_dialog_success,getString(R.string.start_watering));//
|
||||
String status = mDeviceEntity.getStatus();
|
||||
if(status.equals("1")){
|
||||
status = "0";
|
||||
}else{
|
||||
status = "1";
|
||||
}
|
||||
mPresenter.switchDeviceWork(mDeviceEntity.getId(),status,
|
||||
mCustomDuration == 0 ? convertToMinutes(mTimeList.get(mAdapter.getmSelPostion()))
|
||||
: mCustomDuration);
|
||||
handleDeviceSwitch();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -256,6 +270,50 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理设备开关操作
|
||||
*/
|
||||
private void handleDeviceSwitch() {
|
||||
if (mDeviceEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查设备在线状态
|
||||
if (!mDeviceEntity.getStatus().equals("1") && !mDeviceEntity.getStatus().equals("2")) {
|
||||
ToastUtil.showShort(mContext, getString(R.string.device_offline_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isCurrentlyWorking = mDeviceEntity.getWorkStatus().equals("1");
|
||||
|
||||
// 开启浇水时,必须选择时长
|
||||
if (!isCurrentlyWorking) {
|
||||
if (mCustomDuration <= 0 && mAdapter.getmSelPostion() < 0) {
|
||||
ToastUtil.showShort(mContext, getString(R.string.select_watering_duration));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 防止快速点击
|
||||
if (!ClickUtils.onclickTimes()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载状态
|
||||
showLoadingDialog();
|
||||
|
||||
String newStatus = isCurrentlyWorking ? "0" : "1";
|
||||
int duration = 0;
|
||||
|
||||
// 只有开启浇水时才计算时长
|
||||
if (!isCurrentlyWorking) {
|
||||
duration = mCustomDuration > 0 ? mCustomDuration
|
||||
: convertToMinutes(mTimeList.get(mAdapter.getmSelPostion()));
|
||||
}
|
||||
|
||||
mPresenter.switchDeviceWork(mDeviceEntity, newStatus, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -290,6 +348,29 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
mRemoteDeviceEntity = bean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开关设备成功
|
||||
* @param bean
|
||||
* @param status
|
||||
*/
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
hideDialogLoading();
|
||||
mDeviceEntity.setWorkStatus(status);
|
||||
mCustomDuration = 0;
|
||||
mAdapter.setOnSelPosition(-1);
|
||||
viewBinding.tvWorkDuartion.setText("");
|
||||
if(status.equals("0")){
|
||||
showCenterTipDialog(R.mipmap.icon_dialog_success,getString(R.string.end_watering));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.start_watering));
|
||||
}else{
|
||||
showCenterTipDialog(R.mipmap.icon_dialog_success,getString(R.string.start_watering));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.end_watering));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutResId(Bundle savedInstanceState) {
|
||||
return 0;
|
||||
@@ -307,7 +388,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@@ -323,8 +404,9 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void queryDeviceBindStatusSuccess(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) {
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +99,12 @@ public class DeviceInfoActivity extends BaseActivity<DeviceInfoLayoutBinding, De
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ import com.gyf.immersionbar.ImmersionBar;
|
||||
*/
|
||||
public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBinding, DevicePresenter>
|
||||
implements DeviceContract.DeviceView {
|
||||
|
||||
private String mWifiName;
|
||||
private String mWifiPassword;
|
||||
private WaterDeviceEntity mBleDeviceEntity;
|
||||
|
||||
@Override
|
||||
public DevicePresenter createPresenter() {
|
||||
return new DevicePresenter(new DeviceImpl());
|
||||
@@ -31,6 +36,15 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
@Override
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
super.initData(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if (bundle != null) {
|
||||
mBleDeviceEntity = (WaterDeviceEntity) bundle.getSerializable("ble_device_entity");
|
||||
if(mBleDeviceEntity != null){
|
||||
mWifiName = mBleDeviceEntity.getWifiName();
|
||||
mWifiPassword = mBleDeviceEntity.getWifiPassword();
|
||||
}
|
||||
}
|
||||
|
||||
ImmersionBar.with(this)
|
||||
.statusBarColor(R.color.color_F9F9F9) // 设置状态栏颜色
|
||||
.statusBarDarkFont(true) // 设置状态栏字体为黑色
|
||||
@@ -60,10 +74,11 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
ToastUtil.showShort(mContext,getString(R.string.input_device_name_hint));
|
||||
return;
|
||||
}
|
||||
String deviceName = viewBinding.etDeviceName.getText().toString().trim();
|
||||
// ToastUtil.showShort(mContext,"名称保存成功");
|
||||
// goTo(mContext,DeviceControlActivity.class,null);
|
||||
showLoadingDialog();
|
||||
mPresenter.addDevice();
|
||||
mPresenter.addDevice(deviceName,mWifiName,mWifiPassword,mBleDeviceEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -73,14 +88,16 @@ 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);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
goTo(mContext,DeviceControlActivity.class,null);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("device_info",bean);
|
||||
goTo(mContext,DeviceControlActivity.class,bundle);
|
||||
finish();
|
||||
}
|
||||
},800);
|
||||
@@ -119,7 +136,12 @@ public class DeviceReNameActivity extends BaseActivity<SetDeviceNameLayoutBindin
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
@@ -219,7 +221,12 @@ public class DeviceSettingsActivity extends BaseActivity<DeviceSettingsLayoutBin
|
||||
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
package com.ckkj.water.device;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
@@ -26,6 +23,8 @@ import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
import com.ckkj.water.device.mvp.DevicePresenter;
|
||||
import com.ckkj.water.espBle.EspProvisionManager;
|
||||
import com.ckkj.water.espBle.ProvisionCallback;
|
||||
import com.espressif.provisioning.WiFiAccessPoint;
|
||||
import com.espressif.provisioning.listeners.WiFiScanListener;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
@@ -45,18 +44,21 @@ import java.util.Set;
|
||||
public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, DevicePresenter>
|
||||
implements DeviceContract.DeviceView {
|
||||
|
||||
private WifiManager wifiManager;
|
||||
private WifiListAdapter wifiListAdapter;
|
||||
private WifiScanReceiver wifiScanReceiver;
|
||||
//100 来自设备添加, 200 来自设备信息
|
||||
private int WITCH_FROM_CODE = 100;
|
||||
|
||||
private String mWifiName = "";
|
||||
|
||||
private WaterDeviceEntity mBleDeviceEntity;
|
||||
private WaterDeviceEntity mRemoteDeviceEntity;
|
||||
private EspProvisionManager espProvisionManager;
|
||||
private boolean isBleConnecting = false;
|
||||
private boolean isBleConnected = false;
|
||||
private boolean keepBleConnectionForProvision = false;
|
||||
private Handler bleConnectHandler = new Handler();
|
||||
private AnimationDrawable animationDrawable;
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Override
|
||||
public DevicePresenter createPresenter() {
|
||||
@@ -66,27 +68,14 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
wifiScanReceiver = new WifiScanReceiver();
|
||||
ActivityManager.addActivity(this,getClass().getSimpleName() + "_" + ConstantUtil.ADD_DEVICE_FLAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(wifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
unregisterReceiver(wifiScanReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (WITCH_FROM_CODE == 100 && espProvisionManager != null) {
|
||||
bleConnectHandler.removeCallbacksAndMessages(null);
|
||||
if (WITCH_FROM_CODE == 100 && espProvisionManager != null && !keepBleConnectionForProvision) {
|
||||
espProvisionManager.disconnect();
|
||||
espProvisionManager.setCallback(null);
|
||||
}
|
||||
@@ -115,10 +104,35 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
initWifiList();
|
||||
if (WITCH_FROM_CODE == 100) {
|
||||
initEspProvision();
|
||||
connectBleDevice();
|
||||
scheduleBleConnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void startConnectAnimation() {
|
||||
if (animationDrawable != null && animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
}
|
||||
|
||||
viewBinding.ivConnectAnimation.setImageResource(R.drawable.anim_connect_ble_device);
|
||||
animationDrawable = (AnimationDrawable) viewBinding.ivConnectAnimation.getDrawable();
|
||||
|
||||
if (animationDrawable != null) {
|
||||
animationDrawable.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void stopConnectAnimation() {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
if (animationDrawable != null) {
|
||||
animationDrawable.stop();
|
||||
animationDrawable = null;
|
||||
}
|
||||
viewBinding.linearConnectBle.setVisibility(GONE);
|
||||
viewBinding.linearWifiContent.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
private void initWifiList() {
|
||||
wifiListAdapter = new WifiListAdapter(mContext);
|
||||
viewBinding.rvWifiList.setAdapter(wifiListAdapter);
|
||||
@@ -154,7 +168,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
scanWifi();
|
||||
break;
|
||||
@@ -168,12 +182,13 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
ToastUtil.showShort(mContext,getString(R.string.toast_select_wifi_psd_tip));
|
||||
return;
|
||||
}
|
||||
String wifiPassword = viewBinding.etInputPsd.getText().toString();
|
||||
if(WITCH_FROM_CODE == 100){
|
||||
provisionWifi();
|
||||
goToDeviceConnect(wifiPassword);
|
||||
}else{
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("wifi_name",mWifiName);
|
||||
intent.putExtra("wifi_psd",viewBinding.etInputPsd.getText().toString());
|
||||
intent.putExtra("wifi_psd",wifiPassword);
|
||||
setResult(RESULT_OK,intent);
|
||||
finish();
|
||||
}
|
||||
@@ -181,26 +196,34 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置网络
|
||||
*/
|
||||
private void provisionWifi() {
|
||||
private void goToDeviceConnect(String wifiPassword) {
|
||||
if (espProvisionManager == null) {
|
||||
ToastUtil.showShort(mContext, "设备连接未初始化");
|
||||
initEspProvision();
|
||||
}
|
||||
if (mBleDeviceEntity == null) {
|
||||
ToastUtil.showShort(mContext, "\u8bbe\u5907\u8fde\u63a5\u672a\u521d\u59cb\u5316");
|
||||
return;
|
||||
}
|
||||
isBleConnected = espProvisionManager != null && espProvisionManager.isConnected();
|
||||
if (!isBleConnected) {
|
||||
if (!isBleConnecting) {
|
||||
connectBleDevice();
|
||||
scheduleBleConnect();
|
||||
}
|
||||
ToastUtil.showShort(mContext, "设备连接中,请稍后再试");
|
||||
ToastUtil.showShort(mContext, "\u8bbe\u5907\u8fde\u63a5\u4e2d\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5");
|
||||
return;
|
||||
}
|
||||
showProgressLoadingDialog(0);
|
||||
espProvisionManager.provisionWifi(mWifiName, viewBinding.etInputPsd.getText().toString());
|
||||
// goTo(mContext,DeviceConnectActivity.class,null);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("wifi_name", mWifiName);
|
||||
bundle.putString("wifi_password", wifiPassword);
|
||||
bundle.putSerializable("ble_device_entity", mBleDeviceEntity);
|
||||
keepBleConnectionForProvision = true;
|
||||
goTo(mContext, DeviceConnectActivity.class, bundle);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initEspProvision() {
|
||||
espProvisionManager = EspProvisionManager.init(mContext).setCallback(new ProvisionCallback() {
|
||||
@Override
|
||||
@@ -215,6 +238,10 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
isBleConnecting = false;
|
||||
isBleConnected = true;
|
||||
Log.i("TEST","onConnected设备连接成功");
|
||||
stopConnectAnimation();
|
||||
ToastUtil.showShort(mContext, "设备连接成功");
|
||||
//Tips 蓝牙扫描添加的设备不同于二维码扫描连接的设备,由于无法拿到deviceNo,所以需要请求接口获取
|
||||
mPresenter.bindDeviceStatus(mBleDeviceEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,20 +270,22 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
Log.i("TEST","errorCode == " + errorCode + " message == " + message);
|
||||
ToastUtil.showShort(mContext, message);
|
||||
hideDialogLoading();
|
||||
stopConnectAnimation();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = false;
|
||||
hideDialogLoading();
|
||||
stopConnectAnimation();
|
||||
Log.i("TEST","onDisconnected");
|
||||
ToastUtil.showShort(mContext, "设备已断开");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiListReceived(String[] wifiList) {
|
||||
|
||||
Log.i("TEST","onWifiListReceived-Msg==" + wifiList.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,6 +303,17 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
private void scheduleBleConnect() {
|
||||
startConnectAnimation();
|
||||
bleConnectHandler.removeCallbacksAndMessages(null);
|
||||
bleConnectHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connectBleDevice();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private void connectBleDevice() {
|
||||
if (WITCH_FROM_CODE != 100 || mBleDeviceEntity == null || espProvisionManager == null) {
|
||||
return;
|
||||
@@ -287,20 +327,37 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
private void scanWifi() {
|
||||
showLoadingDialog();
|
||||
viewBinding.tvNext.setVisibility(View.GONE);
|
||||
if (wifiManager != null && wifiManager.isWifiEnabled()) {
|
||||
wifiManager.startScan();
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, getString(R.string.wifi_not_enabled));
|
||||
|
||||
if (espProvisionManager == null || !espProvisionManager.isConnected()) {
|
||||
ToastUtil.showShort(mContext, "设备未连接,请稍后重试");
|
||||
hideDialogLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
espProvisionManager.scanWifiFromDevice(new WiFiScanListener() {
|
||||
|
||||
@Override
|
||||
public void onWifiListReceived(ArrayList<WiFiAccessPoint> wifiList) {
|
||||
runOnUiThread(() -> displayWifiListFromDevice(wifiList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiScanFailed(Exception e) {
|
||||
runOnUiThread(() -> {
|
||||
ToastUtil.showShort(mContext, "扫描失败: " + e.getMessage());
|
||||
hideDialogLoading();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void displayWifiList(List<ScanResult> scanResults) {
|
||||
private void displayWifiListFromDevice(ArrayList<WiFiAccessPoint> wifiNetworks) {
|
||||
Set<String> wifiSet = new HashSet<>();
|
||||
List<String> wifiNameList = new ArrayList<>();
|
||||
|
||||
for (ScanResult result : scanResults) {
|
||||
String wifiName = result.SSID;
|
||||
for (WiFiAccessPoint network : wifiNetworks) {
|
||||
String wifiName = network.getWifiName();
|
||||
if (wifiName != null && !wifiName.isEmpty() && !wifiSet.contains(wifiName)) {
|
||||
wifiSet.add(wifiName);
|
||||
wifiNameList.add(wifiName);
|
||||
@@ -319,8 +376,14 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(BaseBean bean) {
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
mBleDeviceEntity = bean.getBindDevice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@@ -340,34 +403,10 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean) {
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
private class WifiScanReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())) {
|
||||
boolean success = intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false);
|
||||
if (success) {
|
||||
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
List<ScanResult> results = wifiManager.getScanResults();
|
||||
displayWifiList(results);
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, getString(R.string.wifi_scan_failed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutResId(Bundle savedInstanceState) {
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
package com.ckkj.water.device;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.databinding.DeviceResetWifiBinding;
|
||||
import com.ckkj.water.device.adapter.WifiListAdapter;
|
||||
import com.ckkj.water.device.mvp.DeviceContract;
|
||||
import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
import com.ckkj.water.device.mvp.DevicePresenter;
|
||||
import com.ckkj.water.espBle.EspProvisionManager;
|
||||
import com.ckkj.water.espBle.ProvisionCallback;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
import com.ckkj.water.utils.manager.ActivityManager;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配置wifi
|
||||
*/
|
||||
public class SelectWifiActivity_copy extends BaseActivity<DeviceResetWifiBinding, DevicePresenter>
|
||||
implements DeviceContract.DeviceView {
|
||||
|
||||
private WifiManager wifiManager;
|
||||
private WifiListAdapter wifiListAdapter;
|
||||
private WifiScanReceiver wifiScanReceiver;
|
||||
//100 来自设备添加, 200 来自设备信息
|
||||
private int WITCH_FROM_CODE = 100;
|
||||
|
||||
private String mWifiName = "";
|
||||
|
||||
private WaterDeviceEntity mBleDeviceEntity;
|
||||
private EspProvisionManager espProvisionManager;
|
||||
private boolean isBleConnecting = false;
|
||||
private boolean isBleConnected = false;
|
||||
|
||||
@Override
|
||||
public DevicePresenter createPresenter() {
|
||||
return new DevicePresenter(new DeviceImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
wifiScanReceiver = new WifiScanReceiver();
|
||||
ActivityManager.addActivity(this,getClass().getSimpleName() + "_" + ConstantUtil.ADD_DEVICE_FLAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(wifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
unregisterReceiver(wifiScanReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (WITCH_FROM_CODE == 100 && espProvisionManager != null) {
|
||||
espProvisionManager.disconnect();
|
||||
espProvisionManager.setCallback(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
super.initData(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if(bundle != null){
|
||||
WITCH_FROM_CODE = bundle.getInt(ConstantUtil.ACTIVITY_NAVIGATE_FLAG);
|
||||
mBleDeviceEntity = (WaterDeviceEntity) bundle.getSerializable("ble_device_entity");
|
||||
}
|
||||
|
||||
ImmersionBar.with(this)
|
||||
.statusBarColor(R.color.color_gray_theme)
|
||||
.statusBarDarkFont(ThemeManager.isAppThemeLight(mContext))
|
||||
.titleBar(viewBinding.rlTitle)
|
||||
.init();
|
||||
if(WITCH_FROM_CODE == 200){
|
||||
viewBinding.tvNext.setText(getString(R.string.confirm_text));
|
||||
}
|
||||
viewBinding.includedTitle.tvTitle.setText(R.string.select_wifi_tip);
|
||||
|
||||
initListener();
|
||||
initWifiList();
|
||||
if (WITCH_FROM_CODE == 100) {
|
||||
initEspProvision();
|
||||
connectBleDevice();
|
||||
}
|
||||
}
|
||||
|
||||
private void initWifiList() {
|
||||
wifiListAdapter = new WifiListAdapter(mContext);
|
||||
viewBinding.rvWifiList.setAdapter(wifiListAdapter);
|
||||
wifiListAdapter.setOnWifiItemClickListener(wifiName -> {
|
||||
mWifiName = wifiName;
|
||||
viewBinding.etWifiName.setText(wifiName);
|
||||
viewBinding.rvWifiList.setVisibility(View.GONE);
|
||||
viewBinding.linearWifiInfo.setVisibility(View.VISIBLE);
|
||||
viewBinding.tvNext.setVisibility(View.VISIBLE);
|
||||
});
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
setClick(viewBinding.includedTitle.imgBack);
|
||||
setClick(viewBinding.tvSelectWifi);
|
||||
setClick(viewBinding.tvNext);
|
||||
}
|
||||
|
||||
private void setClick(View view) {
|
||||
view.setOnClickListener(this::onClick);
|
||||
}
|
||||
|
||||
public void onClick(View view){
|
||||
switch (view.getId()){
|
||||
case R.id.img_back:
|
||||
finish();
|
||||
break;
|
||||
|
||||
case R.id.tv_select_wifi:
|
||||
String[] permission = {
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
};
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}else{
|
||||
}
|
||||
scanWifi();
|
||||
break;
|
||||
|
||||
case R.id.tv_next:
|
||||
if(TextUtils.isEmpty(mWifiName)){
|
||||
ToastUtil.showShort(mContext,getString(R.string.toast_select_wifi_tip));
|
||||
return;
|
||||
}
|
||||
if(TextUtils.isEmpty(viewBinding.etInputPsd.getText().toString())){
|
||||
ToastUtil.showShort(mContext,getString(R.string.toast_select_wifi_psd_tip));
|
||||
return;
|
||||
}
|
||||
if(WITCH_FROM_CODE == 100){
|
||||
provisionWifi();
|
||||
}else{
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("wifi_name",mWifiName);
|
||||
intent.putExtra("wifi_psd",viewBinding.etInputPsd.getText().toString());
|
||||
setResult(RESULT_OK,intent);
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置网络
|
||||
*/
|
||||
private void provisionWifi() {
|
||||
if (espProvisionManager == null) {
|
||||
ToastUtil.showShort(mContext, "设备连接未初始化");
|
||||
return;
|
||||
}
|
||||
if (!isBleConnected) {
|
||||
if (!isBleConnecting) {
|
||||
connectBleDevice();
|
||||
}
|
||||
ToastUtil.showShort(mContext, "设备连接中,请稍后再试");
|
||||
return;
|
||||
}
|
||||
showProgressLoadingDialog(0);
|
||||
espProvisionManager.provisionWifi(mWifiName, viewBinding.etInputPsd.getText().toString());
|
||||
// goTo(mContext,DeviceConnectActivity.class,null);
|
||||
}
|
||||
|
||||
private void initEspProvision() {
|
||||
espProvisionManager = EspProvisionManager.init(mContext).setCallback(new ProvisionCallback() {
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
isBleConnecting = true;
|
||||
isBleConnected = false;
|
||||
Log.i("TEST","onConnecting");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = true;
|
||||
Log.i("TEST","onConnected设备连接成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvisioning(int progress) {
|
||||
Log.i("TEST","WIFI连接进度 == " + progress);
|
||||
mProgressLoadingDialog.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String deviceName, String deviceType) {
|
||||
Log.i("TEST","deviceName:" + deviceName + "连接成功");
|
||||
ToastUtil.showShort(mContext, deviceName + "连接成功");
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideDialogLoading();
|
||||
}
|
||||
}, 800);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int errorCode, String message) {
|
||||
isBleConnecting = false;
|
||||
if (errorCode != 0) {
|
||||
isBleConnected = espProvisionManager != null && espProvisionManager .isConnected();
|
||||
}
|
||||
Log.i("TEST","errorCode == " + errorCode + " message == " + message);
|
||||
ToastUtil.showShort(mContext, message);
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = false;
|
||||
hideDialogLoading();
|
||||
Log.i("TEST","onDisconnected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiListReceived(String[] wifiList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiListFailed(String message) {
|
||||
Log.i("TEST","onWifiListFailed-Msg==" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvisioningRejected() {
|
||||
Log.i("TEST","onProvisioningRejected");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
private void connectBleDevice() {
|
||||
if (WITCH_FROM_CODE != 100 || mBleDeviceEntity == null || espProvisionManager == null) {
|
||||
return;
|
||||
}
|
||||
if (isBleConnected || isBleConnecting) {
|
||||
return;
|
||||
}
|
||||
espProvisionManager.connect(mBleDeviceEntity.getMacAddress(), mBleDeviceEntity.getDeviceName());
|
||||
}
|
||||
|
||||
private void scanWifi() {
|
||||
showLoadingDialog();
|
||||
viewBinding.tvNext.setVisibility(View.GONE);
|
||||
if (wifiManager != null && wifiManager.isWifiEnabled()) {
|
||||
wifiManager.startScan();
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, getString(R.string.wifi_not_enabled));
|
||||
hideDialogLoading();
|
||||
}
|
||||
}
|
||||
|
||||
private void displayWifiList(List<ScanResult> scanResults) {
|
||||
Set<String> wifiSet = new HashSet<>();
|
||||
List<String> wifiNameList = new ArrayList<>();
|
||||
|
||||
for (ScanResult result : scanResults) {
|
||||
String wifiName = result.SSID;
|
||||
if (wifiName != null && !wifiName.isEmpty() && !wifiSet.contains(wifiName)) {
|
||||
wifiSet.add(wifiName);
|
||||
wifiNameList.add(wifiName);
|
||||
}
|
||||
}
|
||||
hideDialogLoading();
|
||||
|
||||
if (wifiNameList.isEmpty()) {
|
||||
ToastUtil.showShort(mContext, getString(R.string.no_wifi_found));
|
||||
viewBinding.linearWifiInfo.setVisibility(View.VISIBLE);
|
||||
viewBinding.rvWifiList.setVisibility(View.GONE);
|
||||
} else {
|
||||
wifiListAdapter.setData(wifiNameList);
|
||||
viewBinding.linearWifiInfo.setVisibility(View.GONE);
|
||||
viewBinding.rvWifiList.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDeviceDetailInfo(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editDeviceInfoSuccess(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceSuccess(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
private class WifiScanReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())) {
|
||||
boolean success = intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false);
|
||||
if (success) {
|
||||
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
List<ScanResult> results = wifiManager.getScanResults();
|
||||
displayWifiList(results);
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, getString(R.string.wifi_scan_failed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutResId(Bundle savedInstanceState) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
ToastUtil.showShort(mContext,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut(BaseBean bean) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,12 @@ 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);
|
||||
void turnOnOffDeviceSuccess(BaseBean bean);
|
||||
void turnOnOffDeviceSuccess(BaseBean bean, String status);
|
||||
|
||||
void queryDeviceBindStatusSuccess(WaterDeviceEntity bean);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DeviceImpl implements DeviceContract.DataModel{
|
||||
|
||||
@Override
|
||||
public void getDeviceInfomation(Map<String, String> map, IndexContract.CallBack callBack) {
|
||||
String deviceID = map.get("id");
|
||||
String deviceID = map.get("deviceNo");
|
||||
NetWorkManager.getRequest().getDeviceDetailInfo(NetWorkManager.getToken(), deviceID)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
@@ -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());
|
||||
}
|
||||
@@ -132,9 +132,9 @@ public class DeviceImpl implements DeviceContract.DataModel{
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void deleteDevice(String devID, IndexContract.CallBack callBack) {
|
||||
public void deleteDevice(String deviceNo, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().unBindDevice(NetWorkManager.getToken(), devID)
|
||||
NetWorkManager.getRequest().unBindDevice(NetWorkManager.getToken(), deviceNo)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.ckkj.water.device.mvp;
|
||||
import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.index.mvp.IndexContract;
|
||||
import com.ckkj.water.index.mvp.IndexImpl;
|
||||
import com.ckkj.water.index.mvp.IndexPresenter;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -21,21 +23,24 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @param mWifiName
|
||||
* @param mWifiPassword
|
||||
* @param mBleDeviceEntity
|
||||
*/
|
||||
public void addDevice() {
|
||||
public void addDevice(String deviceName,String mWifiName, String mWifiPassword, WaterDeviceEntity mBleDeviceEntity) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceNo",System.currentTimeMillis() + "");
|
||||
json.put("deviceName",new Random().nextInt(99) + "号设备");
|
||||
json.put("wifiName","橙空科技WiFi");
|
||||
json.put("wifiPassword","12321212");
|
||||
json.put("deviceEm","213123123123");
|
||||
json.put("deviceSn","sdfsd32423gdfgdf3");
|
||||
json.put("fwVer","fwVer-56565644");
|
||||
json.put("macAddress","2E:8H:00:KK:N7");
|
||||
impl.addDevice(json, new IndexContract.CallBack<BaseBean>() {
|
||||
json.put("deviceName",deviceName);
|
||||
json.put("wifiName",mWifiName);
|
||||
json.put("wifiPassword",mWifiPassword);
|
||||
json.put("macAddress",mBleDeviceEntity.getMacAddress());
|
||||
json.put("deviceNo", mBleDeviceEntity.getDeviceNo());
|
||||
// json.put("deviceEm","213123123123");
|
||||
// json.put("deviceSn","sdfsd32423gdfgdf3");
|
||||
// json.put("fwVer","fwVer-56565644");
|
||||
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);
|
||||
}
|
||||
@@ -55,11 +60,11 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
|
||||
/**
|
||||
* 获取设备详情信息
|
||||
* @param deviceID
|
||||
* @param deviceNo
|
||||
*/
|
||||
public void getDeviceDetailInfo(String deviceID) {
|
||||
public void getDeviceDetailInfo(String deviceNo) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("id",deviceID);
|
||||
map.put("deviceNo",deviceNo);
|
||||
impl.getDeviceInfomation(map, new IndexContract.CallBack<WaterDeviceEntity>() {
|
||||
@Override
|
||||
public void success(WaterDeviceEntity bean, int total) {
|
||||
@@ -84,7 +89,7 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
public void updateDeviceInfo(WaterDeviceEntity mDeviceEntity) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id",mDeviceEntity.getId());
|
||||
json.put("deviceNo",mDeviceEntity.getDeviceNo());
|
||||
json.put("deviceName",mDeviceEntity.getDeviceName());
|
||||
json.put("wifiName",mDeviceEntity.getWifiName());
|
||||
json.put("wifiPassword",mDeviceEntity.getWifiPassword());
|
||||
@@ -113,7 +118,7 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
* @param deviceEntity
|
||||
*/
|
||||
public void unBindDevice(WaterDeviceEntity deviceEntity) {
|
||||
impl.deleteDevice(deviceEntity.getId(), new IndexContract.CallBack<BaseBean>() {
|
||||
impl.deleteDevice(deviceEntity.getDeviceNo(), new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean, int total) {
|
||||
if (DevicePresenter.this.getView() != null) {
|
||||
@@ -132,14 +137,14 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
|
||||
/**
|
||||
* 开启/关闭浇水
|
||||
* @param id
|
||||
* @param deviceEntity
|
||||
* @param status
|
||||
* @param duration
|
||||
*/
|
||||
public void switchDeviceWork(String id, String status, int duration) {
|
||||
public void switchDeviceWork(WaterDeviceEntity deviceEntity, String status, int duration) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id",id);
|
||||
json.put("deviceNo",deviceEntity.getDeviceNo());
|
||||
json.put("workStatus",status);
|
||||
// json.put("startTime","09:50");
|
||||
json.put("durationMin",duration + "");
|
||||
@@ -147,7 +152,7 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
@Override
|
||||
public void success(BaseBean bean,int total) {
|
||||
if(DevicePresenter.this.getView() != null){
|
||||
DevicePresenter.this.getView().turnOnOffDeviceSuccess(bean);
|
||||
DevicePresenter.this.getView().turnOnOffDeviceSuccess(bean,status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,4 +167,35 @@ public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定设备状态
|
||||
* @param entity
|
||||
*/
|
||||
public void bindDeviceStatus(WaterDeviceEntity entity) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("macAddress",entity.getMacAddress());
|
||||
new IndexImpl().queryDeviceBindStatus(json, new IndexContract.CallBack<WaterDeviceEntity>() {
|
||||
@Override
|
||||
public void success(WaterDeviceEntity bean, int total) {
|
||||
bean.setMacAddress(entity.getMacAddress());
|
||||
bean.setDeviceName(entity.getDeviceName());
|
||||
if(DevicePresenter.this.getView() != null){
|
||||
DevicePresenter.this.getView().queryDeviceBindStatusSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(DevicePresenter.this.getView() != null){
|
||||
DevicePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ public class EspProvisionManager {
|
||||
private final Context context;
|
||||
private final Handler mainHandler;
|
||||
private final com.espressif.provisioning.ESPProvisionManager provisionManager;
|
||||
private static final long CONNECT_COOLDOWN = 1200L;
|
||||
private static final long QUICK_DISCONNECT_WINDOW = 3000L;
|
||||
private static final long RETRY_DELAY = 1200L;
|
||||
private static final int MAX_CONNECT_RETRY = 2;
|
||||
|
||||
private ESPDevice espDevice;
|
||||
private ProvisionCallback callback;
|
||||
@@ -47,12 +51,28 @@ public class EspProvisionManager {
|
||||
private boolean expectDisconnected; // 标记是否预期断开(配网成功后)
|
||||
private String currentDeviceName;
|
||||
private String currentDeviceType = ProvisionConfig.TRANSPORT_BLE;
|
||||
private BluetoothDevice pendingBluetoothDevice;
|
||||
private String pendingDeviceName;
|
||||
private String pendingServiceUuid;
|
||||
private String pendingProofOfPossession;
|
||||
private String pendingUserName;
|
||||
private int pendingSecurityType;
|
||||
private int connectRetryCount;
|
||||
private long lastDisconnectTime;
|
||||
private long connectStartTime;
|
||||
|
||||
private final Runnable connectionTimeoutTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connecting && !connected) {
|
||||
connecting = false;
|
||||
disconnectDeviceOnly();
|
||||
lastDisconnectTime = System.currentTimeMillis();
|
||||
if (retryConnectIfAllowed()) {
|
||||
return;
|
||||
}
|
||||
resetState(true);
|
||||
clearPendingConnect();
|
||||
notifyFailed(ProvisionConfig.ERROR_CONNECT_TIMEOUT, "蓝牙连接超时");
|
||||
disconnectDeviceOnly();
|
||||
}
|
||||
@@ -68,6 +88,13 @@ public class EspProvisionManager {
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable connectRetryTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startPendingConnect(false);
|
||||
}
|
||||
};
|
||||
|
||||
private EspProvisionManager(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.mainHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -150,65 +177,94 @@ public class EspProvisionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
String primaryServiceUuid = TextUtils.isEmpty(serviceUuid) ? ProvisionConfig.SERVICE_UUID : serviceUuid;
|
||||
String displayName = !TextUtils.isEmpty(deviceName) ? deviceName : bluetoothDevice.getName();
|
||||
if (connecting && pendingBluetoothDevice != null
|
||||
&& TextUtils.equals(pendingBluetoothDevice.getAddress(), bluetoothDevice.getAddress())) {
|
||||
return;
|
||||
}
|
||||
|
||||
pendingBluetoothDevice = bluetoothDevice;
|
||||
pendingDeviceName = deviceName;
|
||||
pendingServiceUuid = TextUtils.isEmpty(serviceUuid) ? ProvisionConfig.SERVICE_UUID : serviceUuid;
|
||||
pendingProofOfPossession = proofOfPossession == null ? "" : proofOfPossession;
|
||||
pendingUserName = userName == null ? "" : userName;
|
||||
pendingSecurityType = securityType;
|
||||
connectRetryCount = 0;
|
||||
startPendingConnect(true);
|
||||
}
|
||||
|
||||
|
||||
private void startPendingConnect(boolean respectCooldown) {
|
||||
if (pendingBluetoothDevice == null) {
|
||||
notifyFailed(ProvisionConfig.ERROR_INVALID_DEVICE, "蓝牙设备无效");
|
||||
return;
|
||||
}
|
||||
if (provisioning) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainHandler.removeCallbacks(connectRetryTask);
|
||||
long elapsedSinceDisconnect = System.currentTimeMillis() - lastDisconnectTime;
|
||||
if (respectCooldown && lastDisconnectTime > 0 && elapsedSinceDisconnect < CONNECT_COOLDOWN) {
|
||||
mainHandler.postDelayed(connectRetryTask, CONNECT_COOLDOWN - elapsedSinceDisconnect);
|
||||
return;
|
||||
}
|
||||
|
||||
String displayName = !TextUtils.isEmpty(pendingDeviceName)
|
||||
? pendingDeviceName : pendingBluetoothDevice.getName();
|
||||
currentDeviceName = displayName;
|
||||
currentDeviceType = ProvisionConfig.TRANSPORT_BLE;
|
||||
|
||||
ignoreNextDisconnectEvent = espDevice != null;
|
||||
boolean hadActiveDevice = espDevice != null && (connecting || connected || provisioning);
|
||||
ignoreNextDisconnectEvent = hadActiveDevice;
|
||||
disconnectDeviceOnly();
|
||||
ensureEventBusRegistered();
|
||||
|
||||
espDevice = provisionManager.createESPDevice(
|
||||
ESPConstants.TransportType.TRANSPORT_BLE,
|
||||
parseSecurityType(securityType)
|
||||
parseSecurityType(pendingSecurityType)
|
||||
);
|
||||
espDevice.setBluetoothDevice(bluetoothDevice);
|
||||
espDevice.setPrimaryServiceUuid(primaryServiceUuid);
|
||||
espDevice.setBluetoothDevice(pendingBluetoothDevice);
|
||||
espDevice.setPrimaryServiceUuid(pendingServiceUuid);
|
||||
espDevice.setDeviceName(displayName);
|
||||
espDevice.setProofOfPossession(proofOfPossession == null ? "" : proofOfPossession);
|
||||
espDevice.setUserName(userName == null ? "" : userName);
|
||||
espDevice.setProofOfPossession(pendingProofOfPossession);
|
||||
espDevice.setUserName(pendingUserName);
|
||||
|
||||
connecting = true;
|
||||
connected = false;
|
||||
provisioning = false;
|
||||
connectStartTime = System.currentTimeMillis();
|
||||
mainHandler.removeCallbacks(connectionTimeoutTask);
|
||||
mainHandler.postDelayed(connectionTimeoutTask, ProvisionConfig.CONNECTION_TIMEOUT);
|
||||
notifyConnecting();
|
||||
espDevice.connectBLEDevice(bluetoothDevice, primaryServiceUuid);
|
||||
espDevice.connectBLEDevice(pendingBluetoothDevice, pendingServiceUuid);
|
||||
}
|
||||
|
||||
public void scanDeviceWifiList() {
|
||||
if (!checkConnected()) {
|
||||
notifyWifiListFailed("设备未连接");
|
||||
return;
|
||||
private boolean retryConnectIfAllowed() {
|
||||
if (pendingBluetoothDevice == null || provisioning || connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
espDevice.scanNetworks(new WiFiScanListener() {
|
||||
@Override
|
||||
public void onWifiListReceived(ArrayList<WiFiAccessPoint> wifiList) {
|
||||
Set<String> wifiNames = new LinkedHashSet<>();
|
||||
if (wifiList != null) {
|
||||
for (WiFiAccessPoint accessPoint : wifiList) {
|
||||
if (accessPoint != null && !TextUtils.isEmpty(accessPoint.getWifiName())) {
|
||||
wifiNames.add(accessPoint.getWifiName());
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyWifiListReceived(wifiNames.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiScanFailed(Exception e) {
|
||||
notifyWifiListFailed(getErrorMessage(e, "获取设备 WiFi 列表失败"));
|
||||
}
|
||||
});
|
||||
if (connectRetryCount >= MAX_CONNECT_RETRY) {
|
||||
return false;
|
||||
}
|
||||
connectRetryCount++;
|
||||
resetState(true);
|
||||
mainHandler.removeCallbacks(connectRetryTask);
|
||||
mainHandler.postDelayed(connectRetryTask, RETRY_DELAY * connectRetryCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void provision(String ssid, String password) {
|
||||
provisionWifi(ssid, password);
|
||||
private void clearPendingConnect() {
|
||||
pendingBluetoothDevice = null;
|
||||
pendingDeviceName = null;
|
||||
pendingServiceUuid = null;
|
||||
pendingProofOfPossession = null;
|
||||
pendingUserName = null;
|
||||
pendingSecurityType = 0;
|
||||
connectRetryCount = 0;
|
||||
connectStartTime = 0;
|
||||
}
|
||||
|
||||
|
||||
public void provisionWifi(String ssid, String password) {
|
||||
if (!checkConnected()) {
|
||||
notifyFailed(ProvisionConfig.ERROR_NOT_CONNECTED, "设备未连接");
|
||||
@@ -269,27 +325,40 @@ public class EspProvisionManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过蓝牙请求 ESP32 扫描周围 WiFi
|
||||
* @param scanListener 扫描结果监听器
|
||||
*/
|
||||
public void scanWifiFromDevice(WiFiScanListener scanListener) {
|
||||
if (!checkConnected()) {
|
||||
if (scanListener != null) {
|
||||
scanListener.onWiFiScanFailed(new Exception("设备未连接"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (espDevice == null) {
|
||||
if (scanListener != null) {
|
||||
scanListener.onWiFiScanFailed(new Exception("设备实例为空"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
espDevice.scanNetworks(scanListener);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
boolean shouldNotify = connected || connecting || provisioning;
|
||||
mainHandler.removeCallbacks(connectRetryTask);
|
||||
disconnectDeviceOnly();
|
||||
resetState();
|
||||
lastDisconnectTime = System.currentTimeMillis();
|
||||
resetState(true);
|
||||
clearPendingConnect();
|
||||
if (shouldNotify) {
|
||||
notifyDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
disconnect();
|
||||
callback = null;
|
||||
mainHandler.removeCallbacksAndMessages(null);
|
||||
if (eventBusRegistered) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
eventBusRegistered = false;
|
||||
}
|
||||
if (instance == this) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onDeviceConnectionEvent(DeviceConnectionEvent event) {
|
||||
@@ -300,8 +369,10 @@ public class EspProvisionManager {
|
||||
switch (event.getEventType()) {
|
||||
case ESPConstants.EVENT_DEVICE_CONNECTED:
|
||||
mainHandler.removeCallbacks(connectionTimeoutTask);
|
||||
mainHandler.removeCallbacks(connectRetryTask);
|
||||
connecting = false;
|
||||
connected = true;
|
||||
connectRetryCount = 0;
|
||||
notifyConnected();
|
||||
break;
|
||||
|
||||
@@ -312,7 +383,13 @@ public class EspProvisionManager {
|
||||
connecting = false;
|
||||
connected = false;
|
||||
provisioning = false;
|
||||
lastDisconnectTime = System.currentTimeMillis();
|
||||
if (wasConnecting && retryConnectIfAllowed()) {
|
||||
break;
|
||||
}
|
||||
if (wasConnecting) {
|
||||
resetState(true);
|
||||
clearPendingConnect();
|
||||
notifyFailed(ProvisionConfig.ERROR_CONNECT_FAILED, "蓝牙连接失败");
|
||||
} else {
|
||||
notifyFailed(ProvisionConfig.ERROR_PROVISION_FAILED, "设备通信失败");
|
||||
@@ -327,14 +404,27 @@ public class EspProvisionManager {
|
||||
mainHandler.removeCallbacks(connectionTimeoutTask);
|
||||
mainHandler.removeCallbacks(provisionTimeoutTask);
|
||||
boolean shouldNotify = connected || connecting || provisioning;
|
||||
resetState();
|
||||
boolean expectedDisconnect = expectDisconnected;
|
||||
boolean wasConnecting2 = connecting;
|
||||
long connectDuration = System.currentTimeMillis() - connectStartTime;
|
||||
lastDisconnectTime = System.currentTimeMillis();
|
||||
resetState(true);
|
||||
if (wasConnecting2 && !expectedDisconnect
|
||||
&& connectDuration < QUICK_DISCONNECT_WINDOW
|
||||
&& retryConnectIfAllowed()) {
|
||||
break;
|
||||
}
|
||||
if (wasConnecting2 && !expectedDisconnect) {
|
||||
clearPendingConnect();
|
||||
notifyFailed(ProvisionConfig.ERROR_CONNECT_FAILED, "蓝牙连接失败");
|
||||
break;
|
||||
}
|
||||
if (shouldNotify) {
|
||||
// 如果是配网成功后的预期断开,不发送断开回调
|
||||
// 因为 onSuccess 已经通知过了
|
||||
if (!expectDisconnected) {
|
||||
if (!expectedDisconnect) {
|
||||
notifyDisconnected();
|
||||
}
|
||||
expectDisconnected = false; // 重置标志
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -363,14 +453,17 @@ public class EspProvisionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void resetState() {
|
||||
private void resetState(boolean clearDevice) {
|
||||
mainHandler.removeCallbacks(connectionTimeoutTask);
|
||||
mainHandler.removeCallbacks(provisionTimeoutTask);
|
||||
connecting = false;
|
||||
connected = false;
|
||||
provisioning = false;
|
||||
ignoreNextDisconnectEvent = false;
|
||||
// expectDisconnected 保持不变,用于断开回调判断
|
||||
expectDisconnected = false;
|
||||
if (clearDevice) {
|
||||
espDevice = null;
|
||||
}
|
||||
}
|
||||
|
||||
private ESPConstants.SecurityType parseSecurityType(int securityType) {
|
||||
@@ -490,27 +583,6 @@ public class EspProvisionManager {
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyWifiListReceived(final String[] wifiList) {
|
||||
runOnMainThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (callback != null) {
|
||||
callback.onWifiListReceived(wifiList);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyWifiListFailed(final String message) {
|
||||
runOnMainThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (callback != null) {
|
||||
callback.onWifiListFailed(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyProvisioningRejected() {
|
||||
runOnMainThread(new Runnable() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.databinding.GuideActivityLayoutBinding;
|
||||
import com.ckkj.water.login.LoginActivity;
|
||||
import com.ckkj.water.login.entity.LoginEntity;
|
||||
import com.ckkj.water.login.mvp.LoginContract;
|
||||
import com.ckkj.water.login.mvp.LoginImpl;
|
||||
@@ -95,8 +96,11 @@ public class GuideActivity extends BaseActivity<GuideActivityLayoutBinding, Logi
|
||||
|
||||
viewBinding.tvStart.setOnClickListener(v -> {
|
||||
SharePreUtil.putBoolean(ConstantUtil.SHARE_PRE_NAME, mContext, ConstantUtil.FIRST_ENTER_APP_FLAG, true);
|
||||
Intent intent = new Intent(mContext, MainActivity.class);
|
||||
startActivity(intent);
|
||||
if(AppConfig.USER_LOGIN){
|
||||
goTo(mContext, MainActivity.class,null);
|
||||
}else{
|
||||
goTo(mContext, LoginActivity.class,null);
|
||||
}
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import lombok.NoArgsConstructor;
|
||||
* @date 2026/5/15
|
||||
* @description 浇水历史记录
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class WateringRecord implements Serializable {
|
||||
|
||||
/**
|
||||
@@ -45,9 +45,21 @@ public class WateringRecord implements Serializable {
|
||||
private String userId;
|
||||
private String deviceNo;
|
||||
private String deviceId;
|
||||
private int scheduleId;
|
||||
private String scheduleId;
|
||||
private String durationMin;
|
||||
private Object zones;
|
||||
private String zones;
|
||||
private String createTime;
|
||||
|
||||
|
||||
/**
|
||||
* commandId : null
|
||||
* scheduleId : 2062827585485807618
|
||||
* zones : null
|
||||
* remark : 设备离线,按排程自动补记
|
||||
*/
|
||||
|
||||
private String commandId;
|
||||
private String scheduleIdX;
|
||||
private String zonesX;
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ public class HistoryPresenter extends BasePresenter<HistoryContract.HistoryView>
|
||||
map.put("pageNum",mCurrentPage+"");
|
||||
if(!TextUtils.isEmpty(mFilterStartTime)){
|
||||
// map.put("beginTime",mFilterStartTime);
|
||||
map.put("param[beginTime]", mFilterStartTime);
|
||||
map.put("params[beginTime]", mFilterStartTime);
|
||||
}
|
||||
|
||||
if(!TextUtils.isEmpty(mFilterStartTime)){
|
||||
// map.put("endTime",mFilterEndTime);
|
||||
map.put("param[endTime]", mFilterEndTime);
|
||||
map.put("params[endTime]", mFilterEndTime);
|
||||
|
||||
}
|
||||
if(mFilterType != -1){
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
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;
|
||||
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;
|
||||
@@ -27,11 +37,15 @@ import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.maning.mlkitscanner.scan.MNScanManager;
|
||||
import com.maning.mlkitscanner.scan.callback.act.MNScanCallback;
|
||||
import com.scwang.smart.refresh.footer.ClassicsFooter;
|
||||
import com.scwang.smart.refresh.layout.api.RefreshHeader;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,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) {
|
||||
}
|
||||
@@ -99,25 +122,29 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
switch (v.getId()){
|
||||
|
||||
case R.id.img_scan:
|
||||
//检测有无相机权限
|
||||
String readPermission = Manifest.permission.CAMERA;
|
||||
if(!hasRecordPermission(readPermission)){
|
||||
getPermissionRequst(readPermission,
|
||||
getString(R.string.permission_request_title),
|
||||
getString(R.string.camera_permission_scan_desc),
|
||||
REQUEST_EVENT_CODE_10001);
|
||||
if(checkBluetoothPermissions()){
|
||||
//检测有无相机权限
|
||||
String readPermission = Manifest.permission.CAMERA;
|
||||
if(!hasRecordPermission(readPermission)){
|
||||
getPermissionRequst(readPermission,
|
||||
getString(R.string.permission_request_title),
|
||||
getString(R.string.camera_permission_scan_desc),
|
||||
REQUEST_EVENT_CODE_10001);
|
||||
}else{
|
||||
scanQrcode();
|
||||
}
|
||||
}else{
|
||||
scanQrcode();
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case R.id.img_add:
|
||||
String permission = Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}else{
|
||||
if(checkBluetoothPermissions()){
|
||||
goTo(mContext, AddDeviceActivity_copy.class,null);
|
||||
}else{
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -136,8 +163,41 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
switch (resultCode) {
|
||||
case MNScanManager.RESULT_SUCCESS:
|
||||
ArrayList<String> results = data.getStringArrayListExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
|
||||
if(results != null){
|
||||
ToastUtil.showShort(mContext,results.get(0).toString());
|
||||
|
||||
if (results == null || results.isEmpty()) {
|
||||
ToastUtil.showShort(mContext, "二维码内容不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
String scanContent = results.get(0);
|
||||
if (TextUtils.isEmpty(scanContent)) {
|
||||
ToastUtil.showShort(mContext, "二维码内容不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject json;
|
||||
try {
|
||||
json = new JSONObject(scanContent);
|
||||
} catch (JSONException e) {
|
||||
ToastUtil.showShort(mContext, "二维码格式错误");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
WaterDeviceEntity entity = new WaterDeviceEntity();
|
||||
if(TextUtils.isEmpty(json.getString("mac"))
|
||||
|| TextUtils.isEmpty(json.getString("name"))){
|
||||
ToastUtil.showShort(mContext,"请扫描正确的二维码");
|
||||
return;
|
||||
}
|
||||
entity.setMacAddress(json.getString("mac"));
|
||||
entity.setDeviceName(json.getString("name"));
|
||||
if(entity != null){
|
||||
//这里拿到Mac地址,需要去服务器查询当前Mac的绑定状态
|
||||
mPresenter.bindDeviceStatus(entity);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
ToastUtil.showShort(mContext, "二维码格式错误");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case MNScanManager.RESULT_FAIL:
|
||||
@@ -198,6 +258,139 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前设备绑定状态
|
||||
* @param entity
|
||||
*/
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity entity) {
|
||||
switch (entity.getBindDeviceStatus()){
|
||||
|
||||
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 303:
|
||||
//目前该设备,不属于该用户,需要提示解绑
|
||||
showDialogtext(null,
|
||||
false,
|
||||
false,
|
||||
getString(R.string.tip_text),
|
||||
getString(R.string.device_binding_conflict_message),
|
||||
"",
|
||||
"",
|
||||
new OnDialogClick() {
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirmClick() {
|
||||
}
|
||||
});
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Android 12 以下需要位置权限
|
||||
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
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() {
|
||||
@@ -218,15 +411,72 @@ 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())));
|
||||
}
|
||||
|
||||
@@ -45,9 +45,12 @@ public class WaterDeviceEntity implements Serializable {
|
||||
private String macAddress;
|
||||
private Object expirationTime;
|
||||
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;
|
||||
@@ -65,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.ckkj.water.index.mvp;
|
||||
import com.ckkj.water.base.IView;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,10 +23,14 @@ public class IndexContract {
|
||||
|
||||
//获取设备列表
|
||||
void getDeviceList(Map<String,String> map,CallBack callBack);
|
||||
//查询二维码当前设备绑定状态
|
||||
void queryDeviceBindStatus(JSONObject json, CallBack callBack);
|
||||
|
||||
}
|
||||
|
||||
public interface IndexView extends IView{
|
||||
void getDeviceListSuccess(List<WaterDeviceEntity> list, int total);
|
||||
//查询二维码当前设备绑定状态
|
||||
void queryDeviceBindStatusSuccess(WaterDeviceEntity entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -49,4 +51,44 @@ public class IndexImpl implements IndexContract.DataModel{
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前设备绑定状态
|
||||
* @param json
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void queryDeviceBindStatus(JSONObject json, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().bindDeviceStatus(NetWorkManager.getToken(),NetWorkManager.toRequestBody(json))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<WaterDeviceEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<WaterDeviceEntity> bean) {
|
||||
if (bean.getCode() == 200) {
|
||||
callBack.success(bean.getData(),0);
|
||||
} else {
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ckkj.water.index.mvp;
|
||||
|
||||
import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -35,4 +39,35 @@ public class IndexPresenter extends BasePresenter<IndexContract.IndexView>{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定设备状态
|
||||
* @param entity
|
||||
*/
|
||||
public void bindDeviceStatus(WaterDeviceEntity entity) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("macAddress",entity.getMacAddress());
|
||||
mImpl.queryDeviceBindStatus(json, new IndexContract.CallBack<WaterDeviceEntity>() {
|
||||
@Override
|
||||
public void success(WaterDeviceEntity bean, int total) {
|
||||
bean.setMacAddress(entity.getMacAddress());
|
||||
bean.setDeviceName(entity.getDeviceName());
|
||||
if(IndexPresenter.this.getView() != null){
|
||||
IndexPresenter.this.getView().queryDeviceBindStatusSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(IndexPresenter.this.getView() != null){
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ public class LoginActivity extends BaseActivity<LoginLayoutBinding, LoginPresent
|
||||
setClick(viewBinding.tvLanguage);
|
||||
setClick(viewBinding.tvResetPsd);
|
||||
setClick(viewBinding.checkboxRead);
|
||||
setClick(viewBinding.btn133);
|
||||
setClick(viewBinding.btn151);
|
||||
}
|
||||
|
||||
private void setClick(View view) {
|
||||
@@ -169,6 +171,21 @@ public class LoginActivity extends BaseActivity<LoginLayoutBinding, LoginPresent
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
|
||||
case R.id.btn_133:
|
||||
showLoadingDialog();
|
||||
mPresenter.loginBySmsCode("password",
|
||||
"13305376054",
|
||||
"",
|
||||
"000000");
|
||||
break;
|
||||
case R.id.btn_151:
|
||||
showLoadingDialog();
|
||||
mPresenter.loginBySmsCode("password",
|
||||
"15192412330",
|
||||
"",
|
||||
"000000");
|
||||
break;
|
||||
|
||||
case R.id.checkbox_read:
|
||||
if(mYinsiConfirm){
|
||||
mYinsiConfirm = false;
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.ckkj.water.login.entity.LoginEntity;
|
||||
import com.ckkj.water.login.mvp.LoginContract;
|
||||
import com.ckkj.water.login.mvp.LoginImpl;
|
||||
import com.ckkj.water.login.mvp.LoginPresenter;
|
||||
import com.ckkj.water.main.activity.MainActivity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
@@ -45,7 +46,7 @@ public class RegisterSuccessActivity extends BaseActivity<RegisterSuccessLayoutB
|
||||
viewBinding.tvCommit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
goTo(mContext, MainActivity.class,null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,16 +92,22 @@ public class MineFragment extends BaseFragment<MineFragmentBinding, MinePresente
|
||||
goTo(mContext, LoginActivity.class, null);
|
||||
return;
|
||||
}
|
||||
new XPopup.Builder(mContext).asBottomList("头像", new String[]{"上传头像", "查看大图"}, new OnSelectListener() {
|
||||
new XPopup.Builder(mContext).asBottomList(
|
||||
getString(R.string.avatar),
|
||||
new String[]{
|
||||
getString(R.string.upload_avatar),
|
||||
getString(R.string.view_full_image)}, new OnSelectListener() {
|
||||
@Override
|
||||
public void onSelect(int position, String text) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
String readPermission = Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
if (!hasRecordPermission(readPermission)) {
|
||||
// 没有权限,只在ACTION_DOWN时去申请
|
||||
getPermissionRequst(readPermission, "相机、文件访问权限申请",
|
||||
"星语明灯需要您的授权,获取文件访问权限来修改头像", REQUEST_CODE_100);
|
||||
// 没有权限,只在ACTION_DOWN时去申请+
|
||||
getPermissionRequst(readPermission,
|
||||
getString(R.string.request_camera_storage_permission),
|
||||
getString(R.string.avatar_permission_tips),
|
||||
REQUEST_CODE_100);
|
||||
return;
|
||||
} else {
|
||||
imagePicker(1, REQUEST_CODE_100, MineFragment.this);
|
||||
|
||||
@@ -90,7 +90,11 @@ public class MineInfomationActivity extends BaseActivity<MineInformationLayoutBi
|
||||
|
||||
case R.id.img_avatar:
|
||||
case R.id.img_camera:
|
||||
new XPopup.Builder(mContext).asBottomList("选择头像", new String[]{"上传头像", "查看大图"}, new OnSelectListener() {
|
||||
new XPopup.Builder(mContext).asBottomList(
|
||||
getString(R.string.avatar),
|
||||
new String[]{
|
||||
getString(R.string.upload_avatar),
|
||||
getString(R.string.view_full_image)}, new OnSelectListener() {
|
||||
@Override
|
||||
public void onSelect(int position, String text) {
|
||||
switch (position) {
|
||||
@@ -98,8 +102,10 @@ public class MineInfomationActivity extends BaseActivity<MineInformationLayoutBi
|
||||
String readPermission = Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
if (!hasRecordPermission(readPermission)) {
|
||||
// 没有权限,只在ACTION_DOWN时去申请
|
||||
getPermissionRequst(readPermission,"相册权限申请",
|
||||
"智能浇水需要您的授权,获取相册修改头像",REQUEST_EVENT_CODE_10001);
|
||||
getPermissionRequst(readPermission,
|
||||
getString(R.string.request_camera_storage_permission),
|
||||
getString(R.string.avatar_permission_tips),
|
||||
REQUEST_EVENT_CODE_10001);
|
||||
return;
|
||||
}else{
|
||||
imagePicker(1,PICK_IMAGE_REQUEST_100);
|
||||
@@ -115,12 +121,13 @@ public class MineInfomationActivity extends BaseActivity<MineInformationLayoutBi
|
||||
break;
|
||||
|
||||
case R.id.rl_nickname:
|
||||
showEditDialog("修改昵称",
|
||||
"请输入昵称",
|
||||
showEditDialog(
|
||||
getString(R.string.edit_nickname),
|
||||
getString(R.string.input_nickname),
|
||||
mUserBean.getUser().getNickName(),
|
||||
true,
|
||||
"取消",
|
||||
"确定",
|
||||
getString(R.string.cancel_text),
|
||||
getString(R.string.confirm_text),
|
||||
INPUT_TYPE_NORMAL,
|
||||
new OnDialogClick() {
|
||||
@Override
|
||||
@@ -202,26 +209,26 @@ public class MineInfomationActivity extends BaseActivity<MineInformationLayoutBi
|
||||
String fileName = file.getName();
|
||||
if (fileSizeInMB > 5) {
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext, "文件大小超出5M");
|
||||
ToastUtil.showShort(mContext, getString(R.string.file_size_exceeds_5m));
|
||||
return;
|
||||
}
|
||||
if (!fileName.toLowerCase().endsWith(".png") &&
|
||||
!fileName.toLowerCase().endsWith(".jpg") &&
|
||||
!fileName.toLowerCase().endsWith(".jpeg")) {
|
||||
ToastUtil.showShort(mContext, "文件格式不正确");
|
||||
ToastUtil.showShort(mContext, getString(R.string.invalid_file_format));
|
||||
hideDialogLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext,"头像修改成功");
|
||||
ToastUtil.showShort(mContext,getString(R.string.avatar_update_success));
|
||||
|
||||
Glide.with(mContext)
|
||||
.load(file)
|
||||
.error(mContext.getDrawable(R.mipmap.icon_mine_user_head_defaul))
|
||||
.into(viewBinding.imgAvatar);
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "文件不存在");
|
||||
ToastUtil.showShort(mContext, getString(R.string.file_not_exist));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,11 @@ public class SettingsActivity extends BaseActivity<ActivitySettingsLayoutBinding
|
||||
|
||||
case R.id.tv_log_out:
|
||||
showDialogtext(mContext.getResources().getDrawable(R.mipmap.img_location), false, false,true,
|
||||
"提示", "确定要退出当前账号?",
|
||||
"取消", "确定", new BaseFragment.OnDialogClick() {
|
||||
getString(R.string.tip_text),
|
||||
getString(R.string.logout_dialog_tips),
|
||||
getString(R.string.cancel_text),
|
||||
getString(R.string.confirm_text),
|
||||
new BaseFragment.OnDialogClick() {
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
}
|
||||
|
||||
@@ -83,6 +83,52 @@ public class NetWorkManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应拦截器:在 OkHttp 响应阶段直接捕获 HTTP 401/406/499 状态码,
|
||||
* 同时打印请求 URL,方便定位触发登录过期弹窗的具体接口。
|
||||
*/
|
||||
class ResponseInterceptor implements Interceptor {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
okhttp3.Request request = chain.request();
|
||||
String requestUrl = request.url().toString();
|
||||
String requestMethod = request.method();
|
||||
okhttp3.Response response = chain.proceed(request);
|
||||
|
||||
int httpCode = response.code();
|
||||
if (httpCode == 401 || httpCode == 406 || httpCode == 499) {
|
||||
Log.e("TEST", "触发401拦截 → HTTP状态码=" + httpCode
|
||||
+ " | 请求方法=" + requestMethod
|
||||
+ " | 请求URL=" + requestUrl);
|
||||
}
|
||||
|
||||
try {
|
||||
String responseBody = response.peekBody(1024 * 1024).string();
|
||||
if (responseBody != null && !responseBody.trim().isEmpty()) {
|
||||
JSONObject jsonObject = new JSONObject(responseBody);
|
||||
String businessCode = jsonObject.optString("code");
|
||||
if ("401".equals(businessCode)) {
|
||||
Log.e("TEST", "业务401拦截 -> method=" + requestMethod
|
||||
+ " | url=" + requestUrl
|
||||
+ " | body=" + jsonObject.toString());
|
||||
} else if ("406".equals(businessCode)) {
|
||||
Log.e("TEST", "业务406拦截 -> method=" + requestMethod
|
||||
+ " | url=" + requestUrl
|
||||
+ " | body=" + jsonObject.toString());
|
||||
} else if ("499".equals(businessCode)) {
|
||||
Log.e("TEST", "业务499拦截 -> method=" + requestMethod
|
||||
+ " | url=" + requestUrl
|
||||
+ " | body=" + jsonObject.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("TEST", "响应体解析失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化必要对象和参数
|
||||
*/
|
||||
@@ -101,10 +147,14 @@ public class NetWorkManager {
|
||||
Log.e("RetrofitLog", "retrofitBack=" + new Gson().toJson(jsonObject));
|
||||
String s = jsonObject.getString("code");
|
||||
if (s.equals("401")) {
|
||||
Log.e("TEST", "触发401弹窗 → 业务code=401,响应体=" + jsonObject.toString());
|
||||
Log.e("TEST", "401发送堆栈:", new Throwable("NetWorkManager发送401堆栈"));
|
||||
EventBus.getDefault().post(new EventMessage(EventMessage.USER_LOGIN_LOST));
|
||||
} else if (s.equals("406")) {
|
||||
|
||||
}else if(s.equals("499")){
|
||||
Log.e("TEST", "触发499弹窗 → 业务code=499,响应体=" + jsonObject.toString());
|
||||
Log.e("TEST", "499发送堆栈:", new Throwable("NetWorkManager发送499堆栈"));
|
||||
EventBus.getDefault().post(new EventMessage(EventMessage.CODE_LOGIN_LOST));
|
||||
|
||||
// Activity activity = MyApplication.getCurrentActivity();
|
||||
@@ -131,6 +181,7 @@ public class NetWorkManager {
|
||||
// 初始化OkHttp
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(loggingInterceptor) //添加网络拦截器
|
||||
.addInterceptor(new ResponseInterceptor()) // HTTP状态码401/406/499拦截
|
||||
.addInterceptor(new HeaderInterceptor()) //添加网络拦截器
|
||||
.connectTimeout(120, TimeUnit.SECONDS)// 连接超时时间
|
||||
.readTimeout(120, TimeUnit.SECONDS) //读取超时
|
||||
|
||||
@@ -57,12 +57,18 @@ public interface Request {
|
||||
//首页设备列表
|
||||
@GET("app/v1/deviceList")
|
||||
Observable<BaseBean<List<WaterDeviceEntity>>> getIndexDeviceList(@HeaderMap Map<String, String> headMap);
|
||||
|
||||
//查询设备编码,是否被绑定过,即当前设备状态
|
||||
@POST("app/v1/bindDeviceStatus")
|
||||
Observable<BaseBean<WaterDeviceEntity>> bindDeviceStatus(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
|
||||
|
||||
//添加设备
|
||||
@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/{id}")
|
||||
Observable<BaseBean<WaterDeviceEntity>> getDeviceDetailInfo(@HeaderMap Map<String, String> headMap, @Path("id") String id);
|
||||
@GET("app/v1/device/{deviceNo}")
|
||||
Observable<BaseBean<WaterDeviceEntity>> getDeviceDetailInfo(@HeaderMap Map<String, String> headMap, @Path("deviceNo") String id);
|
||||
|
||||
//开启/关闭设备
|
||||
@PUT("app/v1/switchDevice")
|
||||
@@ -115,8 +121,8 @@ public interface Request {
|
||||
|
||||
|
||||
//删除设备
|
||||
@DELETE("app/v1/deleteDevice/{ids}")
|
||||
Observable<BaseBean> unBindDevice(@HeaderMap Map<String,String> headMap, @Path("ids") String id);
|
||||
@DELETE("app/v1/deleteDevice/{deviceNo}")
|
||||
Observable<BaseBean> unBindDevice(@HeaderMap Map<String,String> headMap, @Path("deviceNo") String id);
|
||||
|
||||
//排程解绑设备
|
||||
@DELETE("app/v1/deleteScheduleDevice")
|
||||
|
||||
@@ -73,7 +73,7 @@ public class BindDeviceFragment extends BaseFragment<PlanBindDeviceLayoutBinding
|
||||
for(WaterDeviceEntity.DeviceListBean bean : mDeviceList){
|
||||
if(bean.getStatus().equals("1")){
|
||||
isSelected = true;
|
||||
selected.add(bean.getId());
|
||||
selected.add(bean.getDeviceNo());
|
||||
}
|
||||
}
|
||||
if(!isSelected){
|
||||
|
||||
@@ -32,12 +32,12 @@ public class PlanBoundDeviceFragment extends BaseFragment<PlanBoundDeviceLayoutB
|
||||
@Override
|
||||
public void initData(Bundle state) {
|
||||
// 初始化适配器,如果有数据则设置
|
||||
if (mEditEntity != null && mEditEntity.getDeviceIds() != null) {
|
||||
mAdapter = new PlanBoundDeviceAdapter(mContext, R.layout.plan_bound_device_item, mEditEntity.getDeviceIds());
|
||||
if (mEditEntity != null && mEditEntity.getDeviceNos() != null) {
|
||||
mAdapter = new PlanBoundDeviceAdapter(mContext, R.layout.plan_bound_device_item, mEditEntity.getDeviceNos());
|
||||
viewBinding.rvDevices.setAdapter(mAdapter);
|
||||
|
||||
// 根据数据状态显示/隐藏视图
|
||||
if (mEditEntity.getDeviceIds().isEmpty()) {
|
||||
if (mEditEntity.getDeviceNos().isEmpty()) {
|
||||
viewBinding.linearContent.setVisibility(View.GONE);
|
||||
viewBinding.relNoresult.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
@@ -66,7 +66,7 @@ public class PlanBoundDeviceFragment extends BaseFragment<PlanBoundDeviceLayoutB
|
||||
public void onConfirmClick() {
|
||||
showLoadingDialog();
|
||||
mPresenter.planUnbindDevice(mEditEntity.getId(),
|
||||
mEditEntity.getDeviceIds().get(position).getId(),
|
||||
mEditEntity.getDeviceNos().get(position).getDeviceNo(),
|
||||
position);
|
||||
}
|
||||
});
|
||||
@@ -94,20 +94,20 @@ public class PlanBoundDeviceFragment extends BaseFragment<PlanBoundDeviceLayoutB
|
||||
if (viewBinding == null) {
|
||||
return;
|
||||
}
|
||||
if (mEditEntity == null || mEditEntity.getDeviceIds() == null) {
|
||||
if (mEditEntity == null || mEditEntity.getDeviceNos() == null) {
|
||||
viewBinding.linearContent.setVisibility(View.GONE);
|
||||
viewBinding.relNoresult.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mEditEntity.getDeviceIds().isEmpty()) {
|
||||
if (mEditEntity.getDeviceNos().isEmpty()) {
|
||||
viewBinding.linearContent.setVisibility(View.GONE);
|
||||
viewBinding.relNoresult.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewBinding.linearContent.setVisibility(View.VISIBLE);
|
||||
viewBinding.relNoresult.setVisibility(View.GONE);
|
||||
if (mAdapter != null) {
|
||||
mAdapter.setNewData(mEditEntity.getDeviceIds());
|
||||
mAdapter.setNewData(mEditEntity.getDeviceNos());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class PlanBoundDeviceFragment extends BaseFragment<PlanBoundDeviceLayoutB
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext, "解绑成功");
|
||||
mAdapter.notifyItemRemoved(position);
|
||||
mEditEntity.getDeviceIds().remove(position);
|
||||
mEditEntity.getDeviceNos().remove(position);
|
||||
if (mAdapter.getItemCount() != 0) {
|
||||
viewBinding.relNoresult.setVisibility(View.GONE);
|
||||
viewBinding.linearContent.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -200,7 +200,7 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
||||
}
|
||||
//设备显示
|
||||
if(deviceAdapter != null){
|
||||
deviceAdapter.setNewData(entity.getDeviceIds());
|
||||
deviceAdapter.setNewData(entity.getDeviceNos());
|
||||
if(deviceAdapter.getItemCount() == 0){
|
||||
viewBinding.rvBindDevices.setVisibility(View.GONE);
|
||||
viewBinding.tvNoDevice.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.ckkj.water.plan;
|
||||
|
||||
import static android.view.View.INVISIBLE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.ckkj.water.R;
|
||||
@@ -33,6 +36,7 @@ public class WaterPlanFragment extends BaseFragment<WaterPlanFragmentBinding, Wa
|
||||
private List<WaterPlanWeekEntity> mPlanList = new ArrayList<>();
|
||||
private WaterPlanListAdapter mAdapter;
|
||||
private int mCurrentPage = 1;
|
||||
private String mSearchOption = "";
|
||||
@Override
|
||||
public void initData(Bundle state) {
|
||||
|
||||
@@ -63,13 +67,36 @@ public class WaterPlanFragment extends BaseFragment<WaterPlanFragmentBinding, Wa
|
||||
viewBinding.refresh.setRefreshHeader(header);
|
||||
viewBinding.refresh.setRefreshFooter(new ClassicsFooter(mContext));
|
||||
viewBinding.refresh.setOnRefreshListener(layout -> {
|
||||
mSearchOption = "";
|
||||
mCurrentPage = 1;
|
||||
viewBinding.refresh.setNoMoreData(false);
|
||||
mPresenter.getWaterPlanList(mCurrentPage);
|
||||
mPresenter.getWaterPlanList(mCurrentPage,mSearchOption);
|
||||
viewBinding.etInputPlanName.setText("");
|
||||
});
|
||||
viewBinding.refresh.setOnLoadMoreListener(layout -> {
|
||||
mCurrentPage++;
|
||||
mPresenter.getWaterPlanList(mCurrentPage);
|
||||
mPresenter.getWaterPlanList(mCurrentPage,mSearchOption);
|
||||
});
|
||||
//文本输入搜索排程
|
||||
viewBinding.etInputPlanName.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
// 隐藏键盘
|
||||
InputMethodManager imm = (InputMethodManager) v.getContext()
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
// 清除焦点(可选,避免键盘再次弹出)
|
||||
v.clearFocus();
|
||||
mSearchOption = v.getText().toString().trim();
|
||||
mCurrentPage = 1;
|
||||
// 执行搜索
|
||||
mPresenter.getWaterPlanList(mCurrentPage,mSearchOption);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +104,7 @@ public class WaterPlanFragment extends BaseFragment<WaterPlanFragmentBinding, Wa
|
||||
protected void onResumeInitData() {
|
||||
super.onResumeInitData();
|
||||
showLoadingDialog();
|
||||
mPresenter.getWaterPlanList(mCurrentPage);
|
||||
mPresenter.getWaterPlanList(mCurrentPage,mSearchOption);
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
@@ -97,7 +124,7 @@ public class WaterPlanFragment extends BaseFragment<WaterPlanFragmentBinding, Wa
|
||||
|
||||
case R.id.btn_refresh:
|
||||
mCurrentPage = 1;
|
||||
mPresenter.getWaterPlanList(mCurrentPage);
|
||||
mPresenter.getWaterPlanList(mCurrentPage,mSearchOption);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class WaterPlanWeekEntity implements Serializable {
|
||||
private String userId;
|
||||
private String name;
|
||||
private List<WaterDeviceEntity> deviceIds;
|
||||
private List<WaterDeviceEntity> deviceNos;
|
||||
private String status = "1";
|
||||
private List<DetailsBean> details;
|
||||
|
||||
|
||||
@@ -24,10 +24,11 @@ public class WaterPlanPresenter extends BasePresenter<WaterPlanContract.WaterPla
|
||||
/**
|
||||
* 获取排程信息
|
||||
*/
|
||||
public void getWaterPlanList(int mCurrentPage) {
|
||||
public void getWaterPlanList(int mCurrentPage,String searchOption) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("pageNum", mCurrentPage + "");
|
||||
map.put("pageSize", "10");
|
||||
map.put("name", searchOption);
|
||||
impl.getWaterConfigList(map, new WaterPlanContract.CallBack<List<WaterPlanWeekEntity>>() {
|
||||
|
||||
@Override
|
||||
@@ -195,19 +196,19 @@ public class WaterPlanPresenter extends BasePresenter<WaterPlanContract.WaterPla
|
||||
/**
|
||||
* 排程绑定设备
|
||||
* @param entity
|
||||
* @param deviceIds
|
||||
* @param deviceNo
|
||||
*/
|
||||
public void planBindWithDevices(WaterPlanWeekEntity entity, String deviceIds) {
|
||||
public void planBindWithDevices(WaterPlanWeekEntity entity, String deviceNo) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("scheduleId", entity.getId());
|
||||
// 将逗号分隔的字符串转换为 JSONArray (数字类型)
|
||||
JSONArray deviceIdArray = new JSONArray();
|
||||
String[] idArray = deviceIds.split(",");
|
||||
String[] idArray = deviceNo.split(",");
|
||||
for (String id : idArray) {
|
||||
deviceIdArray.put(id);
|
||||
}
|
||||
json.put("deviceIds", deviceIdArray);
|
||||
json.put("deviceNos", deviceIdArray);
|
||||
impl.planBindDevice(json, new WaterPlanContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean, int total) {
|
||||
@@ -288,7 +289,7 @@ public class WaterPlanPresenter extends BasePresenter<WaterPlanContract.WaterPla
|
||||
public void planUnbindDevice(String planID, String deviceID,int position) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("scheduleId",planID);
|
||||
map.put("deviceId",deviceID);
|
||||
map.put("deviceNo",deviceID);
|
||||
impl.planUnbindDevice(map, new WaterPlanContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean, int total) {
|
||||
|
||||
17
app/src/main/res/drawable/anim_connect_ble_device.xml
Normal file
17
app/src/main/res/drawable/anim_connect_ble_device.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:oneshot="false">
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_1"
|
||||
android:duration="300" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_2"
|
||||
android:duration="300" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_3"
|
||||
android:duration="300" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_2"
|
||||
android:duration="500" />
|
||||
|
||||
</animation-list>
|
||||
@@ -1,33 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:oneshot="false">
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_1"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_2"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_3"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_add_dev_aini_2"
|
||||
android:duration="500" />
|
||||
|
||||
|
||||
<item
|
||||
android:drawable="@mipmap/img_connect_anim_phone1"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_connect_anim_phone2"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_connect_anim_phone3"
|
||||
android:duration="200" />
|
||||
<item
|
||||
android:drawable="@mipmap/img_connect_anim_phone1"
|
||||
android:duration="500" />
|
||||
|
||||
|
||||
<item
|
||||
android:drawable="@mipmap/img_connect_anim_wifi1"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="5dp"/>
|
||||
<solid android:color="@color/color_d9d9d9"/>
|
||||
</shape>
|
||||
@@ -37,8 +37,8 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_connect_animation"
|
||||
android:layout_width="@dimen/dp_200"
|
||||
android:layout_height="@dimen/dp_200"
|
||||
android:layout_width="@dimen/dp_300"
|
||||
android:layout_height="@dimen/dp_300"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:src="@drawable/anim_add_device_scan"/>
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
android:gravity="center"
|
||||
android:background="@drawable/shape_device_ctrl_green_cor12">
|
||||
<ImageView
|
||||
android:id="@+id/img_ble"
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_ctrl_bt_white"/>
|
||||
@@ -58,6 +59,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"
|
||||
|
||||
@@ -15,118 +15,141 @@
|
||||
layout="@layout/include_activity_back_gray_layout" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/select_wifi_tip"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_wifi_info"
|
||||
android:id="@+id/linear_wifi_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/dp_10">
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_wifi"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:background="@drawable/shape_round_corner_100"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="@dimen/dp_20">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_wifi"/>
|
||||
<EditText
|
||||
android:id="@+id/et_wifi_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:layout_marginLeft="@dimen/dp_5"
|
||||
android:background="@null"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:textColorHint="@color/textPrimaryColor"
|
||||
android:hint="@string/input_wifi_name_tip"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_select_wifi"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.2"
|
||||
android:background="@drawable/shape_green_50"
|
||||
android:paddingVertical="@dimen/dp_8"
|
||||
android:gravity="center"
|
||||
android:textSize="13sp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/select_wifi_tip"/>
|
||||
</LinearLayout>
|
||||
android:visibility="gone">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="@string/select_wifi_tip"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_psd"
|
||||
android:id="@+id/linear_wifi_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:background="@drawable/shape_round_corner_100"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="@dimen/dp_20">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_phone_code"/>
|
||||
<EditText
|
||||
android:id="@+id/et_input_psd"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/dp_10">
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_wifi"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_5"
|
||||
android:background="@null"
|
||||
android:textSize="14sp"
|
||||
android:textColorHint="@color/textPrimaryColor"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:hint="@string/input_wifi_psd_tip"/>
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:background="@drawable/shape_round_corner_100"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="@dimen/dp_20">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_wifi"/>
|
||||
<EditText
|
||||
android:id="@+id/et_wifi_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:layout_marginLeft="@dimen/dp_5"
|
||||
android:background="@null"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:textColorHint="@color/textPrimaryColor"
|
||||
android:hint="@string/input_wifi_name_tip"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_select_wifi"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.2"
|
||||
android:background="@drawable/shape_green_50"
|
||||
android:paddingVertical="@dimen/dp_8"
|
||||
android:gravity="center"
|
||||
android:textSize="13sp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/select_wifi_tip"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_psd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:background="@drawable/shape_round_corner_100"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="@dimen/dp_20">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_24"
|
||||
android:layout_height="@dimen/dp_24"
|
||||
android:src="@mipmap/icon_phone_code"/>
|
||||
<EditText
|
||||
android:id="@+id/et_input_psd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_5"
|
||||
android:background="@null"
|
||||
android:textSize="14sp"
|
||||
android:textColorHint="@color/textPrimaryColor"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:hint="@string/input_wifi_psd_tip"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_wifi_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/button_next"
|
||||
android:background="@drawable/shape_green_button_bg"
|
||||
android:paddingVertical="@dimen/dp_10"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_40"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/tv_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="进度"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_wifi_list"
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_connect_ble"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:visibility="gone"/>
|
||||
android:orientation="vertical">
|
||||
<ImageView
|
||||
android:id="@+id/iv_connect_animation"
|
||||
android:layout_width="@dimen/dp_300"
|
||||
android:layout_height="@dimen/dp_300"
|
||||
android:layout_marginTop="@dimen/dp_50"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:src="@drawable/anim_add_device_scan"
|
||||
android:visibility="visible"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:gravity="center"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="蓝牙连接中"
|
||||
android:textStyle="bold"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/button_next"
|
||||
android:background="@drawable/shape_green_button_bg"
|
||||
android:paddingVertical="@dimen/dp_10"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_40"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_loading"
|
||||
android:layout_width="@dimen/dp_50"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:layout_width="@dimen/dp_55"
|
||||
android:layout_height="@dimen/dp_55"
|
||||
android:layout_marginTop="@dimen/dp_3"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:src="@mipmap/icon_water_loading"
|
||||
android:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:paddingHorizontal="@dimen/dp_15"
|
||||
tools:itemCount="3"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/index_device_list_item" />
|
||||
|
||||
|
||||
@@ -15,6 +15,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<Button
|
||||
android:id="@+id/btn_133"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="133"/>
|
||||
<Button
|
||||
android:id="@+id/btn_151"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="151"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="@dimen/dp_35"
|
||||
android:layout_marginRight="@dimen/dp_35"
|
||||
android:layout_marginTop="20dp"
|
||||
@@ -81,6 +81,7 @@
|
||||
android:layout_height="@dimen/dp_40"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_login_radius8_huise_bg"
|
||||
android:layout_marginRight="@dimen/dp_25"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/color_gray_tab"
|
||||
android:text="取消"/>
|
||||
@@ -92,7 +93,6 @@
|
||||
android:background="@drawable/shape_login_radius8_jb_bg"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/color_white"
|
||||
android:layout_marginLeft="@dimen/dp_13"
|
||||
android:text="确定"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
android:layout_toRightOf="@+id/img_search"
|
||||
android:layout_marginLeft="@dimen/dp_8"
|
||||
android:textSize="14sp"
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="text"
|
||||
android:hint="@string/input_plan_name"
|
||||
android:textColorHint="@color/color_subtitle"/>
|
||||
</RelativeLayout>
|
||||
|
||||
BIN
app/src/main/res/mipmap-xxhdpi/icon_ctrl_bt_green.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/icon_ctrl_bt_green.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 959 B |
BIN
app/src/main/res/mipmap-xxhdpi/icon_water_loading.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/icon_water_loading.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/icon_ctrl_bt_green.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/icon_ctrl_bt_green.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/icon_water_loading.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/icon_water_loading.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
@@ -66,6 +66,8 @@
|
||||
<string name="keep_device_bt_tips">Keep Bluetooth enabled and stay close to the device</string>
|
||||
<string name="keep_device_bt_tips2">Sending information to device</string>
|
||||
<string name="keep_device_bt_tips3">Connecting device to network</string>
|
||||
<string name="reset_device_provision">Please manually reset the device and put it into pairing mode before continuing.</string>
|
||||
<string name="device_binding_conflict_message">This device is already linked to another account. Please unbind it from that account or reset the device and set it up again.</string>
|
||||
|
||||
<string name="button_finish">Finish</string>
|
||||
<string name="button_reset">Reset</string>
|
||||
@@ -100,6 +102,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>
|
||||
@@ -147,13 +151,20 @@
|
||||
<string name="history_filter_type_toast">Select a trigger type</string>
|
||||
<string name="history_watering_adapter_time">Watering Time</string>
|
||||
|
||||
<string name="total_water_count">Total Watering Sessions</string>
|
||||
<string name="week_water_count">This Week</string>
|
||||
<string name="month_water_count">This Month</string>
|
||||
<string name="schedule_water_count">Scheduled Sessions</string>
|
||||
<string name="manual_water_count">Manual Sessions</string>
|
||||
<string name="total_water_duration">Total Watering Time</string>
|
||||
<string name="avg_water_duration">Average Duration</string>
|
||||
<string name="total_water_count">Total</string>
|
||||
|
||||
<string name="week_water_count">Week</string>
|
||||
|
||||
<string name="month_water_count">Month</string>
|
||||
|
||||
<string name="schedule_water_count">Scheduled</string>
|
||||
|
||||
<string name="manual_water_count">Manual</string>
|
||||
|
||||
<string name="total_water_duration">Duration</string>
|
||||
|
||||
<string name="avg_water_duration">Average</string>
|
||||
|
||||
<string name="unit_times">times</string>
|
||||
|
||||
<!-- Profile -->
|
||||
@@ -166,6 +177,7 @@
|
||||
<string name="mine_psd_reset">Change Password</string>
|
||||
<string name="mine_find_psd">Forgot Password</string>
|
||||
<string name="logout_tips">Sign out of your account</string>
|
||||
<string name="logout_dialog_tips">Are you sure you want to log out?</string>
|
||||
|
||||
|
||||
<string name="agree_user_policy">
|
||||
@@ -208,6 +220,29 @@
|
||||
<string name="theme_dark">Dark</string>
|
||||
<string name="press_again_to_exit">Press again to exit</string>
|
||||
|
||||
|
||||
<!-- 头像 -->
|
||||
<string name="avatar">Avatar</string>
|
||||
|
||||
<!-- 上传头像 -->
|
||||
<string name="upload_avatar">Upload Avatar</string>
|
||||
|
||||
<!-- 查看大图 -->
|
||||
<string name="view_full_image">View Full Image</string>
|
||||
|
||||
<!-- 相机、文件访问权限申请 -->
|
||||
<string name="request_camera_storage_permission">Camera File Access Permission</string>
|
||||
|
||||
<!-- 需要您的授权,获取文件访问权限来修改头像 -->
|
||||
<string name="avatar_permission_tips">We need your permission to access files so you can change your avatar.</string>
|
||||
<string name="edit_nickname">Edit Nickname</string>
|
||||
<string name="input_nickname">Please enter a nickname</string>
|
||||
|
||||
<string name="file_size_exceeds_5m">File size exceeds 5 MB</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
<string name="avatar_update_success">Avatar updated successfully</string>
|
||||
<string name="file_not_exist">File does not exist</string>
|
||||
|
||||
<!-- End -->
|
||||
|
||||
|
||||
|
||||
@@ -89,8 +89,13 @@
|
||||
<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>
|
||||
<string name="start_watering">开启浇水</string>
|
||||
<string name="end_watering">关闭浇水</string>
|
||||
<string name="device_offline_tip">设备已离线</string>
|
||||
<string name="reset_device_provision">该操作需要手动将设备重置到配网模式</string>
|
||||
<string name="device_binding_conflict_message">该设备已被其他用户绑定,您可以登录该账号尝试解绑,或重置设备进入配网模式</string>
|
||||
|
||||
|
||||
<!--排程-->
|
||||
@@ -161,6 +166,11 @@
|
||||
<string name="mine_psd_reset">重置密码</string>
|
||||
<string name="mine_find_psd">找回密码</string>
|
||||
<string name="logout_tips">退出当前账号</string>
|
||||
<string name="logout_dialog_tips">确定退出当前账号</string>
|
||||
<string name="edit_nickname">修改昵称</string>
|
||||
<string name="input_nickname">请输入昵称</string>
|
||||
|
||||
|
||||
|
||||
|
||||
<string name="agree_user_policy">
|
||||
@@ -198,6 +208,28 @@
|
||||
|
||||
<string name="press_again_to_exit">再按一次退出</string>
|
||||
|
||||
|
||||
<!-- 头像 -->
|
||||
<string name="avatar">头像</string>
|
||||
|
||||
<!-- 上传头像 -->
|
||||
<string name="upload_avatar">上传头像</string>
|
||||
|
||||
<!-- 查看大图 -->
|
||||
<string name="view_full_image">查看大图</string>
|
||||
|
||||
<!-- 相机、文件访问权限申请 -->
|
||||
<string name="request_camera_storage_permission">文件访问权限申请</string>
|
||||
|
||||
<!-- 需要您的授权,获取文件访问权限来修改头像 -->
|
||||
<string name="avatar_permission_tips">需要您的授权,获取文件访问权限来修改头像</string>
|
||||
|
||||
<string name="file_size_exceeds_5m">文件大小超出5M</string>
|
||||
<string name="invalid_file_format">文件格式不正确</string>
|
||||
<string name="avatar_update_success">头像修改成功</string>
|
||||
<string name="file_not_exist">文件不存在</string>
|
||||
|
||||
|
||||
<!--结束-->
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user