Added fundamentals of the Model View Controler Structure of the device handling
This commit is contained in:
parent
9f253b655c
commit
559a95b1c2
29
app/src/main/java/com/example/greenwatch/mvc/Device.java
Normal file
29
app/src/main/java/com/example/greenwatch/mvc/Device.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.example.greenwatch.mvc;
|
||||
|
||||
|
||||
public class Device {
|
||||
|
||||
private String sensor;
|
||||
private Boolean isActive;
|
||||
|
||||
public Device(String Sensor, Boolean Status) {
|
||||
this.sensor = Sensor;
|
||||
this.isActive = Status;
|
||||
}
|
||||
|
||||
public void setSensor(String Sensor) {
|
||||
this.sensor = Sensor;
|
||||
}
|
||||
|
||||
public String getSensor() {
|
||||
return sensor;
|
||||
}
|
||||
|
||||
public void setIsActive(Boolean Status) {
|
||||
this.isActive = Status;
|
||||
}
|
||||
|
||||
public Boolean getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.example.greenwatch.mvc;
|
||||
|
||||
public class DeviceController {
|
||||
|
||||
private DeviceModel deviceModel;
|
||||
private DeviceView deviceView;
|
||||
|
||||
public DeviceController(DeviceView view) {
|
||||
this.deviceModel = DeviceModel.getInstance();
|
||||
this.deviceView = view;
|
||||
}
|
||||
|
||||
public void createDevice(String Sensor, Boolean Status) {
|
||||
Device device = new Device(Sensor, Status);
|
||||
deviceModel.addDevice(device);
|
||||
// todo: Inform view and sender about changes
|
||||
}
|
||||
public void setDeviceSensor(String UUID, String Sensor) {
|
||||
deviceModel.setDeviceSensor(UUID, Sensor);
|
||||
}
|
||||
|
||||
public String getDeviceSensor(String UUID) {
|
||||
return deviceModel.getDeviceSensor(UUID);
|
||||
}
|
||||
|
||||
public void setDeviceStatus(String UUID, Boolean Status) {
|
||||
deviceModel.setDeviceStatus(UUID, Status);
|
||||
}
|
||||
|
||||
public Boolean getDeviceStatus(String UUID) {
|
||||
return deviceModel.getDeviceStatus(UUID);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.example.greenwatch.mvc;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class DeviceModel {
|
||||
private static DeviceModel itemModelInstance;
|
||||
// todo: should be a hashmap with UUID Keys
|
||||
private Vector<Device> connectetDevicesList;
|
||||
|
||||
private DeviceModel() {
|
||||
connectetDevicesList = new Vector<Device>();
|
||||
}
|
||||
|
||||
public static synchronized DeviceModel getInstance() {
|
||||
if (itemModelInstance == null){
|
||||
itemModelInstance = new DeviceModel();
|
||||
}
|
||||
return itemModelInstance;
|
||||
}
|
||||
|
||||
public void addDevice(Device device) {
|
||||
// todo: Check if divece already exist
|
||||
connectetDevicesList.add(device);
|
||||
}
|
||||
|
||||
public Vector<Device> getConnectetDevicesList() {
|
||||
return connectetDevicesList;
|
||||
}
|
||||
|
||||
public void setDeviceSensor(String UUID, String Sensor) {
|
||||
// todo: iterate through HashMap and find Divece for UUID
|
||||
}
|
||||
|
||||
public String getDeviceSensor(String UUID) {
|
||||
// todo: iterate through HashMap and find Divece for UUID
|
||||
return "hasToBeDone";
|
||||
}
|
||||
|
||||
public void setDeviceStatus(String UUID, Boolean Status) {
|
||||
// todo: iterate through HashMap and find Divece for UUID
|
||||
}
|
||||
|
||||
public Boolean getDeviceStatus(String UUID) {
|
||||
// todo: iterate through HashMap and find Divece for UUID
|
||||
return false;
|
||||
}
|
||||
}
|
10
app/src/main/java/com/example/greenwatch/mvc/DeviceView.java
Normal file
10
app/src/main/java/com/example/greenwatch/mvc/DeviceView.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.example.greenwatch.mvc;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class DeviceView {
|
||||
|
||||
public void updateView(Vector<Device> deviceVector) {
|
||||
// todo: what should be displayed
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user