Browse Source

Added ViewModelInterface

DoNotMerge_Runnable_Test_Branch
Christian Tinz 1 year ago
parent
commit
317bef2b59

+ 16
- 1
app/src/main/java/com/example/greenwatch/viewmodels/AccelerometerViewModel.java View File

@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class AccelerometerViewModel extends ViewModel {
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {

private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
@@ -26,6 +26,7 @@ public class AccelerometerViewModel extends ViewModel {
float thresholdValue;
boolean startMeasuring;

@Override
public void init() {
if (mDeviceList == null) {
mDeviceRepository = DeviceRepository.getInstance();
@@ -89,58 +90,72 @@ public class AccelerometerViewModel extends ViewModel {
return mMovementDetected;
}

@Override
public LiveData<List<Device>> getConnectedDeviceList() {
return mDeviceList;
}

@Override
public LiveData<List<Device>> getAlarmHistoryList() {
return mAlarmHistoryList;
}

@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}

@Override
public void setTimeStamp(String deviceID, String timeStamp) {
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
}

@Override
public String getTimeStamp(String deviceID) {
return mDeviceRepository.getTimeStamp(deviceID);
}

@Override
public void setDeviceID(String deviceID, String newDeviceID) {
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
}

@Override
public String getDeviceID(String deviceID) {
return mDeviceRepository.getDeviceID(deviceID);
}

@Override
public void setSensorStatus(String deviceID, boolean sensorStatus) {
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
}

@Override
public boolean getSensorStatus(String deviceID) {
return mDeviceRepository.getSensorStatus(deviceID);
}

@Override
public void setSensorType(String deviceID, String sensorType) {
mDeviceRepository.setSensorType(deviceID, sensorType);
}

@Override
public String getSensorType(String deviceID) {
return mDeviceRepository.getSensorType(deviceID);
}

@Override
public void setSensorMassage(String deviceID, int sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
}

@Override
public int getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID);
}

@Override
public String getLocalDeviceUUID() {
return mDeviceRepository.getLocalDeviceUUID();
}

+ 16
- 2
app/src/main/java/com/example/greenwatch/viewmodels/MainActivityViewModel.java View File

@@ -10,13 +10,13 @@ import com.example.greenwatch.repositories.DeviceRepository;

import java.util.List;

public class MainActivityViewModel extends ViewModel {
public class MainActivityViewModel extends ViewModel implements ViewModelInterface {

private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<List<Device>> mAlarmHistoryList;
private DeviceRepository mDeviceRepository;

@Override
public void init() {
WiFiCommunication mWiFiCommunication;
if(mDeviceList != null) {
@@ -33,58 +33,72 @@ public class MainActivityViewModel extends ViewModel {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}

@Override
public LiveData<List<Device>> getConnectedDeviceList() {
return mDeviceList;
}

@Override
public LiveData<List<Device>> getAlarmHistoryList() {
return mAlarmHistoryList;
}

@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}

@Override
public void setTimeStamp(String deviceID, String timeStamp) {
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
}

@Override
public String getTimeStamp(String deviceID) {
return mDeviceRepository.getTimeStamp(deviceID);
}

@Override
public void setDeviceID(String deviceID, String newDeviceID) {
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
}

@Override
public String getDeviceID(String deviceID) {
return mDeviceRepository.getDeviceID(deviceID);
}

@Override
public void setSensorStatus(String deviceID, boolean sensorStatus) {
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
}

@Override
public boolean getSensorStatus(String deviceID) {
return mDeviceRepository.getSensorStatus(deviceID);
}

@Override
public void setSensorType(String deviceID, String sensorType) {
mDeviceRepository.setSensorType(deviceID, sensorType);
}

@Override
public String getSensorType(String deviceID) {
return mDeviceRepository.getSensorType(deviceID);
}

@Override
public void setSensorMassage(String deviceID, int sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
}

@Override
public int getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID);
}

@Override
public String getLocalDeviceUUID() {
return mDeviceRepository.getLocalDeviceUUID();
}

+ 25
- 0
app/src/main/java/com/example/greenwatch/viewmodels/ViewModelInterface.java View File

@@ -0,0 +1,25 @@
package com.example.greenwatch.viewmodels;

import androidx.lifecycle.LiveData;

import com.example.greenwatch.models.Device;

import java.util.List;

public interface ViewModelInterface {
void init();
LiveData<List<Device>> getConnectedDeviceList();
LiveData<List<Device>> getAlarmHistoryList();
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
void setTimeStamp(String deviceID, String timeStamp);
String getTimeStamp(String deviceID);
void setDeviceID(String deviceID, String newDeviceID);
String getDeviceID(String deviceID);
void setSensorStatus(String deviceID, boolean sensorStatus);
boolean getSensorStatus(String deviceID);
void setSensorType(String deviceID, String sensorType);
String getSensorType(String deviceID);
void setSensorMassage(String deviceID, int sensorMessage);
int getSensorMassage(String deviceID);
String getLocalDeviceUUID();
}

Loading…
Cancel
Save