|
|
@@ -13,14 +13,15 @@ import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.google.gson.reflect.TypeToken;
|
|
|
import com.lzy.okgo.OkGo;
|
|
|
import com.lzy.okgo.cache.CacheMode;
|
|
|
import com.lzy.okgo.callback.StringCallback;
|
|
|
import com.silence.commonframe.R;
|
|
|
+import com.silence.commonframe.activity.Interface.AirGuardWordTimeListener;
|
|
|
+import com.silence.commonframe.activity.presenter.AirGuardWordTimePresenter;
|
|
|
import com.silence.commonframe.adapter.AirGuardWorKTimeAdapter;
|
|
|
import com.silence.commonframe.base.basemvp.BaseActivity;
|
|
|
-import com.silence.commonframe.bean.BaseBean;
|
|
|
+import com.silence.commonframe.bean.AirGuardWordTimeBean;
|
|
|
import com.silence.commonframe.common.constant.UrlConstants;
|
|
|
import com.silence.commonframe.model.AirGuardRunTimeListModel;
|
|
|
import com.silence.commonframe.utils.Data;
|
|
|
@@ -31,7 +32,6 @@ import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
@@ -42,7 +42,7 @@ import okhttp3.Response;
|
|
|
* 空气卫士-工作时间段
|
|
|
* @author 郑嘉明
|
|
|
*/
|
|
|
-public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
+public class AirGuardWordTimeActivity extends BaseActivity implements AirGuardWordTimeListener.View {
|
|
|
|
|
|
/**
|
|
|
* 导航栏信息
|
|
|
@@ -58,10 +58,11 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
|
|
|
AirGuardWorKTimeAdapter airGuardWorKTimeAdapter; //工作时间适配器
|
|
|
|
|
|
- List<AirGuardRunTimeListModel> listTime = new ArrayList<>();
|
|
|
+ List<AirGuardRunTimeListModel.DataBean> listTime = new ArrayList<>();
|
|
|
|
|
|
- private String id;
|
|
|
- private String deviceId = "000";
|
|
|
+ private String deviceId = "";
|
|
|
+
|
|
|
+ AirGuardWordTimePresenter presenter;
|
|
|
|
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
|
@@ -70,7 +71,7 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initPresenter() {
|
|
|
-
|
|
|
+ presenter = new AirGuardWordTimePresenter(this,this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -80,23 +81,11 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
//设置全屏
|
|
|
initWindows();
|
|
|
|
|
|
- /**
|
|
|
- * 这里获取接口数据给listTime
|
|
|
- */
|
|
|
-// //测试数据
|
|
|
-// HashMap<String, String> hashMap = new HashMap<>();
|
|
|
-// hashMap.put("time","00:18-18:30");
|
|
|
-// hashMap.put("switch","0");
|
|
|
-// listTime.add(hashMap);
|
|
|
-// HashMap<String, String> hashMap2 = new HashMap<>();
|
|
|
-// hashMap2.put("time","12:22-22:21");
|
|
|
-// hashMap2.put("switch_state","1");
|
|
|
-// listTime.add(hashMap2);
|
|
|
-// //测试数据
|
|
|
-
|
|
|
- getRunTime();
|
|
|
+ deviceId = getIntent().getStringExtra("airDevId");
|
|
|
|
|
|
+ presenter.getData();
|
|
|
|
|
|
+ setTimeDate();
|
|
|
|
|
|
//导航栏添加按钮点击事件
|
|
|
addNewTimeListener();
|
|
|
@@ -116,7 +105,65 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
System.out.println(data.getData());
|
|
|
if (data.getCode() == 0){
|
|
|
//设置工作时间数据
|
|
|
- setTimeDate(data.getData());
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(data.getData());
|
|
|
+ airGuardWorKTimeAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Response response, Exception e) {
|
|
|
+ super.onError(call, response, e);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRunTime() {
|
|
|
+ OkGo.get(UrlConstants.AIRGUARD_RUNTIMELIST)
|
|
|
+ .tag(this)
|
|
|
+ .params("deviceId",deviceId)
|
|
|
+ .cacheKey("cacheGetKey")
|
|
|
+ .cacheMode(CacheMode.DEFAULT)
|
|
|
+ .headers("token", Data.getToken())
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String s, Call call, Response response) {
|
|
|
+ AirGuardRunTimeListModel data = new Gson().fromJson(s,AirGuardRunTimeListModel.class);
|
|
|
+ System.out.println(data.getData());
|
|
|
+ if (data.getCode() == 0){
|
|
|
+ //设置工作时间数据
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(data.getData());
|
|
|
+ airGuardWorKTimeAdapter.addWorkTime(listTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Response response, Exception e) {
|
|
|
+ super.onError(call, response, e);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRunTime(int pos) {
|
|
|
+ OkGo.get(UrlConstants.AIRGUARD_RUNTIMELIST)
|
|
|
+ .tag(this)
|
|
|
+ .params("deviceId",deviceId)
|
|
|
+ .cacheKey("cacheGetKey")
|
|
|
+ .cacheMode(CacheMode.DEFAULT)
|
|
|
+ .headers("token", Data.getToken())
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String s, Call call, Response response) {
|
|
|
+ AirGuardRunTimeListModel data = new Gson().fromJson(s,AirGuardRunTimeListModel.class);
|
|
|
+ System.out.println(data.getData());
|
|
|
+ if (data.getCode() == 0){
|
|
|
+ //设置工作时间数据
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(data.getData());
|
|
|
+ airGuardWorKTimeAdapter.updateWorkTime(listTime.get(pos),pos);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -139,6 +186,7 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
Intent intent = new Intent(AirGuardWordTimeActivity.this,AirGuardNewTimeActivity.class);
|
|
|
intent.putExtra("wind_speed",0);
|
|
|
intent.putExtra("type","add");
|
|
|
+ intent.putExtra("deviceId",deviceId);
|
|
|
startActivityForResult(intent,222);
|
|
|
}
|
|
|
});
|
|
|
@@ -153,33 +201,24 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
- if (requestCode == 222 && resultCode == 222){
|
|
|
- assert data != null;
|
|
|
- //获取运行时间段
|
|
|
- getRunTime();
|
|
|
-
|
|
|
- }else if (requestCode == 333 && resultCode == 333){
|
|
|
- assert data != null;
|
|
|
-// String newtime = data.getStringExtra("worktime");
|
|
|
-// int pos = data.getIntExtra("position",-1);
|
|
|
-// int wind_speed = data.getIntExtra("wind_speed",0);
|
|
|
-// HashMap<String,String> hashMap = new HashMap<>();
|
|
|
-// hashMap.put("time",newtime);
|
|
|
-// hashMap.put("wind_speed",String.valueOf(wind_speed));
|
|
|
-// hashMap.put("switch_state","0"); //开关状态,0是关,1是开。有接口后要传值
|
|
|
-// airGuardWorKTimeAdapter.updateWorkTime(hashMap,pos); //适配器修改数据刷新
|
|
|
-
|
|
|
- //这里加修改时间的接口方法。
|
|
|
- getRunTime();
|
|
|
+ if (data!=null){
|
|
|
+ if (requestCode == 222 && resultCode == 222){
|
|
|
+ //获取运行时间段
|
|
|
+ presenter.updateRunTime();
|
|
|
+ }else if (requestCode == 333 && resultCode == 333){
|
|
|
+ int pos = data.getIntExtra("position",-1);
|
|
|
+ //这里加修改时间的接口方法。
|
|
|
+ presenter.updateRunTime(pos);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置工作时间数据
|
|
|
*/
|
|
|
- private void setTimeDate(List<AirGuardRunTimeListModel.DataBean> listRunTime) {
|
|
|
+ private void setTimeDate() {
|
|
|
|
|
|
- airGuardWorKTimeAdapter = new AirGuardWorKTimeAdapter(AirGuardWordTimeActivity.this,listRunTime);
|
|
|
+ airGuardWorKTimeAdapter = new AirGuardWorKTimeAdapter(AirGuardWordTimeActivity.this,listTime);
|
|
|
worktime_recyclerview.setLayoutManager(new LinearLayoutManager(AirGuardWordTimeActivity.this));
|
|
|
worktime_recyclerview.addItemDecoration(new LinearItemDecoration(AirGuardWordTimeActivity.this,LinearLayoutManager.HORIZONTAL,R.drawable.decoration_item)); //设置分割线
|
|
|
worktime_recyclerview.setAdapter(airGuardWorKTimeAdapter);
|
|
|
@@ -194,9 +233,11 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
public void onDeleteClick(int position) {
|
|
|
//删除操作,删除的接口在这写
|
|
|
Toast.makeText(AirGuardWordTimeActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
|
|
|
- airGuardWorKTimeAdapter.deleteWorkTime(position); //适配器删除数据刷新
|
|
|
+
|
|
|
//这里加删除时间的接口方法。
|
|
|
- delRunTime();
|
|
|
+// delRunTime(position);
|
|
|
+ presenter.delRunTime(position);
|
|
|
+ airGuardWorKTimeAdapter.deleteWorkTime(position); //适配器删除数据刷新
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -206,7 +247,7 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
intent.putExtra("wind_speed",wind);
|
|
|
intent.putExtra("type","update");
|
|
|
intent.putExtra("position",position);
|
|
|
- intent.putExtra("id","");
|
|
|
+ intent.putExtra("id",listTime.get(position).getId());
|
|
|
startActivityForResult(intent,333);
|
|
|
}
|
|
|
|
|
|
@@ -215,10 +256,10 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
//开关
|
|
|
if (isCheck){
|
|
|
// Toast.makeText(AirGuardWordTimeActivity.this,"打开",Toast.LENGTH_SHORT).show();
|
|
|
- openCloseRunTime();
|
|
|
+ presenter.openCloseRunTime(position);
|
|
|
}else {
|
|
|
// Toast.makeText(AirGuardWordTimeActivity.this,"关闭",Toast.LENGTH_SHORT).show();
|
|
|
- openCloseRunTime();
|
|
|
+ presenter.openCloseRunTime(position);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -230,10 +271,10 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
/**
|
|
|
* 删除运行时间间隔
|
|
|
*/
|
|
|
- private void delRunTime() {
|
|
|
+ private void delRunTime(int position) {
|
|
|
OkGo.get(UrlConstants.AIRGUARD_DEL_RUNTIME)
|
|
|
.tag(this)
|
|
|
- .params("id",id)
|
|
|
+ .params("id",listTime.get(position).getId())
|
|
|
.cacheKey("cacheGetKey")
|
|
|
.cacheMode(CacheMode.DEFAULT)
|
|
|
.headers("token", Data.getToken())
|
|
|
@@ -260,10 +301,10 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
/**
|
|
|
* 打开或关闭运行时间间隔
|
|
|
*/
|
|
|
- private void openCloseRunTime() {
|
|
|
+ private void openCloseRunTime(int position) {
|
|
|
OkGo.get(UrlConstants.AIRGUARD_OPEN_CLOSE_RUNTIME)
|
|
|
.tag(this)
|
|
|
- .params("id",id) //
|
|
|
+ .params("id",listTime.get(position).getId()) //
|
|
|
.cacheKey("cacheGetKey")
|
|
|
.cacheMode(CacheMode.DEFAULT)
|
|
|
.headers("token", Data.getToken())
|
|
|
@@ -275,7 +316,7 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
int code = jsonObject.getInt("code");
|
|
|
String message = jsonObject.get("msg").toString();
|
|
|
if (code == 0){
|
|
|
- Toast.makeText(AirGuardWordTimeActivity.this,"0",Toast.LENGTH_SHORT).show();
|
|
|
+ Toast.makeText(AirGuardWordTimeActivity.this,""+message,Toast.LENGTH_SHORT).show();
|
|
|
}else {
|
|
|
LoginIn.tokenOut(code,AirGuardWordTimeActivity.this);
|
|
|
Toast.makeText(AirGuardWordTimeActivity.this,""+message,Toast.LENGTH_SHORT).show();
|
|
|
@@ -310,4 +351,42 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
finish();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getDevId() {
|
|
|
+ return deviceId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AirGuardRunTimeListModel.DataBean> getListTime() {
|
|
|
+ return listTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(List<AirGuardRunTimeListModel.DataBean> bean) {
|
|
|
+ //设置工作时间数据
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(bean);
|
|
|
+ airGuardWorKTimeAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUpdateSuccess(int position, AirGuardRunTimeListModel data) {
|
|
|
+ //设置工作时间数据
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(data.getData());
|
|
|
+ airGuardWorKTimeAdapter.updateWorkTime(listTime.get(position),position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUpdateSuccess(AirGuardRunTimeListModel data) {
|
|
|
+ //设置工作时间数据
|
|
|
+ listTime.clear();
|
|
|
+ listTime.addAll(data.getData());
|
|
|
+ airGuardWorKTimeAdapter.addWorkTime(listTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFile(String msg) {
|
|
|
+ Toast.makeText(this,""+msg,Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
}
|