|
|
@@ -1,9 +1,7 @@
|
|
|
package com.silence.commonframe.activity;
|
|
|
-
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Build;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
@@ -12,41 +10,24 @@ import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
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.scwang.smartrefresh.layout.SmartRefreshLayout;
|
|
|
-import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
|
|
-import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
|
|
|
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.AirGuardRunTimeListModel;
|
|
|
-import com.silence.commonframe.bean.BaseBean;
|
|
|
-import com.silence.commonframe.common.constant.UrlConstants;
|
|
|
-import com.silence.commonframe.utils.Data;
|
|
|
+import com.silence.commonframe.model.AirGuardRunTimeListModel;
|
|
|
import com.silence.commonframe.utils.LinearItemDecoration;
|
|
|
-import com.silence.commonframe.utils.LoginIn;
|
|
|
-
|
|
|
-import org.json.JSONException;
|
|
|
-import org.json.JSONObject;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
-import okhttp3.Call;
|
|
|
-import okhttp3.Response;
|
|
|
|
|
|
/**
|
|
|
* 空气卫士-工作时间段
|
|
|
* @author 郑嘉明
|
|
|
*/
|
|
|
-public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
+public class AirGuardWordTimeActivity extends BaseActivity implements AirGuardWordTimeListener.View {
|
|
|
|
|
|
/**
|
|
|
* 导航栏信息
|
|
|
@@ -60,17 +41,13 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
@BindView(R.id.worktime_recyclerview)
|
|
|
RecyclerView worktime_recyclerview; //时间列表
|
|
|
|
|
|
- @BindView(R.id.srl_refresh)
|
|
|
- SmartRefreshLayout srlRefresh;
|
|
|
-
|
|
|
AirGuardWorKTimeAdapter airGuardWorKTimeAdapter; //工作时间适配器
|
|
|
|
|
|
List<AirGuardRunTimeListModel.DataBean> listTime = new ArrayList<>();
|
|
|
|
|
|
- private String id;
|
|
|
private String deviceId = "";
|
|
|
|
|
|
- private List<AirGuardRunTimeListModel.DataBean> listRunTime=new ArrayList<>();
|
|
|
+ AirGuardWordTimePresenter presenter;
|
|
|
|
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
|
@@ -79,62 +56,24 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initPresenter() {
|
|
|
-
|
|
|
+ presenter = new AirGuardWordTimePresenter(this,this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
navi_head_text.setText(R.string.airguard_worktime); //设置标题
|
|
|
navi_head_text_right.setText(R.string.add); //设置右侧文字
|
|
|
- setTimeDate();
|
|
|
//设置全屏
|
|
|
initWindows();
|
|
|
- getRunTime();
|
|
|
+
|
|
|
+ deviceId = getIntent().getStringExtra("airDevId");
|
|
|
+
|
|
|
+ presenter.getData();
|
|
|
+
|
|
|
+ setTimeDate();
|
|
|
|
|
|
//导航栏添加按钮点击事件
|
|
|
addNewTimeListener();
|
|
|
- srlRefresh.setEnableLoadMore(false);
|
|
|
- srlRefresh.setOnRefreshListener(new OnRefreshListener() {
|
|
|
- @Override
|
|
|
- public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
- getRunTime();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void getRunTime() {
|
|
|
- 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.notifyDataSetChanged();
|
|
|
- }
|
|
|
- if (srlRefresh!=null){
|
|
|
- srlRefresh.finishLoadMore();
|
|
|
- srlRefresh.finishRefresh();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(Call call, Response response, Exception e) {
|
|
|
- super.onError(call, response, e);
|
|
|
- if (srlRefresh!=null){
|
|
|
- srlRefresh.finishLoadMore();
|
|
|
- srlRefresh.finishRefresh();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -148,13 +87,14 @@ 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);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取添加和修改的时间,添加修改时间的接口在这加
|
|
|
+ * 获取添加和修改的时间,添加修改时间的接口
|
|
|
* @param requestCode 222 333
|
|
|
* @param resultCode 222 333
|
|
|
* @param data worktime
|
|
|
@@ -162,24 +102,15 @@ 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -188,7 +119,7 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
*/
|
|
|
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);
|
|
|
@@ -203,9 +134,11 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
public void onDeleteClick(int position) {
|
|
|
//删除操作,删除的接口在这写
|
|
|
Toast.makeText(AirGuardWordTimeActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
|
|
|
- airGuardWorKTimeAdapter.deleteWorkTime(position); //适配器删除数据刷新
|
|
|
+
|
|
|
//这里加删除时间的接口方法。
|
|
|
- delRunTime(position);
|
|
|
+// delRunTime(position);
|
|
|
+ presenter.delRunTime(position);
|
|
|
+ airGuardWorKTimeAdapter.deleteWorkTime(position); //适配器删除数据刷新
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -223,9 +156,11 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
public void onSwitchListener(Boolean isCheck, int position) {
|
|
|
//开关
|
|
|
if (isCheck){
|
|
|
- openCloseRunTime(position);
|
|
|
+// Toast.makeText(AirGuardWordTimeActivity.this,"打开",Toast.LENGTH_SHORT).show();
|
|
|
+ presenter.openCloseRunTime(position);
|
|
|
}else {
|
|
|
- openCloseRunTime(position);
|
|
|
+// Toast.makeText(AirGuardWordTimeActivity.this,"关闭",Toast.LENGTH_SHORT).show();
|
|
|
+ presenter.openCloseRunTime(position);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -235,66 +170,6 @@ public class AirGuardWordTimeActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除运行时间间隔
|
|
|
- */
|
|
|
- private void delRunTime(int position) {
|
|
|
- OkGo.get(UrlConstants.AIRGUARD_DEL_RUNTIME)
|
|
|
- .tag(this)
|
|
|
- .params("id",listTime.get(position).getId())
|
|
|
- .cacheKey("cacheGetKey")
|
|
|
- .cacheMode(CacheMode.DEFAULT)
|
|
|
- .headers("token", Data.getToken())
|
|
|
- .execute(new StringCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(String s, Call call, Response response) {
|
|
|
- try {
|
|
|
- JSONObject jsonObject = new JSONObject(s);
|
|
|
- int code = jsonObject.getInt("code");
|
|
|
- String message = jsonObject.get("msg").toString();
|
|
|
- if (code == 0){
|
|
|
- Toast.makeText(AirGuardWordTimeActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
|
|
|
- }else {
|
|
|
- LoginIn.tokenOut(code+"",AirGuardWordTimeActivity.this);
|
|
|
- Toast.makeText(AirGuardWordTimeActivity.this,""+message,Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 打开或关闭运行时间间隔
|
|
|
- */
|
|
|
- private void openCloseRunTime(int position) {
|
|
|
- OkGo.get(UrlConstants.AIRGUARD_OPEN_CLOSE_RUNTIME)
|
|
|
- .tag(this)
|
|
|
- .params("id",listTime.get(position).getId()) //
|
|
|
- .cacheKey("cacheGetKey")
|
|
|
- .cacheMode(CacheMode.DEFAULT)
|
|
|
- .headers("token", Data.getToken())
|
|
|
- .execute(new StringCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(String s, Call call, Response response) {
|
|
|
- try {
|
|
|
- JSONObject jsonObject = new JSONObject(s);
|
|
|
- int code = jsonObject.getInt("code");
|
|
|
- String message = jsonObject.get("msg").toString();
|
|
|
- if (code == 0){
|
|
|
- Toast.makeText(AirGuardWordTimeActivity.this,""+message,Toast.LENGTH_SHORT).show();
|
|
|
- }else {
|
|
|
- LoginIn.tokenOut(code+"",AirGuardWordTimeActivity.this);
|
|
|
- Toast.makeText(AirGuardWordTimeActivity.this,""+message,Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 页面全屏
|
|
|
*/
|
|
|
private void initWindows() {
|
|
|
@@ -317,4 +192,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();
|
|
|
+ }
|
|
|
}
|