优化
This commit is contained in:
@@ -21,8 +21,8 @@ public class AppConfig {
|
||||
// public static boolean IS_TEST_REQUEST = true;
|
||||
|
||||
/**************************本地*******************************/
|
||||
public static String BASE_URL = "http://192.168.1.217:8081/";//后端本地测试
|
||||
// public static String BASE_URL = "http://47.97.217.123:8081/";//服务器测试
|
||||
// public static String BASE_URL = "http://192.168.1.217:8081/";//后端本地测试
|
||||
public static String BASE_URL = "http://47.97.217.123:8081/";//服务器测试
|
||||
public static String BASE_URL_TWO = BASE_URL;//测试
|
||||
public static String BASE_URL_THREE = BASE_URL;//测试
|
||||
public static boolean IS_TEST_REQUEST = true;
|
||||
|
||||
@@ -113,7 +113,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
//此时处于工作中,不可点击
|
||||
if(mDeviceEntity.getWorkStatus().equals("1")){
|
||||
ToastUtil.showShort(mContext,"当前设备处于工作中,请先关闭浇水任务");
|
||||
ToastUtil.showShort(mContext,getString(R.string.tips_device_working_stop_task));
|
||||
return;
|
||||
}
|
||||
mAdapter.setOnSelPosition(position);
|
||||
@@ -147,7 +147,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
viewBinding.imgWifiLogo.setImageResource(R.mipmap.icon_ctrl_wifi_white);
|
||||
}else{
|
||||
viewBinding.tvDeviceStatus.setText(getString(R.string.device_status_offline));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.tvDeviceStatus.setTextColor(mContext.getResources().getColor(R.color.color_E60000));
|
||||
viewBinding.tvConfirm.setEnabled(false);
|
||||
viewBinding.tvConfirm.setTextColor(mContext.getResources().getColor(R.color.color_999999));
|
||||
viewBinding.tvConfirm.setBackgroundResource((R.drawable.shape_gray_button_bg_enable));
|
||||
@@ -156,7 +156,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
stopWorkProgressUpdate();
|
||||
updateProgressView(0);
|
||||
}
|
||||
viewBinding.tvDeviceUpdateTime.setText(entity.getPowerLevelUpdatatime());
|
||||
viewBinding.tvDeviceUpdateTime.setText(getString(R.string.update_time) + entity.getPowerLevelUpdatatime());
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
@@ -213,16 +213,16 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
.isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个
|
||||
.atView(viewBinding.linearBat)
|
||||
.hasShadowBg(false) // 去掉半透明背景
|
||||
.asCustom(new CustomBubbleAttachPopup(mContext,"设备电量:"+
|
||||
.asCustom(new CustomBubbleAttachPopup(mContext,getString(R.string.device_battery)+
|
||||
mDeviceEntity.getPowerLevel() + "%" +
|
||||
" 更新时间: " + mDeviceEntity.getPowerLevelUpdatatime()))
|
||||
getString(R.string.update_time) + mDeviceEntity.getPowerLevelUpdatatime()))
|
||||
.show();
|
||||
break;
|
||||
|
||||
case R.id.tv_work_duartion:
|
||||
//此时处于工作中,不可点击
|
||||
if(mDeviceEntity.getWorkStatus().equals("1")){
|
||||
ToastUtil.showShort(mContext,"当前设备处于工作中,请先关闭浇水任务");
|
||||
ToastUtil.showShort(mContext,getString(R.string.tips_device_working_stop_task));
|
||||
return;
|
||||
}
|
||||
inputDuration(mCustomDuration);
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.Set;
|
||||
public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, DevicePresenter>
|
||||
implements DeviceContract.DeviceView {
|
||||
|
||||
private static final long BLE_CONNECT_TIMEOUT = 40 * 1000L;
|
||||
|
||||
private WifiListAdapter wifiListAdapter;
|
||||
//100 来自设备添加, 200 来自设备信息
|
||||
private int WITCH_FROM_CODE = 100;
|
||||
@@ -57,9 +59,23 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
private boolean isBleConnecting = false;
|
||||
private boolean isBleConnected = false;
|
||||
private boolean keepBleConnectionForProvision = false;
|
||||
private Handler bleConnectHandler = new Handler();
|
||||
private boolean isBleConnectTimedOut = false;
|
||||
private boolean isBleConnectTimeoutRunning = false;
|
||||
private Handler bleConnectHandler = new Handler(Looper.getMainLooper());
|
||||
private AnimationDrawable animationDrawable;
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
private final Runnable bleConnectTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connectBleDevice();
|
||||
}
|
||||
};
|
||||
private final Runnable bleConnectTimeoutTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleBleConnectTimeout();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public DevicePresenter createPresenter() {
|
||||
@@ -75,7 +91,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
bleConnectHandler.removeCallbacksAndMessages(null);
|
||||
cancelBleConnectTask();
|
||||
if (WITCH_FROM_CODE == 100 && espProvisionManager != null && !keepBleConnectionForProvision) {
|
||||
espProvisionManager.disconnect();
|
||||
espProvisionManager.setCallback(null);
|
||||
@@ -219,6 +235,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
bundle.putString("wifi_password", wifiPassword);
|
||||
bundle.putSerializable("ble_device_entity", mBleDeviceEntity);
|
||||
keepBleConnectionForProvision = true;
|
||||
cancelBleConnectTask();
|
||||
goTo(mContext, DeviceConnectActivity.class, bundle);
|
||||
finish();
|
||||
}
|
||||
@@ -231,6 +248,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
public void onConnecting() {
|
||||
isBleConnecting = true;
|
||||
isBleConnected = false;
|
||||
startBleConnectTimeout();
|
||||
Log.i("TEST","onConnecting");
|
||||
}
|
||||
|
||||
@@ -238,6 +256,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
public void onConnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = true;
|
||||
cancelBleConnectTask();
|
||||
Log.i("TEST","onConnected设备连接成功");
|
||||
stopConnectAnimation();
|
||||
ToastUtil.showShort(mContext, getString(R.string.device_connected_success));
|
||||
@@ -265,6 +284,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
|
||||
@Override
|
||||
public void onFailed(int errorCode, String message) {
|
||||
cancelBleConnectTask();
|
||||
isBleConnecting = false;
|
||||
if (errorCode != 0) {
|
||||
isBleConnected = espProvisionManager != null && espProvisionManager .isConnected();
|
||||
@@ -279,8 +299,12 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
public void onDisconnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = false;
|
||||
cancelBleConnectTask();
|
||||
stopConnectAnimation();
|
||||
Log.i("TEST","onDisconnected");
|
||||
if (isBleConnectTimedOut) {
|
||||
return;
|
||||
}
|
||||
ToastUtil.showShort(mContext, getString(R.string.device_disconnected));
|
||||
}
|
||||
|
||||
@@ -306,13 +330,9 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
*/
|
||||
private void scheduleBleConnect() {
|
||||
startConnectAnimation();
|
||||
bleConnectHandler.removeCallbacksAndMessages(null);
|
||||
bleConnectHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connectBleDevice();
|
||||
}
|
||||
}, 1000);
|
||||
startBleConnectTimeout();
|
||||
bleConnectHandler.removeCallbacks(bleConnectTask);
|
||||
bleConnectHandler.postDelayed(bleConnectTask, 1000);
|
||||
}
|
||||
|
||||
private void connectBleDevice() {
|
||||
@@ -326,6 +346,40 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
mBleDeviceEntity.getDeviceName());
|
||||
}
|
||||
|
||||
private void startBleConnectTimeout() {
|
||||
if (isBleConnected || keepBleConnectionForProvision) {
|
||||
return;
|
||||
}
|
||||
if (isBleConnectTimeoutRunning) {
|
||||
return;
|
||||
}
|
||||
isBleConnectTimedOut = false;
|
||||
isBleConnectTimeoutRunning = true;
|
||||
bleConnectHandler.removeCallbacks(bleConnectTimeoutTask);
|
||||
bleConnectHandler.postDelayed(bleConnectTimeoutTask, BLE_CONNECT_TIMEOUT);
|
||||
}
|
||||
|
||||
private void cancelBleConnectTask() {
|
||||
isBleConnectTimeoutRunning = false;
|
||||
bleConnectHandler.removeCallbacks(bleConnectTask);
|
||||
bleConnectHandler.removeCallbacks(bleConnectTimeoutTask);
|
||||
}
|
||||
|
||||
private void handleBleConnectTimeout() {
|
||||
if (WITCH_FROM_CODE != 100 || isBleConnected || keepBleConnectionForProvision) {
|
||||
return;
|
||||
}
|
||||
isBleConnectTimedOut = true;
|
||||
isBleConnecting = false;
|
||||
cancelBleConnectTask();
|
||||
if (espProvisionManager != null) {
|
||||
espProvisionManager.disconnect();
|
||||
}
|
||||
stopConnectAnimation();
|
||||
ToastUtil.showShort(mContext, getString(R.string.ble_connect_timeout));
|
||||
finish();
|
||||
}
|
||||
|
||||
private void scanWifi() {
|
||||
showLoadingDialog();
|
||||
viewBinding.tvNext.setVisibility(View.GONE);
|
||||
|
||||
@@ -46,8 +46,8 @@ public class DeviceAdapter extends BaseQuickAdapter<WaterDeviceEntity, BaseViewH
|
||||
}
|
||||
}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.setTextColor(R.id.tv_device_status,mContext.getResources().getColor(R.color.color_E60000));
|
||||
viewStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_status_dot_red));
|
||||
}
|
||||
|
||||
// if(item.getStatus().equals("1") || item.getStatus().equals("2")){
|
||||
|
||||
5
app/src/main/res/drawable/shape_status_dot_red.xml
Normal file
5
app/src/main/res/drawable/shape_status_dot_red.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/color_E60000" />
|
||||
</shape>
|
||||
@@ -24,7 +24,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="133"
|
||||
android:visibility="visible"/>
|
||||
android:visibility="gone"/>
|
||||
<Button
|
||||
android:id="@+id/btn_151"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
<string name="device_not_initialized">Device connection is not initialized</string>
|
||||
|
||||
<string name="device_connecting_please_wait">Device is connecting, please try again later</string>
|
||||
<string name="ble_connect_timeout">Bluetooth connection timed out, please try again</string>
|
||||
|
||||
<string name="device_not_connected_retry">Device is not connected, please try again</string>
|
||||
|
||||
@@ -304,6 +305,13 @@
|
||||
<string name="bluetooth_permission_required">Bluetooth permission is required to add a device.</string>
|
||||
<string name="bluetooth_enabled">Bluetooth is enabled.</string>
|
||||
<string name="enable_bluetooth_to_add_device">Please enable Bluetooth to add a device.</string>
|
||||
|
||||
|
||||
<string name="tips_device_working_stop_task">The device is currently in operation. Please stop the watering task first.</string>
|
||||
|
||||
<string name="device_battery">Battery:</string>
|
||||
|
||||
<string name="update_time">Last Updated:</string>
|
||||
<!-- End -->
|
||||
|
||||
|
||||
|
||||
@@ -242,6 +242,7 @@
|
||||
<string name="device_not_initialized">设备连接未初始化</string>
|
||||
|
||||
<string name="device_connecting_please_wait">设备连接中,请稍后再试</string>
|
||||
<string name="ble_connect_timeout">蓝牙连接超时,请重试</string>
|
||||
|
||||
<string name="device_not_connected_retry">设备未连接,请稍后重试</string>
|
||||
|
||||
@@ -297,6 +298,13 @@
|
||||
<string name="bluetooth_enabled">蓝牙已开启</string>
|
||||
<string name="enable_bluetooth_to_add_device">请开启蓝牙以添加设备</string>
|
||||
|
||||
|
||||
<string name="tips_device_working_stop_task">当前设备处于工作中,请先关闭浇水任务</string>
|
||||
|
||||
<string name="device_battery">设备电量:</string>
|
||||
|
||||
<string name="update_time">更新时间:</string>
|
||||
|
||||
<!--结束-->
|
||||
|
||||
|
||||
@@ -599,4 +607,4 @@
|
||||
书法艺术体现了中华文化的深厚底蕴,学习书法有助于增强文化自信和民族认同感。
|
||||
</string>
|
||||
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user