Compare commits
No commits in common. "373ca2d1067bff2605a77d9d011ad5cbb51ab069" and "559a95b1c27b1baf4945b3f55aa0b077c755a3db" have entirely different histories.
373ca2d106
...
559a95b1c2
@ -1,101 +1,54 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private TextView tvstatusmessage;
|
|
||||||
private Button audiodetectionButton;
|
private Button audiodetectionButton;
|
||||||
private Button videodetectionButton;
|
private Button videodetectionButton;
|
||||||
private Button accelerometerButton;
|
private Button accelerometerButton;
|
||||||
private Button audiodetectionAndAccelerometerButton;
|
private Button audiodetectionAndAccelerometerButton;
|
||||||
private Button videodetectionAndAccelerometerButton;
|
private Button videodetectionAndAccelerometerButton;
|
||||||
private Button connectionButton;
|
private Button connectionButton;
|
||||||
private MainActivityViewModel mMainActivityViewModel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
tvstatusmessage = (TextView) findViewById(R.id.tvStatusmessage);
|
|
||||||
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
||||||
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
||||||
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
||||||
audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton);
|
audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton);
|
||||||
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
|
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
|
||||||
connectionButton = (Button) findViewById(R.id.connectionButton);
|
connectionButton = (Button) findViewById(R.id.connectionButton);
|
||||||
|
|
||||||
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
|
||||||
mMainActivityViewModel.init();
|
|
||||||
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(List<Device> devices) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("Time Stamp: ");
|
|
||||||
sb.append(mMainActivityViewModel.getTimeStamp(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("DeviceID: ");
|
|
||||||
sb.append(mMainActivityViewModel.getDeviceID(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Status: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorStatus(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Type: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorType(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Massage: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorMassage(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
tvstatusmessage.setText(sb);
|
|
||||||
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//openAudiodetectionActivity();
|
openAudiodetectionActivity();
|
||||||
mMainActivityViewModel.setDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", "12345", false, "Audio", 10);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//openVideodetectionActivity();
|
openVideodetectionActivity();
|
||||||
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "Video");
|
|
||||||
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "12:50");
|
|
||||||
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getLocalDeviceUUID());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//openAccelerometerActivity();
|
openAccelerometerActivity();
|
||||||
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "Accelerometer");
|
|
||||||
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "24:00");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
audiodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
audiodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//openAudiodetectionAndAccelerometerActivity();
|
openAudiodetectionAndAccelerometerActivity();
|
||||||
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "AudiodetectionAndAccelerometer");
|
|
||||||
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "00:00");
|
|
||||||
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), "6789");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
package com.example.greenwatch.models;
|
|
||||||
|
|
||||||
|
|
||||||
public class Device {
|
|
||||||
|
|
||||||
private String timeStamp;
|
|
||||||
private String deviceID;
|
|
||||||
private boolean sensorStatus;
|
|
||||||
private String sensorType;
|
|
||||||
private int sensorMassage;
|
|
||||||
|
|
||||||
public Device(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
|
||||||
this.timeStamp = timeStamp;
|
|
||||||
this.deviceID = deviceID;
|
|
||||||
this.sensorStatus = sensorStatus;
|
|
||||||
this.sensorType = sensorType;
|
|
||||||
this.sensorMassage = sensorMassage;
|
|
||||||
}
|
|
||||||
public void setTimeStamp(String timeStamp) {
|
|
||||||
this.timeStamp = timeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimeStamp() {
|
|
||||||
return timeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceID(String deviceID) {
|
|
||||||
this.deviceID = deviceID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceID() {
|
|
||||||
return deviceID;
|
|
||||||
}
|
|
||||||
public void setSensorType(String sensorType) {
|
|
||||||
this.sensorType = sensorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSensorType() {
|
|
||||||
return sensorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorStatus(boolean sensorStatus) {
|
|
||||||
this.sensorStatus = sensorStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getSensorStatus() {
|
|
||||||
return sensorStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorMassage(int sensorMassage) {
|
|
||||||
this.sensorMassage = sensorMassage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSensorMassage() {
|
|
||||||
return sensorMassage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,216 +0,0 @@
|
|||||||
package com.example.greenwatch.repositories;
|
|
||||||
|
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DeviceRepository {
|
|
||||||
|
|
||||||
private String delimiter = ", ";
|
|
||||||
private String deviceUUID;
|
|
||||||
private static DeviceRepository deviceRepositoryInstance;
|
|
||||||
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
|
||||||
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
|
||||||
private HashMap<String, String> deviceIDMapper = new HashMap<>();
|
|
||||||
|
|
||||||
public static synchronized DeviceRepository getInstance() {
|
|
||||||
if (deviceRepositoryInstance == null){
|
|
||||||
deviceRepositoryInstance = new DeviceRepository();
|
|
||||||
deviceRepositoryInstance.setDeviceUUID();
|
|
||||||
}
|
|
||||||
return deviceRepositoryInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MutableLiveData<List<Device>> getConnectedDeviceList() {
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
return deviceList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
|
||||||
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
|
||||||
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNewRemoteDevice(String message) {
|
|
||||||
String[] messageString = messageStringSplitter(message);
|
|
||||||
String timeStamp = messageString[0];
|
|
||||||
String deviceID = messageString[1];
|
|
||||||
boolean sensorStatus = Boolean.valueOf(messageString[1]);
|
|
||||||
String sensorType = messageString[3];
|
|
||||||
int sensorMassage = Integer.valueOf(messageString[4]);
|
|
||||||
|
|
||||||
if(!connectedDevicesList.containsKey(deviceID)) {
|
|
||||||
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String messageStringBuilder(String deviceID) {
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
Device device = connectedDevicesList.get(deviceID);
|
|
||||||
if(device != null) {
|
|
||||||
message.append(device.getTimeStamp())
|
|
||||||
.append(delimiter)
|
|
||||||
.append(device.getDeviceID())
|
|
||||||
.append(delimiter)
|
|
||||||
.append(device.getSensorStatus())
|
|
||||||
.append(delimiter)
|
|
||||||
.append(device.getSensorType())
|
|
||||||
.append(delimiter)
|
|
||||||
.append(device.getSensorMassage());
|
|
||||||
return message.toString();
|
|
||||||
}
|
|
||||||
return message.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalDeviceUUID() {
|
|
||||||
return deviceUUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevice(String deviceID, String timeStamp, String newDeviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setTimeStamp(timeStamp);
|
|
||||||
device.setDeviceID(newDeviceID);
|
|
||||||
device.setSensorStatus(sensorStatus);
|
|
||||||
device.setSensorType(sensorType);
|
|
||||||
device.setSensorMassage(sensorMassage);
|
|
||||||
setDeviceIDMapper(newDeviceID);
|
|
||||||
connectedDevicesList.remove(checkedDeviceID);
|
|
||||||
addToConnectedDeviceList(newDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeStamp(String deviceID, String timeStamp) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setTimeStamp(timeStamp);
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimeStamp(String deviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
return device.getTimeStamp();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceID(String deviceID, String newDeviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setDeviceID(newDeviceID);
|
|
||||||
setDeviceIDMapper(newDeviceID);
|
|
||||||
connectedDevicesList.remove(checkedDeviceID);
|
|
||||||
addToConnectedDeviceList(newDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceID(String deviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
return device.getDeviceID();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setSensorStatus(sensorStatus);
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getSensorStatus(String deviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
return device.getSensorStatus();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorType(String deviceID, String sensorType) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setSensorType(sensorType);
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSensorType(String deviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
return device.getSensorType();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorMassage(String deviceID, int sensorMessage) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
device.setSensorMassage(sensorMessage);
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
|
||||||
setMutableLiveDataValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSensorMassage(String deviceID) {
|
|
||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
|
||||||
if(device != null) {
|
|
||||||
return device.getSensorMassage();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMutableLiveDataValue() {
|
|
||||||
List<Device> list = new ArrayList<>(connectedDevicesList.values());
|
|
||||||
deviceList.setValue(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToConnectedDeviceList(String key, Device device) {
|
|
||||||
connectedDevicesList.put(key, device);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String checkDeviceID(String deviceID) {
|
|
||||||
if(!deviceIDMapper.isEmpty() && deviceID.equals(deviceUUID)) {
|
|
||||||
return deviceIDMapper.get(deviceID);
|
|
||||||
}
|
|
||||||
return deviceID;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDeviceIDMapper(String deviceID) {
|
|
||||||
deviceIDMapper.put(deviceUUID, deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDeviceUUID(){
|
|
||||||
this.deviceUUID = UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] messageStringSplitter(String message) {
|
|
||||||
return message.split(delimiter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.repositories.DeviceRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MainActivityViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
|
||||||
private MutableLiveData<Device> mLocalDevice;
|
|
||||||
private DeviceRepository mDeviceRepository;
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
if(mDeviceList != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
mDeviceRepository.createNewDevice("", mDeviceRepository.getLocalDeviceUUID(), false, "", 0);
|
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<List<Device>> getConnectedDeviceList() {
|
|
||||||
return mDeviceList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevice(String deviceID, String timeStamp, String newDeviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
|
||||||
mDeviceRepository.setDevice(deviceID, timeStamp,newDeviceID, sensorStatus, sensorType, sensorMassage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeStamp(String deviceID, String timeStamp) {
|
|
||||||
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimeStamp(String deviceID) {
|
|
||||||
return mDeviceRepository.getTimeStamp(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceID(String deviceID, String newDeviceID) {
|
|
||||||
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceID(String deviceID) {
|
|
||||||
return mDeviceRepository.getDeviceID(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
|
||||||
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getSensorStatus(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorStatus(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorType(String deviceID, String sensorType) {
|
|
||||||
mDeviceRepository.setSensorType(deviceID, sensorType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSensorType(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorType(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSensorMassage(String deviceID, int sensorMessage) {
|
|
||||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSensorMassage(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorMassage(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalDeviceUUID() {
|
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user